convert install.py to black code format

This commit is contained in:
Hans-Christoph Steiner 2024-02-15 08:49:35 +01:00
parent 9dc14674f1
commit 617a9e75c7
2 changed files with 39 additions and 17 deletions

View file

@ -47,17 +47,31 @@ def main():
global options, config global options, config
# Parse command line... # Parse command line...
parser = ArgumentParser(usage="%(prog)s [options] [APPID[:VERCODE] [APPID[:VERCODE] ...]]") parser = ArgumentParser(
usage="%(prog)s [options] [APPID[:VERCODE] [APPID[:VERCODE] ...]]"
)
common.setup_global_opts(parser) common.setup_global_opts(parser)
parser.add_argument("appid", nargs='*', help=_("application ID with optional versionCode in the form APPID[:VERCODE]")) parser.add_argument(
parser.add_argument("-a", "--all", action="store_true", default=False, "appid",
help=_("Install all signed applications available")) nargs='*',
help=_("application ID with optional versionCode in the form APPID[:VERCODE]"),
)
parser.add_argument(
"-a",
"--all",
action="store_true",
default=False,
help=_("Install all signed applications available"),
)
options = parser.parse_args() options = parser.parse_args()
common.set_console_logging(options.verbose) common.set_console_logging(options.verbose)
if not options.appid and not options.all: if not options.appid and not options.all:
parser.error(_("option %s: If you really want to install all the signed apps, use --all") % "all") parser.error(
_("option %s: If you really want to install all the signed apps, use --all")
% "all"
)
config = common.read_config(options) config = common.read_config(options)
@ -67,14 +81,12 @@ def main():
sys.exit(0) sys.exit(0)
if options.appid: if options.appid:
vercodes = common.read_pkg_args(options.appid, True) vercodes = common.read_pkg_args(options.appid, True)
common.get_metadata_files(vercodes) # only check appids common.get_metadata_files(vercodes) # only check appids
apks = {appid: None for appid in vercodes} apks = {appid: None for appid in vercodes}
# Get the signed APK with the highest vercode # Get the signed APK with the highest vercode
for apkfile in sorted(glob.glob(os.path.join(output_dir, '*.apk'))): for apkfile in sorted(glob.glob(os.path.join(output_dir, '*.apk'))):
try: try:
appid, vercode = common.publishednameinfo(apkfile) appid, vercode = common.publishednameinfo(apkfile)
except FDroidException: except FDroidException:
@ -90,9 +102,10 @@ def main():
raise FDroidException(_("No signed APK available for %s") % appid) raise FDroidException(_("No signed APK available for %s") % appid)
else: else:
apks = {
apks = {common.publishednameinfo(apkfile)[0]: apkfile for apkfile in common.publishednameinfo(apkfile)[0]: apkfile
sorted(glob.glob(os.path.join(output_dir, '*.apk')))} for apkfile in sorted(glob.glob(os.path.join(output_dir, '*.apk')))
}
for appid, apk in apks.items(): for appid, apk in apks.items():
# Get device list each time to avoid device not found errors # Get device list each time to avoid device not found errors
@ -101,7 +114,11 @@ def main():
raise FDroidException(_("No attached devices found")) raise FDroidException(_("No attached devices found"))
logging.info(_("Installing %s...") % apk) logging.info(_("Installing %s...") % apk)
for dev in devs: for dev in devs:
logging.info(_("Installing '{apkfilename}' on {dev}...").format(apkfilename=apk, dev=dev)) logging.info(
_("Installing '{apkfilename}' on {dev}...").format(
apkfilename=apk, dev=dev
)
)
p = SdkToolsPopen(['adb', "-s", dev, "install", apk]) p = SdkToolsPopen(['adb', "-s", dev, "install", apk])
fail = "" fail = ""
for line in p.output.splitlines(): for line in p.output.splitlines():
@ -111,11 +128,17 @@ def main():
continue continue
if fail == "INSTALL_FAILED_ALREADY_EXISTS": if fail == "INSTALL_FAILED_ALREADY_EXISTS":
logging.warning(_('"{apkfilename}" is already installed on {dev}.') logging.warning(
.format(apkfilename=apk, dev=dev)) _('"{apkfilename}" is already installed on {dev}.').format(
apkfilename=apk, dev=dev
)
)
else: else:
raise FDroidException(_("Failed to install '{apkfilename}' on {dev}: {error}") raise FDroidException(
.format(apkfilename=apk, dev=dev, error=fail)) _("Failed to install '{apkfilename}' on {dev}: {error}").format(
apkfilename=apk, dev=dev, error=fail
)
)
logging.info('\n' + _('Finished')) logging.info('\n' + _('Finished'))

View file

@ -41,7 +41,6 @@ force-exclude = '''(
| fdroidserver/deploy\.py | fdroidserver/deploy\.py
| fdroidserver/import_subcommand\.py | fdroidserver/import_subcommand\.py
| fdroidserver/index\.py | fdroidserver/index\.py
| fdroidserver/install\.py
| fdroidserver/metadata\.py | fdroidserver/metadata\.py
| fdroidserver/nightly\.py | fdroidserver/nightly\.py
| fdroidserver/publish\.py | fdroidserver/publish\.py