]>
git.ipfire.org Git - pakfire.git/blob - pakfire/__init__.py
19 from constants
import *
20 from errors
import BuildError
26 class Pakfire(object):
27 def __init__(self
, path
="/tmp/pakfire", builder
=False, configs
=[]):
28 # The path where we are operating in
31 # Save if we are in the builder mode
32 self
.builder
= builder
35 rnd
= random
.sample(string
.lowercase
+ string
.digits
, 12)
36 self
.path
= os
.path
.join(BUILD_ROOT
, "".join(rnd
))
40 # Read configuration file(s)
41 self
.config
= config
.Config(pakfire
=self
)
42 for filename
in configs
:
43 self
.config
.read(filename
)
46 logger
.setup_logging(self
.config
)
50 self
.plugins
= plugins
.Plugins(pakfire
=self
)
52 # Get more information about the distribution we are running
54 self
.distro
= distro
.Distribution(pakfire
=self
)
56 # Load all repositories
57 self
.repos
= repository
.Repositories(pakfire
=self
)
59 # Run plugins that implement an initialization method.
60 self
.plugins
.run("init")
62 # XXX disable repositories if passed on command line
64 def check_build_mode(self
):
66 Check if we are running in build mode.
67 Otherwise, raise an exception.
70 raise BuildError
, "Cannot build when not in build mode."
72 def check_host_arch(self
, arch
):
74 Check if we can build for arch.
77 # If no arch was given on the command line we build for our
78 # own arch which should always work.
82 if not self
.distro
.host_supports_arch(arch
):
83 raise BuildError
, "Cannot build for the target architecture: %s" % arch
85 raise BuildError
, arch
87 def build(self
, pkg
, arch
=None, resultdir
=None):
88 self
.check_build_mode()
89 self
.check_host_arch(arch
)
91 b
= builder
.Builder(pakfire
=self
, pkg
=pkg
)
95 resultdir
= self
.config
.get("resultdir")
99 b
.copy_result(resultdir
)
103 def shell(self
, pkg
, arch
=None):
104 self
.check_build_mode()
105 self
.check_host_arch(arch
)
107 b
= builder
.Builder(pakfire
=self
, pkg
=pkg
)
108 b
.extract(SHELL_PACKAGES
)
115 def dist(self
, pkg
, resultdir
=None):
116 self
.check_build_mode()
118 b
= builder
.Builder(pakfire
=self
, pkg
=pkg
)
119 b
.extract(build_deps
=False)
122 resultdir
= self
.config
.get("resultdir")
126 b
.copy_result(resultdir
)
130 def install(self
, requires
):
131 ds
= depsolve
.DependencySet(pakfire
=self
)
134 if isinstance(BinaryPackage
, req
):
141 ts
= transaction
.TransactionSet(self
, ds
)
144 ret
= cli
.ask_user(_("Is this okay?"))