本文整理汇总了Python中portage.util.grabfile函数的典型用法代码示例。如果您正苦于以下问题:Python grabfile函数的具体用法?Python grabfile怎么用?Python grabfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了grabfile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, filename, greedy=False, dbapi=None):
super(StaticFileSet, self).__init__(allow_repo=True)
self._filename = filename
self._mtime = None
self.description = "Package set loaded from file %s" % self._filename
self.loader = ItemFileLoader(self._filename, self._validate)
if greedy and not dbapi:
self.errors.append(
_("%s configured as greedy set, but no dbapi instance passed in constructor") % self._filename
)
greedy = False
self.greedy = greedy
self.dbapi = dbapi
metadata = grabfile(self._filename + ".metadata")
key = None
value = []
for line in metadata:
line = line.strip()
if len(line) == 0 and key != None:
setattr(self, key, " ".join(value))
key = None
elif line[-1] == ":" and key == None:
key = line[:-1].lower()
value = []
elif key != None:
value.append(line)
else:
pass
else:
if key != None:
setattr(self, key, " ".join(value))
示例2: load_unpack_dependencies_configuration
def load_unpack_dependencies_configuration(repositories):
repo_dict = {}
for repo in repositories.repos_with_profiles():
for eapi in _supported_eapis:
if eapi_has_automatic_unpack_dependencies(eapi):
file_name = os.path.join(repo.location, "profiles", "unpack_dependencies", eapi)
lines = grabfile(file_name, recursive=True)
for line in lines:
elements = line.split()
suffix = elements[0].lower()
if len(elements) == 1:
writemsg(_("--- Missing unpack dependencies for '%s' suffix in '%s'\n") % (suffix, file_name))
depend = " ".join(elements[1:])
try:
use_reduce(depend, eapi=eapi)
except InvalidDependString as e:
writemsg(_("--- Invalid unpack dependencies for '%s' suffix in '%s': '%s'\n" % (suffix, file_name, e)))
else:
repo_dict.setdefault(repo.name, {}).setdefault(eapi, {})[suffix] = depend
ret = {}
for repo in repositories.repos_with_profiles():
for repo_name in [x.name for x in repo.masters] + [repo.name]:
for eapi in repo_dict.get(repo_name, {}):
for suffix, depend in repo_dict.get(repo_name, {}).get(eapi, {}).items():
ret.setdefault(repo.name, {}).setdefault(eapi, {})[suffix] = depend
return ret
示例3: getUnreadItems
def getUnreadItems(self, repoid, update=False):
"""
Determine if there are unread relevant items in news.repoid.unread.
If there are unread items return their number.
If update is specified, updateNewsItems( repoid ) will be called to
check for new items.
"""
if update:
self.updateItems(repoid)
unread_filename = self._unread_filename(repoid)
unread_lock = None
try:
unread_lock = lockfile(unread_filename, wantnewlockfile=1)
except (InvalidLocation, OperationNotPermitted, PermissionDenied):
pass
try:
try:
return len(grabfile(unread_filename))
except PermissionDenied:
return 0
finally:
if unread_lock:
unlockfile(unread_lock)
示例4: _addProfile
def _addProfile(self, currentPath):
parentsFile = os.path.join(currentPath, "parent")
eapi_file = os.path.join(currentPath, "eapi")
try:
eapi = codecs.open(_unicode_encode(eapi_file,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace'
).readline().strip()
except IOError:
pass
else:
if not eapi_is_supported(eapi):
raise ParseError(_(
"Profile contains unsupported "
"EAPI '%s': '%s'") % \
(eapi, os.path.realpath(eapi_file),))
if os.path.exists(parentsFile):
parents = grabfile(parentsFile)
if not parents:
raise ParseError(
_("Empty parent file: '%s'") % parentsFile)
for parentPath in parents:
parentPath = normalize_path(os.path.join(
currentPath, parentPath))
if os.path.exists(parentPath):
self._addProfile(parentPath)
else:
raise ParseError(
_("Parent '%s' not found: '%s'") % \
(parentPath, parentsFile))
self.profiles.append(currentPath)
示例5: get_applied_glsas
def get_applied_glsas(settings):
"""
Return a list of applied or injected GLSA IDs
@type settings: portage.config
@param settings: portage config instance
@rtype: list
@return: list of glsa IDs
"""
return grabfile(os.path.join(settings["EROOT"], PRIVATE_PATH, "glsa_injected"))
示例6: _parse_repository_packageusealiases
def _parse_repository_packageusealiases(self, repositories):
ret = {}
for repo in repositories.repos_with_profiles():
file_name = os.path.join(repo.location, "profiles", "package.use.aliases")
eapi = read_corresponding_eapi_file(file_name)
useflag_re = _get_useflag_re(eapi)
lines = grabfile(file_name, recursive=True)
file_dict = {}
for line in lines:
elements = line.split()
atom = elements[0]
try:
atom = Atom(atom, eapi=eapi)
except InvalidAtom:
writemsg(_("--- Invalid atom in '%s': '%s'\n") % (file_name, atom))
continue
if len(elements) == 1:
writemsg(_("--- Missing real USE flag for '%s' in '%s'\n") % (atom, file_name), noiselevel=-1)
continue
real_flag = elements[1]
if useflag_re.match(real_flag) is None:
writemsg(
_("--- Invalid real USE flag for '%s' in '%s': '%s'\n") % (atom, file_name, real_flag),
noiselevel=-1,
)
else:
for alias in elements[2:]:
if useflag_re.match(alias) is None:
writemsg(
_("--- Invalid USE flag alias for '%s' real USE flag for '%s' in '%s': '%s'\n")
% (real_flag, atom, file_name, alias),
noiselevel=-1,
)
else:
# Duplicated USE flag aliases in entries for different atoms
# matching the same package version are detected in getUseAliases().
if any(
alias in v
for k, v in file_dict.get(atom.cp, {}).get(atom, {}).items()
if k != real_flag
):
writemsg(
_("--- Duplicated USE flag alias for '%s' in '%s': '%s'\n")
% (atom, file_name, alias),
noiselevel=-1,
)
else:
file_dict.setdefault(atom.cp, {}).setdefault(atom, {}).setdefault(real_flag, []).append(
alias
)
ret[repo.name] = file_dict
return ret
示例7: _parse_file_to_tuple
def _parse_file_to_tuple(self, file_name, recursive=True):
ret = []
lines = grabfile(file_name, recursive=recursive)
eapi = read_corresponding_eapi_file(file_name)
useflag_re = _get_useflag_re(eapi)
for prefixed_useflag in lines:
if prefixed_useflag[:1] == "-":
useflag = prefixed_useflag[1:]
else:
useflag = prefixed_useflag
if useflag_re.match(useflag) is None:
writemsg(_("--- Invalid USE flag in '%s': '%s'\n") %
(file_name, prefixed_useflag), noiselevel=-1)
else:
ret.append(prefixed_useflag)
return tuple(ret)
示例8: old_tree_timestamp_warn
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:
if have_english_locale():
writemsg_stdout(">>> Last emerge --sync was %s ago\n" % \
whenago(unixtime - lastsync), noiselevel=-1)
else:
writemsg_stdout(">>> %s\n" % \
_("Last emerge --sync was %s") % \
time.strftime('%c', time.localtime(lastsync)),
noiselevel=-1)
return True
return False
示例9: _parse_file_to_tuple
def _parse_file_to_tuple(self, file_name, recursive=True,
eapi_filter=None, eapi=None, eapi_default="0"):
"""
@param file_name: input file name
@type file_name: str
@param recursive: triggers recursion if the input file is a
directory
@type recursive: bool
@param eapi_filter: a function that accepts a single eapi
argument, and returns true if the the current file type
is supported by the given EAPI
@type eapi_filter: callable
@param eapi: the EAPI of the current profile node, which allows
a call to read_corresponding_eapi_file to be skipped
@type eapi: str
@param eapi_default: the default EAPI which applies if the
current profile node does not define a local EAPI
@type eapi_default: str
@rtype: tuple
@return: collection of USE flags
"""
ret = []
lines = grabfile(file_name, recursive=recursive)
if eapi is None:
eapi = read_corresponding_eapi_file(
file_name, default=eapi_default)
if eapi_filter is not None and not eapi_filter(eapi):
if lines:
writemsg(_("--- EAPI '%s' does not support '%s': '%s'\n") %
(eapi, os.path.basename(file_name), file_name),
noiselevel=-1)
return ()
useflag_re = _get_useflag_re(eapi)
for prefixed_useflag in lines:
if prefixed_useflag[:1] == "-":
useflag = prefixed_useflag[1:]
else:
useflag = prefixed_useflag
if useflag_re.match(useflag) is None:
writemsg(_("--- Invalid USE flag in '%s': '%s'\n") %
(file_name, prefixed_useflag), noiselevel=-1)
else:
ret.append(prefixed_useflag)
return tuple(ret)
示例10: _parse_file_to_tuple
def _parse_file_to_tuple(self, file_name, recursive=True, eapi_filter=None):
ret = []
lines = grabfile(file_name, recursive=recursive)
eapi = read_corresponding_eapi_file(file_name)
if eapi_filter is not None and not eapi_filter(eapi):
if lines:
writemsg(_("--- EAPI '%s' does not support '%s': '%s'\n") %
(eapi, os.path.basename(file_name), file_name),
noiselevel=-1)
return ()
useflag_re = _get_useflag_re(eapi)
for prefixed_useflag in lines:
if prefixed_useflag[:1] == "-":
useflag = prefixed_useflag[1:]
else:
useflag = prefixed_useflag
if useflag_re.match(useflag) is None:
writemsg(_("--- Invalid USE flag in '%s': '%s'\n") %
(file_name, prefixed_useflag), noiselevel=-1)
else:
ret.append(prefixed_useflag)
return tuple(ret)
示例11: updateItems
def updateItems(self, repoid):
"""
Figure out which news items from NEWS_PATH are both unread and relevant to
the user (according to the GLEP 42 standards of relevancy). Then add these
items into the news.repoid.unread file.
"""
# Ensure that the unread path exists and is writable.
try:
ensure_dirs(self.unread_path, uid=self._uid, gid=self._gid,
mode=self._dir_mode, mask=self._mode_mask)
except (OperationNotPermitted, PermissionDenied):
return
if not os.access(self.unread_path, os.W_OK):
return
news_dir = self._news_dir(repoid)
try:
news = _os.listdir(_unicode_encode(news_dir,
encoding=_encodings['fs'], errors='strict'))
except OSError:
return
skip_filename = self._skip_filename(repoid)
unread_filename = self._unread_filename(repoid)
unread_lock = lockfile(unread_filename, wantnewlockfile=1)
try:
try:
unread = set(grabfile(unread_filename))
unread_orig = unread.copy()
skip = set(grabfile(skip_filename))
skip_orig = skip.copy()
except PermissionDenied:
return
for itemid in news:
try:
itemid = _unicode_decode(itemid,
encoding=_encodings['fs'], errors='strict')
except UnicodeDecodeError:
itemid = _unicode_decode(itemid,
encoding=_encodings['fs'], errors='replace')
writemsg_level(
_("!!! Invalid encoding in news item name: '%s'\n") % \
itemid, level=logging.ERROR, noiselevel=-1)
continue
if itemid in skip:
continue
filename = os.path.join(news_dir, itemid,
itemid + "." + self.language_id + ".txt")
if not os.path.isfile(filename):
continue
item = NewsItem(filename, itemid)
if not item.isValid():
continue
if item.isRelevant(profile=self._profile_path,
config=self.config, vardb=self.vdb):
unread.add(item.name)
skip.add(item.name)
if unread != unread_orig:
write_atomic(unread_filename,
"".join("%s\n" % x for x in sorted(unread)))
apply_secpass_permissions(unread_filename,
uid=self._uid, gid=self._gid,
mode=self._file_mode, mask=self._mode_mask)
if skip != skip_orig:
write_atomic(skip_filename,
"".join("%s\n" % x for x in sorted(skip)))
apply_secpass_permissions(skip_filename,
uid=self._uid, gid=self._gid,
mode=self._file_mode, mask=self._mode_mask)
finally:
unlockfile(unread_lock)
示例12: _addProfile
def _addProfile(self, currentPath, repositories, known_repos):
current_abs_path = os.path.abspath(currentPath)
allow_directories = True
allow_parent_colon = True
repo_loc = None
compat_mode = False
eapi_file = os.path.join(currentPath, "eapi")
eapi = "0"
f = None
try:
f = io.open(_unicode_encode(eapi_file,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace')
eapi = f.readline().strip()
except IOError:
pass
else:
if not eapi_is_supported(eapi):
raise ParseError(_(
"Profile contains unsupported "
"EAPI '%s': '%s'") % \
(eapi, os.path.realpath(eapi_file),))
finally:
if f is not None:
f.close()
intersecting_repos = [x for x in known_repos if current_abs_path.startswith(x[0])]
if intersecting_repos:
# protect against nested repositories. Insane configuration, but the longest
# path will be the correct one.
repo_loc, layout_data = max(intersecting_repos, key=lambda x:len(x[0]))
allow_directories = eapi_allows_directories_on_profile_level_and_repository_level(eapi) or \
any(x in _portage1_profiles_allow_directories for x in layout_data['profile-formats'])
compat_mode = not eapi_allows_directories_on_profile_level_and_repository_level(eapi) and \
layout_data['profile-formats'] == ('portage-1-compat',)
allow_parent_colon = any(x in _allow_parent_colon
for x in layout_data['profile-formats'])
if compat_mode:
offenders = _PORTAGE1_DIRECTORIES.intersection(os.listdir(currentPath))
offenders = sorted(x for x in offenders
if os.path.isdir(os.path.join(currentPath, x)))
if offenders:
warnings.warn(_("Profile '%(profile_path)s' in repository "
"'%(repo_name)s' is implicitly using 'portage-1' profile format, but "
"the repository profiles are not marked as that format. This will break "
"in the future. Please either convert the following paths "
"to files, or add\nprofile-formats = portage-1\nto the "
"repositories layout.conf. Files: '%(files)s'\n")
% dict(profile_path=currentPath, repo_name=repo_loc,
files=', '.join(offenders)))
parentsFile = os.path.join(currentPath, "parent")
if os.path.exists(parentsFile):
parents = grabfile(parentsFile)
if not parents:
raise ParseError(
_("Empty parent file: '%s'") % parentsFile)
for parentPath in parents:
abs_parent = parentPath[:1] == os.sep
if not abs_parent and allow_parent_colon:
parentPath = self._expand_parent_colon(parentsFile,
parentPath, repo_loc, repositories)
# NOTE: This os.path.join() call is intended to ignore
# currentPath if parentPath is already absolute.
parentPath = normalize_path(os.path.join(
currentPath, parentPath))
if abs_parent or repo_loc is None or \
not parentPath.startswith(repo_loc):
# It seems that this parent may point outside
# of the current repo, so realpath it.
parentPath = os.path.realpath(parentPath)
if os.path.exists(parentPath):
self._addProfile(parentPath, repositories, known_repos)
else:
raise ParseError(
_("Parent '%s' not found: '%s'") % \
(parentPath, parentsFile))
self.profiles.append(currentPath)
self.profiles_complex.append(
_profile_node(currentPath, allow_directories))
示例13: _do_global_updates
def _do_global_updates(trees, prev_mtimes, quiet=False, if_mtime_changed=True):
root = trees._running_eroot
mysettings = trees[root]["vartree"].settings
portdb = trees[root]["porttree"].dbapi
vardb = trees[root]["vartree"].dbapi
bindb = trees[root]["bintree"].dbapi
world_file = os.path.join(mysettings['EROOT'], WORLD_FILE)
world_list = grabfile(world_file)
world_modified = False
world_warnings = set()
updpath_map = {}
# Maps repo_name to list of updates. If a given repo has no updates
# directory, it will be omitted. If a repo has an updates directory
# but none need to be applied (according to timestamp logic), the
# value in the dict will be an empty list.
repo_map = {}
timestamps = {}
retupd = False
update_notice_printed = False
for repo_name in portdb.getRepositories():
repo = portdb.getRepositoryPath(repo_name)
updpath = os.path.join(repo, "profiles", "updates")
if not os.path.isdir(updpath):
continue
if updpath in updpath_map:
repo_map[repo_name] = updpath_map[updpath]
continue
try:
if if_mtime_changed:
update_data = grab_updates(updpath, prev_mtimes=prev_mtimes)
else:
update_data = grab_updates(updpath)
except DirectoryNotFound:
continue
myupd = []
updpath_map[updpath] = myupd
repo_map[repo_name] = myupd
if len(update_data) > 0:
for mykey, mystat, mycontent in update_data:
if not update_notice_printed:
update_notice_printed = True
writemsg_stdout("\n")
if quiet:
writemsg_stdout(colorize("GOOD",
_("Performing Global Updates\n")))
writemsg_stdout(_("(Could take a couple of minutes if you have a lot of binary packages.)\n"))
else:
writemsg_stdout(colorize("GOOD",
_("Performing Global Updates:\n")))
writemsg_stdout(_("(Could take a couple of minutes if you have a lot of binary packages.)\n"))
writemsg_stdout(_(" %s='update pass' %s='binary update' "
"%s='/var/db update' %s='/var/db move'\n"
" %s='/var/db SLOT move' %s='binary move' "
"%s='binary SLOT move'\n %s='update /etc/portage/package.*'\n") % \
(bold("."), bold("*"), bold("#"), bold("@"), bold("s"), bold("%"), bold("S"), bold("p")))
valid_updates, errors = parse_updates(mycontent)
myupd.extend(valid_updates)
if not quiet:
writemsg_stdout(bold(mykey))
writemsg_stdout(len(valid_updates) * "." + "\n")
if len(errors) == 0:
# Update our internal mtime since we
# processed all of our directives.
timestamps[mykey] = mystat[stat.ST_MTIME]
else:
for msg in errors:
writemsg("%s\n" % msg, noiselevel=-1)
if myupd:
retupd = True
if retupd:
if os.access(bindb.bintree.pkgdir, os.W_OK):
# Call binarytree.populate(), since we want to make sure it's
# only populated with local packages here (getbinpkgs=0).
bindb.bintree.populate()
else:
bindb = None
master_repo = portdb.getRepositoryName(portdb.porttree_root)
if master_repo in repo_map:
repo_map['DEFAULT'] = repo_map[master_repo]
for repo_name, myupd in repo_map.items():
if repo_name == 'DEFAULT':
continue
if not myupd:
continue
def repo_match(repository):
return repository == repo_name or \
(repo_name == master_repo and repository not in repo_map)
def _world_repo_match(atoma, atomb):
"""
Check whether to perform a world change from atoma to atomb.
If best vardb match for atoma comes from the same repository
#.........这里部分代码省略.........
示例14: ExtractKernelVersion
def ExtractKernelVersion(base_dir):
"""
Try to figure out what kernel version we are running
@param base_dir: Path to sources (usually /usr/src/linux)
@type base_dir: string
@rtype: tuple( version[string], error[string])
@return:
1. tuple( version[string], error[string])
Either version or error is populated (but never both)
"""
lines = []
pathname = os.path.join(base_dir, 'Makefile')
try:
f = io.open(_unicode_encode(pathname,
encoding=_encodings['fs'], errors='strict'), mode='r',
encoding=_encodings['content'], errors='replace')
except OSError as details:
return (None, str(details))
except IOError as details:
return (None, str(details))
try:
for i in range(4):
lines.append(f.readline())
except OSError as details:
return (None, str(details))
except IOError as details:
return (None, str(details))
finally:
f.close()
lines = [l.strip() for l in lines]
version = ''
#XXX: The following code relies on the ordering of vars within the Makefile
for line in lines:
# split on the '=' then remove annoying whitespace
items = line.split("=")
items = [i.strip() for i in items]
if items[0] == 'VERSION' or \
items[0] == 'PATCHLEVEL':
version += items[1]
version += "."
elif items[0] == 'SUBLEVEL':
version += items[1]
elif items[0] == 'EXTRAVERSION' and \
items[-1] != items[0]:
version += items[1]
# Grab a list of files named localversion* and sort them
localversions = os.listdir(base_dir)
for x in range(len(localversions) - 1, -1, -1):
if localversions[x][:12] != "localversion":
del localversions[x]
localversions.sort()
# Append the contents of each to the version string, stripping ALL whitespace
for lv in localversions:
version += "".join(" ".join(grabfile(base_dir + "/" + lv)).split())
# Check the .config for a CONFIG_LOCALVERSION and append that too, also stripping whitespace
kernelconfig = getconfig(base_dir+"/.config")
if kernelconfig and "CONFIG_LOCALVERSION" in kernelconfig:
version += "".join(kernelconfig["CONFIG_LOCALVERSION"].split())
return (version, None)
示例15: _parse_profile_files_to_list
def _parse_profile_files_to_list(self, file_name, locations):
return tuple(
tuple(grabfile(os.path.join(x, file_name), recursive=1))
for x in locations)