36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
import os
|
|
import ConfigParser
|
|
|
|
class _Configuration(object):
|
|
def __init__(self):
|
|
self.filename = os.path.join(os.path.join(os.getenv("HOME"), ".4grab"), "config.cfg")
|
|
self.configparser = ConfigParser.RawConfigParser()
|
|
if not os.path.exists(self.filename):
|
|
self.create_new()
|
|
else:
|
|
self.configparser.read(self.filename)
|
|
|
|
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.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)
|
|
|
|
def raw_input_with_default(self, default, prompt):
|
|
inp = raw_input("%s (default=%s): " % (prompt, default))
|
|
if inp == "":
|
|
return default
|
|
return inp
|
|
|
|
def get_download_location(self):
|
|
return self.configparser.get("locations", "download")
|
|
|
|
def get_category(self):
|
|
return self.configparser.get("settings", "category")
|
|
|
|
_configuration = _Configuration()
|
|
def Configuration(): return _configuration
|