Add missing database and account fields
[aur.git] / scripts / aurblup.py
blob6733b45d023945b32e83bb0d417a2a05d24c5957
1 #!/usr/bin/python3
3 import configparser
4 import mysql.connector
5 import os
6 import pyalpm
7 import re
9 config = configparser.RawConfigParser()
10 config.read(os.path.dirname(os.path.realpath(__file__)) + "/../conf/config")
12 aur_db_host = config.get('database', 'host')
13 aur_db_name = config.get('database', 'name')
14 aur_db_user = config.get('database', 'user')
15 aur_db_pass = config.get('database', 'password')
16 aur_db_socket = config.get('database', 'socket')
17 db_path = config.get('aurblup', 'db-path')
18 sync_dbs = config.get('aurblup', 'sync-dbs').split(' ')
19 servers = config.get('aurblup', 'servers').split(' ')
21 blacklist = set()
22 providers = set()
23 repomap = dict()
25 h = pyalpm.Handle("/", db_path)
26 for sync_db in sync_dbs:
27 repo = h.register_syncdb(sync_db, pyalpm.SIG_DATABASE_OPTIONAL)
28 repo.servers = [server.replace("%s", sync_db) for server in servers]
29 t = h.init_transaction()
30 repo.update(False)
31 t.release()
33 for pkg in repo.pkgcache:
34 blacklist.add(pkg.name)
35 [blacklist.add(x) for x in pkg.replaces]
36 providers.add((pkg.name, pkg.name))
37 repomap[(pkg.name, pkg.name)] = repo.name
38 for provision in pkg.provides:
39 provisionname = re.sub(r'(<|=|>).*', '', provision)
40 providers.add((pkg.name, provisionname))
41 repomap[(pkg.name, provisionname)] = repo.name
43 db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
44 passwd=aur_db_pass, db=aur_db_name,
45 unix_socket=aur_db_socket, buffered=True)
46 cur = db.cursor()
48 cur.execute("SELECT Name, Provides FROM OfficialProviders")
49 oldproviders = set(cur.fetchall())
51 for pkg, provides in providers.difference(oldproviders):
52 repo = repomap[(pkg, provides)]
53 cur.execute("INSERT INTO OfficialProviders (Name, Repo, Provides) "
54 "VALUES (%s, %s, %s)", [pkg, repo, provides])
55 for pkg, provides in oldproviders.difference(providers):
56 cur.execute("DELETE FROM OfficialProviders "
57 "WHERE Name = %s AND Provides = %s", [pkg, provides])
59 db.commit()
60 db.close()