mirror of
https://github.com/miurahr/aqtinstall.git
synced 2025-12-17 20:54:38 +03:00
Add logging argument options
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
@@ -20,10 +20,10 @@
|
|||||||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
import logging
|
|
||||||
import requests
|
import requests
|
||||||
import traceback
|
import traceback
|
||||||
import xml.etree.ElementTree as ElementTree
|
import xml.etree.ElementTree as ElementTree
|
||||||
|
from logging import getLogger
|
||||||
from six import StringIO
|
from six import StringIO
|
||||||
|
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ class QtArchives:
|
|||||||
archives = []
|
archives = []
|
||||||
base = None
|
base = None
|
||||||
|
|
||||||
def __init__(self, os_name, qt_version, target, arch, mirror=None):
|
def __init__(self, os_name, qt_version, target, arch, mirror=None, logging=None):
|
||||||
self.qt_version = qt_version
|
self.qt_version = qt_version
|
||||||
self.target = target
|
self.target = target
|
||||||
self.arch = arch
|
self.arch = arch
|
||||||
@@ -56,10 +56,17 @@ class QtArchives:
|
|||||||
self.base = mirror + '/online/qtsdkrepository/'
|
self.base = mirror + '/online/qtsdkrepository/'
|
||||||
else:
|
else:
|
||||||
self.base = self.BASE_URL
|
self.base = self.BASE_URL
|
||||||
qt_ver_num = qt_version.replace(".", "")
|
if logging:
|
||||||
|
self.logger = logging
|
||||||
|
else:
|
||||||
|
self.logger = getLogger('aqt')
|
||||||
|
self._get_archives(os_name)
|
||||||
|
|
||||||
|
def _get_archives(self, os_name):
|
||||||
|
qt_ver_num = self.qt_version.replace(".", "")
|
||||||
|
|
||||||
# install mingw runtime package
|
# install mingw runtime package
|
||||||
if arch in ['win64_mingw73', 'win32_mingw73', 'win64_mingw53', 'win32_mingw53']:
|
if self.arch in ['win64_mingw73', 'win32_mingw73', 'win64_mingw53', 'win32_mingw53']:
|
||||||
archive_url = self.base + 'windows_x86/desktop/tools_mingw/'
|
archive_url = self.base + 'windows_x86/desktop/tools_mingw/'
|
||||||
update_xml_url = "{0}Updates.xml".format(archive_url)
|
update_xml_url = "{0}Updates.xml".format(archive_url)
|
||||||
try:
|
try:
|
||||||
@@ -68,13 +75,13 @@ class QtArchives:
|
|||||||
print("Caught download error: %s" % e.args)
|
print("Caught download error: %s" % e.args)
|
||||||
exc_buffer = StringIO()
|
exc_buffer = StringIO()
|
||||||
traceback.print_exc(file=exc_buffer)
|
traceback.print_exc(file=exc_buffer)
|
||||||
logging.error('Download error:\n%s', exc_buffer.getvalue())
|
self.logger.error('Download error:\n%s', exc_buffer.getvalue())
|
||||||
raise e
|
raise e
|
||||||
else:
|
else:
|
||||||
self.update_xml = ElementTree.fromstring(r.text)
|
self.update_xml = ElementTree.fromstring(r.text)
|
||||||
for packageupdate in self.update_xml.iter("PackageUpdate"):
|
for packageupdate in self.update_xml.iter("PackageUpdate"):
|
||||||
name = packageupdate.find("Name").text
|
name = packageupdate.find("Name").text
|
||||||
if name.split(".")[-1] != arch:
|
if name.split(".")[-1] != self.arch:
|
||||||
continue
|
continue
|
||||||
downloadable_archives = packageupdate.find("DownloadableArchives").text.split(", ")
|
downloadable_archives = packageupdate.find("DownloadableArchives").text.split(", ")
|
||||||
full_version = packageupdate.find("Version").text
|
full_version = packageupdate.find("Version").text
|
||||||
@@ -85,12 +92,12 @@ class QtArchives:
|
|||||||
# ex. 7.3.0-1x86_64-7.3.0-release-posix-seh-rt_v5-rev0.7z
|
# ex. 7.3.0-1x86_64-7.3.0-release-posix-seh-rt_v5-rev0.7z
|
||||||
package_url = archive_url + name + "/" + named_version + archive
|
package_url = archive_url + name + "/" + named_version + archive
|
||||||
self.archives.append(QtPackage(name, package_url, archive, package_desc,
|
self.archives.append(QtPackage(name, package_url, archive, package_desc,
|
||||||
has_mirror=(mirror is not None)))
|
has_mirror=(self.mirror is not None)))
|
||||||
# Ordinary packages
|
# Ordinary packages
|
||||||
if os_name == 'windows':
|
if os_name == 'windows':
|
||||||
archive_url = self.base + os_name + '_x86/' + target + '/' + 'qt5_' + qt_ver_num + '/'
|
archive_url = self.base + os_name + '_x86/' + self.target + '/' + 'qt5_' + qt_ver_num + '/'
|
||||||
else:
|
else:
|
||||||
archive_url = self.base + os_name + '_x64/' + target + '/' + 'qt5_' + qt_ver_num + '/'
|
archive_url = self.base + os_name + '_x64/' + self.target + '/' + 'qt5_' + qt_ver_num + '/'
|
||||||
|
|
||||||
# Get packages index
|
# Get packages index
|
||||||
update_xml_url = "{0}Updates.xml".format(archive_url)
|
update_xml_url = "{0}Updates.xml".format(archive_url)
|
||||||
@@ -100,19 +107,19 @@ class QtArchives:
|
|||||||
print("Caught download error: %s" % e.args)
|
print("Caught download error: %s" % e.args)
|
||||||
exc_buffer = StringIO()
|
exc_buffer = StringIO()
|
||||||
traceback.print_exc(file=exc_buffer)
|
traceback.print_exc(file=exc_buffer)
|
||||||
logging.error('Download error:\n%s', exc_buffer.getvalue())
|
self.logger.error('Download error:\n%s', exc_buffer.getvalue())
|
||||||
raise e
|
raise e
|
||||||
else:
|
else:
|
||||||
self.update_xml = ElementTree.fromstring(r.text)
|
self.update_xml = ElementTree.fromstring(r.text)
|
||||||
for packageupdate in self.update_xml.iter("PackageUpdate"):
|
for packageupdate in self.update_xml.iter("PackageUpdate"):
|
||||||
name = packageupdate.find("Name").text
|
name = packageupdate.find("Name").text
|
||||||
if name.split(".")[-1] != arch:
|
if name.split(".")[-1] != self.arch:
|
||||||
continue
|
continue
|
||||||
if name.split(".")[-2] == "debug_info":
|
if name.split(".")[-2] == "debug_info":
|
||||||
continue
|
continue
|
||||||
if packageupdate.find("DownloadableArchives").text is None:
|
if packageupdate.find("DownloadableArchives").text is None:
|
||||||
continue
|
continue
|
||||||
if name == "qt.qt5.{}.{}".format(qt_ver_num, arch) or name == "qt.{}.{}".format(qt_ver_num, arch):
|
if name == "qt.qt5.{}.{}".format(qt_ver_num, self.arch) or name == "qt.{}.{}".format(qt_ver_num, self.arch):
|
||||||
# basic packages
|
# basic packages
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@@ -124,7 +131,7 @@ class QtArchives:
|
|||||||
for archive in downloadable_archives:
|
for archive in downloadable_archives:
|
||||||
package_url = archive_url + name + "/" + full_version + archive
|
package_url = archive_url + name + "/" + full_version + archive
|
||||||
self.archives.append(QtPackage(name, package_url, archive, package_desc,
|
self.archives.append(QtPackage(name, package_url, archive, package_desc,
|
||||||
has_mirror=(mirror is not None)))
|
has_mirror=self.has_mirror))
|
||||||
|
|
||||||
if len(self.archives) == 0:
|
if len(self.archives) == 0:
|
||||||
print("Error while parsing package information!")
|
print("Error while parsing package information!")
|
||||||
|
|||||||
24
aqt/cli.py
24
aqt/cli.py
@@ -21,9 +21,12 @@
|
|||||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging.config
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
|
import yaml
|
||||||
|
from logging import getLogger
|
||||||
|
|
||||||
from aqt.archives import QtArchives
|
from aqt.archives import QtArchives
|
||||||
from aqt.installer import QtInstaller
|
from aqt.installer import QtInstaller
|
||||||
@@ -93,17 +96,18 @@ class Cli():
|
|||||||
exit(1)
|
exit(1)
|
||||||
qt_version = args.qt_version
|
qt_version = args.qt_version
|
||||||
if not self.check_arg_combination(qt_version, os_name, target, arch):
|
if not self.check_arg_combination(qt_version, os_name, target, arch):
|
||||||
print("Specified target combination is not valid: {} {} {}".format(os_name, target, arch))
|
self.logger.error("Specified target combination is not valid: {} {} {}".format(os_name, target, arch))
|
||||||
exit(1)
|
exit(1)
|
||||||
if mirror is not None:
|
if mirror is not None:
|
||||||
if not mirror.startswith('http://') or mirror.startswith('https://') or mirror.startswith('ftp://'):
|
if not mirror.startswith('http://') or mirror.startswith('https://') or mirror.startswith('ftp://'):
|
||||||
args.print_help()
|
args.print_help()
|
||||||
exit(1)
|
exit(1)
|
||||||
if output_dir is not None:
|
if output_dir is not None:
|
||||||
QtInstaller(QtArchives(os_name, qt_version, target, arch, mirror=mirror)).install(command=sevenzip,
|
QtInstaller(QtArchives(os_name, qt_version, target, arch, mirror=mirror, logging=self.logger),
|
||||||
target_dir=output_dir)
|
logging=self.logger).install(command=sevenzip, target_dir=output_dir)
|
||||||
else:
|
else:
|
||||||
QtInstaller(QtArchives(os_name, qt_version, target, arch, mirror=mirror)).install(command=sevenzip)
|
QtInstaller(QtArchives(os_name, qt_version, target, arch, mirror=mirror, logging=self.logger),
|
||||||
|
logging = self.logger).install(command=sevenzip)
|
||||||
|
|
||||||
sys.stdout.write("\033[K")
|
sys.stdout.write("\033[K")
|
||||||
print("Finished installation")
|
print("Finished installation")
|
||||||
@@ -118,6 +122,9 @@ class Cli():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
parser = argparse.ArgumentParser(prog='aqt', description='Installer for Qt SDK.',
|
parser = argparse.ArgumentParser(prog='aqt', description='Installer for Qt SDK.',
|
||||||
formatter_class=argparse.RawTextHelpFormatter, add_help=True)
|
formatter_class=argparse.RawTextHelpFormatter, add_help=True)
|
||||||
|
parser.add_argument('--logging-conf', type=argparse.FileType('r'),
|
||||||
|
nargs=1, help="Specify logging configuration YAML file.")
|
||||||
|
parser.add_argument('--logger', nargs=1, help="Specify logger name")
|
||||||
subparsers = parser.add_subparsers(title='subcommands', description='Valid subcommands',
|
subparsers = parser.add_subparsers(title='subcommands', description='Valid subcommands',
|
||||||
help='subcommand for aqt Qt installer')
|
help='subcommand for aqt Qt installer')
|
||||||
install_parser = subparsers.add_parser('install')
|
install_parser = subparsers.add_parser('install')
|
||||||
@@ -150,4 +157,13 @@ class Cli():
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
args = self.parser.parse_args()
|
args = self.parser.parse_args()
|
||||||
|
if args.logging_conf:
|
||||||
|
log_config = yaml.load(args.logging_conf)
|
||||||
|
else:
|
||||||
|
log_config = yaml.load(os.path.join(os.path.dirname(__file__), 'logging.yml'))
|
||||||
|
logging.config.dictConfig(log_config)
|
||||||
|
if args.logger is not None:
|
||||||
|
self.logger = getLogger(args.logger)
|
||||||
|
else:
|
||||||
|
self.logger = getLogger('aqt')
|
||||||
args.func(args)
|
args.func(args)
|
||||||
|
|||||||
@@ -21,12 +21,12 @@
|
|||||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
import py7zr
|
import py7zr
|
||||||
import requests
|
import requests
|
||||||
import traceback
|
import traceback
|
||||||
import xml.etree.ElementTree as ElementTree
|
import xml.etree.ElementTree as ElementTree
|
||||||
|
from logging import getLogger
|
||||||
from six import StringIO
|
from six import StringIO
|
||||||
from multiprocessing.dummy import Pool
|
from multiprocessing.dummy import Pool
|
||||||
from operator import and_
|
from operator import and_
|
||||||
@@ -47,8 +47,13 @@ class QtInstaller:
|
|||||||
Installer class to download packages and extract it.
|
Installer class to download packages and extract it.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, qt_archives):
|
def __init__(self, qt_archives, logging=None):
|
||||||
self.qt_archives = qt_archives
|
self.qt_archives = qt_archives
|
||||||
|
if logging:
|
||||||
|
self.logger = logging
|
||||||
|
else:
|
||||||
|
self.logger = getLogger('aqt')
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def retrieve_archive(package, path=None, command=None):
|
def retrieve_archive(package, path=None, command=None):
|
||||||
@@ -126,7 +131,7 @@ class QtInstaller:
|
|||||||
print("Configuration file generation error: %s" % e.args)
|
print("Configuration file generation error: %s" % e.args)
|
||||||
exc_buffer = StringIO()
|
exc_buffer = StringIO()
|
||||||
traceback.print_exc(file=exc_buffer)
|
traceback.print_exc(file=exc_buffer)
|
||||||
logging.error('Error happened when writing configuration files:\n%s', exc_buffer.getvalue())
|
self.logger.error('Error happened when writing configuration files:\n%s', exc_buffer.getvalue())
|
||||||
raise e
|
raise e
|
||||||
else:
|
else:
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|||||||
22
aqt/logging.yml
Normal file
22
aqt/logging.yml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
version: 1
|
||||||
|
formatters:
|
||||||
|
brief:
|
||||||
|
format: '%(message)s'
|
||||||
|
default:
|
||||||
|
format: '%(asctime)s %(levelname)-8s %(name)-15s %(message)s'
|
||||||
|
datefmt: '%Y-%m-%d %H:%M:%S'
|
||||||
|
handlers:
|
||||||
|
console:
|
||||||
|
class: logging.StreamHandler
|
||||||
|
level: WARN
|
||||||
|
formatter: brief
|
||||||
|
stream: ext://sys.stdout
|
||||||
|
file:
|
||||||
|
class : logging.FileHandler
|
||||||
|
formatter: default
|
||||||
|
filename: aqtinstall.log
|
||||||
|
root:
|
||||||
|
level: INFO
|
||||||
|
handlers:
|
||||||
|
- console
|
||||||
|
- file
|
||||||
@@ -7,3 +7,4 @@ flake8
|
|||||||
wheel
|
wheel
|
||||||
twine
|
twine
|
||||||
py7zr
|
py7zr
|
||||||
|
pyyaml
|
||||||
Reference in New Issue
Block a user