aboutsummaryrefslogtreecommitdiff
blob: a4379df103d8c1274bf757dc612e1ba8756f817c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# written 2007 by Markus Ullmann <jokey@gentoo.org>
# License: GPL-2

"""core module"""

from backend import domain_repo_interface
import sys


def init_front_back():
    """initialize backend and frontend"""

    backend = domain_repo_interface()
    backend.set_domain_by_name("livefs domain")
    backend.set_work_repo_by_id("gentoo")

    from etc.database_config import DatabaseConfig
    database = None
    if DatabaseConfig.mode == 'sqlite':
        from database import SQLitePackageDB
        database = SQLitePackageDB(DatabaseConfig.settings['sqlite'])
    if DatabaseConfig.mode == 'mysql':
        from database import MySQLPackageDB
        database = MySQLPackageDB(DatabaseConfig.settings['mysql_rw'])
    if database is None:
        print "choose database in core.py first"
        sys.exit(1)

    return (backend, database)


def latest_changelog(full_changelog):
    """return latest message from changelog file"""

    changelog = ""
    if full_changelog != "No ChangeLog file there":
        partimestamp = full_changelog.split("\n\n", 3)
        tmp_changelog = partimestamp[1]
        if tmp_changelog.startswith("*"):
            tmp_changelog += "\n" + partimestamp[2]
        changelog = tmp_changelog.replace("  ", "")

    return changelog


def main():
    """build new / refresh current package database"""

    (backend, database) = init_front_back()

    #iter over all packages
    for (category, package) in backend.all_packages_list:
        max_timestamp = 0
        max_mtime = 0

        # iter over ebuilds for keyword data
        versions = backend.get_package_keywords_dict((category, package))
        for version, keywords_dict, mtime in versions:
            if not database.initdb:
                timestamp = database.find_cpv_mtime(category, package, version)
                max_timestamp = max(max_timestamp, timestamp)
                max_mtime = max(max_mtime, mtime)
                if timestamp >= mtime:
                    continue
            database.add_version(category, package, version, mtime)
            database.add_keywords(category, package, version, keywords_dict)

        if not database.initdb and max_timestamp >= max_mtime:
            #print "Skipping %s/%s" % (category, package)
            continue

        print "Working on %s/%s" % (category, package)

        # get general metadata
        description, homepage, pkglicense = backend.get_app_metadata((category, package))

        changelog = latest_changelog(backend.get_changelog((category, package)))

        #store metadata
        database.add_metadata(category, package, description, homepage,
            pkglicense, changelog)
        database.commit()

if __name__ == "__main__":
    main()

# vim:ts=4 et ft=python: