pyuserconfig/cli/__init__.py

57 lines
2.2 KiB
Python
Executable File

import os
import argparse
from userconfig.cfgfile import Conf
from userconfig.tools import Debug
from userconfig.checks import classes_for_host
from userconfig import Userconfig
def main():
parser = argparse.ArgumentParser(prog='userconfig',
description='Manages configuration files, usually in the user home directory')
parser.add_argument('-v',
help='Verbosity level (multiple v for higher level)',
dest='verbose', action='count', default=0)
parser.add_argument('-f', '--file',
help='userconfig2.cfg config file',
dest='file', action='store')
cmdline = parser.parse_args()
cfg = Conf(cmdline.file)
debug = Debug()
cfg.set_debug(debug)
uc = Userconfig(cfg)
cfg.debug(f"Verbose level is {cfg.debug.get_verbose()}", 1)
cfg.debug("================ main ===============", 1)
temp_classes = ""
for h in classes_for_host():
temp_classes = temp_classes + str(h) + ","
cfg.debug("+++ Current host is in classes %s" % temp_classes, 1)
configdir = cfg.get("configdir")
for d in os.listdir(configdir):
name = configdir+"/"+d
cfg.debug("+++ Working in %s" % name, 1)
if not os.path.isdir(name):
cfg.debug("--- %s is not a directory, skipping." % name, 3)
continue
elif d.startswith(".svn") or d.startswith(".git"):
cfg.debug("--- %s is .svn or .git, skipping." % name, 3)
continue
elif os.path.isfile(name+"/.ignore"):
cfg.debug("--- %s contains file .ignore, skipping." % name, 3)
continue
else:
cfg.debug("+++ Processing files in %s" % name, 2)
(destfiles, dirConfig) = uc.workdir(name)
if isinstance(destfiles, dict):
if len(destfiles.keys()) > 0:
cfg.debug("+++ Building %d files: %s" % (len(destfiles.keys()), destfiles.keys()), 3)
uc.process_all_files(destfiles, dirConfig)
else:
cfg.debug("--- No files found for %s, skipping." % name, 1)
if __name__ == '__main__':
main()