summaryrefslogtreecommitdiff
path: root/aurweb/scripts/aurblup.py
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2016-10-17 15:34:21 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2016-10-17 15:34:21 +0200
commitfdd932ff8d5e5899cfeae9a8b29011fa2cf9d439 (patch)
tree07afb8664e18e4d4fb479525b16db6edf026b72b /aurweb/scripts/aurblup.py
parentb091fb77580d56dbdca6424f9065581945b8e815 (diff)
parentc3f464f50fb35ffb7825b90437bd912051a994ee (diff)
Merge branch 'master' into maintaurweb/maint
Diffstat (limited to 'aurweb/scripts/aurblup.py')
-rwxr-xr-xaurweb/scripts/aurblup.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/aurweb/scripts/aurblup.py b/aurweb/scripts/aurblup.py
new file mode 100755
index 0000000..1b6de2f
--- /dev/null
+++ b/aurweb/scripts/aurblup.py
@@ -0,0 +1,55 @@
+#!/usr/bin/python3
+
+import pyalpm
+import re
+
+import aurweb.config
+import aurweb.db
+
+db_path = aurweb.config.get('aurblup', 'db-path')
+sync_dbs = aurweb.config.get('aurblup', 'sync-dbs').split(' ')
+server = aurweb.config.get('aurblup', 'server')
+
+
+def main():
+ blacklist = set()
+ providers = set()
+ repomap = dict()
+
+ h = pyalpm.Handle("/", db_path)
+ for sync_db in sync_dbs:
+ repo = h.register_syncdb(sync_db, pyalpm.SIG_DATABASE_OPTIONAL)
+ repo.servers = [server.replace("%s", sync_db)]
+ t = h.init_transaction()
+ repo.update(False)
+ t.release()
+
+ for pkg in repo.pkgcache:
+ blacklist.add(pkg.name)
+ [blacklist.add(x) for x in pkg.replaces]
+ providers.add((pkg.name, pkg.name))
+ repomap[(pkg.name, pkg.name)] = repo.name
+ for provision in pkg.provides:
+ provisionname = re.sub(r'(<|=|>).*', '', provision)
+ providers.add((pkg.name, provisionname))
+ repomap[(pkg.name, provisionname)] = repo.name
+
+ conn = aurweb.db.Connection()
+
+ cur = conn.execute("SELECT Name, Provides FROM OfficialProviders")
+ oldproviders = set(cur.fetchall())
+
+ for pkg, provides in providers.difference(oldproviders):
+ repo = repomap[(pkg, provides)]
+ conn.execute("INSERT INTO OfficialProviders (Name, Repo, Provides) "
+ "VALUES (?, ?, ?)", [pkg, repo, provides])
+ for pkg, provides in oldproviders.difference(providers):
+ conn.execute("DELETE FROM OfficialProviders "
+ "WHERE Name = ? AND Provides = ?", [pkg, provides])
+
+ conn.commit()
+ conn.close()
+
+
+if __name__ == '__main__':
+ main()