diff options
author | chrisjbillington | 2020-02-20 22:04:09 -0500 |
---|---|---|
committer | chrisjbillington | 2020-02-20 22:04:09 -0500 |
commit | c783cc83e7b90634321ff3534afa64919b5dc0b9 (patch) | |
tree | 01bcc8de68f66e916878ceeaec93e65f186987ee /update.py | |
parent | fd8685c927eac62ff6191860071576a578187a51 (diff) | |
download | aur-c783cc83e7b90634321ff3534afa64919b5dc0b9.tar.gz |
Get rid of eval for package names
Instead add a Python script to update the PKGBUILD with new package
names.
Change grub hook optdepends to grub-mkconfig-hook, as the former
seems abandoned.
Diffstat (limited to 'update.py')
-rw-r--r-- | update.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/update.py b/update.py new file mode 100644 index 000000000000..88f72edc59a0 --- /dev/null +++ b/update.py @@ -0,0 +1,62 @@ +import subprocess +import json +import sys + +# Script to update the PKGBUILD to the latest [core]/linux + +url = "https://www.archlinux.org/packages/core/x86_64/linux/json/" + +data = subprocess.check_output(['curl', '-s', url]).decode() +info = json.loads(data) +latest_kernver, latest_archver = info['pkgver'].rsplit('.', 1) +latest_archrel = info['pkgrel'] + +kernver, archver, archrel, pkgrel = subprocess.check_output( + ['bash', '-c', f'source PKGBUILD; echo $_kernver $_archver $_pkgrel $pkgrel'] +).decode('utf8').strip().split() + +if (kernver, archver, archrel) != (latest_kernver, latest_archver, latest_archrel): + print("out of date!") + with open('PKGBUILD') as f: + pkgbuild = f.read() + + replacements = ( + (f'_kernver={kernver}', f'_kernver={latest_kernver}'), + (f'_archver={archver}', f'_archver={latest_archver}'), + (f'_pkgrel={archrel}', f'_pkgrel={latest_archrel}'), + ( + f'{kernver}-{archver}-{archrel}', + f'{latest_kernver}-{latest_archver}-{latest_archrel}', + ), + ) + + for a, b in replacements: + pkgbuild = pkgbuild.replace(a, b) + + if kernver == latest_kernver: + pkgbuild = pkgbuild.replace(f'\npkgrel={pkgrel}', f'\npkgrel={int(pkgrel)+1}') + else: + pkgbuild = pkgbuild.replace(f'\npkgrel={pkgrel}', f'\npkgrel=1') + + with open('PKGBUILD', 'w') as f: + f.write(pkgbuild) + + subprocess.check_call(['updpkgsums']) + + with open('.SRCINFO', 'w') as f: + f.write(subprocess.check_output(['makepkg', '--printsrcinfo']).decode()) + + subprocess.check_call(['git', 'add', 'PKGBUILD', '.SRCINFO']) + subprocess.check_call(['git', 'commit', '-m', f'{kernver}-{archver}-{archrel}']) + + def yn_choice(message, default='y'): + try: + choices = 'Y/n' if default.lower() in ('y', 'yes') else 'y/N' + choice = input("%s\n(%s): " % (message, choices)) + values = ('y', 'yes', '') if default == 'y' else ('y', 'yes') + return choice.strip().lower() in values + except (KeyboardInterrupt, EOFError): + sys.exit(1) + + if yn_choice('git push?'): + subprocess.check_call(['git', 'push']) |