From: Michael Tremer Date: Mon, 6 Sep 2010 21:05:51 +0000 (+0200) Subject: naoki: Re-add shell function. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=846c9302ac7a3a6fd43a3cb44a55e5cf4874b164;p=ipfire-3.x.git naoki: Re-add shell function. --- diff --git a/naoki/__init__.py b/naoki/__init__.py index 4a87ce88f..fbaaaa293 100644 --- a/naoki/__init__.py +++ b/naoki/__init__.py @@ -10,6 +10,7 @@ import time import backend import build import chroot +import environ import logger import repo import terminal @@ -225,32 +226,13 @@ Release : %(release)s os.remove(os.path.join(TARBALLDIR, file)) def call_shell(self, args): - environ = chroot.ShellEnvironment(naoki=self) + p = repo.find_source_package(args.package) + if not p: + raise Exception, "Could not find package: %s" % args.package - actionmap = { - "clean" : self.call_shell_clean, - "extract" : self.call_shell_extract, - "enter" : self.call_shell_enter, - } - - if args.action.name in ("enter", "execute"): - environ.init(clean=False) - - return actionmap[args.action.name](environ, args.action) - - def call_shell_clean(self, environ, args): - return environ.clean() - - def call_shell_extract(self, environ, args): - if args.packages == ["all"]: - args.packages = backend.get_package_names() - - packages = backend.parse_package(args.packages, naoki=self) - for package in backend.depsolve(packages, recursive=True): - package.getPackage(self).extract(environ.chrootPath()) + build_set = build.BuildSet(p) - def call_shell_enter(self, environ, args): - return environ.shell() + return build_set.shell() def call_repository(self, args): actionmap = { diff --git a/naoki/build.py b/naoki/build.py index 1a36bd085..5489db8f8 100644 --- a/naoki/build.py +++ b/naoki/build.py @@ -5,6 +5,7 @@ import logging import deps import environ +from constants import * from exception import * class BuildSet(object): @@ -18,6 +19,15 @@ class BuildSet(object): def __repr__(self): return "<%s %s>" % (self.__class__.__name__, self.package.name) + def _resolve(self, ignore_errors=False): + try: + self.dependency_set.resolve() + except DependencyResolutionError, e: + if ignore_errors: + logging.warning("Ignoring dependency errors: %s" % e) + else: + raise + @property def arch(self): return self.package.arch @@ -27,21 +37,32 @@ class BuildSet(object): logging.info(" %s" % self.package.summary) logging.info("") - def run(self, ignore_dependency_errors=False): + def build(self, ignore_dependency_errors=False): logging.debug("Running build process for %s" % self) self.print_info() - try: - self.dependency_set.resolve() - except DependencyResolutionError, e: - if ignore_dependency_errors: - logging.warning("Ignoring dependency errors: %s" % e) - else: - raise + self._resolve(ignore_errors=ignore_dependency_errors) env = environ.Environment(self) env.build() + run = build + + def shell(self): + logging.debug("Running shell for %s" % self) + self.print_info() + + # Add some packages that are kind of nice in a shell + # like an editor and less... + for dependency in [deps.Dependency(d) for d in config["shell_packages"]]: + logging.debug("Adding shell dependency: %s" % dependency) + self.dependency_set.add_dependency(dependency) + + self._resolve() + + env = environ.Shell(self) + env.shell() + class Builder(object): def __init__(self): @@ -66,3 +87,4 @@ class Builder(object): # Run the actual build i.run(*args, **kwargs) + diff --git a/naoki/constants.py b/naoki/constants.py index 878f02d75..86e625c74 100644 --- a/naoki/constants.py +++ b/naoki/constants.py @@ -65,6 +65,11 @@ class Config(object): "tar", "xz", ], + "shell_packages" : [ + "/bin/bash", + "less", + "vim", + ], "nice_level" : 0, "parallelism" : calc_parallelism(), # diff --git a/naoki/deps.py b/naoki/deps.py index ebae22cf0..cbe833280 100644 --- a/naoki/deps.py +++ b/naoki/deps.py @@ -110,7 +110,7 @@ class DependencySet(object): def resolve(self): logging.debug("Resolving %s" % self) - self.reset() + #self.reset() # Always add the default packages _dependencies = [Dependency(i) for i in config["mandatory_packages"]] diff --git a/naoki/environ.py b/naoki/environ.py index d8e3cd187..d3de724e5 100644 --- a/naoki/environ.py +++ b/naoki/environ.py @@ -301,3 +301,34 @@ class Environment(object): "mount -n -t tmpfs naoki_chroot_shmfs %s" % self.chrootPath("dev", "shm")]) return ret + + +class Shell(Environment): + def shell(self, args=[]): + self.extract() + + # Preparing source... + self.make("prepare") + + command = "chroot %s /usr/src/tools/chroot-shell %s" % \ + (self.chrootPath(), " ".join(args)) + + for key, val in self.environ.items(): + command = "%s=\"%s\" " % (key, val) + command + + if self.package.source_dir: + command = "SOURCE_DIR=%s %s" % (self.package.source_dir, command) + + logging.debug("Shell command: %s" % command) + + try: + self._mountall() + + shell = os.system(command) + return os.WEXITSTATUS(shell) + + finally: + self._umountall() + + # Clean up the environment + self.clean() diff --git a/naoki/paks.py b/naoki/paks.py index 3a6d87569..26795420c 100644 --- a/naoki/paks.py +++ b/naoki/paks.py @@ -87,6 +87,10 @@ class SourcePackage(Package): def summary(self): return self._info["PKG_SUMMARY"] + @property + def source_dir(self): + return self._info.get("SOURCE_DIR", "") + class BinaryPackage(Package): def __init__(self, filename): diff --git a/naoki/terminal.py b/naoki/terminal.py index bdf6b2a51..ca794fff9 100644 --- a/naoki/terminal.py +++ b/naoki/terminal.py @@ -349,14 +349,8 @@ class Commandline(object): # Shell Parser("shell", help="Shell environment", - parsers=[ - Parser("clean", help="Cleanup the environment"), - Parser("extract", - help="Extract packages", - arguments=[ - List("packages", help="Give a list of packages") - ]), - Parser("enter", help="Enter into environment"), + arguments=[ + Argument("package", help="Package to process."), ]), # Repository diff --git a/pkgs/Targets b/pkgs/Targets index dbb0d2d58..0ee051c8a 100644 --- a/pkgs/Targets +++ b/pkgs/Targets @@ -22,6 +22,7 @@ info: @echo "PKG_REL=\"$(PKG_REL)\"" @echo "PKG_SUMMARY=\"$(strip $(PKG_SUMMARY))\"" @echo "PKG_URL=\"$(PKG_URL)\"" + @echo "SOURCE_DIR=\"$(DIR_APP)\"" $(OBJECTS): @echo "Object file \"$@\" is required." >&2 diff --git a/tools/chroot-shell b/tools/chroot-shell index e9ab9e052..48833ef32 100755 --- a/tools/chroot-shell +++ b/tools/chroot-shell @@ -16,6 +16,9 @@ EOF export PS1="naoki-chroot \w> " # Change to directory the user will most likely work in -cd /usr/src +if [ -z "${SOURCE_DIR}" ]; then + SOURCE_DIR="/usr/src" +fi +cd "${SOURCE_DIR}" exec /bin/bash --login