From: Michael Tremer Date: Fri, 19 Mar 2010 13:22:30 +0000 (+0100) Subject: naoki: Fix logging. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fdc7c3044fea2e94070e5e868ce99b2bbf1cfdae;p=ipfire-3.x.git naoki: Fix logging. --- diff --git a/naoki/__init__.py b/naoki/__init__.py index 1a236d48e..515a55379 100644 --- a/naoki/__init__.py +++ b/naoki/__init__.py @@ -21,14 +21,12 @@ class Naoki(object): # Second, parse the command line options self.cli = terminal.Commandline(self) - self.log.debug("Successfully initialized naoki instance") for k, v in config.items(): self.log.debug(" %s: %s" % (k, v)) def run(self): args = self.cli.args - print "DEBUG", args # If there is no action provided, exit if not args.has_key("action"): @@ -66,18 +64,34 @@ class Naoki(object): return toolchain.download() - def call_build(self, packages): + def call_build(self, args): force = True - if packages == ["all"]: + if args.packages == ["all"]: force = False - packages = package.list() + package_names = backend.get_package_names() else: - packages = [package.find(p) for p in packages] - for p in packages: - if not p: packages.remove(p) + package_names = args.packages + + packages = [] + for package in package_names: + package = backend.Package(package, naoki=self) + packages.append(package) + + if len(packages) >= 2: + packages_sorted = backend.depsort(packages) + if packages_sorted == packages: + self.log.warn("Packages were resorted for build: %s" % packages_sorted) + packages = packages_sorted + + for package in packages: + environ = chroot.Environment(package) + + if not environ.toolchain.exists: + self.log.error("You need to build or download a toolchain first.") + continue - self._build(packages, force=force) + environ.build() def call_package(self, args): if not args.has_key("action"): diff --git a/naoki/backend.py b/naoki/backend.py index 59c8eb50a..0d3582b52 100644 --- a/naoki/backend.py +++ b/naoki/backend.py @@ -69,6 +69,34 @@ def depsolve(packages, recursive=False): deps.sort() return deps +def deptree(packages): + ret = [packages] + + while True: + next = [] + stage = ret[-1][:] + for package in stage[:]: + for dep in package.info.dependencies_all: + if dep in ret[-1]: + stage.remove(package) + next.append(package) + break + + ret[-1] = stage + if next: + ret.append(next) + continue + + break + + return ret + +def depsort(packages): + ret = [] + for l1 in deptree(packages): + ret.extend(l1) + return ret + class PackageInfo(object): __data = {} diff --git a/naoki/logger.py b/naoki/logger.py index 47f9944a3..4aaea8dd0 100644 --- a/naoki/logger.py +++ b/naoki/logger.py @@ -53,6 +53,8 @@ class Logging(object): def _setupBuildLogger(self, logger): logger.setLevel(logging.DEBUG) + logger.parent = self.log + logger.propagate = 1 handler = logging.handlers.RotatingFileHandler( os.path.join(LOGDIR, logger.name + ".log"), maxBytes=10*1024**2, @@ -108,8 +110,7 @@ class _ColorLogFormatter(logging.Formatter): record.message = "Bad message (%r): %r" % (e, record.__dict__) record.asctime = time.strftime( "%H:%M:%S", self.converter(record.created)) - prefix = '[%(levelname)7s | %(asctime)s]' % \ - record.__dict__ + prefix = " %(levelname)-7s" % record.__dict__ color = self._colors.get(record.levelno, self._normal) formatted = color + prefix + self._normal + " " + record.message if record.exc_info: diff --git a/naoki/util.py b/naoki/util.py index d0dcf55c3..a514a8a23 100644 --- a/naoki/util.py +++ b/naoki/util.py @@ -98,7 +98,7 @@ def logOutput(fds, logger, returnOutput=1, start=0, timeout=0): tail = lines.pop() for line in lines: if line == '': continue - logger.debug(line) + logger.info(line) for h in logger.handlers: h.flush() if returnOutput: