]>
Commit | Line | Data |
---|---|---|
a2d1644c | 1 | #!/usr/bin/python |
b792d887 MT |
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 | ############################################################################### | |
a2d1644c | 21 | |
8b6bc023 MT |
22 | import logging |
23 | log = logging.getLogger("pakfire") | |
24 | ||
964aa579 | 25 | from .. import satsolver |
0f8d6745 | 26 | |
964aa579 MT |
27 | from . import index |
28 | from . import packages | |
c605d735 | 29 | |
a2d1644c MT |
30 | class RepositoryFactory(object): |
31 | def __init__(self, pakfire, name, description): | |
32 | self.pakfire = pakfire | |
c605d735 MT |
33 | self.name = name |
34 | self.description = description | |
35 | ||
36 | # Reference to corresponding Repo object in the solver. | |
37 | self.solver_repo = satsolver.Repo(self.pool, self.name) | |
a7cd7a38 | 38 | self.solver_repo.set_priority(self.priority) |
a2d1644c | 39 | |
0f8d6745 MT |
40 | # Some repositories may have a cache. |
41 | self.cache = None | |
a2d1644c | 42 | |
0f8d6745 | 43 | log.debug("Initialized new repository: %s" % self) |
a2d1644c | 44 | |
0f8d6745 MT |
45 | # Create an index (in memory). |
46 | self.index = index.Index(self.pakfire, self) | |
d4c94aa5 | 47 | |
36b328f2 MT |
48 | # Marks if this repository has been opened. |
49 | self.opened = False | |
50 | ||
a2d1644c MT |
51 | def __repr__(self): |
52 | return "<%s %s>" % (self.__class__.__name__, self.name) | |
53 | ||
54 | def __cmp__(self, other): | |
55 | return cmp(self.priority * -1, other.priority * -1) or \ | |
56 | cmp(self.name, other.name) | |
57 | ||
c605d735 MT |
58 | def __len__(self): |
59 | return self.solver_repo.size() | |
60 | ||
8276111d MT |
61 | def __iter__(self): |
62 | pkgs = [] | |
63 | ||
64 | for solv in self.solver_repo.get_all(): | |
65 | pkg = packages.SolvPackage(self.pakfire, solv, self) | |
66 | pkgs.append(pkg) | |
67 | ||
68 | return iter(pkgs) | |
69 | ||
c605d735 MT |
70 | @property |
71 | def pool(self): | |
72 | return self.pakfire.pool | |
73 | ||
74 | def get_enabled(self): | |
75 | return self.solver_repo.get_enabled() | |
76 | ||
77 | def set_enabled(self, val): | |
78 | self.solver_repo.set_enabled(val) | |
79 | ||
80 | if val: | |
8b6bc023 | 81 | log.debug("Enabled repository '%s'." % self.name) |
c605d735 | 82 | else: |
8b6bc023 | 83 | log.debug("Disabled repository '%s'." % self.name) |
c605d735 MT |
84 | |
85 | enabled = property(get_enabled, set_enabled) | |
86 | ||
87 | @property | |
88 | def arch(self): | |
89 | return self.pakfire.distro.arch | |
90 | ||
a2d1644c MT |
91 | @property |
92 | def distro(self): | |
93 | """ | |
94 | Link to distro object. | |
95 | """ | |
96 | return self.pakfire.distro | |
97 | ||
98 | @property | |
99 | def priority(self): | |
100 | raise NotImplementedError | |
101 | ||
102 | @property | |
103 | def local(self): | |
104 | """ | |
105 | Say if a repository is a local one or remotely located. | |
106 | ||
107 | Used to check if we need to download files. | |
108 | """ | |
109 | return False | |
110 | ||
36b328f2 MT |
111 | def open(self): |
112 | """ | |
113 | Opens the repository, so we can work with the data. | |
114 | """ | |
115 | self.opened = True | |
116 | ||
117 | def close(self): | |
a2d1644c | 118 | """ |
36b328f2 | 119 | Close and delete all resources that are used by this repository. |
a2d1644c | 120 | """ |
36b328f2 | 121 | self.opened = False |
c605d735 | 122 | |
31267a64 MT |
123 | def clean(self): |
124 | """ | |
125 | Cleanup all temporary files of this repository. | |
126 | """ | |
8b6bc023 | 127 | log.info("Cleaning up repository '%s'..." % self.name) |
31267a64 | 128 | |
0f8d6745 | 129 | # Clear all packages in the index. |
31267a64 MT |
130 | self.index.clear() |
131 | ||
c157d1e2 MT |
132 | def dump(self, long=False, filelist=False): |
133 | dumps = [] | |
134 | # Dump all package information of the packages in this repository. | |
135 | for pkg in self: | |
964aa579 | 136 | dump = pkg.dump(int=int, filelist=filelist) |
c157d1e2 MT |
137 | dumps.append(dump) |
138 | ||
139 | return "\n\n".join(dumps) | |
140 | ||
854d8ccf MT |
141 | def get_config(self): |
142 | """ | |
143 | Return the configuration as a list of string which | |
144 | can be written to a configuration file. | |
145 | """ | |
146 | pass | |
147 | ||
fc1d6149 MT |
148 | |
149 | class RepositoryDummy(RepositoryFactory): | |
150 | """ | |
151 | Just a dummy repository that actually does nothing. | |
152 | """ | |
153 | def __init__(self, pakfire): | |
154 | RepositoryFactory.__init__(self, pakfire, "dummy", | |
155 | "This is a dummy repository.") | |
a7cd7a38 MT |
156 | |
157 | @property | |
158 | def priority(self): | |
159 | # This will never be used in the solving process, but still it needs | |
160 | # a value. | |
161 | return 0 |