Compare commits

..

4 Commits

5 changed files with 15 additions and 9 deletions

View File

@ -17,10 +17,9 @@ def main():
help='userconfig2.cfg config file', help='userconfig2.cfg config file',
dest='file', action='store') dest='file', action='store')
cmdline = parser.parse_args() cmdline = parser.parse_args()
cfg = Conf(cmdline.file)
debug = Debug() debug = Debug()
debug.set_verbose(cmdline.verbose) debug.set_verbose(cmdline.verbose)
cfg.set_debug(debug) cfg = Conf(filename=cmdline.file, debug=debug)
uc = Userconfig(cfg) uc = Userconfig(cfg)
cfg.debug.stdout(f"Verbose level is {cfg.debug.get_verbose()}", 1) cfg.debug.stdout(f"Verbose level is {cfg.debug.get_verbose()}", 1)

View File

@ -14,3 +14,6 @@ userconfig = "cli:main"
[tool.setuptools] [tool.setuptools]
packages = [ "userconfig", "cli" ] packages = [ "userconfig", "cli" ]
[tool.setuptools.data-files]
"etc" = [ "userconfig2.conf" ]

View File

@ -1,6 +0,0 @@
[Main]
configdir = $HOME/.userconfig
configfile = userconfig.cfg
debug = 0
stamp = %userconfig_generated 1.0%
stampreplace = $userconfig_stamp$

View File

@ -1,5 +1,6 @@
import configparser import configparser
import os import os
import sys
class Conf(object): class Conf(object):
@ -14,7 +15,10 @@ class Conf(object):
if filename: if filename:
filenames.append(filename) filenames.append(filename)
if not force_filename: if not force_filename:
filenames.append(f'{os.environ.get("HOME")}/etc/userconfig2.conf') if os.path.isfile(f'{os.environ.get("HOME")}/etc/userconfig2.conf'):
filenames.append(f'{os.environ.get("HOME")}/etc/userconfig2.conf')
if os.path.isfile(f'{sys.prefix}/etc/userconfig2.conf'):
filenames.append(f'{sys.prefix}/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)}')

6
userconfig2.conf Normal file
View File

@ -0,0 +1,6 @@
[userconfig]
configdir = %(HOME)s/.userconfig
configfile = userconfig2.cfg
debug = 0
stamp = %%userconfig_generated 1.0%%
stampreplace = $userconfig_stamp$