Drop direct execution of apply_config.py

Now we generate the console script using setuptools, and we don't
expect users may directly execute the *.py file.

Change-Id: I6ddeb659c641cf3af33518bb7bf4c24b101f87be
This commit is contained in:
Takashi Kajinami 2024-01-29 23:35:49 +09:00
parent 436cc14867
commit 38b900efa7
2 changed files with 16 additions and 26 deletions

36
os_apply_config/apply_config.py Executable file → Normal file
View File

@ -33,6 +33,11 @@ from os_apply_config import version
DEFAULT_TEMPLATES_DIR = '/usr/libexec/os-apply-config/templates'
LOG_FORMAT = '[%(asctime)s] [%(levelname)s] %(message)s'
DATE_FORMAT = '%Y/%m/%d %I:%M:%S %p'
logger = logging.getLogger('os-apply-config')
def templates_dir():
"""Determine the default templates directory path
@ -322,12 +327,23 @@ def load_list_from_json(json_file):
return json_obj
def add_handler(logger, handler):
handler.setFormatter(logging.Formatter(LOG_FORMAT, datefmt=DATE_FORMAT))
logger.addHandler(handler)
def main(argv=sys.argv):
opts = parse_opts(argv)
if opts.print_templates:
print(opts.templates)
return 0
logger.setLevel(logging.INFO)
add_handler(logger, logging.StreamHandler())
if os.geteuid() == 0:
add_handler(logger,
logging.FileHandler('/var/log/os-apply-config.log'))
if not opts.metadata:
if 'OS_CONFIG_FILES' in os.environ:
opts.metadata = os.environ['OS_CONFIG_FILES'].split(':')
@ -365,23 +381,3 @@ def main(argv=sys.argv):
logger.error(e)
return 1
return 0
# logging
LOG_FORMAT = '[%(asctime)s] [%(levelname)s] %(message)s'
DATE_FORMAT = '%Y/%m/%d %I:%M:%S %p'
def add_handler(logger, handler):
handler.setFormatter(logging.Formatter(LOG_FORMAT, datefmt=DATE_FORMAT))
logger.addHandler(handler)
logger = logging.getLogger('os-apply-config')
logger.setLevel(logging.INFO)
add_handler(logger, logging.StreamHandler())
if os.geteuid() == 0:
add_handler(logger, logging.FileHandler('/var/log/os-apply-config.log'))
if __name__ == '__main__':
sys.exit(main(sys.argv))

View File

@ -78,12 +78,6 @@ CHOWN_OUTPUT = {
}
def main_path():
return (
os.path.dirname(os.path.realpath(__file__)) +
'/../os_apply_config.py')
def template(relpath):
return os.path.join(TEMPLATES, relpath[1:])