def parse_attr(self, make): """Parse the attributes from a port and call the requested function.""" # TODO: if make.wait() != make.SUCCESS if make.wait() != 0: log.error("Attr.parse_attr()", "Failed to get port %s attributes (err=%s)\n%s" % (self.origin, make.returncode, "".join(make.stderr.readlines()))) self.emit(self.origin, None) return errs = make.stderr.readlines() if len(errs): log.error("Attr.parse_attr()", "Non-fatal errors in port %s attributes\n%s" % (self.origin, "".join(errs))) attr_map = {} for name, value in ports_attr.iteritems(): if value[1] is str: # Get the string (stripped) attr_map[name] = make.stdout.readline().strip() else: # Pass the string through a special processing (like list/tuple) attr_map[name] = value[1](make.stdout.readline().split()) # Apply all filters for the attribute for i in value[2:]: try: attr_map[name] = i(attr_map[name]) except BaseException, e: log.error("Attr.parse_attr()", "Failed to process port %s attributes: %s" % (self.origin, str(e))) self.emit(self.origin, None) return
def load_defaults(): """ Load the defaults as specified from /etc/make.conf. Requires flags["chroot"] and env.env to be initialised. """ menv = [ # DEPENDS_TARGET modifiers "DEPENDS_CLEAN", "DEPENDS_PRECLEAN", "DEPENDS_TARGET", # Sundry items "BATCH", "USE_PACKAGE_DEPENDS", "WITH_DEBUG", "WITH_PKGNG" ] master_keys = env.env_master.keys() keys = set(menv + master_keys) args = ["make", "-f/dev/null"] + ["-V%s" % i for i in keys] args += ["-D%s" % k if v is True else "%s=%s" % (k, v) for k, v in env.env.items()] if env.flags["chroot"]: args = ["chroot", env.flags["chroot"]] + args make = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) make.stdin.close() make.stderr.close() if make.wait() == 0: make_env = dict((i, j.strip()) for i, j in zip(keys, make.stdout.readlines())) else: make_env = dict((i, "") for i in keys) # Update env_master with predefined values from make.conf for k in master_keys: if k in env.env: env.env_master[k] = None elif make_env[k]: env.env[k] = env.env_master[k] = make_env[k] else: env.env[k] = env.env_master[k] # DEPENDS_TARGET / flags["target"] modifiers if make_env["DEPENDS_TARGET"]: env.flags["target"] = make_env["DEPENDS_TARGET"].split() for i in env.flags["target"]: if i == "reinstall": i = env.flags["target"][env.flags["target"].find(i)] = "install" if i not in env.TARGET: raise ValueError("unsupported DEPENDS_TARGET: '%s'" % i) if "install" not in env.flags["target"] and \ "package" not in env.flags["target"]: raise ValueError("DEPENDS_TARGET must have either install or package") else: if make_env["DEPENDS_CLEAN"] and env.flags["target"][-1] != "clean": env.flags["target"] = env.flags["target"] + ["clean"] if make_env["DEPENDS_PRECLEAN"] and env.flags["target"][0] != "clean": env.flags["target"] = ["clean"] + env.flags["target"] # Sundry items if make_env["BATCH"]: env.flags["config"] = "none" if make_env["USE_PACKAGE_DEPENDS"]: env.flags["depend"] = ["package", "build"] if make_env["WITH_DEBUG"]: env.flags["debug"] = True if make_env["WITH_PKGNG"]: env.flags["pkg_mgmt"] = "pkgng"