From f3f2936331ce7e27c4e4c3326513d542a0c94be3 Mon Sep 17 00:00:00 2001 From: Daniel Narvaez Date: Fri, 23 Nov 2012 13:30:25 +0000 Subject: Refactor to use a Module class --- (limited to 'devbot') diff --git a/devbot/autoinstall.py b/devbot/autoinstall.py index d9103e6..0b9fac4 100755 --- a/devbot/autoinstall.py +++ b/devbot/autoinstall.py @@ -16,8 +16,8 @@ monitors = [] def install(module, file): print "Installing %s" % file.get_path() - source_dir = config.get_module_source_dir(module) - build_dir = config.get_module_build_dir(module) + source_dir = module.get_source_dir() + build_dir = module.get_build_dir() dir = os.path.dirname(file.get_path()) relative_path = os.path.relpath(dir, source_dir) @@ -40,7 +40,7 @@ def observe(): if module.get("autoinstall", False): print "Observing the %s module" % module["name"] - source_dir = config.get_module_source_dir(module) + source_dir = module.get_source_dir() for root, dirs, files in os.walk(source_dir): for dir in dirs: file = Gio.File.new_for_path(os.path.join(root, dir)) diff --git a/devbot/build.py b/devbot/build.py index c2d32b9..78ad400 100644 --- a/devbot/build.py +++ b/devbot/build.py @@ -38,15 +38,9 @@ def add_path(name, path): os.environ[name] = ":".join(splitted) -def get_module_source_dir(module): - return os.path.join(config.source_dir, module["name"]) - -def get_module_build_dir(module): - return os.path.join(config.build_dir, module["name"]) - def get_module_commit_id(module): orig_cwd = os.getcwd() - os.chdir(config.get_module_source_dir(module)) + os.chdir(module.get_source_dir()) commit_id = subprocess.check_output(["git", "rev-parse", "HEAD"]) @@ -64,28 +58,27 @@ def unlink_libtool_files(): os.chdir(orig_cwd) def pull_source(module): - module_dir = config.get_module_source_dir(module) + module_dir = module.get_source_dir() if os.path.exists(module_dir): os.chdir(module_dir) - command.run(["git", "remote", "set-url", "origin", module["repo"]]) + command.run(["git", "remote", "set-url", "origin", module.repo]) command.run(["git", "remote", "update", "origin"], retry=10) else: os.chdir(config.source_dir) command.run(["git", "clone", "--progress", - module["repo"], module["name"]], + module.repo, module.name], retry=10) os.chdir(module_dir) - branch = module.get("branch", "master") - command.run(["git", "checkout", branch]) + command.run(["git", "checkout", module.branch]) def build_make(module): command.run(["make"]) def build_autotools(module): - autogen = os.path.join(config.get_module_source_dir(module), "autogen.sh") + autogen = os.path.join(module.get_source_dir(), "autogen.sh") jobs = multiprocessing.cpu_count() * 2 @@ -102,10 +95,10 @@ def build_activity(module): command.run(["./setup.py", "install", "--prefix", config.install_dir]) def build_module(module): - module_source_dir = config.get_module_source_dir(module) + module_source_dir = module.get_source_dir() - if module.get("out-of-source", True): - module_build_dir = config.get_module_build_dir(module) + if module.out_of_source: + module_build_dir = module.get_build_dir() if not os.path.exists(module_build_dir): os.mkdir(module_build_dir) @@ -124,13 +117,13 @@ def build_module(module): print "Unknown build system" sys.exit(1) - state["built_modules"][module["name"]] = get_module_commit_id(module) + state["built_modules"][module.name] = get_module_commit_id(module) save_state() def clear_built_modules(modules, index): if index < len(modules) - 1: for module in modules[index + 1:]: - name = module["name"] + name = module.name if name in state["built_modules"]: del state["built_modules"][name] @@ -145,12 +138,12 @@ def build(): modules = config.load_modules() for i, module in enumerate(modules): - print "\n=== Building %s ===\n" % module["name"] + print "\n=== Building %s ===\n" % module.name try: pull_source(module) - old_commit_id = state["built_modules"].get(module["name"], None) + old_commit_id = state["built_modules"].get(module.name, None) new_commit_id = get_module_commit_id(module) if old_commit_id is None or old_commit_id != new_commit_id: @@ -166,5 +159,5 @@ def clean(): rmtree(config.build_dir) for module in config.load_modules(): - if not module.get("out-of-source", True): - rmtree(config.get_module_source_dir(module)) + if not module.out_of_source: + rmtree(module.get_source_dir()) diff --git a/devbot/config.py b/devbot/config.py index 8dc320a..85ed9d3 100644 --- a/devbot/config.py +++ b/devbot/config.py @@ -25,6 +25,19 @@ if use_lib64: else: system_lib_dir = "/usr/lib" +class Module: + def __init__(self, info): + self.name = info["name"] + self.repo = info["repo"] + self.branch = info.get("branch", "master") + self.out_of_source = info.get("out-of-source", True) + + def get_source_dir(self): + return os.path.join(source_dir, self.name) + + def get_build_dir(self): + return os.path.join(build_dir, self.name) + def set_config_dir(dir): global config_dir config_dir = dir @@ -94,12 +107,6 @@ def get_pref(name): return prefs[name] -def get_module_source_dir(module): - return os.path.join(source_dir, module["name"]) - -def get_module_build_dir(module): - return os.path.join(build_dir, module["name"]) - def load_packages(): packages = {} @@ -134,6 +141,8 @@ def load_modules(): for file in module_files: path = os.path.join(config_dir, "modules", file) - modules.extend(json.load(open(path))) + + for info in json.load(open(path)): + modules.append(Module(info)) return modules -- cgit v0.9.1