Add -c argument, don't init config if -c ''
This commit is contained in:
parent
47c3866f51
commit
97588db71b
@ -29,7 +29,13 @@ class QuteBrowser(QApplication):
|
|||||||
self.initlog()
|
self.initlog()
|
||||||
|
|
||||||
self.dirs = AppDirs('qutebrowser')
|
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.mainwindow = MainWindow()
|
||||||
self.commandparser = cmdutils.CommandParser()
|
self.commandparser = cmdutils.CommandParser()
|
||||||
@ -77,6 +83,8 @@ class QuteBrowser(QApplication):
|
|||||||
parser = ArgumentParser("usage: %(prog)s [options]")
|
parser = ArgumentParser("usage: %(prog)s [options]")
|
||||||
parser.add_argument('-l', '--log', dest='loglevel',
|
parser.add_argument('-l', '--log', dest='loglevel',
|
||||||
help='Set loglevel', default='info')
|
help='Set loglevel', default='info')
|
||||||
|
parser.add_argument('-c', '--confdir', help='Set config directory '
|
||||||
|
'(empty for no config storage)')
|
||||||
self.args = parser.parse_args()
|
self.args = parser.parse_args()
|
||||||
|
|
||||||
def initlog(self):
|
def initlog(self):
|
||||||
|
@ -34,6 +34,9 @@ class Config(ConfigParser):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.optionxform = lambda opt: opt # be case-insensitive
|
self.optionxform = lambda opt: opt # be case-insensitive
|
||||||
self.configdir = configdir
|
self.configdir = configdir
|
||||||
|
if self.configdir is None:
|
||||||
|
self.init_config()
|
||||||
|
return
|
||||||
self.configfile = os.path.join(self.configdir, self.FNAME)
|
self.configfile = os.path.join(self.configdir, self.FNAME)
|
||||||
if not os.path.isfile(self.configfile):
|
if not os.path.isfile(self.configfile):
|
||||||
self.init_config()
|
self.init_config()
|
||||||
@ -42,15 +45,19 @@ class Config(ConfigParser):
|
|||||||
|
|
||||||
def init_config(self):
|
def init_config(self):
|
||||||
logging.info("Initializing default config.")
|
logging.info("Initializing default config.")
|
||||||
if not os.path.exists(self.configdir):
|
|
||||||
os.makedirs(self.configdir, 0o755)
|
|
||||||
cp = ConfigParser()
|
cp = ConfigParser()
|
||||||
cp.optionxform = lambda opt: opt # be case-insensitive
|
cp.optionxform = lambda opt: opt # be case-insensitive
|
||||||
cp.read_dict(default_config)
|
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:
|
with open(self.configfile, 'w') as f:
|
||||||
cp.write(f)
|
cp.write(f)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
if self.configdir is None:
|
||||||
|
return
|
||||||
if not os.path.exists(self.configdir):
|
if not os.path.exists(self.configdir):
|
||||||
os.makedirs(self.configdir, 0o755)
|
os.makedirs(self.configdir, 0o755)
|
||||||
logging.debug("Saving config to {}".format(self.configfile))
|
logging.debug("Saving config to {}".format(self.configfile))
|
||||||
|
Loading…
Reference in New Issue
Block a user