Skip to content

Commit 7fd3c93

Browse files
committed
WIP: feat: add script to generate report about new packages
Signed-off-by: Christopher Arndt <[email protected]>
1 parent ec41aad commit 7fd3c93

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ src/
2020
/out2
2121
/out-debug
2222
/.hugo_build.lock
23+
/tools/history.db
24+
/tools/package-db

tools/getnewpackages.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/usr/bin/env python
2+
"""Get newest packages from an Arch package database."""
3+
4+
import argparse
5+
import shelve
6+
import pyalpm
7+
from datetime import datetime, timedelta
8+
from operator import attrgetter
9+
10+
PROG = "getnewpackages"
11+
PKG_ATTRS = [
12+
"arch",
13+
"backup",
14+
"base",
15+
"base64_sig",
16+
"builddate",
17+
"checkdepends",
18+
"conflicts",
19+
"depends",
20+
"desc",
21+
"download_size",
22+
"filename",
23+
"files",
24+
"groups",
25+
"licenses",
26+
"makedepends",
27+
"md5sum",
28+
"name",
29+
"optdepends",
30+
"packager",
31+
"provides",
32+
"replaces",
33+
"sha256sum",
34+
"size",
35+
"url",
36+
"version",
37+
]
38+
39+
40+
def main(args=None):
41+
ap = argparse.ArgumentParser(prog=PROG, description=__doc__.splitlines()[0])
42+
ap.add_argument(
43+
"-d",
44+
"--db",
45+
metavar="NAME",
46+
default="proaudio",
47+
help="package database name (default: %(default)r)",
48+
)
49+
ap.add_argument(
50+
"-i",
51+
"--interval",
52+
type=int,
53+
default=7,
54+
help="interval in days (default: %(default)i days)",
55+
)
56+
ap.add_argument(
57+
"-H",
58+
"--history-file",
59+
metavar="FILE",
60+
default="history.db",
61+
help="history database file name (default: %(default)r)",
62+
)
63+
ap.add_argument(
64+
"-I",
65+
"--ignore-history",
66+
action="store_true",
67+
help="Report new package versions, even when they are already in the history database",
68+
)
69+
ap.add_argument(
70+
"-N",
71+
"--no-history-update",
72+
action="store_true",
73+
help="Do not update history database",
74+
)
75+
ap.add_argument(
76+
"dbpath",
77+
nargs="?",
78+
metavar="DIR",
79+
default="package-db",
80+
help="database root path (default: %(default)r)",
81+
)
82+
83+
args = ap.parse_args(args)
84+
85+
handle = pyalpm.Handle(".", args.dbpath)
86+
pkgdb = handle.register_syncdb(args.db, pyalpm.SIG_DATABASE_OPTIONAL)
87+
88+
hstdb = shelve.open(args.history_file, writeback=True)
89+
90+
now = datetime.utcnow()
91+
then = now - timedelta(days=args.interval)
92+
93+
new = []
94+
95+
for pkg in pkgdb.search(""):
96+
versions = hstdb.get(pkg.name, {})
97+
if datetime.fromtimestamp(pkg.builddate) >= then and (
98+
args.ignore_history or pkg.version not in versions
99+
):
100+
new.append(pkg)
101+
102+
# Update history DB
103+
if not args.no_history_update:
104+
for pkg in pkgdb.search(""):
105+
if pkg.name not in hstdb:
106+
hstdb[pkg.name] = {}
107+
108+
if (
109+
pkg.version not in hstdb[pkg.name]
110+
or hstdb[pkg.name][pkg.version]["builddate"] < pkg.builddate
111+
):
112+
hstdb[pkg.name][pkg.version] = {attr: getattr(pkg, attr) for attr in PKG_ATTRS}
113+
114+
hstdb.close()
115+
116+
for pkg in sorted(new, key=attrgetter('builddate')):
117+
print(f"{pkg.name}, {pkg.version}, {pkg.desc}")
118+
119+
120+
if __name__ == "__main__":
121+
import sys
122+
123+
sys.exit(main() or 0)

tools/reportnewpackages.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash -x
2+
3+
PKGDB_URL="https://arch.osamc.de/proaudio/x86_64/proaudio.db"
4+
INTERVAL=14
5+
ETAG="./package-db/sync/proaudio.db.etag"
6+
CURL_OPTS="--etag-save $ETAG"
7+
8+
mkdir -p ./package-db/sync
9+
10+
if [[ -f "$ETAG" ]]; then
11+
CURL_OPTS="$CURL_OPTS --etag-compare $ETAG"
12+
fi
13+
curl --silent \
14+
--compressed \
15+
--remote-time \
16+
-o ./package-db/sync/proaudio.db \
17+
$CURL_OPTS \
18+
"$PKGDB_URL"
19+
python getnewpackages.py \
20+
--db proaudio \
21+
--history-file history.db \
22+
--interval $INTERVAL \
23+
"$@" \
24+
$(pwd)/package-db

0 commit comments

Comments
 (0)