second revision, logging output polished
This commit is contained in:
@@ -15,7 +15,7 @@ class Debug:
|
||||
_COLOR_YELLOW = '\033[93m'
|
||||
_COLOR_END = '\33[0m'
|
||||
|
||||
_FORMAT = {'STANDARD': '',
|
||||
_FORMAT = {'STANDARD': 'INFO: ',
|
||||
'ERROR': f'{_COLOR_RED}ERROR:{_COLOR_END} ',
|
||||
'NOTICE': f'{_COLOR_BLUE}NOTICE:{_COLOR_END} ',
|
||||
'WARNING': f'{_COLOR_YELLOW}WARNING:{_COLOR_END} ',
|
||||
@@ -35,11 +35,15 @@ class Debug:
|
||||
return self._verbose
|
||||
|
||||
def stdout(self, out, verbose_level=0, category='STANDARD'):
|
||||
spaces = ''
|
||||
if verbose_level > 1:
|
||||
spaces = ' '*(verbose_level-1)
|
||||
|
||||
if self._verbose >= verbose_level:
|
||||
if category in self._FORMAT:
|
||||
print(f'{self._FORMAT[category]}{out}')
|
||||
print(f'{spaces}{self._FORMAT[category]}{out}')
|
||||
else:
|
||||
print(f'[category {category} unknown]:{out}')
|
||||
print(f'{spaces}[category {category} unknown]:{out}')
|
||||
|
||||
def stderr(self, out, verbose_level=0, category='STANDARD'):
|
||||
if self._verbose >= verbose_level:
|
||||
@@ -74,11 +78,11 @@ def main():
|
||||
debug = Debug()
|
||||
# debug.set_verbose(cmdline.verbose)
|
||||
# cfg = Conf(filename=cmdline.file, debug=debug)
|
||||
debug.set_verbose(1)
|
||||
cfg = Conf(filename='/home/lysis/userconfig2-test.conf', debug=debug)
|
||||
debug.set_verbose(3)
|
||||
cfg = Conf(filename='/Users/lysis/userconfig2-test.conf', debug=debug)
|
||||
uc = Userconfig(cfg)
|
||||
|
||||
cfg.debug.stdout(f'Verbose level: {cfg.debug.get_verbose()}', 1, 'STANDARD')
|
||||
cfg.debug.stdout(f'Verbose level: {cfg.debug.get_verbose()}', 1)
|
||||
configdir = cfg.get('configdir')
|
||||
# configdir is the root of the userconfig files
|
||||
# Directory structure:
|
||||
@@ -107,6 +111,7 @@ def main():
|
||||
|
||||
cfg.debug.stdout(f'configdir: {configdir}', 1)
|
||||
for package in os.scandir(configdir):
|
||||
# Skip on non-production files
|
||||
if not package.is_dir():
|
||||
cfg.debug.stdout(f'{package.path} is not a directory, skipping', 2, 'WARNING')
|
||||
continue
|
||||
@@ -115,12 +120,13 @@ def main():
|
||||
if os.path.isfile(f'{package.path}/.ignore'):
|
||||
cfg.debug.stdout(f'{package.path} contains .ignore, skipping', 2, 'WARNING')
|
||||
continue
|
||||
cfg.debug.stdout(f'Package: {package.path}', 1, 'NOTICE')
|
||||
cfg.debug.stdout(f'============ start {cfg.debug.green(package.path)} ============', 2)
|
||||
# Start processing
|
||||
cfg.debug.stdout(f'Start Package {cfg.debug.green(package.path)}', 1, 'NOTICE')
|
||||
# Get all category directories for package
|
||||
(category_dirs, dir_config) = uc.process_package_dir(package.path)
|
||||
cfg.debug.stdout(f'Got categories: {category_dirs}', 2)
|
||||
host_category_dirs = uc.filter_categories(category_dirs)
|
||||
cfg.debug.stdout(f'Filtered categories for host: {host_category_dirs}', 2)
|
||||
cfg.debug.stdout(f'Host uses categories: {", ".join([f'{v[1]}_{v[2]}' for v in host_category_dirs])}', 2)
|
||||
file_list = dict()
|
||||
for c in host_category_dirs:
|
||||
file_list = uc.process_category_dir(c, file_list)
|
||||
@@ -130,16 +136,26 @@ def main():
|
||||
subprocess.call([f'{package.path}/install.sh'])
|
||||
for file in file_list:
|
||||
dest = f'{dir_config.get(section="Main", option="dest")}/{file}'
|
||||
cfg.debug.stdout(f'Generating {dest} from:\n {"\n ".join(file_list[file])}', 1)
|
||||
|
||||
try:
|
||||
comment_string = dir_config.get(section="Main", option="commentstring")
|
||||
except ValueError:
|
||||
cfg.debug.stdout(f'commentstring does not exist in config file {dir_config._cfgfiles}', 0, 'ERROR')
|
||||
sys.exit(1)
|
||||
# Make sure all directories for destination file exist
|
||||
uc.create_destination_directories(dir_config.get(section="Main", option="dest"))
|
||||
if uc.create_destination_directories(dir_config.get(section="Main", option="dest")):
|
||||
cfg.debug.stdout(f'Created target directories {cfg.debug.green(dir_config.get(section="Main", option="dest"))}',
|
||||
0, 'SUCCESS')
|
||||
else:
|
||||
cfg.debug.stdout(f'All target directories exist', 2)
|
||||
temp_filename = uc.build_file(file_list[file], dest, comment_string)
|
||||
uc.diff_and_copy_file(temp_filename, dest, comment_string)
|
||||
cfg.debug.stdout(f'============ end {cfg.debug.green(package.path)} ============\n\n', 2)
|
||||
if uc.diff_and_copy_file(temp_filename, dest, comment_string):
|
||||
cfg.debug.stdout(f'Copy {temp_filename} -> {cfg.debug.green(dest)} (changed)\n', 0, 'SUCCESS')
|
||||
else:
|
||||
cfg.debug.stdout(f'Generated file and destination are the same.\n', 1)
|
||||
|
||||
cfg.debug.stdout(f'End Package {cfg.debug.green(package.path)}\n\n', 1, 'NOTICE')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Reference in New Issue
Block a user