Add -c argument, don't init config if -c ''

This commit is contained in:
Florian Bruhin 2014-01-22 17:04:10 +01:00
parent 47c3866f51
commit 97588db71b
2 changed files with 18 additions and 3 deletions

View File

@ -29,7 +29,13 @@ class QuteBrowser(QApplication):
self.initlog()
self.dirs = AppDirs('qutebrowser')
self.config = Config(self.dirs.user_data_dir)
if self.args.confdir is None:
confdir = self.dirs.user_data_dir
elif self.args.confdir == '':
confdir = None
else:
confdir = self.args.confdir
self.config = Config(confdir)
self.mainwindow = MainWindow()
self.commandparser = cmdutils.CommandParser()
@ -77,6 +83,8 @@ class QuteBrowser(QApplication):
parser = ArgumentParser("usage: %(prog)s [options]")
parser.add_argument('-l', '--log', dest='loglevel',
help='Set loglevel', default='info')
parser.add_argument('-c', '--confdir', help='Set config directory '
'(empty for no config storage)')
self.args = parser.parse_args()
def initlog(self):

View File

@ -34,6 +34,9 @@ class Config(ConfigParser):
super().__init__()
self.optionxform = lambda opt: opt # be case-insensitive
self.configdir = configdir
if self.configdir is None:
self.init_config()
return
self.configfile = os.path.join(self.configdir, self.FNAME)
if not os.path.isfile(self.configfile):
self.init_config()
@ -42,15 +45,19 @@ class Config(ConfigParser):
def init_config(self):
logging.info("Initializing default config.")
if not os.path.exists(self.configdir):
os.makedirs(self.configdir, 0o755)
cp = ConfigParser()
cp.optionxform = lambda opt: opt # be case-insensitive
cp.read_dict(default_config)
if self.configdir is None:
return
if not os.path.exists(self.configdir):
os.makedirs(self.configdir, 0o755)
with open(self.configfile, 'w') as f:
cp.write(f)
def save(self):
if self.configdir is None:
return
if not os.path.exists(self.configdir):
os.makedirs(self.configdir, 0o755)
logging.debug("Saving config to {}".format(self.configfile))