]>
git.ipfire.org Git - pakfire.git/blob - pakfire/__init__.py
19 from constants
import *
20 from errors
import BuildError
, PakfireError
26 class Pakfire(object):
27 def __init__(self
, path
="/tmp/pakfire", builder
=False, configs
=[],
29 # Check if we are operating as the root user.
30 self
.check_root_user()
32 # The path where we are operating in
35 # Save if we are in the builder mode
36 self
.builder
= builder
39 rnd
= random
.sample(string
.lowercase
+ string
.digits
, 12)
40 self
.path
= os
.path
.join(BUILD_ROOT
, "".join(rnd
))
44 # Read configuration file(s)
45 self
.config
= config
.Config(pakfire
=self
)
46 for filename
in configs
:
47 self
.config
.read(filename
)
50 logger
.setup_logging(self
.config
)
54 self
.plugins
= plugins
.Plugins(pakfire
=self
)
56 # Get more information about the distribution we are running
58 self
.distro
= distro
.Distribution(pakfire
=self
)
60 # Load all repositories
61 self
.repos
= repository
.Repositories(pakfire
=self
)
63 # Run plugins that implement an initialization method.
64 self
.plugins
.run("init")
66 # Disable repositories if passed on command line
68 for repo
in disable_repos
:
69 self
.repos
.disable_repo(repo
)
71 # Check if there is at least one enabled repository.
72 if len(self
.repos
) < 2:
73 raise PakfireError
, "No repositories were configured."
75 # Update all indexes of the repositories (not force) so that we will
76 # always work with valid data.
79 def check_root_user(self
):
80 if not os
.getuid() == 0 or not os
.getgid() == 0:
81 raise Exception, "You must run pakfire as the root user."
83 def check_build_mode(self
):
85 Check if we are running in build mode.
86 Otherwise, raise an exception.
89 raise BuildError
, "Cannot build when not in build mode."
91 def check_host_arch(self
, arch
):
93 Check if we can build for arch.
96 # If no arch was given on the command line we build for our
97 # own arch which should always work.
101 if not self
.distro
.host_supports_arch(arch
):
102 raise BuildError
, "Cannot build for the target architecture: %s" % arch
104 raise BuildError
, arch
106 def build(self
, pkg
, arch
=None, resultdirs
=None):
107 self
.check_build_mode()
108 self
.check_host_arch(arch
)
113 # Always include local repository
114 resultdirs
.append(self
.repos
.local_build
.path
)
116 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 provides(self
, patterns
):
213 for pattern
in patterns
:
214 requires
= depsolve
.Requires(None, pattern
)
215 pkgs
+= self
.repos
.get_by_provides(requires
)
217 pkgs
= packages
.PackageListing(pkgs
)
222 def repo_create(self
, path
, input_paths
):
223 repo
= repository
.LocalRepository(
226 description
="New repository.",
230 for input_path
in input_paths
:
231 repo
._collect
_packages
(input_path
)