summaryrefslogtreecommitdiffstats
path: root/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'config.py')
-rw-r--r--config.py65
1 files changed, 52 insertions, 13 deletions
diff --git a/config.py b/config.py
index 2f15933..66f3297 100644
--- a/config.py
+++ b/config.py
@@ -21,21 +21,19 @@ import os
import ConfigParser
import sys
+# Get our reference point. preferably $HOME.
homedir = os.getenv("HOME")
if homedir is None:
homedir = os.path.dirname(sys.argv[0])
class _Configuration(object):
- def __init__(self):
+ def __init__(self, optioncreator):
self.filename = os.path.join(os.path.join(homedir, ".4grab"), "config.cfg")
self.configparser = ConfigParser.RawConfigParser()
-
- self.check()
+ self.optioncreator = optioncreator
self.configparser.read(self.filename)
-
- def set_optioncreator(self, optioncreator):
- self.optioncreator = optioncreator
+ print "__init__"
def check(self):
changed = False
@@ -55,6 +53,17 @@ class _Configuration(object):
"you would like the "
"downloads to go: ")
changed = True
+ # locations/archive
+ if not self.configparser.has_option("locations", "archive"):
+ self.create_option("locations",
+ "archive",
+ os.path.join(self.configparser.get("locations",
+ "download_base"),
+ ".arch"),
+ "Please enter where in {download_base} you "
+ "would like to store archived images (used for "
+ "checking what to download): ")
+ changed = True
# settings
if not self.configparser.has_section("settings"):
self.configparser.add_section("settings")
@@ -67,7 +76,15 @@ class _Configuration(object):
"category you would like "
"to download from: ")
changed = True
-
+ # settings/resolutions
+ if not self.configparser.has_option("settings", "resolutions"):
+ self.create_option("settings",
+ "resolutions",
+ "1600x1050,1900x1200,1900x1080",
+ "Please enter your preferred "
+ "resolutions (* for all)")
+ changed = True
+ # save
if changed:
self.save()
@@ -79,12 +96,23 @@ class _Configuration(object):
def get_download_location(self):
return self.configparser.get("locations", "download_base")
+ def set_download_location(self, value):
+ self.configparser.set("locations", "download_base", value)
- def get_category(self):
- return self.configparser.get("settings", "categories")
+ def get_archive_location(self):
+ return self.configparser.get("locations", "archive")
+ def set_archive_location(self, value):
+ self.configparser.set("locations", "archive", value)
- def set_category(self, value):
- self.configparser.set("settings", "category", value)
+ def get_categories(self):
+ return self.configparser.get("settings", "categories").split(',')
+ def set_categories(self, value = []):
+ self.configparser.set("settings", "category", ','.join(value))
+
+ def get_resolutions(self):
+ return self.configparser.get("settings", "resolutions").split(',')
+ def set_resolutions(self, value = []):
+ self.configparser.set("settings", "resolutions", ','.join(value))
def option_exists(self, option):
sections = self.configparser.sections()
@@ -93,6 +121,7 @@ class _Configuration(object):
return True
return False
+ # Should only be used by the command-line
def set_option(self, option, value):
sec = None
sections = self.configparser.sections()
@@ -113,5 +142,15 @@ class _Configuration(object):
configfile = open(self.filename, "w")
self.configparser.write(configfile)
-_configuration = _Configuration()
-def Configuration(): return _configuration
+_configuration = None
+_optioncreator = None
+def Configuration():
+ global _optioncreator
+ global _configuration
+
+ if _optioncreator is None:
+ raise ValueError("optioncreator must be set")
+ if _configuration is None:
+ _configuration = _Configuration(_optioncreator)
+ _configuration.check()
+ return _configuration