]>
Commit | Line | Data |
---|---|---|
47a4cb89 MT |
1 | #!/usr/bin/python |
2 | ||
7c8f2953 MT |
3 | import logging |
4 | import os | |
5 | import random | |
6 | import string | |
7 | ||
8 | import depsolve | |
9 | import distro | |
10 | import logger | |
11 | import packages | |
12 | import transaction | |
13 | import util | |
14 | ||
15 | from config import Config | |
16 | from constants import * | |
17 | from distro import Distribution | |
18 | from errors import BuildError, PakfireError | |
19 | from repository import Repositories | |
20 | from i18n import _ | |
21 | ||
22 | __version__ = PAKFIRE_VERSION | |
23 | ||
24 | class Pakfire(object): | |
25 | def __init__(self, builder=False, configs=[], disable_repos=None, | |
26 | distro_config=None): | |
27 | # Check if we are operating as the root user. | |
28 | self.check_root_user() | |
29 | ||
30 | # The path where we are operating in. | |
31 | if builder: | |
32 | self.builder = True | |
33 | self.path = os.path.join(BUILD_ROOT, util.random_string()) | |
34 | else: | |
35 | self.builder = False | |
36 | self.path = "/" | |
37 | ||
38 | # XXX check if we are actually running on an ipfire system. | |
39 | ||
40 | # Read configuration file(s) | |
41 | self.config = Config(pakfire=self) | |
42 | for filename in configs: | |
43 | self.config.read(filename) | |
44 | ||
45 | # Setup the logger | |
46 | logger.setup_logging(self.config) | |
47 | self.config.dump() | |
48 | ||
49 | # Get more information about the distribution we are running | |
50 | # or building | |
51 | self.distro = Distribution(self, distro_config) | |
52 | self.repos = Repositories(self) | |
53 | ||
54 | # XXX Disable repositories if passed on command line | |
55 | #if disable_repos: | |
56 | # for repo in disable_repos: | |
57 | # self.repos.disable_repo(repo) | |
58 | ||
59 | # Update all indexes of the repositories (not force) so that we will | |
60 | # always work with valid data. | |
61 | self.repos.update() | |
62 | ||
63 | def destroy(self): | |
64 | if not self.path == "/": | |
65 | util.rm(self.path) | |
66 | ||
67 | @property | |
68 | def supported_arches(self): | |
69 | return self.distro.supported_arches | |
70 | ||
71 | def check_root_user(self): | |
72 | if not os.getuid() == 0 or not os.getgid() == 0: | |
73 | raise Exception, "You must run pakfire as the root user." | |
74 | ||
75 | def check_build_mode(self): | |
76 | """ | |
77 | Check if we are running in build mode. | |
78 | Otherwise, raise an exception. | |
79 | """ | |
80 | if not self.builder: | |
81 | raise BuildError, "Cannot build when not in build mode." | |
82 | ||
83 | def check_host_arch(self, arch): | |
84 | """ | |
85 | Check if we can build for arch. | |
86 | """ | |
87 | ||
88 | # If no arch was given on the command line we build for our | |
89 | # own arch which should always work. | |
90 | if not arch: | |
91 | return True | |
92 | ||
93 | if not self.distro.host_supports_arch(arch): | |
94 | raise BuildError, "Cannot build for the target architecture: %s" % arch | |
95 | ||
96 | raise BuildError, arch |