def old_tree_timestamp_warn(portdir, settings): unixtime = time.time() default_warnsync = 30 timestamp_file = os.path.join(portdir, "metadata/timestamp.x") try: lastsync = grabfile(timestamp_file) except PortageException: return False if not lastsync: return False lastsync = lastsync[0].split() if not lastsync: return False try: lastsync = int(lastsync[0]) except ValueError: return False var_name = "PORTAGE_SYNC_STALE" try: warnsync = float(settings.get(var_name, default_warnsync)) except ValueError: writemsg_level( "!!! %s contains non-numeric value: %s\n" % (var_name, settings[var_name]), level=logging.ERROR, noiselevel=-1, ) return False if warnsync <= 0: return False if (unixtime - 86400 * warnsync) > lastsync: out = EOutput() if have_english_locale(): out.ewarn("Last emerge --sync was %s ago." % whenago(unixtime - lastsync)) else: out.ewarn( _("Last emerge --sync was %s.") % _unicode_decode(time.strftime("%c", time.localtime(lastsync)))) return True return False
class HookDirectory(object): def __init__ (self, phase, settings, myopts=None, myaction=None, mytargets=None): self.myopts = myopts self.myaction = myaction self.mytargets = mytargets check_config_instance(settings) self.settings = settings self.path = os.path.join(settings["PORTAGE_CONFIGROOT"], HOOKS_PATH, phase + '.d') self.output = EOutput() def execute (self, path=None): if "hooks" not in self.settings['FEATURES']: return if not path: path = self.path path = normalize_path(path) if not os.path.exists(path): if self.myopts and "--debug" in self.myopts: # behavior mimicked by hook.sh self.output.ewarn('This hook path could not be found; ignored: ' + path) return if os.path.isdir(path): command=[HOOKS_SH_BINARY] if self.myopts: for myopt in self.myopts: command.extend(['--opt', myopt]) if self.myaction: command.extend(['--action', self.myaction]) if self.mytargets: for mytarget in self.mytargets: command.extend(['--target', mytarget]) command=[BASH_BINARY, '-c', 'cd "'+path+'" && source "' + PORTAGE_BIN_PATH + '/isolated-functions.sh" && source ' + ' '.join(command)] if self.myopts and "--verbose" in self.myopts: self.output.einfo('Executing hooks directory "' + self.path + '"...') code = spawn(mycommand=command, env=self.settings.environ()) if code: # if failure # behavior mimicked by hook.sh raise PortageException('!!! Hook directory %s failed with exit code %s' % (self.path, code)) else: raise InvalidLocation('This hook path ought to be a directory: ' + path)
def old_tree_timestamp_warn(portdir, settings): unixtime = time.time() default_warnsync = 30 timestamp_file = os.path.join(portdir, "metadata/timestamp.x") try: lastsync = grabfile(timestamp_file) except PortageException: return False if not lastsync: return False lastsync = lastsync[0].split() if not lastsync: return False try: lastsync = int(lastsync[0]) except ValueError: return False var_name = 'PORTAGE_SYNC_STALE' try: warnsync = float(settings.get(var_name, default_warnsync)) except ValueError: writemsg_level("!!! %s contains non-numeric value: %s\n" % \ (var_name, settings[var_name]), level=logging.ERROR, noiselevel=-1) return False if warnsync <= 0: return False if (unixtime - 86400 * warnsync) > lastsync: out = EOutput() if have_english_locale(): out.ewarn("Last emerge --sync was %s ago." % \ whenago(unixtime - lastsync)) else: out.ewarn(_("Last emerge --sync was %s.") % \ _unicode_decode(time.strftime( '%c', time.localtime(lastsync)))) return True return False
def verify_head(self): if (self.repo.module_specific_options.get( 'sync-git-verify-commit-signature', 'false') != 'true'): return True if self.repo.sync_openpgp_key_path is not None: if gemato is None: writemsg_level( "!!! Verifying against specified key requires gemato-11.0+ installed\n", level=logging.ERROR, noiselevel=-1) return False openpgp_env = gemato.openpgp.OpenPGPEnvironment() else: openpgp_env = None try: out = EOutput() env = None if openpgp_env is not None: try: out.einfo('Using keys from %s' % (self.repo.sync_openpgp_key_path, )) with io.open(self.repo.sync_openpgp_key_path, 'rb') as f: openpgp_env.import_key(f) out.ebegin('Refreshing keys from keyserver') openpgp_env.refresh_keys() out.eend(0) except GematoException as e: writemsg_level( "!!! Verification impossible due to keyring problem:\n%s\n" % (e, ), level=logging.ERROR, noiselevel=-1) return (1, False) env = os.environ.copy() env['GNUPGHOME'] = openpgp_env.home rev_cmd = [self.bin_command, "log", "--pretty=format:%G?", "-1"] try: status = (portage._unicode_decode( subprocess.check_output(rev_cmd, cwd=portage._unicode_encode( self.repo.location), env=env)).strip()) except subprocess.CalledProcessError: return False if status == 'G': # good signature is good out.einfo('Trusted signature found on top commit') return True elif status == 'U': # untrusted out.ewarn('Top commit signature is valid but not trusted') return True else: if status == 'B': expl = 'bad signature' elif status == 'X': expl = 'expired signature' elif status == 'Y': expl = 'expired key' elif status == 'R': expl = 'revoked key' elif status == 'E': expl = 'unable to verify signature (missing key?)' elif status == 'N': expl = 'no signature' else: expl = 'unknown issue' out.eerror('No valid signature found: %s' % (expl, )) return False finally: if openpgp_env is not None: openpgp_env.close()
files_list = set() for dir in gir_dirs: # Walk the gir directories to find files for (path, dirs, files) in os.walk(osp.join(root, dir)): for f in files: if not f.endswith('.gir'): continue if force: files_list.add(osp.join(path, f)) continue spinner.update() # Get the .gir version version = get_version(osp.join(path, f)) # If not the same version as GIRepository.gir, rebuild it if vercmp(girversion, version) != 0: eoutput.ewarn("GIR file to be rebuilt: " + \ osp.join(path, f)) files_list.add(osp.join(path, f)) eoutput.eend(0) # FIXME: Doesn't warn if it was unable to assign a file to a package rebuild_list = set() if files_list: eoutput.ebegin("Assigning files to packages") files_assigned = set() for cpv in vardbapi.cpv_all(): spinner.update() # If some of the files of this package are in the gir file list files_owned = get_contents(cpv).intersection(files_list) if files_owned: files_assigned.update(files_owned) slot = vardbapi.aux_get(cpv, ['SLOT'])[0]
def verify_head(self, revision="-1"): if self.repo.module_specific_options.get( "sync-git-verify-commit-signature", "false").lower() not in ("true", "yes"): return True if self.repo.sync_openpgp_key_path is not None and gemato is None: writemsg_level( "!!! Verifying against specified key requires gemato-14.5+ installed\n", level=logging.ERROR, noiselevel=-1, ) return False openpgp_env = self._get_openpgp_env(self.repo.sync_openpgp_key_path) try: out = EOutput() env = None if openpgp_env is not None and self.repo.sync_openpgp_key_path is not None: try: out.einfo("Using keys from %s" % (self.repo.sync_openpgp_key_path, )) with io.open(self.repo.sync_openpgp_key_path, "rb") as f: openpgp_env.import_key(f) self._refresh_keys(openpgp_env) except (GematoException, asyncio.TimeoutError) as e: writemsg_level( "!!! Verification impossible due to keyring problem:\n%s\n" % (e, ), level=logging.ERROR, noiselevel=-1, ) return False env = os.environ.copy() env["GNUPGHOME"] = openpgp_env.home rev_cmd = [ self.bin_command, "log", "-n1", "--pretty=format:%G?", revision ] try: status = portage._unicode_decode( subprocess.check_output( rev_cmd, cwd=portage._unicode_encode(self.repo.location), env=env, )).strip() except subprocess.CalledProcessError: return False if status == "G": # good signature is good out.einfo("Trusted signature found on top commit") return True if status == "U": # untrusted out.ewarn("Top commit signature is valid but not trusted") return True if status == "B": expl = "bad signature" elif status == "X": expl = "expired signature" elif status == "Y": expl = "expired key" elif status == "R": expl = "revoked key" elif status == "E": expl = "unable to verify signature (missing key?)" elif status == "N": expl = "no signature" else: expl = "unknown issue" out.eerror("No valid signature found: %s" % (expl, )) return False finally: if openpgp_env is not None: openpgp_env.close()
def verify_head(self, revision='-1'): if (self.repo.module_specific_options.get( 'sync-git-verify-commit-signature', 'false') != 'true'): return True if self.repo.sync_openpgp_key_path is not None: if gemato is None: writemsg_level("!!! Verifying against specified key requires gemato-11.0+ installed\n", level=logging.ERROR, noiselevel=-1) return False openpgp_env = gemato.openpgp.OpenPGPEnvironment() else: openpgp_env = None try: out = EOutput() env = None if openpgp_env is not None: try: out.einfo('Using keys from %s' % (self.repo.sync_openpgp_key_path,)) with io.open(self.repo.sync_openpgp_key_path, 'rb') as f: openpgp_env.import_key(f) out.ebegin('Refreshing keys from keyserver') openpgp_env.refresh_keys() out.eend(0) except GematoException as e: writemsg_level("!!! Verification impossible due to keyring problem:\n%s\n" % (e,), level=logging.ERROR, noiselevel=-1) return False env = os.environ.copy() env['GNUPGHOME'] = openpgp_env.home rev_cmd = [self.bin_command, "log", "-n1", "--pretty=format:%G?", revision] try: status = (portage._unicode_decode( subprocess.check_output(rev_cmd, cwd=portage._unicode_encode(self.repo.location), env=env)) .strip()) except subprocess.CalledProcessError: return False if status == 'G': # good signature is good out.einfo('Trusted signature found on top commit') return True elif status == 'U': # untrusted out.ewarn('Top commit signature is valid but not trusted') return True else: if status == 'B': expl = 'bad signature' elif status == 'X': expl = 'expired signature' elif status == 'Y': expl = 'expired key' elif status == 'R': expl = 'revoked key' elif status == 'E': expl = 'unable to verify signature (missing key?)' elif status == 'N': expl = 'no signature' else: expl = 'unknown issue' out.eerror('No valid signature found: %s' % (expl,)) return False finally: if openpgp_env is not None: openpgp_env.close()
class HookDirectory(object): def __init__(self, phase, settings, myopts=None, myaction=None, mytargets=None): self.myopts = myopts self.myaction = myaction self.mytargets = mytargets check_config_instance(settings) self.settings = settings self.path = os.path.join(settings["PORTAGE_CONFIGROOT"], HOOKS_PATH, phase + '.d') self.output = EOutput() def execute(self, path=None): if "hooks" not in self.settings['FEATURES']: return if not path: path = self.path path = normalize_path(path) if not os.path.exists(path): if self.myopts and "--debug" in self.myopts: # behavior mimicked by hook.sh self.output.ewarn( 'This hook path could not be found; ignored: ' + path) return if os.path.isdir(path): command = [HOOKS_SH_BINARY] if self.myopts: for myopt in self.myopts: command.extend(['--opt', myopt]) if self.myaction: command.extend(['--action', self.myaction]) if self.mytargets: for mytarget in self.mytargets: command.extend(['--target', mytarget]) command = [ BASH_BINARY, '-c', 'cd "' + path + '" && source "' + PORTAGE_BIN_PATH + '/isolated-functions.sh" && source ' + ' '.join(command) ] if self.myopts and "--verbose" in self.myopts: self.output.einfo('Executing hooks directory "' + self.path + '"...') code = spawn(mycommand=command, env=self.settings.environ()) if code: # if failure # behavior mimicked by hook.sh raise PortageException( '!!! Hook directory %s failed with exit code %s' % (self.path, code)) else: raise InvalidLocation('This hook path ought to be a directory: ' + path)