summarylogtreecommitdiffstats
path: root/update.py
diff options
context:
space:
mode:
authorchrisjbillington2021-03-07 17:06:54 +1100
committerchrisjbillington2021-03-07 17:06:54 +1100
commit71bbe14366ef133a0d78a85a12986ae9cb0a795d (patch)
treeb2b86c7e05c254bce5c54c425d9228e80f16b992 /update.py
parent22fe8097749003fc8720cdedc94c343892e8afa5 (diff)
downloadaur-71bbe14366ef133a0d78a85a12986ae9cb0a795d.tar.gz
Check if out of date using local databases only
So that checking is faster and doesn't hit the server too often
Diffstat (limited to 'update.py')
-rw-r--r--update.py122
1 files changed, 66 insertions, 56 deletions
diff --git a/update.py b/update.py
index ee2494b4739c..1b3a01fa7000 100644
--- a/update.py
+++ b/update.py
@@ -1,83 +1,93 @@
-import sys
import subprocess
import json
import string
from pathlib import Path
-# Script to update the PKGBUILD to the latest [core]/linux
+NAME = 'linux-lts'
+
+# Script to update the PKGBUILD to the latest [core]/linux-lts
+
+def get_current():
+ cmd = ['bash', '-c', 'source PKGBUILD; echo ${pkgver}-${pkgrel}']
+ version = subprocess.check_output(cmd).decode('utf8').strip()
+ return version
+
+
+def get_latest():
+ cmd = ['pacman', '-Si', NAME]
+ info = subprocess.check_output(cmd).decode('utf8').strip()
+ version = info.split('Version', 1)[1].split(':', 1)[1].split('\n', 1)[0].strip()
+ return version
+
def get_info(pkgname):
url = f"https://archlinux.org/packages/core/x86_64/{pkgname}/json/"
data = subprocess.check_output(['curl', '-s', url]).decode()
return json.loads(data)
+
class Template(string.Template):
delimiter="%"
+
def arr(name, values):
delimiter = '\n' + ' ' * (len(name) + 4)
values = [f"'{value}'" if ':' in value else value for value in values]
return f"{name}=({delimiter.join(values)})"
-kern_info = get_info('linux-lts')
-headers_info = get_info('linux-lts-headers')
-docs_info = get_info('linux-lts-docs')
-
-template = Template(Path('PKGBUILD.template').read_text())
-
-pkgbuild = template.substitute(
- PKGVER=kern_info['pkgver'],
- PKGREL=kern_info['pkgrel'],
- URL=kern_info['url'],
- KERN_PKGDESC=kern_info['pkgdesc'],
- KERN_DEPENDS=arr("depends", kern_info['depends']),
- KERN_CONFLICTS=arr("conflicts", kern_info['conflicts'] + ['"${_pkgname}"']),
- KERN_OPTDEPENDS=arr("optdepends", kern_info['optdepends']),
- KERN_PROVIDES=arr("provides", kern_info['provides']),
- KERN_REPLACES=arr("replaces", kern_info['replaces']),
- HEADERS_PKGDESC=headers_info['pkgdesc'],
- HEADERS_DEPENDS=arr("depends", headers_info['depends']),
- HEADERS_CONFLICTS=arr(
- "conflicts", headers_info['conflicts'] + ['"${_pkgname}-headers"']
- ),
- HEADERS_OPTDEPENDS=arr("optdepends", headers_info['optdepends']),
- HEADERS_PROVIDES=arr("provides", headers_info['provides']),
- HEADERS_REPLACES=arr("replaces", headers_info['replaces']),
- DOCS_PKGDESC=docs_info['pkgdesc'],
- DOCS_DEPENDS=arr("depends", docs_info['depends']),
- DOCS_CONFLICTS=arr("conflicts", docs_info['conflicts'] + ['"${_pkgname}-docs"']),
- DOCS_OPTDEPENDS=arr("optdepends", docs_info['optdepends']),
- DOCS_PROVIDES=arr("provides", docs_info['provides']),
- DOCS_REPLACES=arr("replaces", docs_info['replaces']),
-)
-
-# Delete empty arrays:
-pkgbuild = '\n'.join(line for line in pkgbuild.splitlines() if not line.endswith('=()'))
-Path('PKGBUILD').write_text(pkgbuild + '\n')
-
-subprocess.check_call(['updpkgsums'])
-
-if subprocess.check_output(['git', 'diff', 'PKGBUILD']).strip():
- print("linux-lts-versioned-bin is out of date!")
+def update():
+ kern_info = get_info(NAME)
+ headers_info = get_info(f'{NAME}-headers')
+ docs_info = get_info(f'{NAME}-docs')
+
+ template = Template(Path('PKGBUILD.template').read_text())
+
+ pkgbuild = template.substitute(
+ PKGVER=kern_info['pkgver'],
+ PKGREL=kern_info['pkgrel'],
+ URL=kern_info['url'],
+ KERN_PKGDESC=kern_info['pkgdesc'],
+ KERN_DEPENDS=arr("depends", kern_info['depends']),
+ KERN_CONFLICTS=arr("conflicts", kern_info['conflicts'] + ['"${_pkgname}"']),
+ KERN_OPTDEPENDS=arr("optdepends", kern_info['optdepends']),
+ KERN_PROVIDES=arr("provides", kern_info['provides']),
+ KERN_REPLACES=arr("replaces", kern_info['replaces']),
+ HEADERS_PKGDESC=headers_info['pkgdesc'],
+ HEADERS_DEPENDS=arr("depends", headers_info['depends']),
+ HEADERS_CONFLICTS=arr(
+ "conflicts", headers_info['conflicts'] + ['"${_pkgname}-headers"']
+ ),
+ HEADERS_OPTDEPENDS=arr("optdepends", headers_info['optdepends']),
+ HEADERS_PROVIDES=arr("provides", headers_info['provides']),
+ HEADERS_REPLACES=arr("replaces", headers_info['replaces']),
+ DOCS_PKGDESC=docs_info['pkgdesc'],
+ DOCS_DEPENDS=arr("depends", docs_info['depends']),
+ DOCS_CONFLICTS=arr(
+ "conflicts", docs_info['conflicts'] + ['"${_pkgname}-docs"']
+ ),
+ DOCS_OPTDEPENDS=arr("optdepends", docs_info['optdepends']),
+ DOCS_PROVIDES=arr("provides", docs_info['provides']),
+ DOCS_REPLACES=arr("replaces", docs_info['replaces']),
+ )
+
+ # Delete empty arrays:
+ pkgbuild = '\n'.join(
+ line for line in pkgbuild.splitlines() if not line.endswith('=()')
+ )
+ Path('PKGBUILD').write_text(pkgbuild + '\n')
+ 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"{kern_info['pkgver']}-{kern_info['pkgrel']}"]
)
+ subprocess.check_call(['git', 'push'])
- 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'])
-else:
- print("linux-lts-versioned-bin is up to date")
+if __name__ == '__main__':
+ if get_current() == get_latest():
+ print(f"{NAME}-versioned-bin is up to date")
+ else:
+ print(f"{NAME}-versioned-bin is out of date!")
+ update()