本文整理汇总了Python中portage.os.listdir函数的典型用法代码示例。如果您正苦于以下问题:Python listdir函数的具体用法?Python listdir怎么用?Python listdir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了listdir函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _prepare_fake_distdir
def _prepare_fake_distdir(settings, alist):
orig_distdir = settings["DISTDIR"]
edpath = os.path.join(settings["PORTAGE_BUILDDIR"], "distdir")
portage.util.ensure_dirs(edpath, gid=portage_gid, mode=0o755)
# Remove any unexpected files or directories.
for x in os.listdir(edpath):
symlink_path = os.path.join(edpath, x)
st = os.lstat(symlink_path)
if x in alist and stat.S_ISLNK(st.st_mode):
continue
if stat.S_ISDIR(st.st_mode):
shutil.rmtree(symlink_path)
else:
os.unlink(symlink_path)
# Check for existing symlinks and recreate if necessary.
for x in alist:
symlink_path = os.path.join(edpath, x)
target = os.path.join(orig_distdir, x)
try:
link_target = os.readlink(symlink_path)
except OSError:
os.symlink(target, symlink_path)
else:
if link_target != target:
os.unlink(symlink_path)
os.symlink(target, symlink_path)
开发者ID:gentoo,项目名称:portage,代码行数:28,代码来源:prepare_build_dirs.py
示例2: hardlock_cleanup
def hardlock_cleanup(path, remove_all_locks=False):
myhost = os.uname()[1]
mydl = os.listdir(path)
results = []
mycount = 0
mylist = {}
for x in mydl:
if os.path.isfile(path + "/" + x):
parts = x.split(".hardlock-")
if len(parts) == 2:
filename = parts[0][1:]
hostpid = parts[1].split("-")
host = "-".join(hostpid[:-1])
pid = hostpid[-1]
if filename not in mylist:
mylist[filename] = {}
if host not in mylist[filename]:
mylist[filename][host] = []
mylist[filename][host].append(pid)
mycount += 1
results.append(_("Found %(count)s locks") % {"count": mycount})
for x in mylist:
if myhost in mylist[x] or remove_all_locks:
mylockname = hardlock_name(path + "/" + x)
if hardlink_is_mine(mylockname, path + "/" + x) or \
not os.path.exists(path + "/" + x) or \
remove_all_locks:
for y in mylist[x]:
for z in mylist[x][y]:
filename = path + "/." + x + ".hardlock-" + y + "-" + z
if filename == mylockname:
continue
try:
# We're sweeping through, unlinking everyone's locks.
os.unlink(filename)
results.append(_("Unlinked: ") + filename)
except OSError:
pass
try:
os.unlink(path + "/" + x)
results.append(_("Unlinked: ") + path + "/" + x)
os.unlink(mylockname)
results.append(_("Unlinked: ") + mylockname)
except OSError:
pass
else:
try:
os.unlink(mylockname)
results.append(_("Unlinked: ") + mylockname)
except OSError:
pass
return results
开发者ID:aeroniero33,项目名称:portage,代码行数:60,代码来源:locks.py
示例3: grab_updates
def grab_updates(updpath, prev_mtimes=None):
"""Returns all the updates from the given directory as a sorted list of
tuples, each containing (file_path, statobj, content). If prev_mtimes is
given then only updates with differing mtimes are considered."""
try:
mylist = os.listdir(updpath)
except OSError as oe:
if oe.errno == errno.ENOENT:
raise DirectoryNotFound(updpath)
raise
if prev_mtimes is None:
prev_mtimes = {}
# validate the file name (filter out CVS directory, etc...)
mylist = [myfile for myfile in mylist if len(myfile) == 7 and myfile[1:3] == "Q-"]
if len(mylist) == 0:
return []
# update names are mangled to make them sort properly
mylist = [myfile[3:]+"-"+myfile[:2] for myfile in mylist]
mylist.sort()
mylist = [myfile[5:]+"-"+myfile[:4] for myfile in mylist]
update_data = []
for myfile in mylist:
file_path = os.path.join(updpath, myfile)
mystat = os.stat(file_path)
if file_path not in prev_mtimes or \
long(prev_mtimes[file_path]) != mystat[stat.ST_MTIME]:
content = codecs.open(_unicode_encode(file_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'], errors='replace'
).read()
update_data.append((file_path, mystat, content))
return update_data
开发者ID:Neuvoo,项目名称:legacy-portage,代码行数:34,代码来源:update.py
示例4: __iter__
def __iter__(self):
"""generator for walking the dir struct"""
dirs = [(0, self.location)]
len_base = len(self.location)
while dirs:
depth, dir_path = dirs.pop()
try:
dir_list = os.listdir(dir_path)
except OSError as e:
if e.errno != errno.ENOENT:
raise
del e
continue
for l in dir_list:
p = os.path.join(dir_path, l)
try:
st = os.lstat(p)
except OSError:
# Cache entry disappeared.
continue
if stat.S_ISDIR(st.st_mode):
# Only recurse 1 deep, in order to avoid iteration over
# entries from another nested cache instance. This can
# happen if the user nests an overlay inside
# /usr/portage/local as in bug #302764.
if depth < 1:
dirs.append((depth+1, p))
continue
try:
yield _pkg_str(p[len_base+1:])
except InvalidData:
continue
开发者ID:amadio,项目名称:portage,代码行数:33,代码来源:flat_hash.py
示例5: collect_ebuild_messages
def collect_ebuild_messages(path):
""" Collect elog messages generated by the bash logging function stored
at 'path'.
"""
mylogfiles = None
try:
mylogfiles = os.listdir(path)
except OSError:
pass
# shortcut for packages without any messages
if not mylogfiles:
return {}
# exploit listdir() file order so we process log entries in chronological order
mylogfiles.reverse()
logentries = {}
for msgfunction in mylogfiles:
filename = os.path.join(path, msgfunction)
if msgfunction not in EBUILD_PHASES:
writemsg(_("!!! can't process invalid log file: %s\n") % filename,
noiselevel=-1)
continue
if not msgfunction in logentries:
logentries[msgfunction] = []
lastmsgtype = None
msgcontent = []
f = io.open(_unicode_encode(filename,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'], errors='replace')
for l in f:
l = l.rstrip('\n')
if not l:
continue
try:
msgtype, msg = l.split(" ", 1)
except ValueError:
writemsg(_("!!! malformed entry in "
"log file: '%s'\n") % filename, noiselevel=-1)
continue
if lastmsgtype is None:
lastmsgtype = msgtype
if msgtype == lastmsgtype:
msgcontent.append(msg)
else:
if msgcontent:
logentries[msgfunction].append((lastmsgtype, msgcontent))
msgcontent = [msg]
lastmsgtype = msgtype
f.close()
if msgcontent:
logentries[msgfunction].append((lastmsgtype, msgcontent))
# clean logfiles to avoid repetitions
for f in mylogfiles:
try:
os.unlink(os.path.join(path, f))
except OSError:
pass
return logentries
开发者ID:Acidburn0zzz,项目名称:portage-funtoo,代码行数:60,代码来源:messages.py
示例6: have_ebuild_dir
def have_ebuild_dir(path, maxdepth=3):
"""
Try to figure out if 'path' or a subdirectory contains one or more
ebuild files named appropriately for their parent directory.
"""
stack = [(normalize_path(path), 1)]
while stack:
path, depth = stack.pop()
basename = os.path.basename(path)
try:
listdir = os.listdir(path)
except OSError:
continue
for filename in listdir:
abs_filename = os.path.join(path, filename)
try:
st = os.stat(abs_filename)
except OSError:
continue
if stat.S_ISDIR(st.st_mode):
if depth < maxdepth:
stack.append((abs_filename, depth + 1))
elif stat.S_ISREG(st.st_mode):
if filename.endswith(".ebuild") and \
filename.startswith(basename + "-"):
return os.path.dirname(os.path.dirname(path))
开发者ID:pombredanne,项目名称:portage-3,代码行数:26,代码来源:utilities.py
示例7: _get_all_modules
def _get_all_modules(self):
"""scans the emaint modules dir for loadable modules
@rtype: dictionary of module_plugins
"""
module_dir = self._module_path
importables = []
names = os.listdir(module_dir)
for entry in names:
# skip any __init__ or __pycache__ files or directories
if entry.startswith('__'):
continue
try:
# test for statinfo to ensure it should a real module
# it will bail if it errors
os.lstat(os.path.join(module_dir, entry, '__init__.py'))
importables.append(entry)
except EnvironmentError:
pass
kids = {}
for entry in importables:
new_module = Module(entry, self._namepath)
for module_name in new_module.kids:
kid = new_module.kids[module_name]
kid['parent'] = new_module
kids[kid['name']] = kid
self.parents.append(entry)
return kids
开发者ID:aeroniero33,项目名称:portage,代码行数:28,代码来源:module.py
示例8: get_glsa_list
def get_glsa_list(myconfig):
"""
Returns a list of all available GLSAs in the given repository
by comparing the filelist there with the pattern described in
the config.
@type myconfig: portage.config
@param myconfig: Portage settings instance
@rtype: List of Strings
@return: a list of GLSA IDs in this repository
"""
rValue = []
if "GLSA_DIR" in myconfig:
repository = myconfig["GLSA_DIR"]
else:
repository = os.path.join(myconfig["PORTDIR"], "metadata", "glsa")
if not os.access(repository, os.R_OK):
return []
dirlist = os.listdir(repository)
prefix = "glsa-"
suffix = ".xml"
for f in dirlist:
try:
if f[:len(prefix)] == prefix and f[-1*len(suffix):] == suffix:
rValue.append(f[len(prefix):-1*len(suffix)])
except IndexError:
pass
return rValue
开发者ID:entoo,项目名称:portage-src,代码行数:32,代码来源:glsa.py
示例9: grablines
def grablines(myfilename, recursive=0, remember_source_file=False):
mylines=[]
if recursive and os.path.isdir(myfilename):
if os.path.basename(myfilename) in _ignorecvs_dirs:
return mylines
dirlist = os.listdir(myfilename)
dirlist.sort()
for f in dirlist:
if not f.startswith(".") and not f.endswith("~"):
mylines.extend(grablines(
os.path.join(myfilename, f), recursive, remember_source_file))
else:
try:
myfile = io.open(_unicode_encode(myfilename,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace')
if remember_source_file:
mylines = [(line, myfilename) for line in myfile.readlines()]
else:
mylines = myfile.readlines()
myfile.close()
except IOError as e:
if e.errno == PermissionDenied.errno:
raise PermissionDenied(myfilename)
pass
return mylines
开发者ID:zy-sunshine,项目名称:easymgc,代码行数:26,代码来源:__init__.py
示例10: cacheddir
def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymlinks=True):
mypath = normalize_path(my_original_path)
try:
pathstat = os.stat(mypath)
if not stat.S_ISDIR(pathstat.st_mode):
raise DirectoryNotFound(mypath)
except EnvironmentError as e:
if e.errno == PermissionDenied.errno:
raise PermissionDenied(mypath)
del e
return [], []
except PortageException:
return [], []
else:
try:
fpaths = os.listdir(mypath)
except EnvironmentError as e:
if e.errno != errno.EACCES:
raise
del e
raise PermissionDenied(mypath)
ftype = []
for x in fpaths:
try:
if followSymlinks:
pathstat = os.stat(mypath+"/"+x)
else:
pathstat = os.lstat(mypath+"/"+x)
if stat.S_ISREG(pathstat[stat.ST_MODE]):
ftype.append(0)
elif stat.S_ISDIR(pathstat[stat.ST_MODE]):
ftype.append(1)
elif stat.S_ISLNK(pathstat[stat.ST_MODE]):
ftype.append(2)
else:
ftype.append(3)
except (IOError, OSError):
ftype.append(3)
if ignorelist or ignorecvs:
ret_list = []
ret_ftype = []
for file_path, file_type in zip(fpaths, ftype):
if file_path in ignorelist:
pass
elif ignorecvs:
if file_path[:2] != ".#" and \
not (file_type == 1 and file_path in VCS_DIRS):
ret_list.append(file_path)
ret_ftype.append(file_type)
else:
ret_list = fpaths
ret_ftype = ftype
return ret_list, ret_ftype
开发者ID:Spencerx,项目名称:portage,代码行数:56,代码来源:listdir.py
示例11: _scan_cat
def _scan_cat(self, cat):
for repo in self._repo_list:
cat_dir = repo.location + "/" + cat
try:
pkg_list = os.listdir(cat_dir)
except OSError as e:
if e.errno not in (errno.ENOTDIR, errno.ENOENT, errno.ESTALE):
raise
continue
for p in pkg_list:
if os.path.isdir(cat_dir + "/" + p):
self._items[cat + "/" + p].append(repo)
self._scanned_cats.add(cat)
开发者ID:gentoo,项目名称:portage,代码行数:13,代码来源:porttree.py
示例12: modify_files
def modify_files(dir_path):
for name in os.listdir(dir_path):
path = os.path.join(dir_path, name)
st = os.lstat(path)
if stat.S_ISREG(st.st_mode):
with io.open(path, mode='a',
encoding=_encodings["stdio"]) as f:
f.write("modified at %d\n" % time.time())
elif stat.S_ISLNK(st.st_mode):
old_dest = os.readlink(path)
os.unlink(path)
os.symlink(old_dest +
" modified at %d" % time.time(), path)
开发者ID:Whissi,项目名称:portage,代码行数:13,代码来源:test_config_protect.py
示例13: new_protect_filename
def new_protect_filename(mydest, newmd5=None, force=False):
"""Resolves a config-protect filename for merging, optionally
using the last filename if the md5 matches. If force is True,
then a new filename will be generated even if mydest does not
exist yet.
(dest,md5) ==> 'string' --- path_to_target_filename
(dest) ==> ('next', 'highest') --- next_target and most-recent_target
"""
# config protection filename format:
# ._cfg0000_foo
# 0123456789012
os = _os_merge
prot_num = -1
last_pfile = ""
if not force and \
not os.path.exists(mydest):
return mydest
real_filename = os.path.basename(mydest)
real_dirname = os.path.dirname(mydest)
for pfile in os.listdir(real_dirname):
if pfile[0:5] != "._cfg":
continue
if pfile[10:] != real_filename:
continue
try:
new_prot_num = int(pfile[5:9])
if new_prot_num > prot_num:
prot_num = new_prot_num
last_pfile = pfile
except ValueError:
continue
prot_num = prot_num + 1
new_pfile = normalize_path(os.path.join(real_dirname,
"._cfg" + str(prot_num).zfill(4) + "_" + real_filename))
old_pfile = normalize_path(os.path.join(real_dirname, last_pfile))
if last_pfile and newmd5:
try:
last_pfile_md5 = portage.checksum._perform_md5_merge(old_pfile)
except FileNotFound:
# The file suddenly disappeared or it's a broken symlink.
pass
else:
if last_pfile_md5 == newmd5:
return old_pfile
return new_pfile
开发者ID:clickbeetle,项目名称:portage-cb,代码行数:51,代码来源:__init__.py
示例14: AddPackagesInDir
def AddPackagesInDir(path):
""" Given a list of dirs, add any packages in it """
ret = []
pkgdirs = os.listdir(path)
for d in pkgdirs:
if d == 'CVS' or d.startswith('.'):
continue
p = os.path.join(path, d)
if os.path.isdir(p):
cat_pkg_dir = os.path.join(*p.split(os.path.sep)[-2:])
logging.debug('adding %s to scanlist' % cat_pkg_dir)
ret.append(cat_pkg_dir)
return ret
开发者ID:pombredanne,项目名称:portage-3,代码行数:14,代码来源:utilities.py
示例15: _calc_changelog
def _calc_changelog(ebuildpath, current, next):
if ebuildpath == None or not os.path.exists(ebuildpath):
return []
current = "-".join(catpkgsplit(current)[1:])
if current.endswith("-r0"):
current = current[:-3]
next = "-".join(catpkgsplit(next)[1:])
if next.endswith("-r0"):
next = next[:-3]
changelogdir = os.path.dirname(ebuildpath)
changelogs = ["ChangeLog"]
# ChangeLog-YYYY (see bug #389611)
changelogs.extend(sorted((fn for fn in os.listdir(changelogdir) if fn.startswith("ChangeLog-")), reverse=True))
divisions = []
found_current = False
for fn in changelogs:
changelogpath = os.path.join(changelogdir, fn)
try:
with io.open(
_unicode_encode(changelogpath, encoding=_encodings["fs"], errors="strict"),
mode="r",
encoding=_encodings["repo.content"],
errors="replace",
) as f:
changelog = f.read()
except EnvironmentError:
return []
for node in _find_changelog_tags(changelog):
if node[0] == current:
found_current = True
break
else:
divisions.append(node)
if found_current:
break
if not found_current:
return []
# print 'XX from',current,'to',next
# for div,text in divisions: print 'XX',div
# skip entries for all revisions above the one we are about to emerge
for i in range(len(divisions)):
if divisions[i][0] == next:
divisions = divisions[i:]
break
return divisions
开发者ID:zy-sunshine,项目名称:easymgc,代码行数:50,代码来源:output_helpers.py
示例16: __iter__
def __iter__(self):
"""generator for walking the dir struct"""
dirs = [self.location]
len_base = len(self.location)
while len(dirs):
for l in os.listdir(dirs[0]):
if l.endswith(".cpickle"):
continue
p = os.path.join(dirs[0],l)
st = os.lstat(p)
if stat.S_ISDIR(st.st_mode):
dirs.append(p)
continue
yield p[len_base+1:]
dirs.pop(0)
开发者ID:TommyD,项目名称:gentoo-portage-multilib,代码行数:15,代码来源:flat_list.py
示例17: _scan
def _scan(self, onProgress=None):
"""
Scan the file system for failed merges and return any found.
@param onProgress: function to call for updating progress
@type onProgress: Function
@rtype: dict
@return: dictionary of packages that failed to merges
"""
failed_pkgs = {}
for cat in os.listdir(self._vardb_path):
pkgs_path = os.path.join(self._vardb_path, cat)
if not os.path.isdir(pkgs_path):
continue
pkgs = os.listdir(pkgs_path)
maxval = len(pkgs)
for i, pkg in enumerate(pkgs):
if onProgress:
onProgress(maxval, i+1)
if MERGING_IDENTIFIER in pkg:
mtime = int(os.stat(os.path.join(pkgs_path, pkg)).st_mtime)
pkg = os.path.join(cat, pkg)
failed_pkgs[pkg] = mtime
return failed_pkgs
开发者ID:jonasstein,项目名称:portage,代码行数:24,代码来源:merges.py
示例18: assertExists
def assertExists(self, path):
"""Make sure |path| exists"""
if not os.path.exists(path):
msg = ['path is missing: %s' % (path,)]
while path != '/':
path = os.path.dirname(path)
if not path:
# If we're given something like "foo", abort once we get to "".
break
result = os.path.exists(path)
msg.append('\tos.path.exists(%s): %s' % (path, result))
if result:
msg.append('\tcontents: %r' % os.listdir(path))
break
raise self.failureException('\n'.join(msg))
开发者ID:aeroniero33,项目名称:portage,代码行数:15,代码来源:__init__.py
示例19: fixdbentries
def fixdbentries(update_iter, dbdir):
"""Performs update commands which result in search and replace operations
for each of the files in dbdir (excluding CONTENTS and environment.bz2).
Returns True when actual modifications are necessary and False otherwise."""
mydata = {}
for myfile in [f for f in os.listdir(dbdir) if f not in ignored_dbentries]:
file_path = os.path.join(dbdir, myfile)
mydata[myfile] = codecs.open(_unicode_encode(file_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
errors='replace').read()
updated_items = update_dbentries(update_iter, mydata)
for myfile, mycontent in updated_items.items():
file_path = os.path.join(dbdir, myfile)
write_atomic(file_path, mycontent, encoding=_encodings['repo.content'])
return len(updated_items) > 0
开发者ID:Neuvoo,项目名称:legacy-portage,代码行数:16,代码来源:update.py
示例20: collect_binaries_from_dir
def collect_binaries_from_dir(dirs, mask, logger):
''' Collects all binaries from specified list of directories.
mask is list of pathes, that are ommited in scanning,
can be eighter single file or entire directory
Returns list of binaries
'''
# contains list of directories found
# allows us to reduce number of fnc calls
found_directories = set()
found_files = set()
for _dir in dirs:
if _dir in mask:
continue
try:
for _listing in os.listdir(_dir):
listing = os.path.join(_dir, _listing)
if listing in mask or _listing in mask:
continue
if os.path.isdir(listing):
if os.path.islink(listing):
#we do not want scan symlink-directories
pass
else:
found_directories.add(listing)
elif os.path.isfile(listing):
# we're looking for binaries
# and with binaries we do not need links
# thus we can optimize a bit
if not os.path.islink(listing):
prv = os.stat(listing)[stat.ST_MODE]
if prv & stat.S_IXUSR == stat.S_IXUSR or \
prv & stat.S_IXGRP == stat.S_IXGRP or \
prv & stat.S_IXOTH == stat.S_IXOTH:
found_files.add(listing)
except Exception as ex:
logger.debug('\t' +
yellow('Exception during binaries collecting: '+
blue('%s') %str(ex)))
if found_directories:
found_files.update(collect_binaries_from_dir(found_directories, mask, logger))
return found_files
开发者ID:zmedico,项目名称:gentoolkit,代码行数:47,代码来源:collect.py
注:本文中的portage.os.listdir函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论