]>
git.ipfire.org Git - pakfire.git/blob - src/pakfire/repository/__init__.py
2 ###############################################################################
4 # Pakfire - The IPFire package management system #
5 # Copyright (C) 2011 Pakfire development team #
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. #
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. #
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/>. #
20 ###############################################################################
25 log
= logging
.getLogger("pakfire")
27 import pakfire
.packages
as packages
29 from pakfire
.i18n
import _
31 from base
import RepositoryDummy
32 from local
import RepositoryDir
, RepositoryBuild
33 from remote
import RepositoryRemote
34 from system
import RepositorySystem
36 class Repositories(object):
38 Class that loads all repositories from the configuration files.
40 This is the place where repositories can be activated or deactivated.
43 def __init__(self
, pakfire
):
44 self
.pakfire
= pakfire
46 # Place to store the repositories
49 # Create a dummy repository
50 self
.dummy
= RepositoryDummy(self
.pakfire
)
52 # Create the local repository.
53 self
.local
= RepositorySystem(self
.pakfire
)
54 self
.add_repo(self
.local
)
56 # If we running in build mode, we include our local build repository.
57 if self
.pakfire
.mode
== "builder":
58 self
.local_build
= RepositoryBuild(self
.pakfire
)
59 self
.add_repo(self
.local_build
)
61 # Fetch all repository from the configuration files.
62 for repo_name
, repo_args
in self
.config
.get_repos():
63 self
._parse
(repo_name
, repo_args
)
66 repositories
= self
.__repos
.values()
69 return iter(repositories
)
73 Return the count of enabled repositories.
75 return len([r
for r
in self
if r
.enabled
])
78 def initialized(self
):
80 Indicates if all repositories are initialized.
89 # Nothing to do, if everything is already up to date.
93 log
.info(_("Initializing repositories..."))
102 Shuts down all repositores.
109 return self
.pakfire
.config
113 return self
.pakfire
.distro
117 return self
.pakfire
.pool
119 def _parse(self
, name
, args
):
128 # Handle variable expansion.
131 "arch" : self
.distro
.arch
,
134 for k
, v
in _args
.items():
135 # Skip all non-strings.
136 if not type(v
) == type("a"):
140 m
= re
.search(packages
.lexer
.LEXER_VARIABLE
, v
)
142 # If we cannot find a match, we are done.
147 # Get the name of the variable.
150 # Replace the variable with its value.
151 v
= v
.replace("%%{%s}" % var
, replaces
.get(var
, ""))
153 repo
= RepositoryRemote(self
.pakfire
, **_args
)
156 def add_repo(self
, repo
):
157 if self
.__repos
.has_key(repo
.name
):
158 raise Exception, "Repository with that name does already exist: %s" % repo
.name
160 self
.__repos
[repo
.name
] = repo
162 def rem_repo(self
, repo
):
164 Remove the given repository from the global repository set.
167 del self
.__repos
[repo
.name
]
169 log
.debug("Repository that was to be removed does not exist: %s" % repo
.name
)
171 def get_repo(self
, name
):
173 Get the repository with the given name, if not available, return
174 the dummy repository.
177 return self
.__repos
[name
]
181 def enable_repo(self
, name
):
183 if repo
== self
.local
:
186 if repo
.name
== name
or name
== "*":
189 def disable_repo(self
, name
):
191 if repo
== self
.local
:
194 if repo
.name
== name
or name
== "*":
197 def whatprovides(self
, *args
, **kwargs
):
198 return self
.pool
.whatprovides(self
.pakfire
, *args
, **kwargs
)
201 log
.info("Cleaning up all repository caches...")