diff options
author | ryuslash | 2010-02-09 01:32:42 +0100 |
---|---|---|
committer | ryuslash | 2010-02-09 01:32:42 +0100 |
commit | 32c4471273097523d64ad0f7704861f211e78f72 (patch) | |
tree | f2fc37c1f38373d3c35e3267b2489eac23fe7edf /config.py | |
parent | 53c7802ae2ef25ebed4e130813ce95e2816c919b (diff) | |
download | 4grab-32c4471273097523d64ad0f7704861f211e78f72.tar.gz 4grab-32c4471273097523d64ad0f7704861f211e78f72.zip |
working on the command-line arguments here
Diffstat (limited to 'config.py')
-rw-r--r-- | config.py | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -12,18 +12,12 @@ class _Configuration(object): def create_new(self): self.configparser.add_section("settings") - self.configparser.set("settings", "category", self.raw_input_with_default("w", "Please enter which category you would like to download from: ")) + self.set_category(self.raw_input_with_default("w", "Please enter which category you would like to download from: ")) self.configparser.add_section("locations") self.configparser.set("locations", "download", self.raw_input_with_default(os.path.join(os.getenv("HOME"), "Pictures"), "Please enter where you would like the downloads to go: ")) - #with open(self.filename) as configfile: - # self.configparser.write(configfile) - dirname = os.path.dirname(self.filename) - if not os.path.exists(dirname): - os.mkdir(dirname) - configfile = open(self.filename, "w") - self.configparser.write(configfile) + self.save() def raw_input_with_default(self, default, prompt): inp = raw_input("%s (default=%s): " % (prompt, default)) @@ -37,5 +31,21 @@ class _Configuration(object): def get_category(self): return self.configparser.get("settings", "category") + def set_category(self, value): + self.configparser.set("settings", "category", value) + + def option_exists(self, option): + for section in self.configparser.sections(): + if self.configparser.has_option(section, option): + return True + return False + + def save(self): + dirname = os.path.dirname(self.filename) + if not os.path.exists(dirname): + os.mkdir(dirname) + configfile = open(self.filename, "w") + self.configparser.write(configfile) + _configuration = _Configuration() def Configuration(): return _configuration |