From d23a83060ddad0b6da5504d8cb5d524891ad9631 Mon Sep 17 00:00:00 2001 From: Daniel Narvaez Date: Wed, 26 Dec 2012 11:25:03 +0000 Subject: pep8ize --- diff --git a/Makefile.tests b/Makefile.tests index 6416268..3ece9dd 100644 --- a/Makefile.tests +++ b/Makefile.tests @@ -6,4 +6,19 @@ test-devbot: TMPDIR=$(TESTS_DATA) PYTHONPATH=$(BASE_DIR) python -m unittest discover rm -rf $(TESTS_DATA) -check: test-devbot run-tests +PYTHON_SCRIPTS = \ + $(COMMANDS_DIR)/build \ + $(COMMANDS_DIR)/clean \ + $(COMMANDS_DIR)/pull \ + $(COMMANDS_DIR)/run-tests \ + $(COMMANDS_DIR)/shell \ + $(COMMANDS_DIR)/check-system \ + $(COMMANDS_DIR)/distribute \ + $(COMMANDS_DIR)/run \ + $(COMMANDS_DIR)/send-patches \ + $(TOOLS_DIR)/json-normalize + +pep8: + pep8 commands devbot tests $(PYTHON_SCRIPTS) + +check: test pep8 run-tests diff --git a/commands/build b/commands/build index 714e783..0a8b2d4 100755 --- a/commands/build +++ b/commands/build @@ -16,7 +16,7 @@ args = parser.parse_args() common.setup() if not system.check(skip_if_unchanged=True): - sys.exit(1) + sys.exit(1) if args.module: success = build.build_one(args.module) diff --git a/commands/clean b/commands/clean index f45e271..1a68817 100755 --- a/commands/clean +++ b/commands/clean @@ -25,7 +25,7 @@ except OSError: for filename in glob.glob("*.log"): try: - os.unlink(filename) + os.unlink(filename) except OSError: # Files migth not exist pass diff --git a/commands/common.py b/commands/common.py index e9f5293..e92f798 100644 --- a/commands/common.py +++ b/commands/common.py @@ -9,6 +9,7 @@ from devbot import config from devbot import command from devbot import git + def setup(): git.set_root_path(base_dir) diff --git a/commands/run-tests b/commands/run-tests index d09f621..f9ffdcb 100755 --- a/commands/run-tests +++ b/commands/run-tests @@ -12,6 +12,7 @@ from devbot import test common.setup() + def _run_ui_tests(): profile_path = os.path.expanduser("~/.sugar/uitests") shutil.rmtree(profile_path, ignore_errors=True) diff --git a/commands/send-patches b/commands/send-patches index 52f81aa..aa2adac 100755 --- a/commands/send-patches +++ b/commands/send-patches @@ -12,6 +12,7 @@ from devbot import config GIT_CONFIG_SETUP = "sugar-build.send-patches.setup" + def get_git_config(name, is_global=False): args = ["git", "config"] @@ -25,9 +26,11 @@ def get_git_config(name, is_global=False): except subprocess.CalledProcessError: return None + def set_git_config(name, value): return subprocess.check_output(["git", "config", name, value]) + def unset_git_config(name): try: subprocess.check_output(["git", "config", "--unset", name]) @@ -35,6 +38,7 @@ def unset_git_config(name): except subprocess.CalledProcessError: return False + def get_from(): name = get_git_config("user.name", is_global=True) email = get_git_config("user.email", is_global=True) @@ -47,11 +51,13 @@ def get_from(): return "%s <%s>" % (name, email) + def get_module(): for line in open("configure.ac"): m = re.match("AC_INIT\((.+)\)", line) if m: - return m.group(1).split(",")[-1][1:-1] + return m.group(1).split(",")[-1][1:-1] + def setup(): print "Choose how to send email \n\n" \ diff --git a/devbot/build.py b/devbot/build.py index 5ea9422..5c35999 100644 --- a/devbot/build.py +++ b/devbot/build.py @@ -16,6 +16,7 @@ from devbot import release _builders = {} _distributors = {} + def build_one(module_name): environ.setup() @@ -25,6 +26,7 @@ def build_one(module_name): return False + def pull_one(module_name): environ.setup() @@ -34,6 +36,7 @@ def pull_one(module_name): return False + def pull(): environ.setup() @@ -43,6 +46,7 @@ def pull(): return True + def build(full=False): if full or state.full_build_is_required(): state.clean_build_state() @@ -64,6 +68,7 @@ def build(full=False): return True + def distribute(): environ.setup() @@ -74,6 +79,7 @@ def distribute(): return True + def clean(): _empty_dir(config.install_dir) _empty_dir(config.get_build_dir()) @@ -83,13 +89,16 @@ def clean(): if module.get_git_module().clean(): print "Cleaned %s git repository." % module.name + def _ccache_reset(): subprocess.check_call(["ccache", "-z"], stdout=utils.devnull) + def _ccache_print_stats(): print "\n=== ccache statistics ===\n" subprocess.check_call(["ccache", "-s"]) + def _unlink_libtool_files(): def func(arg, dirname, fnames): for fname in fnmatch.filter(fnames, "*.la"): @@ -97,6 +106,7 @@ def _unlink_libtool_files(): os.path.walk(config.lib_dir, func, None) + def _pull_module(module): print "\n=== Pulling %s ===\n" % module.name @@ -107,9 +117,11 @@ def _pull_module(module): return True + def _eval_option(option): return eval(option, {"prefix": config.prefix_dir}) + def _build_autotools(module, log): # Workaround for aclocal 1.11 (fixed in 1.12) aclocal_path = os.path.join(config.share_dir, "aclocal") @@ -139,12 +151,14 @@ def _build_autotools(module, log): _builders["autotools"] = _build_autotools + def _build_activity(module, log): setup = os.path.join(module.get_source_dir(), "setup.py") command.run([setup, "install", "--prefix", config.prefix_dir], log) _builders["activity"] = _build_activity + def _distribute_autotools(module): makefile = parse_makefile("Makefile") filename = makefile["DIST_ARCHIVES"] @@ -184,6 +198,7 @@ def _distribute_autotools(module): _distributors["autotools"] = _distribute_autotools + def _build_module(module, log=None): print "\n=== Building %s ===\n" % module.name @@ -217,6 +232,7 @@ def _build_module(module, log=None): return True + def _distribute_module(module, log=None): print "\n=== Distribute %s ===\n" % module.name @@ -240,6 +256,7 @@ def _distribute_module(module, log=None): return True + def _empty_dir(dir_path): print "Emptying %s directory" % dir_path shutil.rmtree(dir_path, ignore_errors=True) diff --git a/devbot/command.py b/devbot/command.py index aaef58f..8ccef6c 100644 --- a/devbot/command.py +++ b/devbot/command.py @@ -3,10 +3,12 @@ import time _logger = None + def set_logger(logger): global _logger _logger = logger + def run(args, log=None, test=False, retry=0): print " ".join(args) if test: @@ -30,6 +32,7 @@ def run(args, log=None, test=False, retry=0): else: raise e + def run_with_sudo(args, test=False, retry=0): args_with_sudo = ["sudo"] args_with_sudo.extend(args) diff --git a/devbot/config.py b/devbot/config.py index a66a196..4c129eb 100644 --- a/devbot/config.py +++ b/devbot/config.py @@ -27,6 +27,7 @@ _source_dir = None _build_dir = None _prefs_path = None + class Module: def __init__(self, info): self.name = info["name"] @@ -66,6 +67,7 @@ class Module: "delete it and pull\nthe source again." return None + def setup(**kwargs): _load_plugins() @@ -90,6 +92,7 @@ def setup(**kwargs): _setup_state_dir(kwargs["state_dir"]) _setup_install_dir(kwargs["install_dir"], relocatable) + def _setup_state_dir(state_dir): utils.ensure_dir(state_dir) @@ -104,6 +107,7 @@ def _setup_state_dir(state_dir): home_dir = os.path.join(base_home_dir, get_pref("PROFILE")) utils.ensure_dir(home_dir) + def _setup_prefix_dir(dir, relocatable): global prefix_dir @@ -129,6 +133,7 @@ def _setup_prefix_dir(dir, relocatable): os.remove(prefix_dir) os.symlink(dir, prefix_dir) + def _setup_install_dir(dir, relocatable=False): global system_lib_dirs global install_dir @@ -161,16 +166,19 @@ def _setup_install_dir(dir, relocatable=False): if distro_info.lib_dir is not None: system_lib_dirs.append(os.path.join("/usr", distro_info.lib_dir)) + def get_source_dir(): global _source_dir utils.ensure_dir(_source_dir) return _source_dir + def get_build_dir(): global _build_dir utils.ensure_dir(_build_dir) return _build_dir + def _read_prefs(): global _prefs_path @@ -186,6 +194,7 @@ def _read_prefs(): return prefs + def _save_prefs(prefs): global _prefs_path @@ -196,6 +205,7 @@ def _save_prefs(prefs): for pref in prefs.items(): f.write("%s\n" % "=".join(pref)) + def get_log_path(prefix): logfile_path = None number = 0 @@ -211,31 +221,36 @@ def get_log_path(prefix): return logfile_path + def get_pref(name): - defaults = { "PROFILE": "default" } + defaults = {"PROFILE": "default"} prefs = _read_prefs() return prefs.get(name, defaults.get(name, None)) + def set_pref(name, value): prefs = _read_prefs() prefs[name] = value _save_prefs(prefs) + def _load_plugins(): for loader, name, ispkg in pkgutil.iter_modules(plugins.__path__): f, filename, desc = imp.find_module(name, plugins.__path__) imp.load_module(name, f, filename, desc) + def _read_index(dir_name): if config_dir is None: return [] index_dir = os.path.join(config_dir, dir_name) with open(os.path.join(index_dir, "index.json")) as f: - return [os.path.join(index_dir, json_file) \ + return [os.path.join(index_dir, json_file) for json_file in json.load(f)] + def get_full_build(): config = None with open(os.path.join(config_dir, "config.json")) as f: @@ -243,6 +258,7 @@ def get_full_build(): return config["full_build"] + def load_packages(): packages = {} @@ -251,20 +267,23 @@ def load_packages(): return packages + def load_prerequisites(): path = os.path.join(config_dir, "deps", "prerequisites.json") return json.load(open(path)) + def _filter_if(item): if "if" not in item: return True distro_info = distro.get_distro_info() - globals = { "gstreamer_version": distro_info.gstreamer_version, - "gnome_version": distro_info.gnome_version } + globals = {"gstreamer_version": distro_info.gstreamer_version, + "gnome_version": distro_info.gnome_version} return eval(item["if"], globals) + def load_checks(): checks = [] for path in _read_index("deps"): @@ -272,6 +291,7 @@ def load_checks(): return filter(_filter_if, checks) + def load_modules(): modules = [] for path in _read_index("modules"): @@ -280,6 +300,7 @@ def load_modules(): return [Module(info) for info in filter(_filter_if, modules)] + def clean(): try: os.rmdir(logs_dir) diff --git a/devbot/distro.py b/devbot/distro.py index 951ea21..c44fff7 100644 --- a/devbot/distro.py +++ b/devbot/distro.py @@ -5,29 +5,34 @@ _package_managers = {} _supported_distros = [] _distro_info = None + def register_distro_info(distro_info): - global _supported_distros - _supported_distros.append(distro_info) + global _supported_distros + _supported_distros.append(distro_info) + def register_package_manager(name, package_manager): global _package_managers _package_managers[name] = package_manager + def get_package_manager(test=False, interactive=True): global _package_managers package_manager_class = _package_managers[get_distro_info().name] return package_manager_class(test=test, interactive=interactive) + def print_distro_info(): info = get_distro_info() print "== Distribution information ==\n" print "Name: %s" % info.name print "Version: %s" % info.version print "GNOME version: %s" % info.gnome_version - print "Gstreamer version: %s" % info.gstreamer_version + print "Gstreamer version: %s" % info.gstreamer_version print "Lib directory: %s" % info.lib_dir print "Supported: %s\n" % info.supported + def get_distro_info(): global _supported_distros global _distro_info @@ -47,7 +52,7 @@ def get_distro_info(): if _distro_info is None: _distro_info = unknown_distro - if not _distro_info.supported: + if not _distro_info.supported: print "*********************************************************\n" \ "You are running an unsupported distribution. You might be\n" \ "able to make sugar work by installing or building \n" \ diff --git a/devbot/environ.py b/devbot/environ.py index e90b174..ae39c54 100644 --- a/devbot/environ.py +++ b/devbot/environ.py @@ -3,10 +3,12 @@ import os from devbot import config + def setup(): _setup_gconf() _setup_variables() + def add_path(name, path): if not path.endswith("/"): path = "%s/" % path @@ -21,6 +23,7 @@ def add_path(name, path): os.environ[name] = ":".join(splitted) + def _setup_variables(): add_path("LD_LIBRARY_PATH", config.lib_dir) add_path("PATH", config.bin_dir) @@ -30,7 +33,7 @@ def _setup_variables(): add_path("PKG_CONFIG_PATH", os.path.join(config.lib_dir, "pkgconfig")) add_path("GST_PLUGIN_PATH", - os.path.join(config.lib_dir , "gstreamer-1.0")) + os.path.join(config.lib_dir, "gstreamer-1.0")) add_path("PYTHONPATH", sysconfig.get_python_lib(prefix=config.prefix_dir)) add_path("PYTHONPATH", @@ -40,30 +43,31 @@ def _setup_variables(): os.path.dirname(os.path.dirname(__file__))) add_path("ACLOCAL_PATH", "/usr/share/aclocal") - add_path("ACLOCAL_FLAGS", "-I /usr/share/aclocal") + add_path("ACLOCAL_FLAGS", "-I /usr/share/aclocal") add_path("XDG_DATA_DIRS", "/usr/share") add_path("XDG_DATA_DIRS", config.share_dir) add_path("XDG_CONFIG_DIRS", "/etc") - add_path("XDG_CONFIG_DIRS", config.etc_dir) + add_path("XDG_CONFIG_DIRS", config.etc_dir) for system_lib_dir in config.system_lib_dirs: modules_path = os.path.join(system_lib_dir, "gio", "modules") - if os.path.exists(modules_path): + if os.path.exists(modules_path): add_path("GIO_EXTRA_MODULES", modules_path) typelib_path = os.path.join(system_lib_dir, "girepository-1.0") - if os.path.exists(typelib_path): + if os.path.exists(typelib_path): add_path("GI_TYPELIB_PATH", typelib_path) add_path("GI_TYPELIB_PATH", os.path.join(config.lib_dir, "girepository-1.0")) - + os.environ["GTK_DATA_PREFIX"] = config.prefix_dir os.environ["GTK_PATH"] = os.path.join(config.lib_dir, "gtk-2.0") os.environ["CC"] = "ccache gcc" + def _setup_gconf(): gconf_dir = os.path.join(config.etc_dir, "gconf") gconf_pathdir = os.path.join(gconf_dir, "2") diff --git a/devbot/git.py b/devbot/git.py index 4a86bd6..4e7d86c 100644 --- a/devbot/git.py +++ b/devbot/git.py @@ -6,6 +6,7 @@ from devbot import utils _root_path = None + def _chdir(func): def wrapped(*args, **kwargs): orig_cwd = os.getcwd() @@ -18,6 +19,7 @@ def _chdir(func): return wrapped + class Module: def __init__(self, path=None, name=None, remote=None, branch="master", tag=None, retry=10): @@ -43,7 +45,7 @@ class Module: if self.tag: command.run(["git", "checkout", self.tag]) - else: + else: command.run(["git", "checkout", self._branch]) def update(self): @@ -68,7 +70,7 @@ class Module: if revision is None: revision = self._branch - command.run(["git", "checkout", revision]) + command.run(["git", "checkout", revision]) @_chdir def describe(self): @@ -93,7 +95,7 @@ class Module: def get_annotation(self, tag): # FIXME this is fragile, there must be a better way - show = subprocess.check_output(["git", "show", tag]) + show = subprocess.check_output(["git", "show", tag]) annotation = [] for line in show.split("\n"): @@ -120,10 +122,12 @@ class Module: return True + def set_root_path(path): global _root_path _root_path = path + def get_root_module(): remote = "git://git.sugarlabs.org/sugar-build/sugar-build.git" diff --git a/devbot/plugins/debian.py b/devbot/plugins/debian.py index 53e6bc4..26cb08c 100644 --- a/devbot/plugins/debian.py +++ b/devbot/plugins/debian.py @@ -5,6 +5,7 @@ from devbot import command from devbot import distro from devbot.plugins import interfaces + class PackageManager(interfaces.PackageManager): def __init__(self, test=False, interactive=True): import apt @@ -70,7 +71,7 @@ class PackageManager(interfaces.PackageManager): self._find_deps(dependency_name, result) def find_with_deps(self, package_names): - result = [] + result = [] for package in package_names: if package is not None: @@ -83,11 +84,13 @@ class PackageManager(interfaces.PackageManager): distro.register_package_manager("debian", PackageManager) + class DistroInfo(interfaces.DistroInfo): _DEBIAN_VERSION_PATH = "/etc/debian_version" + def __init__(self): - arch = self._get_architecture() - + arch = self._get_architecture() + self.name = "debian" self.version = "unknown" self.gnome_version = "3.4" @@ -116,6 +119,6 @@ class DistroInfo(interfaces.DistroInfo): self.supported = False def _get_architecture(self): - return subprocess.check_output(["arch"]).strip() + return subprocess.check_output(["arch"]).strip() distro.register_distro_info(DistroInfo) diff --git a/devbot/plugins/fedora.py b/devbot/plugins/fedora.py index df0aef7..3b6b694 100644 --- a/devbot/plugins/fedora.py +++ b/devbot/plugins/fedora.py @@ -5,6 +5,7 @@ from devbot import command from devbot import distro from devbot.plugins import interfaces + class PackageManager(interfaces.PackageManager): def __init__(self, test=False, interactive=True): self._test = test @@ -72,7 +73,7 @@ class PackageManager(interfaces.PackageManager): "--queryformat=[%{NAME} ]", "--whatprovides"] args.extend(filtered) - + deps_packages = subprocess.check_output(args).strip() for dep_package in deps_packages.split(" "): if dep_package not in result: @@ -81,6 +82,7 @@ class PackageManager(interfaces.PackageManager): distro.register_package_manager("fedora", PackageManager) + class DistroInfo(interfaces.DistroInfo): _FEDORA_RELEASE_PATH = "/etc/fedora-release" diff --git a/devbot/plugins/interfaces.py b/devbot/plugins/interfaces.py index 8c97c65..ecd2d3a 100644 --- a/devbot/plugins/interfaces.py +++ b/devbot/plugins/interfaces.py @@ -4,6 +4,7 @@ import subprocess from devbot import command from devbot import distro + class PackageManager: """Package management""" @@ -33,6 +34,7 @@ class PackageManager: :returns: list of packages with all the dependencies """ + class DistroInfo: """Informations about the distribution""" @@ -42,7 +44,7 @@ class DistroInfo: self.version = None """The distribution version.""" - + self.gnome_version = None """The major version of GNOME shipped with the distribution.""" diff --git a/devbot/plugins/ubuntu.py b/devbot/plugins/ubuntu.py index 005871c..dd0efde 100644 --- a/devbot/plugins/ubuntu.py +++ b/devbot/plugins/ubuntu.py @@ -6,11 +6,13 @@ from devbot.plugins import debian distro.register_package_manager("ubuntu", debian.PackageManager) + class DistroInfo(interfaces.DistroInfo): - _OS_RELEASE_PATH="/etc/os-release" + _OS_RELEASE_PATH = "/etc/os-release" + def __init__(self): arch = self._get_architecture() - + self.name = "ubuntu" self.version = "unknown" self.gnome_version = "3.4" @@ -33,10 +35,10 @@ class DistroInfo(interfaces.DistroInfo): except IOError: release = None self.valid = False - + if os_info["ID"] != "ubuntu": self.valid = False - + self.version = os_info.get("VERSION_ID", None) if self.version != "12.10": @@ -46,6 +48,6 @@ class DistroInfo(interfaces.DistroInfo): self.gnome_version = "3.6" def _get_architecture(self): - return subprocess.check_output(["uname", "-i"]).strip() + return subprocess.check_output(["uname", "-i"]).strip() distro.register_distro_info(DistroInfo) diff --git a/devbot/plugins/unknown.py b/devbot/plugins/unknown.py index 576edef..5e3f530 100644 --- a/devbot/plugins/unknown.py +++ b/devbot/plugins/unknown.py @@ -5,6 +5,7 @@ from devbot import command from devbot import distro from devbot.plugins import interfaces + class PackageManager(interfaces.PackageManager): def __init__(self, test=False, interactive=True): pass @@ -26,6 +27,7 @@ class PackageManager(interfaces.PackageManager): distro.register_package_manager("unknown", PackageManager) + class DistroInfo(interfaces.DistroInfo): def __init__(self): self.lib_dir = None @@ -35,5 +37,5 @@ class DistroInfo(interfaces.DistroInfo): self.gstreamer_version = "0.10" self.valid = True self.supported = False - + distro.register_distro_info(DistroInfo) diff --git a/devbot/release.py b/devbot/release.py index a9f5a64..c82f358 100644 --- a/devbot/release.py +++ b/devbot/release.py @@ -7,16 +7,19 @@ upload_root = "/upload/sources/sucrose/glucose" download_uri = "http://download.sugarlabs.org/sources/sucrose/glucose" announce_to = "sugar-devel@lists.sugarlabs.org" + def exists(module, filename): release_path = os.path.join(upload_root, module.name, filename) result = subprocess.call(["ssh", upload_host, "test", "-f", release_path]) return result == 0 + def upload(module, path): upload_path = os.path.join(upload_root, module.name) upload_dest = "%s:%s" % (upload_host, upload_path) return subprocess.call(["scp", path, upload_dest]) == 0 + def announce(module, filename, version, annotation): fd, announce_path = tempfile.mkstemp(prefix="announce-") @@ -34,7 +37,7 @@ def announce(module, filename, version, annotation): upload_dest = "%s:~" % upload_host if subprocess.call(["scp", announce_path, upload_dest]) == 0: announce_basename = os.path.basename(announce_path) - + if subprocess.call(["ssh", upload_host, "sendmail", "-t", "<", announce_basename]): result = True @@ -45,5 +48,6 @@ def announce(module, filename, version, annotation): return result + def _get_email(): return subprocess.check_output(['git', 'config', 'user.email']).strip() diff --git a/devbot/run.py b/devbot/run.py index 110fe1a..34edab9 100644 --- a/devbot/run.py +++ b/devbot/run.py @@ -11,6 +11,7 @@ import tempfile from devbot import environ from devbot import config + def run(command): environ.setup() @@ -26,6 +27,7 @@ def run(command): os.execlp(args[0], *args) + def run_test(command, test_path, virtual=False): environ.setup() @@ -60,6 +62,7 @@ def run_test(command, test_path, virtual=False): return result + def collect_logs(source_path, log_name): logs = {} for filename in os.listdir(source_path): @@ -82,6 +85,6 @@ def collect_logs(source_path, log_name): os.symlink(log_path, last_log_path) + def _get_random_id(): return ''.join(random.choice(string.letters) for i in xrange(8)) - diff --git a/devbot/shell.py b/devbot/shell.py index 66f26f9..ba9dfc1 100644 --- a/devbot/shell.py +++ b/devbot/shell.py @@ -5,6 +5,7 @@ import os from devbot import environ from devbot import config + def start(rcfile): environ.setup() diff --git a/devbot/state.py b/devbot/state.py index 7c2a839..41d458b 100644 --- a/devbot/state.py +++ b/devbot/state.py @@ -9,9 +9,11 @@ _BUILT_MODULES = "builtmodules" _FULL_BUILD = "fullbuild" _SYSTEM_CHECK = "syscheck" + def _get_state_path(name): return os.path.join(config.build_state_dir, "%s.json" % name) + def _load_state(name, default=None): state = default @@ -23,11 +25,13 @@ def _load_state(name, default=None): return state + def _save_state(name, state): with open(_get_state_path(name), "w+") as f: json.dump(state, f, indent=4) f.write('\n') + def _get_diff_hash(git_module): diff = git_module.diff().strip() if diff: @@ -35,6 +39,7 @@ def _get_diff_hash(git_module): else: return None + def _get_root_commit_id(): git_module = git.get_root_module() if git_module: @@ -44,6 +49,7 @@ def _get_root_commit_id(): return commit_id + def built_module_touch(module): git_module = module.get_git_module() built_modules = _load_state(_BUILT_MODULES, {}) @@ -54,6 +60,7 @@ def built_module_touch(module): _save_state(_BUILT_MODULES, built_modules) + def built_module_is_unchanged(module): git_module = module.get_git_module() built_modules = _load_state(_BUILT_MODULES, {}) @@ -65,6 +72,7 @@ def built_module_is_unchanged(module): return info["diff_hash"] == _get_diff_hash(git_module) and \ info["commit"] == git_module.get_commit_id() + def system_check_is_unchanged(): system_check = _load_state(_SYSTEM_CHECK) if not system_check: @@ -72,11 +80,13 @@ def system_check_is_unchanged(): return system_check["commit"] == _get_root_commit_id() + def system_check_touch(): system_check = _load_state(_SYSTEM_CHECK, {}) system_check["commit"] = _get_root_commit_id() _save_state(_SYSTEM_CHECK, system_check) + def full_build_is_required(): full_build = _load_state(_FULL_BUILD) if not full_build: @@ -84,11 +94,13 @@ def full_build_is_required(): return not (full_build["last"] == config.get_full_build()) + def full_build_touch(): full_build = _load_state(_FULL_BUILD, {}) full_build["last"] = config.get_full_build() _save_state(_FULL_BUILD, full_build) + def clean_build_state(): try: for name in _BUILT_MODULES, _FULL_BUILD: @@ -96,6 +108,7 @@ def clean_build_state(): except OSError: pass + def clean(): _state = None diff --git a/devbot/system.py b/devbot/system.py index 4b014a8..72e21cd 100644 --- a/devbot/system.py +++ b/devbot/system.py @@ -11,79 +11,93 @@ from devbot import state from devbot import utils from devbot import xvfb + def check_binary(check): return subprocess.call(["which", check], stdout=utils.devnull, stderr=subprocess.STDOUT) + def check_pkgconfig(check): return subprocess.call(["pkg-config", "--exists", check]) == 1 + def check_python(check): return subprocess.call(["python", "-c", check], stdout=utils.devnull, stderr=subprocess.STDOUT) == 1 + def check_gtkmodule(check): # Not sure we can do better than this, the gtkmodule stuff is private missing = True - + for libdir in config.system_lib_dirs: if os.path.exists("%s/gtk-2.0/modules/lib%s.so" % (libdir, check)): missing = False return missing + def check_include(check): return not os.path.exists(os.path.join("/usr/include/", check)) + def check_dbus(check): return not os.path.exists("/usr/share/dbus-1/services/%s.service" % check) + def check_metacity_theme(check): - return not os.path.exists("/usr/share/themes/%s/metacity-1/metacity-theme-3.xml" % check) + theme = "/usr/share/themes/%s/metacity-1/metacity-theme-3.xml" + return not os.path.exists(theme % check) + def check_gstreamer(check, version): missing = True - + for libdir in config.system_lib_dirs: - if os.path.exists("%s/gstreamer-%s/libgst%s.so" % \ + if os.path.exists("%s/gstreamer-%s/libgst%s.so" % (libdir, version, check)): missing = False return missing + def check_gstreamer_0_10(check): return check_gstreamer(check, "0.10") + def check_gstreamer_1_0(check): return check_gstreamer(check, "1.0") -checkers = { "binary": check_binary, - "python": check_python, - "pkgconfig": check_pkgconfig, - "gtkmodule": check_gtkmodule, - "dbus": check_dbus, - "gstreamer-0.10": check_gstreamer_0_10, - "gstreamer-1.0": check_gstreamer_1_0, - "metacity-theme": check_metacity_theme, - "include": check_include } +checkers = {"binary": check_binary, + "python": check_python, + "pkgconfig": check_pkgconfig, + "gtkmodule": check_gtkmodule, + "dbus": check_dbus, + "gstreamer-0.10": check_gstreamer_0_10, + "gstreamer-1.0": check_gstreamer_1_0, + "metacity-theme": check_metacity_theme, + "include": check_include} + def _print_checks(checks): for check in checks: print "[%s] %s" % (check["checker"], check["check"]) + def _eval_check_if(check): if "check_if" not in check: return True distro_info = distro.get_distro_info() - globals = { "distro": "%s-%s" % (distro_info.name, distro_info.version) } + globals = {"distro": "%s-%s" % (distro_info.name, distro_info.version)} print eval(check["check_if"], globals) return eval(check["check_if"], globals) == "True" + def run_checks(package_manager, checks, packages): distro_info = distro.get_distro_info() @@ -129,6 +143,7 @@ def run_checks(package_manager, checks, packages): return True + def remove_packages(package_manager, packages): distro_name = distro.get_distro_info().name @@ -154,6 +169,7 @@ def remove_packages(package_manager, packages): if to_remove: package_manager.remove_packages(to_remove) + def check(remove=False, update=False, test=False, interactive=True, skip_if_unchanged=False): if skip_if_unchanged: diff --git a/devbot/test.py b/devbot/test.py index fc2839b..6f57b63 100644 --- a/devbot/test.py +++ b/devbot/test.py @@ -6,6 +6,7 @@ from devbot import environ from devbot import command from devbot import xvfb + def test_one(module_name): environ.setup() @@ -15,6 +16,7 @@ def test_one(module_name): return False + def test(): environ.setup() @@ -25,6 +27,7 @@ def test(): return True + def _test_module(module): result = True diff --git a/devbot/utils.py b/devbot/utils.py index a8988f1..3b26afb 100644 --- a/devbot/utils.py +++ b/devbot/utils.py @@ -2,6 +2,7 @@ import os devnull = open("/dev/null", "w") + def ensure_dir(path): try: os.mkdir(path) diff --git a/devbot/xvfb.py b/devbot/xvfb.py index adc72f0..41110f7 100644 --- a/devbot/xvfb.py +++ b/devbot/xvfb.py @@ -3,14 +3,16 @@ import subprocess from devbot import utils + def _find_free_display(): - for i in range (100, 1000): + for i in range(100, 1000): display = ":%s" % i result = subprocess.call(args=["xdpyinfo", "--display", display], stdout=utils.devnull, stderr=subprocess.STDOUT) if result > 0: - return display + return display + def start(): xvfb_display = _find_free_display() @@ -22,6 +24,7 @@ def start(): return (xvfb_proc, orig_display) + def stop(xvfb_proc, orig_display): if orig_display is not None: os.environ["DISPLAY"] = orig_display diff --git a/tests/devbot/common.py b/tests/devbot/common.py index ace8831..548bd3e 100644 --- a/tests/devbot/common.py +++ b/tests/devbot/common.py @@ -4,6 +4,7 @@ import tempfile from devbot import config + class DevbotTestCase(unittest.TestCase): def setUp(self): self.setup_config() diff --git a/tests/devbot/test_config.py b/tests/devbot/test_config.py index 4309723..072c3a3 100644 --- a/tests/devbot/test_config.py +++ b/tests/devbot/test_config.py @@ -13,6 +13,7 @@ base_dir = os.path.dirname(os.path.dirname(tests_dir)) config_dir = os.path.join(base_dir, "config") data_dir = os.path.join(tests_dir, "data") + class TestConfig(common.DevbotTestCase): def setUp(self): self.setup_config({"config_dir": config_dir}) @@ -22,15 +23,15 @@ class TestConfig(common.DevbotTestCase): for info_class in distro._supported_distros: if info_class.__module__.endswith("fedora"): info_class._FEDORA_RELEASE_PATH = \ - os.path.join(data_dir, "fedora-release-%s" % version) + os.path.join(data_dir, "fedora-release-%s" % version) if info_class.__module__.endswith("debian"): info_class._DEBIAN_VERSION_PATH = \ - os.path.join(data_dir, "debian_version-wheezy") + os.path.join(data_dir, "debian_version-wheezy") if info_class.__module__.endswith("ubuntu"): info_class._OS_RELEASE_PATH = \ - os.path.join(data_dir, "os-release-ubuntu-12.10") + os.path.join(data_dir, "os-release-ubuntu-12.10") def _get_architecture(self): return "x86_64" @@ -71,12 +72,12 @@ class TestConfig(common.DevbotTestCase): self._set_distro("fedora", "17") modules = config.load_modules() - self._assert_module(modules, "gnome-keyring") - self._assert_module(modules, "glib") + self._assert_module(modules, "gnome-keyring") + self._assert_module(modules, "glib") self._assert_module(modules, "gtk+") self._assert_module(modules, "gstreamer") - self._assert_module(modules, "sugar") - + self._assert_module(modules, "sugar") + self._unset_distro() def test_fedora_18_modules(self): @@ -85,11 +86,11 @@ class TestConfig(common.DevbotTestCase): self.assertEquals("fedora", distro.get_distro_info().name) self.assertEquals("18", distro.get_distro_info().version) modules = config.load_modules() - self._assert_module(modules, "glib") + self._assert_module(modules, "glib") self._assert_no_module(modules, "gtk+") - self._assert_no_module(modules, "gnome-keyring") + self._assert_no_module(modules, "gnome-keyring") self._assert_no_module(modules, "gstreamer") - self._assert_module(modules, "sugar") + self._assert_module(modules, "sugar") self._unset_distro() @@ -97,11 +98,11 @@ class TestConfig(common.DevbotTestCase): self._set_distro("ubuntu", "12.10") modules = config.load_modules() - self._assert_module(modules, "glib") + self._assert_module(modules, "glib") self._assert_no_module(modules, "gtk+") - self._assert_no_module(modules, "gnome-keyring") + self._assert_no_module(modules, "gnome-keyring") self._assert_no_module(modules, "gstreamer") - self._assert_module(modules, "sugar") + self._assert_module(modules, "sugar") self._unset_distro() @@ -109,10 +110,10 @@ class TestConfig(common.DevbotTestCase): self._set_distro("debian", "wheezy") modules = config.load_modules() - self._assert_module(modules, "gnome-keyring") - self._assert_module(modules, "glib") + self._assert_module(modules, "gnome-keyring") + self._assert_module(modules, "glib") self._assert_module(modules, "gtk+") self._assert_module(modules, "gstreamer") - self._assert_module(modules, "sugar") + self._assert_module(modules, "sugar") self._unset_distro() diff --git a/tests/devbot/test_git.py b/tests/devbot/test_git.py index 48456bc..1e39650 100644 --- a/tests/devbot/test_git.py +++ b/tests/devbot/test_git.py @@ -5,6 +5,7 @@ import subprocess from devbot import git + class TestGit(unittest.TestCase): def _create_repo(self): path = tempfile.mkdtemp() @@ -53,7 +54,7 @@ class TestGit(unittest.TestCase): def _create_module(self, remote, branch="master", tag=None): path = tempfile.mkdtemp() name = "test" - + return git.Module(path=path, name=name, remote=remote, branch=branch, tag=tag) @@ -66,12 +67,12 @@ class TestGit(unittest.TestCase): return module def test_clone(self): - module = self._setup_module() + module = self._setup_module() self.assertTrue(os.path.exists(os.path.join(module.local, "README"))) def test_update_on_master(self): - module = self._setup_module() - + module = self._setup_module() + self._write_file(module.remote, "masterchange") self._commit(module.remote, "masterchange") @@ -94,7 +95,7 @@ class TestGit(unittest.TestCase): def test_update_detached(self): remote = self._create_repo() - + module = self._create_module(remote, tag=self._get_head(remote)) module.update() @@ -107,7 +108,7 @@ class TestGit(unittest.TestCase): self.assertEquals("detachedchange", self._read_file(module)) def test_clean(self): - module = self._setup_module() + module = self._setup_module() module.update() to_clean_path = os.path.join(module.local, "changetoclean") diff --git a/tests/sugar/shell.py b/tests/sugar/shell.py index 14a0709..ef2e4af 100644 --- a/tests/sugar/shell.py +++ b/tests/sugar/shell.py @@ -5,6 +5,7 @@ import tree ACTIVITIES_WITH_OBJECT_CHOOSER = ["Read", "Jukebox"] + def build_activities_list(): root = tree.get_root() shell = root.find_child(name="sugar-session", role_name="application") @@ -14,7 +15,7 @@ def build_activities_list(): table = shell.find_child(role_name="table") cells = table.find_children(role_name="table cell") - for row in [cells[i:i+5] for i in range(0, len(cells), 5)]: + for row in [cells[i:i + 5] for i in range(0, len(cells), 5)]: activity_name = row[2].text activities.append(activity_name) @@ -22,8 +23,9 @@ def build_activities_list(): return activities + def launch_and_stop_activity(activity_name): - print "Launching %s" % activity_name + print "Launching %s" % activity_name root = tree.get_root() shell = root.find_child(name="sugar-session", role_name="application") @@ -31,14 +33,14 @@ def launch_and_stop_activity(activity_name): table = shell.find_child(role_name="table") cells = table.find_children(role_name="table cell") - for row in [cells[i:i+5] for i in range(0, len(cells), 5)]: + for row in [cells[i:i + 5] for i in range(0, len(cells), 5)]: name = row[2].name icon = row[1] if name == activity_name: icon.click() - print "Stopping %s" % activity_name + print "Stopping %s" % activity_name if activity_name in ACTIVITIES_WITH_OBJECT_CHOOSER: close_button = shell.find_child(name="Close", @@ -58,6 +60,7 @@ def launch_and_stop_activity(activity_name): if activity is not None: raise RuntimeError + def go_to_list_view(): root = tree.get_root() shell = root.find_child(name="sugar-session", role_name="application") @@ -68,6 +71,7 @@ def go_to_list_view(): radio_button = shell.find_child(name="List view", role_name="radio button") radio_button.do_action("click") + def main(): go_to_list_view() diff --git a/tests/sugar/tree.py b/tests/sugar/tree.py index 88080c0..1438acc 100644 --- a/tests/sugar/tree.py +++ b/tests/sugar/tree.py @@ -4,9 +4,11 @@ from gi.repository import Atspi Atspi.set_timeout(-1, -1) + def get_root(): return Node(Atspi.get_desktop(0)) + def _retry_find(func): def wrapped(*args, **kwargs): result = None @@ -33,6 +35,7 @@ def _retry_find(func): return wrapped + class Node: def __init__(self, accessible): self._accessible = accessible diff --git a/tools/json-normalize b/tools/json-normalize index ec6bd0f..069908d 100755 --- a/tools/json-normalize +++ b/tools/json-normalize @@ -15,7 +15,7 @@ for path in args.paths: in_file.close() if args.sort_by is not None: - data.sort(key=itemgetter(args.sort_by)) + data.sort(key=itemgetter(args.sort_by)) out_file = open(path, "wb") json.dump(data, out_file, sort_keys=True, indent=4) -- cgit v0.9.1