]>
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 ###############################################################################
27 log
= logging
.getLogger("pakfire")
30 from .. import packages
32 from .base
import RepositoryDummy
33 from .local
import RepositoryDir
, RepositoryBuild
34 from .remote
import RepositoryRemote
35 from .system
import RepositorySystem
39 class Repositories(object):
41 Class that loads all repositories from the configuration files.
43 This is the place where repositories can be activated or deactivated.
46 def __init__(self
, pakfire
):
47 self
.pakfire
= pakfire
49 # Place to store the repositories
52 # Create a dummy repository
54 self
.dummy
= base
.RepositoryDummy(self
.pakfire
)
56 # Create the local repository.
57 self
.local
= self
.pakfire
.installed_repo
= RepositorySystem(self
.pakfire
)
58 self
.add_repo(self
.local
)
60 # If we running in build mode, we include our local build repository.
61 if self
.pakfire
.mode
== "builder":
62 self
.local_build
= RepositoryBuild(self
.pakfire
)
63 self
.add_repo(self
.local_build
)
65 self
._load
_from
_configuration
(self
.pakfire
.config
)
68 repositories
= list(self
.__repos
.values())
71 return iter(repositories
)
75 Return the count of enabled repositories.
77 return len([r
for r
in self
if r
.enabled
])
81 Refreshes all repositories
89 return self
.pakfire
.distro
91 def load_configuration(self
, *paths
):
96 if os
.path
.isdir(path
):
97 for file in glob
.glob("%s/*.repo" % path
):
104 self
._load
_from
_configuration
(c
)
106 def _load_from_configuration(self
, config
):
107 # Add all repositories that have been found
108 for name
, settings
in config
.get_repos():
109 self
._parse
(name
, settings
)
111 def _parse(self
, name
, args
):
120 # Handle variable expansion.
123 "arch" : self
.pakfire
.arch
,
126 for k
, v
in list(_args
.items()):
127 # Skip all non-strings.
128 if not type(v
) == type("a"):
132 m
= re
.search(packages
.lexer
.LEXER_VARIABLE
, v
)
134 # If we cannot find a match, we are done.
139 # Get the name of the variable.
142 # Replace the variable with its value.
143 v
= v
.replace("%%{%s}" % var
, replaces
.get(var
, ""))
145 repo
= RepositoryRemote(self
.pakfire
, **_args
)
148 def add_repo(self
, repo
):
149 if repo
.name
in self
.__repos
:
150 raise Exception("Repository with that name does already exist: %s" % repo
.name
)
152 self
.__repos
[repo
.name
] = repo
154 def rem_repo(self
, repo
):
156 Remove the given repository from the global repository set.
159 del self
.__repos
[repo
.name
]
161 log
.debug("Repository that was to be removed does not exist: %s" % repo
.name
)
163 def get_repo(self
, name
):
165 Get the repository with the given name, if not available, return
166 the dummy repository.
169 return self
.__repos
[name
]
173 def enable_repo(self
, name
):
175 if repo
== self
.local
:
178 if repo
.name
== name
or name
== "*":
181 def disable_repo(self
, name
):
183 if repo
== self
.local
:
186 if repo
.name
== name
or name
== "*":
189 def whatprovides(self
, *args
, **kwargs
):
190 return self
.pakfire
.whatprovides(*args
, **kwargs
)
193 log
.info("Cleaning up all repository caches...")