Fix no default editor, log_print instead of print
This commit is contained in:
parent
4f957ba5f9
commit
f38e97512c
1 changed files with 24 additions and 19 deletions
43
update.py
43
update.py
|
@ -22,6 +22,7 @@ AUR_GIT_REPO_PATH = "https://aur.archlinux.org"
|
||||||
AUR_GIT_REPO_PATH_TEMPLATE = AUR_GIT_REPO_PATH + "/{}.git"
|
AUR_GIT_REPO_PATH_TEMPLATE = AUR_GIT_REPO_PATH + "/{}.git"
|
||||||
global GLOBAL_LOG_FILE
|
global GLOBAL_LOG_FILE
|
||||||
GLOBAL_LOG_FILE = "log.txt"
|
GLOBAL_LOG_FILE = "log.txt"
|
||||||
|
DEFAULT_EDITOR = "/usr/bin/nano"
|
||||||
|
|
||||||
|
|
||||||
def log_print(string):
|
def log_print(string):
|
||||||
|
@ -48,7 +49,7 @@ def ensure_pkg_dir_exists(pkg, pkg_state):
|
||||||
cwd=SCRIPT_DIR,
|
cwd=SCRIPT_DIR,
|
||||||
)
|
)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
print(
|
log_print(
|
||||||
'ERROR: Failed to git clone "{}" (tried repo path "{}")'.format(
|
'ERROR: Failed to git clone "{}" (tried repo path "{}")'.format(
|
||||||
pkg_dir, pkg_state[pkg]["repo_path"]
|
pkg_dir, pkg_state[pkg]["repo_path"]
|
||||||
)
|
)
|
||||||
|
@ -122,14 +123,14 @@ def update_pkg_dir(pkg, state):
|
||||||
selected_remote = remote.strip()
|
selected_remote = remote.strip()
|
||||||
break
|
break
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
print(
|
log_print(
|
||||||
'ERROR: Failed to update pkg dir of "{}" (getting branch\'s remote).'.format(
|
'ERROR: Failed to update pkg dir of "{}" (getting branch\'s remote).'.format(
|
||||||
pkg
|
pkg
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return False, False
|
return False, False
|
||||||
if len(selected_remote) == 0:
|
if len(selected_remote) == 0:
|
||||||
print(
|
log_print(
|
||||||
'ERROR: Failed to update pkg dir of "{}" (getting branch\'s remote).'.format(
|
'ERROR: Failed to update pkg dir of "{}" (getting branch\'s remote).'.format(
|
||||||
pkg
|
pkg
|
||||||
)
|
)
|
||||||
|
@ -148,14 +149,14 @@ def update_pkg_dir(pkg, state):
|
||||||
)
|
)
|
||||||
current_branch_hash = result.stdout.strip()
|
current_branch_hash = result.stdout.strip()
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
print(
|
log_print(
|
||||||
'ERROR: Failed to update pkg dir of "{}" (getting current branch\'s hash).'.format(
|
'ERROR: Failed to update pkg dir of "{}" (getting current branch\'s hash).'.format(
|
||||||
pkg
|
pkg
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return False, False
|
return False, False
|
||||||
if len(current_branch_hash.strip()) == 0:
|
if len(current_branch_hash.strip()) == 0:
|
||||||
print(
|
log_print(
|
||||||
'ERROR: Failed to update pkg dir of "{}" (getting current branch\'s hash).'.format(
|
'ERROR: Failed to update pkg dir of "{}" (getting current branch\'s hash).'.format(
|
||||||
pkg
|
pkg
|
||||||
)
|
)
|
||||||
|
@ -174,14 +175,14 @@ def update_pkg_dir(pkg, state):
|
||||||
)
|
)
|
||||||
remote_branch_hash = result.stdout.strip()
|
remote_branch_hash = result.stdout.strip()
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
print(
|
log_print(
|
||||||
'ERROR: Failed to update pkg dir of "{}" (getting remote branch\'s hash).'.format(
|
'ERROR: Failed to update pkg dir of "{}" (getting remote branch\'s hash).'.format(
|
||||||
pkg
|
pkg
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return False, False
|
return False, False
|
||||||
if len(remote_branch_hash.strip()) == 0:
|
if len(remote_branch_hash.strip()) == 0:
|
||||||
print(
|
log_print(
|
||||||
'ERROR: Failed to update pkg dir of "{}" (getting remote branch\'s hash).'.format(
|
'ERROR: Failed to update pkg dir of "{}" (getting remote branch\'s hash).'.format(
|
||||||
pkg
|
pkg
|
||||||
)
|
)
|
||||||
|
@ -259,13 +260,13 @@ def check_pkg_version(pkgdir, pkg_state, repo, force_check_srcinfo):
|
||||||
if status != "fetched":
|
if status != "fetched":
|
||||||
return status
|
return status
|
||||||
elif current_version is None:
|
elif current_version is None:
|
||||||
print(
|
log_print(
|
||||||
'ERROR: Failed to get version from package "{}".'.format(
|
'ERROR: Failed to get version from package "{}".'.format(
|
||||||
pkg_state[pkgdir]["pkg_name"]
|
pkg_state[pkgdir]["pkg_name"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return "fail"
|
return "fail"
|
||||||
print(
|
log_print(
|
||||||
'Got version "{}:{}" for installed pkg "{}"'.format(
|
'Got version "{}:{}" for installed pkg "{}"'.format(
|
||||||
current_epoch if current_epoch is not None else "0",
|
current_epoch if current_epoch is not None else "0",
|
||||||
current_version,
|
current_version,
|
||||||
|
@ -396,42 +397,42 @@ def get_srcinfo_check_result(current_epoch, current_version, pkgdir, force_check
|
||||||
ver_success, pkgepoch, pkgver, pkgrel = get_pkgbuild_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:
|
||||||
print(
|
log_print(
|
||||||
'Current installed version of "{}" is out of date (missing epoch).'.format(
|
'Current installed version of "{}" is out of date (missing epoch).'.format(
|
||||||
pkg_state[pkgdir]["pkg_name"]
|
pkg_state[pkgdir]["pkg_name"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return "install"
|
return "install"
|
||||||
elif current_epoch is not None and pkgepoch is None:
|
elif current_epoch is not None and pkgepoch is None:
|
||||||
print(
|
log_print(
|
||||||
'Current installed version of "{}" is up to date (has epoch).'.format(
|
'Current installed version of "{}" is up to date (has epoch).'.format(
|
||||||
pkg_state[pkgdir]["pkg_name"]
|
pkg_state[pkgdir]["pkg_name"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
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):
|
||||||
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):
|
||||||
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"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return "install"
|
return "install"
|
||||||
else:
|
else:
|
||||||
print(
|
log_print(
|
||||||
'Current installed version of "{}" is up to date.'.format(
|
'Current installed version of "{}" is up to date.'.format(
|
||||||
pkg_state[pkgdir]["pkg_name"]
|
pkg_state[pkgdir]["pkg_name"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return "done"
|
return "done"
|
||||||
else:
|
else:
|
||||||
print(
|
log_print(
|
||||||
'ERROR: Failed to get pkg_version of "{}"'.format(
|
'ERROR: Failed to get pkg_version of "{}"'.format(
|
||||||
pkg_state[pkgdir]["pkg_name"]
|
pkg_state[pkgdir]["pkg_name"]
|
||||||
)
|
)
|
||||||
|
@ -440,7 +441,7 @@ def get_srcinfo_check_result(current_epoch, current_version, pkgdir, force_check
|
||||||
|
|
||||||
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)"""
|
||||||
print(
|
log_print(
|
||||||
'Checking version of installed pkg "{}"...'.format(
|
'Checking version of installed pkg "{}"...'.format(
|
||||||
pkg_state[pkgdir]["pkg_name"]
|
pkg_state[pkgdir]["pkg_name"]
|
||||||
)
|
)
|
||||||
|
@ -471,7 +472,7 @@ def get_pkg_current_version(pkgdir, pkg_state, repo):
|
||||||
if not result_dict["version"] is None:
|
if not result_dict["version"] is None:
|
||||||
current_version = result_dict["version"]
|
current_version = result_dict["version"]
|
||||||
else:
|
else:
|
||||||
print(
|
log_print(
|
||||||
"ERROR: Failed to get current version from repo for package {}".format(
|
"ERROR: Failed to get current version from repo for package {}".format(
|
||||||
pkg_state[pkgdir]["pkg_name"]
|
pkg_state[pkgdir]["pkg_name"]
|
||||||
)
|
)
|
||||||
|
@ -855,7 +856,7 @@ def get_latest_pkg(pkg, cache_dir):
|
||||||
def confirm_result(pkg, state_result):
|
def confirm_result(pkg, state_result):
|
||||||
"""Returns "continue", "recheck", "force_build", or "abort"."""
|
"""Returns "continue", "recheck", "force_build", or "abort"."""
|
||||||
while True:
|
while True:
|
||||||
print(
|
log_print(
|
||||||
'Got "{}" for pkg "{}", action: [C(ontinue), r(echeck), f(orce build),\
|
'Got "{}" for pkg "{}", action: [C(ontinue), r(echeck), f(orce build),\
|
||||||
s(kip), b(ack) a(abort)]'.format(
|
s(kip), b(ack) a(abort)]'.format(
|
||||||
state_result, pkg
|
state_result, pkg
|
||||||
|
@ -924,6 +925,7 @@ def test_gpg_passphrase(signing_gpg_dir, signing_key_fp, passphrase):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
editor = None
|
||||||
parser = argparse.ArgumentParser(description="Update AUR pkgs")
|
parser = argparse.ArgumentParser(description="Update AUR pkgs")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--config", help="Info and pkg(s) to update in a .toml config"
|
"--config", help="Info and pkg(s) to update in a .toml config"
|
||||||
|
@ -974,7 +976,7 @@ if __name__ == "__main__":
|
||||||
or not args.logs_dir
|
or not args.logs_dir
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
print(
|
log_print(
|
||||||
"ERROR: --pkg requires also --chroot, --pkg_dir, --repo, --gpg_dir, and --logs_dir"
|
"ERROR: --pkg requires also --chroot, --pkg_dir, --repo, --gpg_dir, and --logs_dir"
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -1085,6 +1087,9 @@ if __name__ == "__main__":
|
||||||
if args.editor is not None:
|
if args.editor is not None:
|
||||||
editor = args.editor
|
editor = args.editor
|
||||||
|
|
||||||
|
if editor is None:
|
||||||
|
editor = DEFAULT_EDITOR
|
||||||
|
|
||||||
os.putenv("CHROOT", os.path.realpath(args_chroot))
|
os.putenv("CHROOT", os.path.realpath(args_chroot))
|
||||||
os.putenv("GNUPGHOME", os.path.realpath(args_gpg_home))
|
os.putenv("GNUPGHOME", os.path.realpath(args_gpg_home))
|
||||||
if not os.path.exists(args_logs_dir):
|
if not os.path.exists(args_logs_dir):
|
||||||
|
|
Loading…
Reference in a new issue