Use a named logger

This commit is contained in:
Valentin Niess
2023-11-10 10:18:12 +01:00
parent e596fec38b
commit e249fdebdb
4 changed files with 29 additions and 24 deletions

View File

@@ -1,6 +1,5 @@
import argparse
from importlib import import_module
import logging
import os
import sys
@@ -24,9 +23,9 @@ def main():
dest='command')
parser.add_argument('-q', '--quiet', help='disable logging',
dest='verbosity', action='store_const', const=logging.ERROR)
dest='verbosity', action='store_const', const='ERROR')
parser.add_argument('-v', '--verbose', help='print extra information',
dest='verbosity', action='store_const', const=logging.DEBUG)
dest='verbosity', action='store_const', const='DEBUG')
install_parser = subparsers.add_parser('install',
description='Install binary dependencies')
@@ -89,7 +88,8 @@ def main():
# Configure the verbosity
if args.verbosity:
logging.getLogger().setLevel(args.verbosity)
from .utils import log
log.set_level(args.verbosity)
# check if no arguments are passed
if args.command is None:

View File

@@ -7,6 +7,7 @@ import sys
from ...appimage import build_appimage, relocate_python
from ...utils.docker import docker_run
from ...utils.fs import copy_tree
from ...utils.manylinux import format_appimage_name, format_tag
from ...utils.tmp import TemporaryDirectory
@@ -19,15 +20,6 @@ def _unpack_args(args):
return args.tag, args.abi, args.contained
def _manylinux_tag(tag):
'''Format Manylinux tag
'''
if tag.startswith('2_'):
return 'manylinux_' + tag
else:
return 'manylinux' + tag
def _get_appimage_name(abi, tag):
'''Format the Python AppImage name using the ABI and OS tags
'''
@@ -36,8 +28,7 @@ def _get_appimage_name(abi, tag):
fullversion = desktop[13:-8]
# Finish building the AppImage on the host. See below.
return 'python{:}-{:}-{:}.AppImage'.format(
fullversion, abi, _manylinux_tag(tag))
return format_appimage_name(abi, fullversion, tag)
def execute(tag, abi, contained=False):
@@ -46,7 +37,7 @@ def execute(tag, abi, contained=False):
if not contained:
# Forward the build to a Docker image
image = 'quay.io/pypa/' + _manylinux_tag(tag)
image = 'quay.io/pypa/' + format_tag(tag)
python = '/opt/python/' + abi + '/bin/python'
pwd = os.getcwd()
@@ -54,7 +45,11 @@ def execute(tag, abi, contained=False):
with TemporaryDirectory() as tmpdir:
copy_tree(dirname, 'python_appimage')
argv = ' '.join(sys.argv[1:])
argv = sys.argv[1:]
if argv:
argv = ' '.join(argv)
else:
argv = 'build manylinux {:} {:}'.format(tag, abi)
if tag.startswith("1_"):
# On manylinux1 tk is not installed
script = [

View File

@@ -35,7 +35,9 @@ def execute(tag):
script,
capture = True
)
for line in result.split(os.linesep):
if line:
log('LIST', "{1:7} -> /opt/python/{0:}".format(
*line.split()))
pythons = [line.split() for line in result.split(os.linesep) if line]
for (abi, version) in pythons:
log('LIST', "{:7} -> /opt/python/{:}".format(version, abi))
return pythons

View File

@@ -7,17 +7,25 @@ __all__ = ['debug', 'log']
# Configure the logger
logging.basicConfig(
format='[%(asctime)s] %(message)s',
level=logging.INFO
level=logging.ERROR
)
logging.getLogger('python-appimage').setLevel(logging.INFO)
def log(task, fmt, *args):
'''Log a standard message
'''
logging.info('%-8s ' + fmt, task, *args)
logging.getLogger('python-appimage').info('%-8s ' + fmt, task, *args)
def debug(task, fmt, *args):
'''Report some debug information
'''
logging.debug('%-8s ' + fmt, task, *args)
logging.getLogger('python-appimage').debug('%-8s ' + fmt, task, *args)
def set_level(level):
'''Set the threshold for logs
'''
level = getattr(logging, level)
logging.getLogger('python-appimage').setLevel(level)