]>
git.ipfire.org Git - pakfire.git/blob - pakfire/__init__.py
18 from constants
import *
19 from errors
import BuildError
, PakfireError
22 __version__
= PAKFIRE_VERSION
25 class Pakfire(object):
26 def __init__(self
, path
="/", builder
=False, configs
=[],
28 # Check if we are operating as the root user.
29 self
.check_root_user()
31 # The path where we are operating in
34 # Save if we are in the builder mode
35 self
.builder
= builder
38 rnd
= random
.sample(string
.lowercase
+ string
.digits
, 12)
39 self
.path
= os
.path
.join(BUILD_ROOT
, "".join(rnd
))
43 # Read configuration file(s)
44 self
.config
= config
.Config(pakfire
=self
)
45 for filename
in configs
:
46 self
.config
.read(filename
)
49 logger
.setup_logging(self
.config
)
53 self
.plugins
= plugins
.Plugins(pakfire
=self
)
55 # Get more information about the distribution we are running
57 self
.distro
= distro
.Distribution(pakfire
=self
)
59 # Load all repositories
60 self
.repos
= repository
.Repositories(pakfire
=self
)
62 # Run plugins that implement an initialization method.
63 self
.plugins
.run("init")
65 # Disable repositories if passed on command line
67 for repo
in disable_repos
:
68 self
.repos
.disable_repo(repo
)
70 # Check if there is at least one enabled repository.
71 if len(self
.repos
) < 2:
72 raise PakfireError
, "No repositories were configured."
74 # Update all indexes of the repositories (not force) so that we will
75 # always work with valid data.
78 def check_root_user(self
):
79 if not os
.getuid() == 0 or not os
.getgid() == 0:
80 raise Exception, "You must run pakfire as the root user."
82 def check_build_mode(self
):
84 Check if we are running in build mode.
85 Otherwise, raise an exception.
88 raise BuildError
, "Cannot build when not in build mode."
90 def check_host_arch(self
, arch
):
92 Check if we can build for arch.
95 # If no arch was given on the command line we build for our
96 # own arch which should always work.
100 if not self
.distro
.host_supports_arch(arch
):
101 raise BuildError
, "Cannot build for the target architecture: %s" % arch
103 raise BuildError
, arch
105 def build(self
, pkg
, arch
=None, resultdirs
=None):
106 self
.check_build_mode()
107 self
.check_host_arch(arch
)
112 # Always include local repository
113 resultdirs
.append(self
.repos
.local_build
.path
)
115 b
= builder
.Builder(pakfire
=self
, pkg
=pkg
)
123 # Copy-out all resultfiles
124 for resultdir
in resultdirs
:
128 b
.copy_result(resultdir
)
136 def shell(self
, pkg
, arch
=None):
137 self
.check_build_mode()
138 self
.check_host_arch(arch
)
140 b
= builder
.Builder(pakfire
=self
, pkg
=pkg
)
149 def dist(self
, pkgs
, resultdirs
=None):
150 self
.check_build_mode()
152 # Select first package out of pkgs.
155 b
= builder
.Builder(pakfire
=self
, pkg
=pkg
)
158 b
.extract(build_deps
=False)
160 # If there is any exception, we destroy our stuff and raise it.
167 # Always include local repository
168 resultdirs
.append(self
.repos
.local_build
.path
)
172 # Change package of the builder to current one.
174 b
.extract(build_deps
=False)
176 # Run the actual dist.
179 # Copy-out all resultfiles
180 for resultdir
in resultdirs
:
184 b
.copy_result(resultdir
)
186 # Cleanup all the stuff from pkg.
191 def install(self
, requires
):
192 ds
= depsolve
.DependencySet(pakfire
=self
)
195 if isinstance(req
, packages
.BinaryPackage
):
203 ret
= cli
.ask_user(_("Is this okay?"))
207 ts
= transaction
.Transaction(self
, ds
)
210 def update(self
, pkgs
):
211 ds
= depsolve
.DependencySet(pakfire
=self
)
213 for pkg
in ds
.packages
:
214 # Skip unwanted packages (passed on command line)
215 if pkgs
and not pkg
.name
in pkgs
:
218 updates
= self
.repos
.get_by_name(pkg
.name
)
219 updates
= packages
.PackageListing(updates
)
221 latest
= updates
.get_most_recent()
223 # If the current package is already the latest
228 # Otherwise we want to update the package.
229 ds
.add_package(latest
)
234 ret
= cli
.ask_user(_("Is this okay?"))
238 ts
= transaction
.Transaction(self
, ds
)
241 def provides(self
, patterns
):
244 for pattern
in patterns
:
245 requires
= depsolve
.Requires(None, pattern
)
246 pkgs
+= self
.repos
.get_by_provides(requires
)
248 pkgs
= packages
.PackageListing(pkgs
)
253 def repo_create(self
, path
, input_paths
):
254 repo
= repository
.LocalRepository(
257 description
="New repository.",
261 for input_path
in input_paths
:
262 repo
._collect
_packages
(input_path
)