本文整理汇总了Python中portage.output.green函数的典型用法代码示例。如果您正苦于以下问题:Python green函数的具体用法?Python green怎么用?Python green使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了green函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: priming_commit
def priming_commit(self, myupdates, myremoved, commitmessage):
myfiles = myupdates + myremoved
commitmessagedir = tempfile.mkdtemp(".repoman.msg")
commitmessagefile = os.path.join(commitmessagedir, "COMMIT_EDITMSG")
with open(commitmessagefile, "wb") as mymsg:
mymsg.write(_unicode_encode(commitmessage))
separator = '-' * 78
print()
print(green("Using commit message:"))
print(green(separator))
print(commitmessage)
print(green(separator))
print()
# Having a leading ./ prefix on file paths can trigger a bug in
# the cvs server when committing files to multiple directories,
# so strip the prefix.
myfiles = [f.lstrip("./") for f in myfiles]
retval = self.vcs_settings.changes.commit(myfiles, commitmessagefile)
# cleanup the commit message before possibly exiting
try:
shutil.rmtree(commitmessagedir)
except OSError:
pass
if retval != os.EX_OK:
writemsg_level(
"!!! Exiting on %s (shell) "
"error code: %s\n" % (self.vcs_settings.vcs, retval),
level=logging.ERROR, noiselevel=-1)
sys.exit(retval)
示例2: 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
示例3: _set_root_columns
def _set_root_columns(self, addl, pkg_info, pkg):
"""sets the indent level and formats the output
@param addl: already defined string to add to
@param pkg_info: dictionary
@param pkg: _emerge.Package instance
@rtype string
Modifies self.verboseadd
"""
if self.conf.quiet:
myprint = addl + " " + self.indent + \
self.pkgprint(pkg_info.cp, pkg_info)
myprint = myprint+" "+green(pkg_info.ver)+" "
myprint = myprint+pkg_info.oldbest
self.verboseadd = None
else:
if not pkg_info.merge:
addl = self.empty_space_in_brackets()
myprint = "[%s%s] %s%s" % \
(self.pkgprint(pkg_info.operation.ljust(13), pkg_info),
addl, self.indent, self.pkgprint(pkg.cp, pkg_info))
else:
myprint = "[%s %s] %s%s" % \
(self.pkgprint(pkg.type_name, pkg_info), addl,
self.indent, self.pkgprint(pkg.cp, pkg_info))
if (self.newlp-nc_len(myprint)) > 0:
myprint = myprint+(" "*(self.newlp-nc_len(myprint)))
myprint = myprint+green(" ["+pkg_info.ver+"] ")
if (self.oldlp-nc_len(myprint)) > 0:
myprint = myprint+(" "*(self.oldlp-nc_len(myprint)))
myprint += pkg_info.oldbest
return myprint
示例4: 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
示例5: 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)
示例6: gettree
def gettree(tree, config):
emsg("Importing " + tree + " portage tree", config)
if '.pyc' in config['esearchdbfile']:
ext = ".pyc"
else:
ext = ".py"
try:
target = tmp_prefix + tree + "tree" + ext
if os.path.exists(target):
os.unlink(target)
os.symlink(os.path.join(config['esearchdbdir'], config['esearchdbfile']), target)
except OSError as e:
if e.errno != 17:
error(str(e), fatal=True)
try:
if tree == "old":
from esyncoldtree import db
try:
from esyncoldtree import dbversion
if dbversion < config['needdbversion']:
outofdateerror()
except ImportError:
outofdateerror()
else:
from esyncnewtree import db
except ImportError:
error("Could not find " + tree +
"esearch-index. Please run " +
green("eupdatedb") + " as root first", fatal=True)
os.unlink(target)
return db
示例7: __init__
def __init__(self, scanned_files, logger, searchlibs=None, searchbits=None,
all_masks=None, masked_dirs=None):
'''LibCheck init function.
@param scanned_files: optional dictionary if the type created by
scan_files(). Defaults to the class instance of scanned_files
@param logger: python style Logging function to use for output.
@param searchlibs: optional set() of libraries to search for. If defined
it toggles several settings to configure this class for
a target search rather than a broken libs search.
'''
self.scanned_files = scanned_files
self.logger = logger
self.searchlibs = searchlibs
self.searchbits = sorted(searchbits) or ['32', '64']
self.all_masks = all_masks
self.masked_dirs = masked_dirs
self.logger.debug("\tLibCheck.__init__(), new searchlibs: %s" %(self.searchbits))
if searchlibs:
self.smsg = '\tLibCheck.search(), Checking for %s bit dependants'
self.pmsg = yellow(" * ") + 'Files that depend on: %s (%s bits)'
self.setlibs = self._setslibs
self.check = self._checkforlib
else:
self.smsg = '\tLibCheck.search(), Checking for broken %s bit libs'
self.pmsg = green(' * ') + bold('Broken files that require:') + ' %s (%s bits)'
self.setlibs = self._setlibs
self.check = self._checkbroken
self.sfmsg = "\tLibCheck.search(); Total found: %(count)d libs, %(deps)d files in %(time)d milliseconds"
self.alllibs = None
示例8: thick_manifest
def thick_manifest(self, updates, headers, no_expansion, expansion):
'''Create a thick manifest
@param updates:
@param headers:
@param no_expansion:
@param expansion:
'''
headerstring = r"'\$(Header|Id).*\$'"
for _file in updates:
# for CVS, no_expansion contains files that are excluded from expansion
if _file in no_expansion:
continue
_out = repoman_getstatusoutput(
"egrep -q %s %s" % (headerstring, portage._shell_quote(_file)))
if _out[0] == 0:
headers.append(_file)
print("%s have headers that will change." % green(str(len(headers))))
print(
"* Files with headers will"
" cause the manifests to be changed and committed separately.")
示例9: priming_commit
def priming_commit(self, myupdates, myremoved, commitmessage):
myfiles = myupdates + myremoved
fd, commitmessagefile = tempfile.mkstemp(".repoman.msg")
mymsg = os.fdopen(fd, "wb")
mymsg.write(_unicode_encode(commitmessage))
mymsg.close()
separator = '-' * 78
print()
print(green("Using commit message:"))
print(green(separator))
print(commitmessage)
print(green(separator))
print()
# Having a leading ./ prefix on file paths can trigger a bug in
# the cvs server when committing files to multiple directories,
# so strip the prefix.
myfiles = [f.lstrip("./") for f in myfiles]
commit_cmd = [self.vcs_settings.vcs]
commit_cmd.extend(self.vcs_settings.vcs_global_opts)
commit_cmd.append("commit")
commit_cmd.extend(self.vcs_settings.vcs_local_opts)
commit_cmd.extend(["-F", commitmessagefile])
commit_cmd.extend(myfiles)
try:
if self.options.pretend:
print("(%s)" % (" ".join(commit_cmd),))
else:
retval = spawn(commit_cmd, env=self.repo_settings.commit_env)
if retval != os.EX_OK:
writemsg_level(
"!!! Exiting on %s (shell) "
"error code: %s\n" % (self.vcs_settings.vcs, retval),
level=logging.ERROR, noiselevel=-1)
sys.exit(retval)
finally:
try:
os.unlink(commitmessagefile)
except OSError:
pass
示例10: update_scroll
def update_scroll(self):
if self._return_early():
return
if(self.spinpos >= len(self.scroll_sequence)):
sys.stdout.write(darkgreen(" \b\b\b" + self.scroll_sequence[
len(self.scroll_sequence) - 1 - (self.spinpos % len(self.scroll_sequence))]))
else:
sys.stdout.write(green("\b " + self.scroll_sequence[self.spinpos]))
sys.stdout.flush()
self.spinpos = (self.spinpos + 1) % (2 * len(self.scroll_sequence))
示例11: _new_slot
def _new_slot(self, pkg, pkg_info):
"""New slot, mark it new.
@returns addl: formatted slot info
@returns myoldbest: installed version list
Modifies self.counters.newslot, self.counters.binary
"""
addl = " " + green("NS") + pkg_info.fetch_symbol + " "
if pkg_info.ordered:
self.counters.newslot += 1
if pkg.type_name == "binary":
self.counters.binary += 1
return addl
示例12: _get_installed_best
def _get_installed_best(self, pkg, pkg_info):
""" we need to use "--emptrytree" testing here rather than
"empty" param testing because "empty"
param is used for -u, where you still *do* want to see when
something is being upgraded.
@param pkg: _emerge.Package.Package instance
@param pkg_info: dictionay
@rtype addl, myoldbest: list, myinslotlist: list
Modifies self.counters.reinst, self.counters.binary, self.counters.new
"""
myoldbest = []
myinslotlist = None
installed_versions = self.vardb.match_pkgs(pkg.cp)
if self.vardb.cpv_exists(pkg.cpv):
addl = " "+yellow("R")+pkg_info.fetch_symbol+" "
installed_version = self.vardb.match_pkgs(pkg.cpv)[0]
if not self.quiet_repo_display and installed_version.repo != pkg.repo:
myoldbest = [installed_version]
if pkg_info.ordered:
if pkg_info.merge:
self.counters.reinst += 1
if pkg.type_name == "binary":
self.counters.binary += 1
elif pkg_info.operation == "uninstall":
self.counters.uninst += 1
# filter out old-style virtual matches
elif installed_versions and \
installed_versions[0].cp == pkg.cp:
myinslotlist = self.vardb.match_pkgs(pkg.slot_atom)
# If this is the first install of a new-style virtual, we
# need to filter out old-style virtual matches.
if myinslotlist and \
myinslotlist[0].cp != pkg.cp:
myinslotlist = None
if myinslotlist:
myoldbest = myinslotlist[:]
addl = self._insert_slot(pkg, pkg_info, myinslotlist)
else:
myoldbest = installed_versions
addl = self._new_slot(pkg, pkg_info)
if self.conf.changelog:
self.do_changelog(pkg, pkg_info)
else:
addl = " " + green("N") + " " + pkg_info.fetch_symbol + " "
if pkg_info.ordered:
self.counters.new += 1
if pkg.type_name == "binary":
self.counters.binary += 1
return addl, myoldbest, myinslotlist
示例13: thick_manifest
def thick_manifest(self, myupdates, myheaders, no_expansion, expansion):
if self.vcs_settings.vcs == 'cvs':
headerstring = "'\$(Header|Id).*\$'"
elif self.vcs_settings.vcs == "svn":
svn_keywords = dict((k.lower(), k) for k in [
"Rev",
"Revision",
"LastChangedRevision",
"Date",
"LastChangedDate",
"Author",
"LastChangedBy",
"URL",
"HeadURL",
"Id",
"Header",
])
for myfile in myupdates:
# for CVS, no_expansion contains files that are excluded from expansion
if self.vcs_settings.vcs == "cvs":
if myfile in no_expansion:
continue
# for SVN, expansion contains files that are included in expansion
elif self.vcs_settings.vcs == "svn":
if myfile not in expansion:
continue
# Subversion keywords are case-insensitive
# in svn:keywords properties,
# but case-sensitive in contents of files.
enabled_keywords = []
for k in expansion[myfile]:
keyword = svn_keywords.get(k.lower())
if keyword is not None:
enabled_keywords.append(keyword)
headerstring = "'\$(%s).*\$'" % "|".join(enabled_keywords)
myout = repoman_getstatusoutput(
"egrep -q %s %s" % (headerstring, portage._shell_quote(myfile)))
if myout[0] == 0:
myheaders.append(myfile)
print("%s have headers that will change." % green(str(len(myheaders))))
print(
"* Files with headers will"
" cause the manifests to be changed and committed separately.")
示例14: _set_root_columns
def _set_root_columns(self, addl, pkg_info, pkg):
"""sets the indent level and formats the output
@param addl: already defined string to add to
@param pkg_info: dictionary
@param pkg: _emerge.Package.Package instance
@rtype string
Modifies self.verboseadd
"""
ver_str = pkg_info.ver
if self.conf.verbosity == 3 and not self.quiet_repo_display and (self.verbose_main_repo_display or
any(x.repo != self.portdb.repositories.mainRepo().name for x in pkg_info.oldbest_list + [pkg])):
ver_str += _repo_separator + pkg.repo
if self.conf.quiet:
myprint = addl + " " + self.indent + \
self.pkgprint(pkg_info.cp, pkg_info)
myprint = myprint+" "+green(ver_str)+" "
myprint = myprint+pkg_info.oldbest
self.verboseadd = None
else:
if not pkg_info.merge:
addl = self.empty_space_in_brackets()
myprint = "[%s%s] %s%s" % \
(self.pkgprint(pkg_info.operation.ljust(13), pkg_info),
addl, self.indent, self.pkgprint(pkg.cp, pkg_info))
else:
myprint = "[%s %s] %s%s" % \
(self.pkgprint(pkg.type_name, pkg_info), addl,
self.indent, self.pkgprint(pkg.cp, pkg_info))
if (self.newlp-nc_len(myprint)) > 0:
myprint = myprint+(" "*(self.newlp-nc_len(myprint)))
myprint = myprint+" "+green("["+ver_str+"]")+" "
if (self.oldlp-nc_len(myprint)) > 0:
myprint = myprint+(" "*(self.oldlp-nc_len(myprint)))
myprint += pkg_info.oldbest
return myprint
示例15: _set_root_columns
def _set_root_columns(self, pkg, pkg_info):
"""sets the indent level and formats the output
@param pkg: _emerge.Package.Package instance
@param pkg_info: dictionary
@rtype string
Modifies self.verboseadd
"""
ver_str = pkg_info.ver
if self.conf.verbosity == 3:
ver_str = self._append_slot(ver_str, pkg, pkg_info)
ver_str = self._append_repository(ver_str, pkg, pkg_info)
if self.conf.quiet:
myprint = _unicode(pkg_info.attr_display) + " " + self.indent + \
self.pkgprint(pkg_info.cp, pkg_info)
myprint = myprint+" "+green(ver_str)+" "
myprint = myprint+pkg_info.oldbest
self.verboseadd = None
else:
if not pkg_info.merge:
addl = self.empty_space_in_brackets()
myprint = "[%s%s] %s%s" % \
(self.pkgprint(pkg_info.operation.ljust(13), pkg_info),
addl, self.indent, self.pkgprint(pkg.cp, pkg_info))
else:
myprint = "[%s %s] %s%s" % \
(self.pkgprint(pkg.type_name, pkg_info),
pkg_info.attr_display,
self.indent, self.pkgprint(pkg.cp, pkg_info))
if (self.newlp-nc_len(myprint)) > 0:
myprint = myprint+(" "*(self.newlp-nc_len(myprint)))
myprint = myprint+" "+green("["+ver_str+"]")+" "
if (self.oldlp-nc_len(myprint)) > 0:
myprint = myprint+(" "*(self.oldlp-nc_len(myprint)))
myprint += pkg_info.oldbest
return myprint