本文整理汇总了Python中portage.output.red函数的典型用法代码示例。如果您正苦于以下问题:Python red函数的具体用法?Python red怎么用?Python red使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了red函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check
def check(self, checkdir, repolevel):
'''Runs checks on the package metadata.xml file
@param checkdir: string, path
@param repolevel: integer
@return boolean, False == bad metadata
'''
if not self.capable:
if self.options.xml_parse or repolevel == 3:
print("%s sorry, xmllint is needed. failing\n" % red("!!!"))
sys.exit(1)
return True
# xmlint can produce garbage output even on success, so only dump
# the ouput when it fails.
st, out = repoman_getstatusoutput(
self.binary + " --nonet --noout --dtdvalid %s %s" % (
portage._shell_quote(self.metadata_dtd),
portage._shell_quote(
os.path.join(checkdir, "metadata.xml"))))
if st != os.EX_OK:
print(red("!!!") + " metadata.xml is invalid:")
for z in out.splitlines():
print(red("!!! ") + z)
return False
return True
示例2: _vcs_autoadd
def _vcs_autoadd(self):
myunadded = self.vcs_settings.changes.unadded
myautoadd = []
if myunadded:
for x in range(len(myunadded) - 1, -1, -1):
xs = myunadded[x].split("/")
if self.repo_settings.repo_config.find_invalid_path_char(myunadded[x]) != -1:
# The Manifest excludes this file,
# so it's safe to ignore.
del myunadded[x]
elif xs[-1] == "files":
print("!!! files dir is not added! Please correct this.")
sys.exit(-1)
elif xs[-1] == "Manifest":
# It's a manifest... auto add
myautoadd += [myunadded[x]]
del myunadded[x]
if myunadded:
print(red(
"!!! The following files are in your local tree"
" but are not added to the master"))
print(red(
"!!! tree. Please remove them from the local tree"
" or add them to the master tree."))
for x in myunadded:
print(" ", x)
print()
print()
sys.exit(1)
return myautoadd
示例3: get_slotted_cps
def get_slotted_cps(cpvs, logger):
"""Uses portage to reduce the cpv list into a cp:slot list and returns it
"""
from portage.versions import catpkgsplit
from portage import portdb
cps = []
for cpv in cpvs:
parts = catpkgsplit(cpv)
if not parts:
logger.warning(('\t' + red("Failed to split the following pkg: "
"%s, not a valid cat/pkg-ver" %cpv)))
continue
cp = parts[0] + '/' + parts[1]
try:
slot = portdb.aux_get(cpv, ["SLOT"])
except KeyError:
match, slot = get_best_match(cpv, cp, logger)
if not match:
logger.warning('\t' + red("Installed package: "
"%s is no longer available" %cp))
continue
if slot[0]:
cps.append(cp + ":" + slot[0])
else:
cps.append(cp)
return cps
示例4: detect_conflicts
def detect_conflicts(options):
"""Determine if the checkout has cvs conflicts.
TODO(antarus): Also this should probably not call sys.exit() as
repoman is run on >1 packages and one failure should not cause
subsequent packages to fail.
Returns:
None (calls sys.exit on fatal problems)
"""
cmd = ("cvs -n up 2>/dev/null | "
"egrep '^[^\?] .*' | "
"egrep -v '^. .*/digest-[^/]+|^cvs server: .* -- ignored$'")
msg = ("Performing a %s with a little magic grep to check for updates."
% green("cvs -n up"))
logging.info(msg)
# Use Popen instead of getstatusoutput(), in order to avoid
# unicode handling problems (see bug #310789).
args = [BASH_BINARY, "-c", cmd]
args = [_unicode_encode(x) for x in args]
proc = subprocess.Popen(
args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out = _unicode_decode(proc.communicate()[0])
proc.wait()
mylines = out.splitlines()
myupdates = []
for line in mylines:
if not line:
continue
# [ ] Unmodified (SVN) [U] Updates [P] Patches
# [M] Modified [A] Added [R] Removed / Replaced
# [D] Deleted
if line[0] not in " UPMARD":
# Stray Manifest is fine, we will readd it anyway.
if line[0] == '?' and line[1:].lstrip() == 'Manifest':
continue
logging.error(red(
"!!! Please fix the following issues reported "
"from cvs: %s" % green("(U,P,M,A,R,D are ok)")))
logging.error(red(
"!!! Note: This is a pretend/no-modify pass..."))
logging.error(out)
sys.exit(1)
elif line[0] in "UP":
myupdates.append(line[2:])
if myupdates:
logging.info(green("Fetching trivial updates..."))
if options.pretend:
logging.info("(cvs update " + " ".join(myupdates) + ")")
retval = os.EX_OK
else:
retval = os.system("cvs update " + " ".join(myupdates))
if retval != os.EX_OK:
logging.fatal("!!! cvs exited with an error. Terminating.")
sys.exit(retval)
return False
示例5: get_best_match
def get_best_match(cpv, cp, logger):
"""Tries to find another version of the pkg with the same slot
as the deprecated installed version. Failing that attempt to get any version
of the same app
@param cpv: string
@param cp: string
@rtype tuple: ([cpv,...], SLOT)
"""
slot = portage.db[portage.root]["vartree"].dbapi.aux_get(cpv, ["SLOT"])[0]
logger.warning('\t%s "%s" %s.' % (yellow('* Warning:'), cpv,bold('ebuild not found.')))
logger.debug('\tget_best_match(); Looking for %s:%s' %(cp, slot))
try:
match = portdb.match('%s:%s' %(cp, slot))
except portage.exception.InvalidAtom:
match = None
if not match:
logger.warning('\t' + red('!!') + ' ' + yellow(
'Could not find ebuild for %s:%s' %(cp, slot)))
slot = ['']
match = portdb.match(cp)
if not match:
logger.warning('\t' + red('!!') + ' ' +
yellow('Could not find ebuild for ' + cp))
return match, slot
示例6: detect_conflicts
def detect_conflicts(options):
"""Determine if the checkout has problems like cvs conflicts.
If you want more vcs support here just keep adding if blocks...
This could be better.
TODO(antarus): Also this should probably not call sys.exit() as
repoman is run on >1 packages and one failure should not cause
subsequent packages to fail.
Args:
vcs - A string identifying the version control system in use
Returns: boolean
(calls sys.exit on fatal problems)
"""
cmd = "svn status -u 2>&1 | egrep -v '^. +.*/digest-[^/]+' | head -n-1"
msg = "Performing a %s with a little magic grep to check for updates." % green("svn status -u")
logging.info(msg)
# Use Popen instead of getstatusoutput(), in order to avoid
# unicode handling problems (see bug #310789).
args = [BASH_BINARY, "-c", cmd]
args = [_unicode_encode(x) for x in args]
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out = _unicode_decode(proc.communicate()[0])
proc.wait()
mylines = out.splitlines()
myupdates = []
for line in mylines:
if not line:
continue
# [ ] Unmodified (SVN) [U] Updates [P] Patches
# [M] Modified [A] Added [R] Removed / Replaced
# [D] Deleted
if line[0] not in " UPMARD":
# Stray Manifest is fine, we will readd it anyway.
if line[0] == "?" and line[1:].lstrip() == "Manifest":
continue
logging.error(
red("!!! Please fix the following issues reported " "from cvs: %s" % green("(U,P,M,A,R,D are ok)"))
)
logging.error(red("!!! Note: This is a pretend/no-modify pass..."))
logging.error(out)
sys.exit(1)
elif line[8] == "*":
myupdates.append(line[9:].lstrip(" 1234567890"))
if myupdates:
logging.info(green("Fetching trivial updates..."))
if options.pretend:
logging.info("(svn update " + " ".join(myupdates) + ")")
retval = os.EX_OK
else:
retval = os.system("svn update " + " ".join(myupdates))
if retval != os.EX_OK:
logging.fatal("!!! svn exited with an error. Terminating.")
sys.exit(retval)
return False
示例7: detect_vcs_conflicts
def detect_vcs_conflicts(options, vcs):
"""Determine if the checkout has problems like cvs conflicts.
If you want more vcs support here just keep adding if blocks...
This could be better.
TODO(antarus): Also this should probably not call sys.exit() as
repoman is run on >1 packages and one failure should not cause
subsequent packages to fail.
Args:
vcs - A string identifying the version control system in use
Returns:
None (calls sys.exit on fatal problems)
"""
retval = ("","")
if vcs == 'cvs':
logging.info("Performing a " + output.green("cvs -n up") + \
" with a little magic grep to check for updates.")
retval = subprocess_getstatusoutput("cvs -n up 2>/dev/null | " + \
"egrep '^[^\?] .*' | " + \
"egrep -v '^. .*/digest-[^/]+|^cvs server: .* -- ignored$'")
if vcs == 'svn':
logging.info("Performing a " + output.green("svn status -u") + \
" with a little magic grep to check for updates.")
retval = subprocess_getstatusoutput("svn status -u 2>&1 | " + \
"egrep -v '^. +.*/digest-[^/]+' | " + \
"head -n-1")
if vcs in ['cvs', 'svn']:
mylines = retval[1].splitlines()
myupdates = []
for line in mylines:
if not line:
continue
if line[0] not in " UPMARD": # unmodified(svn),Updates,Patches,Modified,Added,Removed/Replaced(svn),Deleted(svn)
# Stray Manifest is fine, we will readd it anyway.
if line[0] == '?' and line[1:].lstrip() == 'Manifest':
continue
logging.error(red("!!! Please fix the following issues reported " + \
"from cvs: ")+green("(U,P,M,A,R,D are ok)"))
logging.error(red("!!! Note: This is a pretend/no-modify pass..."))
logging.error(retval[1])
sys.exit(1)
elif vcs == 'cvs' and line[0] in "UP":
myupdates.append(line[2:])
elif vcs == 'svn' and line[8] == '*':
myupdates.append(line[9:].lstrip(" 1234567890"))
if myupdates:
logging.info(green("Fetching trivial updates..."))
if options.pretend:
logging.info("(" + vcs + " update " + " ".join(myupdates) + ")")
retval = os.EX_OK
else:
retval = os.system(vcs + " update " + " ".join(myupdates))
if retval != os.EX_OK:
logging.fatal("!!! " + vcs + " exited with an error. Terminating.")
sys.exit(retval)
示例8: _vcs_deleted
def _vcs_deleted(self, mydeleted):
if self.vcs_settings.vcs == "hg" and mydeleted:
print(red(
"!!! The following files are removed manually"
" from your local tree but are not"))
print(red(
"!!! removed from the repository."
" Please remove them, using \"hg remove [FILES]\"."))
for x in mydeleted:
print(" ", x)
print()
print()
sys.exit(1)
示例9: check_profiles
def check_profiles(profiles, archlist):
for x in archlist:
if x[0] == "~":
continue
if x not in profiles:
print(red(
"\"%s\" doesn't have a valid profile listed in profiles.desc." % x))
print(red(
"You need to either \"cvs update\" your profiles dir"
" or follow this"))
print(red(
"up with the " + x + " team."))
print()
示例10: _vcs_deleted
def _vcs_deleted(self):
if self.vcs_settings.changes.has_deleted:
print(red(
"!!! The following files are removed manually"
" from your local tree but are not"))
print(red(
"!!! removed from the repository."
" Please remove them, using \"%s remove [FILES]\"."
% self.vcs_settings.vcs))
for x in self.vcs_settings.changes.deleted:
print(" ", x)
print()
print()
sys.exit(1)
示例11: assign_packages
def assign_packages(broken, logger, settings):
''' Finds and returns packages that owns files placed in broken.
Broken is list of files
'''
stime = current_milli_time()
broken_matcher = _file_matcher()
for filename in broken:
broken_matcher.add(filename)
assigned_pkgs = set()
assigned_filenames = set()
for group in os.listdir(settings['PKG_DIR']):
grppath = settings['PKG_DIR'] + group
if not os.path.isdir(grppath):
continue
for pkg in os.listdir(grppath):
pkgpath = settings['PKG_DIR'] + group + '/' + pkg
if not os.path.isdir(pkgpath):
continue
f = pkgpath + '/CONTENTS'
if os.path.exists(f):
contents_matcher = _file_matcher()
try:
with io.open(f, 'r', encoding='utf_8') as cnt:
for line in cnt.readlines():
m = re.match('^obj (/[^ ]+)', line)
if m is not None:
contents_matcher.add(m.group(1))
except Exception as e:
logger.warning(red(' !! Failed to read ' + f))
logger.warning(red(' !! Error was:' + str(e)))
else:
for m in contents_matcher.intersection(broken_matcher):
found = group+'/'+pkg
assigned_pkgs.add(found)
assigned_filenames.add(m)
logger.info('\t' + green('* ') + m +
' -> ' + bold(found))
broken_filenames = set(broken)
orphaned = broken_filenames.difference(assigned_filenames)
ftime = current_milli_time()
logger.debug("\tassign_packages(); assigned "
"%d packages, %d orphans in %d milliseconds"
% (len(assigned_pkgs), len(orphaned), ftime-stime))
return (assigned_pkgs, orphaned)
示例12: save_cache
def save_cache(logger, to_save={}, temp_path=DEFAULTS['DEFAULT_TMP_DIR']):
''' Tries to store caching information.
@param logger
@param to_save have to be dict with keys:
libraries, la_libraries, libraries_links and binaries
'''
if not os.path.exists(temp_path):
os.makedirs(temp_path)
try:
_file = open(_unicode_encode(os.path.join(temp_path, 'timestamp'),
encoding=_encodings['fs']), mode='w', encoding=_encodings['content'])
_file.write(_unicode(int(time.time())))
_file.close()
for key,val in to_save.items():
_file = open(_unicode_encode(os.path.join(temp_path, key),
encoding=_encodings['fs']), mode='w',
encoding=_encodings['content'])
for line in val:
_file.write(line + '\n')
_file.close()
except Exception as ex:
logger.warning('\t' + red('Could not save cache: %s' %str(ex)))
示例13: search_ebuilds
def search_ebuilds(path, portdir=True, searchdef="", repo_num="",
config=None, data=None):
pv = ""
pkgs = []
nr = len(data['ebuilds']) + 1
if portdir:
rep = darkgreen("Portage ")
else:
rep = red("Overlay "+str(repo_num)+" ")
if isdir(path):
filelist = listdir(path)
for file in filelist:
if file[-7:] == ".ebuild":
pv = file[:-7]
pkgs.append(list(pkgsplit(pv)))
pkgs[-1].append(path + file)
if searchdef != "" and pv == searchdef:
data['defebuild'] = (searchdef, pkgs[-1][3])
if not portdir:
config['found_in_overlay'] = True
pkgs.sort(key=cmp_sort_key(mypkgcmp))
for pkg in pkgs:
rev = ""
if pkg[2] != "r0":
rev = "-" + pkg[2]
data['output'].append(" " + rep + " [" + bold(str(nr)) + "] " +
pkg[0] + "-" + pkg[1] + rev + "\n")
data['ebuilds'].append(pkg[len(pkg)-1])
nr += 1
示例14: __init__
def __init__(self, options=None, repoman_settings=None):
if options.vcs:
if options.vcs in ('cvs', 'svn', 'git', 'bzr', 'hg'):
self.vcs = options.vcs
else:
self.vcs = None
else:
vcses = FindVCS()
if len(vcses) > 1:
print(red(
'*** Ambiguous workdir -- more than one VCS found'
' at the same depth: %s.' % ', '.join(vcses)))
print(red(
'*** Please either clean up your workdir'
' or specify --vcs option.'))
sys.exit(1)
elif vcses:
self.vcs = vcses[0]
else:
self.vcs = None
if options.if_modified == "y" and self.vcs is None:
logging.info(
"Not in a version controlled repository; "
"disabling --if-modified.")
options.if_modified = "n"
# Disable copyright/mtime check if vcs does not preserve mtime (bug #324075).
self.vcs_preserves_mtime = self.vcs in ('cvs',)
self.vcs_local_opts = repoman_settings.get(
"REPOMAN_VCS_LOCAL_OPTS", "").split()
self.vcs_global_opts = repoman_settings.get(
"REPOMAN_VCS_GLOBAL_OPTS")
if self.vcs_global_opts is None:
if self.vcs in ('cvs', 'svn'):
self.vcs_global_opts = "-q"
else:
self.vcs_global_opts = ""
self.vcs_global_opts = self.vcs_global_opts.split()
if options.mode == 'commit' and not options.pretend and not self.vcs:
logging.info(
"Not in a version controlled repository; "
"enabling pretend mode.")
options.pretend = True
示例15: _get_repos
def _get_repos(self, auto_sync_only=True, match_repos=None):
msgs = []
repos = self.emerge_config.target_config.settings.repositories
if match_repos is not None:
# Discard duplicate repository names or aliases.
match_repos = set(match_repos)
repos = self._match_repos(match_repos, repos)
if len(repos) < len(match_repos):
# Build a set of all the matched repos' names and aliases so we
# can do a set difference for names that are missing.
repo_names = set()
for repo in repos:
repo_names.add(repo.name)
if repo.aliases is not None:
repo_names.update(repo.aliases)
missing = match_repos - repo_names
if missing:
msgs.append(red(" * ") + "The specified repo(s) were not found: %s" %
(" ".join(repo_name for repo_name in missing)) + \
"\n ...returning")
return (False, repos, msgs)
if auto_sync_only:
repos = self._filter_auto(repos)
sync_disabled = [repo for repo in repos if repo.sync_type is None]
if sync_disabled:
repos = [repo for repo in repos if repo.sync_type is not None]
if match_repos is not None:
msgs.append(red(" * " ) + "The specified repo(s) have sync disabled: %s" %
" ".join(repo.name for repo in sync_disabled) + \
"\n ...returning")
return (False, repos, msgs)
missing_sync_uri = [repo for repo in repos if repo.sync_uri is None]
if missing_sync_uri:
repos = [repo for repo in repos if repo.sync_uri is not None]
msgs.append(red(" * ") + "The specified repo(s) are missing sync-uri: %s" %
" ".join(repo.name for repo in missing_sync_uri) + \
"\n ...returning")
return (False, repos, msgs)
return (True, repos, msgs)