Use python-black for formatting update.py

This commit is contained in:
Stephen Seo 2022-06-02 17:22:45 +09:00
parent 934c1feaa0
commit d66261cf4a

View file

@ -256,7 +256,9 @@ def check_pkg_build(pkg, editor):
def check_pkg_version(pkgdir, pkg_state, repo, force_check_srcinfo): def check_pkg_version(pkgdir, pkg_state, repo, force_check_srcinfo):
"""Returns "fail", "install", or "done".""" """Returns "fail", "install", or "done"."""
status, current_epoch, current_version = get_pkg_current_version(pkgdir, pkg_state, repo) status, current_epoch, current_version = get_pkg_current_version(
pkgdir, pkg_state, repo
)
if status != "fetched": if status != "fetched":
return status return status
elif current_version is None: elif current_version is None:
@ -274,7 +276,9 @@ def check_pkg_version(pkgdir, pkg_state, repo, force_check_srcinfo):
) )
) )
return get_srcinfo_check_result(current_epoch, current_version, pkgdir, force_check_srcinfo) return get_srcinfo_check_result(
current_epoch, current_version, pkgdir, force_check_srcinfo
)
def get_srcinfo_version(pkgdir): def get_srcinfo_version(pkgdir):
@ -282,9 +286,7 @@ def get_srcinfo_version(pkgdir):
if not os.path.exists(os.path.join(SCRIPT_DIR, pkgdir, ".SRCINFO")): if not os.path.exists(os.path.join(SCRIPT_DIR, pkgdir, ".SRCINFO")):
log_print(f'ERROR: .SRCINFO does not exist for pkg "{pkgdir}"') log_print(f'ERROR: .SRCINFO does not exist for pkg "{pkgdir}"')
return False, None, None, None return False, None, None, None
pkgver_reprog = re.compile( pkgver_reprog = re.compile("^\\s*pkgver\\s*=\\s*([a-zA-Z0-9._+-]+)\\s*$")
"^\\s*pkgver\\s*=\\s*([a-zA-Z0-9._+-]+)\\s*$"
)
pkgrel_reprog = re.compile("^\\s*pkgrel\\s*=\\s*([0-9.]+)\\s*$") pkgrel_reprog = re.compile("^\\s*pkgrel\\s*=\\s*([0-9.]+)\\s*$")
pkgepoch_reprog = re.compile("^\\s*epoch\\s*=\\s*([0-9]+)\\s*$") pkgepoch_reprog = re.compile("^\\s*epoch\\s*=\\s*([0-9]+)\\s*$")
pkgver = "" pkgver = ""
@ -318,9 +320,11 @@ def get_pkgbuild_version(pkgdir, force_check_srcinfo):
break break
# TODO support split packages # TODO support split packages
if force_check_srcinfo or user_input == "1": if force_check_srcinfo or user_input == "1":
srcinfo_fetch_success, pkgepoch, pkgver, pkgrel = get_srcinfo_version(pkgdir) srcinfo_fetch_success, pkgepoch, pkgver, pkgrel = get_srcinfo_version(
pkgdir
)
if not srcinfo_fetch_success: if not srcinfo_fetch_success:
log_print('ERROR: Failed to get pkg info from .SRCINFO') log_print("ERROR: Failed to get pkg info from .SRCINFO")
return False, None, None, None return False, None, None, None
elif user_input == "2": elif user_input == "2":
try: try:
@ -393,8 +397,12 @@ def get_pkgbuild_version(pkgdir, force_check_srcinfo):
return False, None, None, None return False, None, None, None
def get_srcinfo_check_result(current_epoch, current_version, pkgdir, force_check_srcinfo): def get_srcinfo_check_result(
ver_success, pkgepoch, pkgver, pkgrel = get_pkgbuild_version(pkgdir, force_check_srcinfo) current_epoch, current_version, pkgdir, force_check_srcinfo
):
ver_success, pkgepoch, pkgver, pkgrel = get_pkgbuild_version(
pkgdir, force_check_srcinfo
)
if ver_success: if ver_success:
if current_epoch is None and pkgepoch is not None: if current_epoch is None and pkgepoch is not None:
log_print( log_print(
@ -410,14 +418,23 @@ def get_srcinfo_check_result(current_epoch, current_version, pkgdir, force_check
) )
) )
return "done" return "done"
elif current_epoch is not None and pkgepoch is not None and int(current_epoch) < int(pkgepoch): elif (
current_epoch is not None
and pkgepoch is not None
and int(current_epoch) < int(pkgepoch)
):
log_print( log_print(
'Current installed version of "{}" is out of date (older epoch).'.format( 'Current installed version of "{}" is out of date (older epoch).'.format(
pkg_state[pkgdir]["pkg_name"] pkg_state[pkgdir]["pkg_name"]
) )
) )
return "install" return "install"
elif pkgver is not None and pkgrel is not None and version.parse(current_version) < version.parse(pkgver + "-" + pkgrel): elif (
pkgver is not None
and pkgrel is not None
and version.parse(current_version)
< version.parse(pkgver + "-" + pkgrel)
):
log_print( log_print(
'Current installed version of "{}" is out of date (older version).'.format( 'Current installed version of "{}" is out of date (older version).'.format(
pkg_state[pkgdir]["pkg_name"] pkg_state[pkgdir]["pkg_name"]
@ -439,6 +456,7 @@ def get_srcinfo_check_result(current_epoch, current_version, pkgdir, force_check
) )
return "fail" return "fail"
def get_pkg_current_version(pkgdir, pkg_state, repo): def get_pkg_current_version(pkgdir, pkg_state, repo):
"""Returns (status, epoch, version)""" """Returns (status, epoch, version)"""
log_print( log_print(
@ -822,7 +840,10 @@ def update_pkg_list(
"/usr/bin/ln", "/usr/bin/ln",
"-sf", "-sf",
repo_sig_name, repo_sig_name,
str(os.path.join(pkg_out_dir, f"{repo}")).removesuffix(".tar") + ".sig", str(os.path.join(pkg_out_dir, f"{repo}")).removesuffix(
".tar"
)
+ ".sig",
] ]
) )
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
@ -1125,7 +1146,9 @@ if __name__ == "__main__":
update_pkg_dir_count = 0 update_pkg_dir_count = 0
update_pkg_dir_success = False update_pkg_dir_success = False
while update_pkg_dir_count < 5: while update_pkg_dir_count < 5:
(success, skip_on_same_ver) = update_pkg_dir(pkg_list[i], pkg_state) (success, skip_on_same_ver) = update_pkg_dir(
pkg_list[i], pkg_state
)
if success: if success:
update_pkg_dir_success = True update_pkg_dir_success = True
break break
@ -1137,9 +1160,11 @@ if __name__ == "__main__":
print_state_info_and_get_update_list(pkg_state) print_state_info_and_get_update_list(pkg_state)
sys.exit(1) sys.exit(1)
if skip_on_same_ver: if skip_on_same_ver:
check_pkg_version_result = check_pkg_version(pkg_list[i], pkg_state, args_repo, True) check_pkg_version_result = check_pkg_version(
pkg_list[i], pkg_state, args_repo, True
)
if check_pkg_version_result != "install": if check_pkg_version_result != "install":
log_print(f'Pkg {pkg_list[i]} is up to date, skipping...') log_print(f"Pkg {pkg_list[i]} is up to date, skipping...")
pkg_state[pkg_list[i]]["state"] = "up to date" pkg_state[pkg_list[i]]["state"] = "up to date"
i += 1 i += 1
continue continue
@ -1168,7 +1193,9 @@ if __name__ == "__main__":
if skip_on_same_ver and check_pkg_version_result is not None: if skip_on_same_ver and check_pkg_version_result is not None:
state_result = check_pkg_version_result state_result = check_pkg_version_result
else: else:
state_result = check_pkg_version(pkg_list[i], pkg_state, args_repo, False) state_result = check_pkg_version(
pkg_list[i], pkg_state, args_repo, False
)
confirm_result_result = confirm_result(pkg_list[i], state_result) confirm_result_result = confirm_result(pkg_list[i], state_result)
if confirm_result_result == "continue": if confirm_result_result == "continue":
pkg_state[pkg_list[i]]["state"] = state_result pkg_state[pkg_list[i]]["state"] = state_result