File: config.py

package info (click to toggle)
gr-dab 0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,272 kB
  • sloc: python: 14,976; cpp: 6,738; ansic: 547; makefile: 19; sh: 11
file content (34 lines) | stat: -rw-r--r-- 666 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python


import yaml
import os

class Configuration():

  def __init__(self, folder):
    self.folder = folder
    self.adjust_file_name = "".join([self.folder,"/adjustment.yaml"])
    self.adjust_config = {}
    self.read()


  def read(self):

    try:
      with open(self.adjust_file_name, 'r') as ymlfile:
        self.adjust_config = yaml.safe_load(ymlfile)
    except IOError:
      pass
      

  def save(self):
    try:
      os.makedirs(self.folder)
    except OSError:
      pass # If already exists

    with open(self.adjust_file_name, 'w') as ymlfile:
      yamlcontent = yaml.dump(self.adjust_config)
      ymlfile.write(yamlcontent)