Compare commits

..

No commits in common. "ac41bc7fb60d50462bbff1da96c9d92982db6336" and "b5c898035ad336a33bdca05146374ee696a5fc84" have entirely different histories.

5 changed files with 9 additions and 15 deletions

View File

@ -17,9 +17,10 @@ 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 = Conf(filename=cmdline.file, debug=debug) cfg.set_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,6 +14,3 @@ userconfig = "cli:main"
[tool.setuptools] [tool.setuptools]
packages = [ "userconfig", "cli" ] packages = [ "userconfig", "cli" ]
[tool.setuptools.data-files]
"etc" = [ "userconfig2.conf" ]

6
userconfig.cfg Normal file
View File

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

View File

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

View File

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