aurblup.py 1.67 KB
Newer Older
Lukas Fleischer's avatar
Lukas Fleischer committed
1
2
3
#!/usr/bin/python3

import pyalpm
4
import re
Lukas Fleischer's avatar
Lukas Fleischer committed
5

Lukas Fleischer's avatar
Lukas Fleischer committed
6
7
import aurweb.config
import aurweb.db
Lukas Fleischer's avatar
Lukas Fleischer committed
8

Lukas Fleischer's avatar
Lukas Fleischer committed
9
10
db_path = aurweb.config.get('aurblup', 'db-path')
sync_dbs = aurweb.config.get('aurblup', 'sync-dbs').split(' ')
11
server = aurweb.config.get('aurblup', 'server')
Lukas Fleischer's avatar
Lukas Fleischer committed
12

13
14
15
16
17
18
19
20
21

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)
22
        repo.servers = [server.replace("%s", sync_db)]
23
24
25
26
27
28
29
30
31
32
33
34
35
36
        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

Lukas Fleischer's avatar
Lukas Fleischer committed
37
    conn = aurweb.db.Connection()
38

Lukas Fleischer's avatar
Lukas Fleischer committed
39
    cur = conn.execute("SELECT Name, Provides FROM OfficialProviders")
40
41
42
43
    oldproviders = set(cur.fetchall())

    for pkg, provides in providers.difference(oldproviders):
        repo = repomap[(pkg, provides)]
Lukas Fleischer's avatar
Lukas Fleischer committed
44
45
        conn.execute("INSERT INTO OfficialProviders (Name, Repo, Provides) "
                     "VALUES (?, ?, ?)", [pkg, repo, provides])
46
    for pkg, provides in oldproviders.difference(providers):
Lukas Fleischer's avatar
Lukas Fleischer committed
47
48
        conn.execute("DELETE FROM OfficialProviders "
                     "WHERE Name = ? AND Provides = ?", [pkg, provides])
49

Lukas Fleischer's avatar
Lukas Fleischer committed
50
51
    conn.commit()
    conn.close()
52
53
54
55


if __name__ == '__main__':
    main()