本文整理汇总了Python中portage.util.varexpand函数的典型用法代码示例。如果您正苦于以下问题:Python varexpand函数的具体用法?Python varexpand怎么用?Python varexpand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了varexpand函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testVarExpandPass
def testVarExpandPass(self):
varDict = { "a":"5", "b":"7", "c":"-5" }
for key in varDict:
result = varexpand( "$%s" % key, varDict )
self.assertFalse( result != varDict[key],
msg="Got %s != %s, from varexpand( %s, %s )" % \
( result, varDict[key], "$%s" % key, varDict ) )
result = varexpand( "${%s}" % key, varDict )
self.assertFalse( result != varDict[key],
msg="Got %s != %s, from varexpand( %s, %s )" % \
( result, varDict[key], "${%s}" % key, varDict ) )
示例2: testVarExpandBackslashes
def testVarExpandBackslashes(self):
"""
We want to behave like bash does when expanding a variable
assignment in a sourced file, in which case it performs
backslash removal for \\ and \$ but nothing more. It also
removes escaped newline characters. Note that we don't
handle escaped quotes here, since getconfig() uses shlex
to handle that earlier.
"""
varDict = {}
tests = [
("\\", "\\"),
("\\\\", "\\"),
("\\\\\\", "\\\\"),
("\\\\\\\\", "\\\\"),
("\\$", "$"),
("\\\\$", "\\$"),
("\\a", "\\a"),
("\\b", "\\b"),
("\\n", "\\n"),
("\\r", "\\r"),
("\\t", "\\t"),
("\\\n", ""),
("\\\"", "\\\""),
("\\'", "\\'"),
]
for test in tests:
result = varexpand( test[0], varDict )
self.assertFalse( result != test[1],
msg="Got %s != %s from varexpand( %s, %s )" \
% ( result, test[1], test[0], varDict ) )
示例3: testVarExpandFail
def testVarExpandFail(self):
varDict = { "a":"5", "b":"7", "c":"15" }
testVars = [ "fail" ]
for var in testVars:
result = varexpand( "$%s" % var, varDict )
self.assertFalse( len(result),
msg="Got %s == %s, from varexpand( %s, %s )" \
% ( result, var, "$%s" % var, varDict ) )
result = varexpand( "${%s}" % var, varDict )
self.assertFalse( len(result),
msg="Got %s == %s, from varexpand( %s, %s )" \
% ( result, var, "${%s}" % var, varDict ) )
示例4: file_get
def file_get(baseurl,dest,conn=None,fcmd=None):
"""(baseurl,dest,fcmd=) -- Takes a base url to connect to and read from.
URI should be in the form <proto>://[user[:pass]@]<site>[:port]<path>"""
if not fcmd:
return file_get_lib(baseurl,dest,conn)
variables = {
"DISTDIR": dest,
"URI": baseurl,
"FILE": os.path.basename(baseurl)
}
from portage.util import varexpand
from portage.process import spawn
myfetch = portage.util.shlex_split(fcmd)
myfetch = [varexpand(x, mydict=variables) for x in myfetch]
fd_pipes= {
0:sys.stdin.fileno(),
1:sys.stdout.fileno(),
2:sys.stdout.fileno()
}
retval = spawn(myfetch, env=os.environ.copy(), fd_pipes=fd_pipes)
if retval != os.EX_OK:
sys.stderr.write(_("Fetcher exited with a failure condition.\n"))
return 0
return 1
示例5: file_get
def file_get(baseurl,dest,conn=None,fcmd=None,filename=None):
"""(baseurl,dest,fcmd=) -- Takes a base url to connect to and read from.
URI should be in the form <proto>://[user[:pass]@]<site>[:port]<path>"""
if not fcmd:
warnings.warn("Use of portage.getbinpkg.file_get() without the fcmd "
"parameter is deprecated", DeprecationWarning, stacklevel=2)
return file_get_lib(baseurl,dest,conn)
if not filename:
filename = os.path.basename(baseurl)
variables = {
"DISTDIR": dest,
"URI": baseurl,
"FILE": filename
}
from portage.util import varexpand
from portage.process import spawn
myfetch = portage.util.shlex_split(fcmd)
myfetch = [varexpand(x, mydict=variables) for x in myfetch]
fd_pipes= {
0:sys.__stdin__.fileno(),
1:sys.__stdout__.fileno(),
2:sys.__stdout__.fileno()
}
sys.__stdout__.flush()
sys.__stderr__.flush()
retval = spawn(myfetch, env=os.environ.copy(), fd_pipes=fd_pipes)
if retval != os.EX_OK:
sys.stderr.write(_("Fetcher exited with a failure condition.\n"))
return 0
return 1
示例6: testVarExpandSingleQuotes
def testVarExpandSingleQuotes(self):
varDict = { "a":"5" }
tests = [ ("\'${a}\'", "\'${a}\'") ]
for test in tests:
result = varexpand( test[0], varDict )
self.assertFalse( result != test[1],
msg="Got %s != %s from varexpand( %s, %s )" \
% ( result, test[1], test[0], varDict ) )
示例7: testVarExpandDoubleQuotes
def testVarExpandDoubleQuotes(self):
varDict = { "a":"5" }
tests = [ ("\"${a}\"", "\"5\"") ]
for test in tests:
result = varexpand( test[0], varDict )
self.failIf( result != test[1],
msg="Got %s != %s from varexpand( %s, %s )" \
% ( result, test[1], test[0], varDict ) )
示例8: _start_gpg_proc
def _start_gpg_proc(self):
gpg_vars = self.gpg_vars
if gpg_vars is None:
gpg_vars = {}
else:
gpg_vars = gpg_vars.copy()
gpg_vars["FILE"] = self._manifest_path
gpg_cmd = varexpand(self.gpg_cmd, mydict=gpg_vars)
gpg_cmd = shlex_split(gpg_cmd)
gpg_proc = PopenProcess(proc=subprocess.Popen(gpg_cmd))
self._start_task(gpg_proc, self._gpg_proc_exit)
示例9: file_get
def file_get(baseurl=None, dest=None, conn=None, fcmd=None, filename=None,
fcmd_vars=None):
"""Takes a base url to connect to and read from.
URI should be in the form <proto>://[user[:pass]@]<site>[:port]<path>"""
if not fcmd:
warnings.warn("Use of portage.getbinpkg.file_get() without the fcmd "
"parameter is deprecated", DeprecationWarning, stacklevel=2)
return file_get_lib(baseurl, dest, conn)
variables = {}
if fcmd_vars is not None:
variables.update(fcmd_vars)
if "DISTDIR" not in variables:
if dest is None:
raise portage.exception.MissingParameter(
_("%s is missing required '%s' key") %
("fcmd_vars", "DISTDIR"))
variables["DISTDIR"] = dest
if "URI" not in variables:
if baseurl is None:
raise portage.exception.MissingParameter(
_("%s is missing required '%s' key") %
("fcmd_vars", "URI"))
variables["URI"] = baseurl
if "FILE" not in variables:
if filename is None:
filename = os.path.basename(variables["URI"])
variables["FILE"] = filename
from portage.util import varexpand
from portage.process import spawn
myfetch = portage.util.shlex_split(fcmd)
myfetch = [varexpand(x, mydict=variables) for x in myfetch]
fd_pipes = {
0: portage._get_stdin().fileno(),
1: sys.__stdout__.fileno(),
2: sys.__stdout__.fileno()
}
sys.__stdout__.flush()
sys.__stderr__.flush()
retval = spawn(myfetch, env=os.environ.copy(), fd_pipes=fd_pipes)
if retval != os.EX_OK:
sys.stderr.write(_("Fetcher exited with a failure condition.\n"))
return 0
return 1
示例10: _clean_logs
def _clean_logs(clean_cmd, settings):
logdir = settings.get("PORT_LOGDIR")
if logdir is None or not os.path.isdir(logdir):
return 78
variables = {"PORT_LOGDIR" : logdir}
cmd = [varexpand(x, mydict=variables) for x in clean_cmd]
try:
rval = portage.process.spawn(cmd, env=os.environ)
except portage.exception.CommandNotFound:
rval = 127
return rval
示例11: _start_gpg_proc
def _start_gpg_proc(self):
gpg_vars = self.gpg_vars
if gpg_vars is None:
gpg_vars = {}
else:
gpg_vars = gpg_vars.copy()
gpg_vars["FILE"] = self._manifest_path
gpg_cmd = varexpand(self.gpg_cmd, mydict=gpg_vars)
gpg_cmd = shlex_split(gpg_cmd)
gpg_proc = PopenProcess(proc=subprocess.Popen(gpg_cmd,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
# PipeLogger echos output and efficiently monitors for process
# exit by listening for the stdout EOF event.
gpg_proc.pipe_reader = PipeLogger(background=self.background,
input_fd=gpg_proc.proc.stdout, scheduler=self.scheduler)
self._start_task(gpg_proc, self._gpg_proc_exit)
示例12: add
def add(self, entry):
"""
Add one NEEDED.ELF.2 entry, for inclusion in the generated
REQUIRES and PROVIDES values.
@param entry: NEEDED.ELF.2 entry
@type entry: NeededEntry
"""
multilib_cat = entry.multilib_category
if multilib_cat is None:
# This usage is invalid. The caller must ensure that
# the multilib category data is supplied here.
raise AssertionError(
"Missing multilib category data: %s" % entry.filename)
self._basename_map.setdefault(
os.path.basename(entry.filename), []).append(entry)
if entry.needed and (
self._requires_exclude is None or
self._requires_exclude.match(
entry.filename.lstrip(os.sep)) is None):
runpaths = frozenset()
if entry.runpaths is not None:
expand = {"ORIGIN": os.path.dirname(entry.filename)}
runpaths = frozenset(normalize_path(varexpand(x, expand,
error_leader=lambda: "%s: DT_RUNPATH: " % entry.filename))
for x in entry.runpaths)
for x in entry.needed:
if (self._requires_exclude is None or
self._requires_exclude.match(x) is None):
self._requires_map[multilib_cat][x].add(runpaths)
if entry.soname:
self._provides_unfiltered.setdefault(
multilib_cat, set()).add(entry.soname)
if entry.soname and (
self._provides_exclude is None or
(self._provides_exclude.match(
entry.filename.lstrip(os.sep)) is None and
self._provides_exclude.match(entry.soname) is None)):
self._provides_map.setdefault(
multilib_cat, set()).add(entry.soname)
示例13: read_config
def read_config(mandatory_opts):
eprefix = portage.settings["EPREFIX"]
if portage._not_installed:
config_path = os.path.join(portage.PORTAGE_BASE_PATH, "cnf", "dispatch-conf.conf")
else:
config_path = os.path.join(eprefix or os.sep, "etc/dispatch-conf.conf")
loader = KeyValuePairFileLoader(config_path, None)
opts, _errors = loader.load()
if not opts:
print(_('dispatch-conf: Error reading /etc/dispatch-conf.conf; fatal'), file=sys.stderr)
sys.exit(1)
# Handle quote removal here, since KeyValuePairFileLoader doesn't do that.
quotes = "\"'"
for k, v in opts.items():
if v[:1] in quotes and v[:1] == v[-1:]:
opts[k] = v[1:-1]
for key in mandatory_opts:
if key not in opts:
if key == "merge":
opts["merge"] = "sdiff --suppress-common-lines --output='%s' '%s' '%s'"
else:
print(_('dispatch-conf: Missing option "%s" in /etc/dispatch-conf.conf; fatal') % (key,), file=sys.stderr)
# archive-dir supports ${EPREFIX} expansion, in order to avoid hardcoding
variables = {"EPREFIX": eprefix}
opts['archive-dir'] = varexpand(opts['archive-dir'], mydict=variables)
if not os.path.exists(opts['archive-dir']):
os.mkdir(opts['archive-dir'])
# Use restrictive permissions by default, in order to protect
# against vulnerabilities (like bug #315603 involving rcs).
os.chmod(opts['archive-dir'], 0o700)
elif not os.path.isdir(opts['archive-dir']):
print(_('dispatch-conf: Config archive dir [%s] must exist; fatal') % (opts['archive-dir'],), file=sys.stderr)
sys.exit(1)
return opts
示例14: ionice
def ionice(settings):
ionice_cmd = settings.get("PORTAGE_IONICE_COMMAND")
if ionice_cmd:
ionice_cmd = portage.util.shlex_split(ionice_cmd)
if not ionice_cmd:
return
from portage.util import varexpand
variables = {"PID" : str(os.getpid())}
cmd = [varexpand(x, mydict=variables) for x in ionice_cmd]
try:
rval = portage.process.spawn(cmd, env=os.environ)
except portage.exception.CommandNotFound:
# The OS kernel probably doesn't support ionice,
# so return silently.
return
if rval != os.EX_OK:
out = portage.output.EOutput()
out.eerror("PORTAGE_IONICE_COMMAND returned %d" % (rval,))
out.eerror("See the make.conf(5) man page for PORTAGE_IONICE_COMMAND usage instructions.")
示例15: rebuild
#.........这里部分代码省略.........
fields[1] = fields[1][root_len:]
owner = plibs.pop(fields[1], None)
lines.append((owner, "scanelf", ";".join(fields)))
proc.wait()
proc.stdout.close()
if plibs:
# Preserved libraries that did not appear in the scanelf output.
# This is known to happen with statically linked libraries.
# Generate dummy lines for these, so we can assume that every
# preserved library has an entry in self._obj_properties. This
# is important in order to prevent findConsumers from raising
# an unwanted KeyError.
for x, cpv in plibs.items():
lines.append((cpv, "plibs", ";".join(['', x, '', '', ''])))
# Share identical frozenset instances when available,
# in order to conserve memory.
frozensets = {}
for owner, location, l in lines:
l = l.rstrip("\n")
if not l:
continue
if '\0' in l:
# os.stat() will raise "TypeError: must be encoded string
# without NULL bytes, not str" in this case.
writemsg_level(_("\nLine contains null byte(s) " \
"in %s: %s\n\n") % (location, l),
level=logging.ERROR, noiselevel=-1)
continue
try:
entry = NeededEntry.parse(location, l)
except InvalidData as e:
writemsg_level("\n%s\n\n" % (e,),
level=logging.ERROR, noiselevel=-1)
continue
# If NEEDED.ELF.2 contains the new multilib category field,
# then use that for categorization. Otherwise, if a mapping
# exists, map e_machine (entry.arch) to an approximate
# multilib category. If all else fails, use e_machine, just
# as older versions of portage did.
arch = entry.multilib_category
if arch is None:
arch = _approx_multilib_categories.get(
entry.arch, entry.arch)
obj = entry.filename
soname = entry.soname
expand = {"ORIGIN": os.path.dirname(entry.filename)}
path = frozenset(normalize_path(
varexpand(x, expand, error_leader=lambda: "%s: " % location))
for x in entry.runpaths)
path = frozensets.setdefault(path, path)
needed = frozenset(entry.needed)
needed = frozensets.setdefault(needed, needed)
obj_key = self._obj_key(obj)
indexed = True
myprops = obj_properties.get(obj_key)
if myprops is None:
indexed = False
myprops = self._obj_properties_class(
arch, needed, path, soname, [], owner)
obj_properties[obj_key] = myprops
# All object paths are added into the obj_properties tuple.
myprops.alt_paths.append(obj)
# Don't index the same file more that once since only one
# set of data can be correct and therefore mixing data
# may corrupt the index (include_file overrides previously
# installed).
if indexed:
continue
arch_map = libs.get(arch)
if arch_map is None:
arch_map = {}
libs[arch] = arch_map
if soname:
soname_map = arch_map.get(soname)
if soname_map is None:
soname_map = self._soname_map_class(
providers=[], consumers=[])
arch_map[soname] = soname_map
soname_map.providers.append(obj_key)
for needed_soname in needed:
soname_map = arch_map.get(needed_soname)
if soname_map is None:
soname_map = self._soname_map_class(
providers=[], consumers=[])
arch_map[needed_soname] = soname_map
soname_map.consumers.append(obj_key)
for arch, sonames in libs.items():
for soname_node in sonames.values():
soname_node.providers = tuple(set(soname_node.providers))
soname_node.consumers = tuple(set(soname_node.consumers))