From 0645f79fd43775bc2c93026f159958897fa8a537 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Tue, 10 Jul 2018 04:38:13 -0400 Subject: [PATCH 1/4] language: remove unused handle The QCoreApplication.instance() handle in get_all_languages() is unnecessary and never used. --- src/classes/language.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/classes/language.py b/src/classes/language.py index 38a4a8b372..7528422b14 100644 --- a/src/classes/language.py +++ b/src/classes/language.py @@ -171,9 +171,6 @@ def find_language_match(pattern, path, translator, locale_name): def get_all_languages(): """Get all language names and countries packaged with OpenShot""" - # Get app instance - app = QCoreApplication.instance() - # Loop through all supported language locale codes all_languages = [] for locale_name in info.SUPPORTED_LANGUAGES: From 3b37524c1eafef33324fbb99324112e516b6aa8c Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Tue, 10 Jul 2018 04:40:09 -0400 Subject: [PATCH 2/4] Move output rerouting to method This creates the reroute_output() method, allowing the rerouting of stdout and stderr into the logger to be delayed until after commandline arguments are processed and any output displayed --- src/classes/logger.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/classes/logger.py b/src/classes/logger.py index 5bf4de111d..5fcb7651af 100644 --- a/src/classes/logger.py +++ b/src/classes/logger.py @@ -67,11 +67,12 @@ def errors(self): fh.setFormatter(formatter) log.addHandler(fh) -# Route stdout and stderr to logger (custom handler) -if not getattr(sys, 'frozen', False): - so = StreamToLogger(log, logging.INFO) - sys.stdout = so +def reroute_output(): + """Route stdout and stderr to logger (custom handler)""" + if not getattr(sys, 'frozen', False): + so = StreamToLogger(log, logging.INFO) + sys.stdout = so - se = StreamToLogger(log, logging.ERROR) - sys.stderr = se + se = StreamToLogger(log, logging.ERROR) + sys.stderr = se From 4b61e1b1c5a84bf372a2eaafef2eb2329b7f352b Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Tue, 10 Jul 2018 04:40:28 -0400 Subject: [PATCH 3/4] Add command line arguments to launch.py This add standard Python argparse handling for command-line arguments to launch.py, which now responds to `--help` with: ```console src/launch.py --help Loaded modules from current directory: /home/ferd/rpmbuild/REPOS/openshot-qt/src usage: launch.py [-h] [--list-languages] [-V] OpenShot version 2.4.2 optional arguments: -h, --help show this help message and exit --list-languages -V, --version ``` There is also commented out code for another argument, `--lang`, to set the interface language on the command line via language code (as listed using `--list-languages`). That will require the changes from from PR #1795 before it can be enabled. --- src/launch.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/launch.py b/src/launch.py index e2875b2e0c..9bf2db0e9f 100755 --- a/src/launch.py +++ b/src/launch.py @@ -41,6 +41,7 @@ """ import sys +from argparse import ArgumentParser try: from classes import info @@ -51,17 +52,39 @@ print("Loaded modules from installed directory: %s" % info.PATH) from classes.app import OpenShotApp -from classes.logger import log +from classes.logger import log, reroute_output +from classes.language import get_all_languages def main(): """"Initialize settings (not implemented) and create main window/application.""" + parser = ArgumentParser(description = 'OpenShot version ' + info.SETUP['version']) + # parser.add_argument('-l', '--lang', action='store', + # help='language code for interface (overrides ' + # 'preferences and system environment)') + parser.add_argument('--list-languages', dest='list_languages', + action='store_true') + parser.add_argument('-V', '--version', action='store_true') + + args = parser.parse_args() + # Display version and exit (if requested) - if "--version" in sys.argv: + if args.version: print("OpenShot version %s" % info.SETUP['version']) exit() + if args.list_languages: + print("Supported Languages:") + for lang in get_all_languages(): + print(" {:>12} {}".format(lang[0],lang[1])) + exit() + + # if args.lang: + # info.CMDLINE_LANG = args.lang + + reroute_output() + log.info("------------------------------------------------") log.info(" OpenShot (version %s)" % info.SETUP['version']) log.info("------------------------------------------------") From 110cba3eeaf85ef9ab4eff6c40e7df1c85ca257d Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Tue, 10 Jul 2018 04:55:35 -0400 Subject: [PATCH 4/4] Add explanatory text for --list-lang --- src/launch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/launch.py b/src/launch.py index 9bf2db0e9f..d0945fd134 100755 --- a/src/launch.py +++ b/src/launch.py @@ -64,7 +64,8 @@ def main(): # help='language code for interface (overrides ' # 'preferences and system environment)') parser.add_argument('--list-languages', dest='list_languages', - action='store_true') + action='store_true', help='List all language ' + 'codes supported by OpenShot') parser.add_argument('-V', '--version', action='store_true') args = parser.parse_args()