]> git.ipfire.org Git - people/stevee/pakfire.git/blob - python/pakfire/repository/system.py
Cleanup database and add indexes.
[people/stevee/pakfire.git] / python / pakfire / repository / system.py
1 #!/usr/bin/python
2 ###############################################################################
3 # #
4 # Pakfire - The IPFire package management system #
5 # Copyright (C) 2011 Pakfire development team #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 import os
23
24 import base
25 import database
26
27 import pakfire.packages as packages
28 import pakfire.util as util
29
30 from pakfire.constants import *
31 from pakfire.i18n import _
32
33 class RepositorySystem(base.RepositoryFactory):
34 def __init__(self, pakfire):
35 base.RepositoryFactory.__init__(self, pakfire, "@system", "Local repository")
36
37 # Open database connection.
38 self.db = database.DatabaseLocal(self.pakfire, self)
39
40 # Tell the solver, that these are the installed packages.
41 self.pool.set_installed(self.solver_repo)
42
43 @property
44 def cache_file(self):
45 return os.path.join(self.pakfire.path, PACKAGES_SOLV)
46
47 @property
48 def priority(self):
49 """
50 The local repository has always a high priority.
51 """
52 return 10
53
54 def open(self):
55 # Initialize database.
56 self.db.initialize()
57
58 # Create a progressbar.
59 pb = util.make_progress(_("Loading installed packages"), len(self.db))
60
61 # Remove all data from the current index.
62 self.index.clear()
63
64 i = 0
65 for pkg in self.db.packages:
66 if pb:
67 i += 1
68 pb.update(i)
69
70 self.index.add_package(pkg)
71
72 self.index.optimize()
73
74 if pb:
75 pb.finish()
76
77 # Mark repo as open.
78 self.opened = True
79
80 def close(self):
81 # Commit all data that is currently pending for writing.
82 self.db.commit()
83
84 # Close database.
85 self.db.close()
86
87 # Remove indexed data from memory.
88 self.index.clear()
89
90 # Mark repo as closed.
91 self.opened = False
92
93 def commit(self):
94 # Commit the database to disk.
95 self.db.commit()
96
97 # Make sure that all data in the index is accessable.
98 self.index.optimize()
99
100 # Write the content of the index to a file
101 # for fast parsing.
102 # XXX this is currently disabled
103 #self.index.write(self.cache_file)
104
105 def add_package(self, pkg):
106 # Add package to the database.
107 self.db.add_package(pkg)
108 self.index.add_package(pkg)
109
110 def rem_package(self, pkg):
111 assert isinstance(pkg, packages.SolvPackage), pkg
112
113 # Remove package from the database.
114 self.db.rem_package(pkg)
115
116 @property
117 def filelist(self):
118 return self.db.get_filelist()