def packages(self, only_enabled=False, matching=None): '''Iterates on the installed packages. If only_enabled is True, only enabled packages are returned. matching can be a list of regexps, if it is given a package is returned only if it matches at least one regexp ''' if matching is not None: regexps = [ re.compile(pattern + '$', re.IGNORECASE) for pattern in matching ] for pkgname in os.listdir(os.path.join(self.virtual_path, 'pkgs')): try: pkg = self.get_package(pkgname) except UserError: log.warning('Invalid entry in pkgs: %s', pkgname) continue if not only_enabled or pkg.enabled: if matching is None: yield pkg else: for regexp in regexps: if regexp.match(pkg.name): yield pkg break
def cpu_count(): try: import multiprocessing return multiprocessing.cpu_count() except Exception: log.warning('Can not determine the number of CPUs') return 1
def unittest(self): log.info("Testing sourcedir %s", self.path) sh_line = 'source "%s";' % BASE_SH_SCRIPT + 'cd "%s";' % self._sourcedir + "source bpt-rules;" + "bpt_unittest;" exitstatus = call(["bash", "-e", "-c", sh_line]) if exitstatus != 0: log.warning("unittest exited with exit code %s. Some tests may have failed", exitstatus) return False return True
def get_current_box(): ''' If we are in a box environment, return the current box. Otherwise None.''' box_path = os.environ.get('BPT_BOX_PATH', None) if box_path is not None: try: box = Box(box_path) return box except UserError, exc: log.warning('Not using current box %s because of error "%s"', box_path, str(exc))
def unittest(self): log.info('Testing sourcedir %s', self.path) sh_line = ('source "%s";' % BASE_SH_SCRIPT + 'cd "%s";' % self._sourcedir + 'source bpt-rules;' + 'bpt_unittest;') exitstatus = call(['bash', '-e', '-c', sh_line]) if exitstatus != 0: log.warning( 'unittest exited with exit code %s. Some tests may have failed', exitstatus) return False return True
def unittest(self): log.info('Testing sourcedir %s', self.path) sh_line = ('source "%s";' % BASE_SH_SCRIPT + 'cd "%s";' % self._sourcedir + 'source bpt-rules;' + 'bpt_unittest;' ) exitstatus = call(['bash', '-e', '-c', sh_line]) if exitstatus != 0: log.warning('unittest exited with exit code %s. Some tests may have failed', exitstatus) return False return True
def packages(self, only_enabled=False, matching=None): '''Iterates on the installed packages. If only_enabled is True, only enabled packages are returned. matching can be a list of regexps, if it is given a package is returned only if it matches at least one regexp ''' if matching is not None: regexps = [re.compile(pattern + '$', re.IGNORECASE) for pattern in matching] for pkgname in os.listdir(os.path.join(self.virtual_path, 'pkgs')): try: pkg = self.get_package(pkgname) except UserError: log.warning('Invalid entry in pkgs: %s', pkgname) continue if not only_enabled or pkg.enabled: if matching is None: yield pkg else: for regexp in regexps: if regexp.match(pkg.name): yield pkg break