57 lines
2.3 KiB
Python
Executable File
57 lines
2.3 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()
|
|
debug = Debug()
|
|
debug.set_verbose(cmdline.verbose)
|
|
cfg = Conf(filename=cmdline.file, debug=debug)
|
|
uc = Userconfig(cfg)
|
|
|
|
cfg.debug.stdout(f"Verbose level is {cfg.debug.get_verbose()}", 1)
|
|
cfg.debug.stdout("================ main ===============", 1)
|
|
temp_classes = ""
|
|
for h in classes_for_host():
|
|
temp_classes = temp_classes + str(h) + ","
|
|
cfg.debug.stdout("+++ Current host is in classes %s" % temp_classes, 1)
|
|
configdir = cfg.get("configdir")
|
|
for d in os.listdir(configdir):
|
|
name = configdir+"/"+d
|
|
cfg.debug.stdout("+++ Working in %s" % name, 1)
|
|
if not os.path.isdir(name):
|
|
cfg.debug.stdout("--- %s is not a directory, skipping." % name, 3)
|
|
continue
|
|
elif d.startswith(".svn") or d.startswith(".git"):
|
|
cfg.debug.stdout("--- %s is .svn or .git, skipping." % name, 3)
|
|
continue
|
|
elif os.path.isfile(name+"/.ignore"):
|
|
cfg.debug.stdout("--- %s contains file .ignore, skipping." % name, 3)
|
|
continue
|
|
else:
|
|
cfg.debug.stdout("+++ Processing files in %s" % name, 2)
|
|
(destfiles, dirConfig) = uc.workdir(name)
|
|
if isinstance(destfiles, dict):
|
|
if len(destfiles.keys()) > 0:
|
|
cfg.debug.stdout("+++ Building %d files: %s" % (len(destfiles.keys()), destfiles.keys()), 3)
|
|
uc.process_all_files(destfiles, dirConfig)
|
|
else:
|
|
cfg.debug.stdout("--- No files found for %s, skipping." % name, 1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|