]>
Commit | Line | Data |
---|---|---|
9137135a MT |
1 | #!/usr/bin/python |
2 | ||
3 | import database | |
4 | import settings | |
5 | import uploads | |
6 | ||
7 | from build import Builds | |
8 | from builders import Builders | |
9 | from distribution import Distributions | |
10 | from messages import Messages | |
11 | from packages import Packages | |
12 | from repository import Repositories | |
13 | from sources import Sources | |
14 | from users import Users | |
15 | ||
16 | # Database access. | |
17 | MYSQL_SERVER = "mysql.ipfire.org" | |
18 | MYSQL_USER = "pakfire" | |
19 | MYSQL_DB = "pakfire" | |
20 | ||
21 | class Pakfire(object): | |
22 | def __init__(self): | |
23 | self.db = database.Connection(MYSQL_SERVER, MYSQL_DB, user=MYSQL_USER) | |
24 | ||
25 | # Global pakfire settings (from database). | |
26 | self.settings = settings.Settings(self) | |
27 | ||
28 | self.builds = Builds(self) | |
29 | self.builders = Builders(self) | |
30 | self.distros = Distributions(self) | |
31 | self.messages = Messages(self) | |
32 | self.packages = Packages(self) | |
33 | self.repos = Repositories(self) | |
34 | self.sources = Sources(self) | |
35 | self.uploads = uploads.Uploads(self) | |
36 | self.users = Users(self) | |
37 | ||
38 | def __del__(self): | |
39 | if self.db: | |
40 | self.db.close() | |
41 | del self.db | |
42 | ||
43 | def logger(self, message, text=None, build=None, pkg=None): | |
44 | if not build and not pkg: | |
45 | raise Exception, "need to give at least one parameter for log" | |
46 | ||
47 | log_id = self.db.execute("INSERT INTO `log`(message, text) VALUES(%s, %s)", message, text) | |
48 | ||
49 | query = "UPDATE `log` SET %s = %%s WHERE id = %%s" | |
50 | ||
51 | if build: | |
52 | self.db.execute(query % "build_id", build.id, log_id) | |
53 | ||
54 | if build.host: | |
55 | self.db.execute(query % "host_id", build.host.id, log_id) | |
56 | ||
57 | pkg = getattr(build, "pkg", None) | |
58 | ||
59 | if pkg: | |
60 | self.db.execute(query % "pkg_id", pkg.id, log_id) | |
61 | self.db.execute(query % "source_id", pkg.source.id, log_id) | |
62 | ||
63 | return log_id | |
64 | ||
65 | @property | |
66 | def log(self, limit=100): | |
67 | return self.db.query("SELECT * FROM log ORDER BY time DESC LIMIT %s", limit) |