Skip to content

Commit

Permalink
Load/save fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
midenok committed Oct 27, 2013
1 parent 072a40f commit d3dd8c1
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions usbcreator/backends/base/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,41 @@ class Config:
def __init__(self, backend):
self.file = os.path.expanduser('~/.usb-creator.ini')
self.folder = os.path.expanduser('~')
self.section = 'images'
self.parser = configparser.SafeConfigParser()
self.backend = backend

def load(self):
p = self.parser
p.read(self.file)
try:
folder = p.get('DEFAULT', 'folder')
folder = p.get('global', 'folder')
self.folder = folder
except:
python_govno = 'Yes!'
if p.has_section(self.section):
for f in p.items(self.section):
source = 1
s = 'images'
if p.has_section(s):
for f in p.items(s):
self.backend.add_image(f[1])
if source:
self.backend.set_current_source(f[1])
source = 0

def save(self):
p = self.parser
p.set('DEFAULT', 'folder', self.folder)
s = self.section
s = 'global'
if p.has_section(s):
p.remove_section(s)
p.add_section(s)
p.set(s, 'folder', self.folder)
s = 'images'
if p.has_section(s):
p.remove_section(s)
p.add_section(s)
n = 0
for image_file in self.backend.sources.keys():
p.set(s, str(n), image_file)
n = n + 1
with open(self.file, 'w') as configfile:
p.write(configfile)

Expand Down

0 comments on commit d3dd8c1

Please sign in to comment.