Compare commits
4 Commits
16020e8fbb
...
e82fd99a16
Author | SHA1 | Date | |
---|---|---|---|
e82fd99a16 | |||
4790429f24 | |||
57b3600d47 | |||
e46c8249de |
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ build/
|
|||||||
.idea/
|
.idea/
|
||||||
.venv
|
.venv
|
||||||
userconfig.egg-info/
|
userconfig.egg-info/
|
||||||
|
*.swp
|
||||||
|
@ -19,6 +19,7 @@ def main():
|
|||||||
cmdline = parser.parse_args()
|
cmdline = parser.parse_args()
|
||||||
cfg = Conf(cmdline.file)
|
cfg = Conf(cmdline.file)
|
||||||
debug = Debug()
|
debug = Debug()
|
||||||
|
debug.set_verbose(cmdline.verbose)
|
||||||
cfg.set_debug(debug)
|
cfg.set_debug(debug)
|
||||||
uc = Userconfig(cfg)
|
uc = Userconfig(cfg)
|
||||||
|
|
||||||
|
@ -7,13 +7,14 @@ class Conf(object):
|
|||||||
_cfgfiles = []
|
_cfgfiles = []
|
||||||
debug = None
|
debug = None
|
||||||
|
|
||||||
def __init__(self, filename=None, debug=None):
|
def __init__(self, filename=None, debug=None, force_filename=False):
|
||||||
if debug:
|
if debug:
|
||||||
self.set_debug(debug)
|
self.set_debug(debug)
|
||||||
filenames = []
|
filenames = []
|
||||||
if filename:
|
if filename:
|
||||||
filenames.append(filename)
|
filenames.append(filename)
|
||||||
filenames.append(f'{os.environ.get("HOME")}/etc/userconfig2.conf')
|
if not force_filename:
|
||||||
|
filenames.append(f'{os.environ.get("HOME")}/etc/userconfig2.conf')
|
||||||
ret = self.set_filenames(filenames)
|
ret = self.set_filenames(filenames)
|
||||||
if not ret:
|
if not ret:
|
||||||
raise ValueError(f'Cannot open either configuration file: {",".join(filenames)}')
|
raise ValueError(f'Cannot open either configuration file: {",".join(filenames)}')
|
||||||
|
@ -38,12 +38,12 @@ def get_config(filename, cfg):
|
|||||||
cfg.debug.stderr("Error reading config file %s" % filename)
|
cfg.debug.stderr("Error reading config file %s" % filename)
|
||||||
return False
|
return False
|
||||||
# check for DEST parameter
|
# check for DEST parameter
|
||||||
if not ret.check("Main", "dest"):
|
if not ret.check(section="Main", option="dest"):
|
||||||
cfg.debug.stderr("No dest in config file %s" % filename)
|
cfg.debug.stderr("No dest in config file %s" % filename)
|
||||||
return False
|
return False
|
||||||
# make sure DEST ends with /
|
# make sure DEST ends with /
|
||||||
if not ret.get("Main", "dest").endswith("/"):
|
if not ret.get(section="Main", option="dest").endswith("/"):
|
||||||
ret.set("Main", "dest", ret.get("Main", "dest")+"/")
|
ret.set(section="Main", option="dest", value=ret.get(section="Main", option="dest")+"/")
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
@ -95,14 +95,14 @@ def user_config_generated(filename, cfg):
|
|||||||
# filename does not exist, so it was not generated by userconfig
|
# filename does not exist, so it was not generated by userconfig
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not cfg.check("Main", "stamp"):
|
if not cfg.check("stamp"):
|
||||||
# no STAMP in userconfig.cfg, so no way to check if file was generated by userconfig
|
# no STAMP in userconfig.cfg, so no way to check if file was generated by userconfig
|
||||||
return False
|
return False
|
||||||
|
|
||||||
fp = open(filename, "r")
|
fp = open(filename, "r")
|
||||||
|
|
||||||
for line in fp:
|
for line in fp:
|
||||||
if re.search(re.escape(cfg.get("Main", "stamp")), line):
|
if re.search(re.escape(cfg.get("stamp")), line):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user