本文整理汇总了Python中snakeoil.data_source.local_source函数的典型用法代码示例。如果您正苦于以下问题:Python local_source函数的具体用法?Python local_source怎么用?Python local_source使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了local_source函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _internal_load_key
def _internal_load_key(self, path, key):
key = self._metadata_rewrites.get(key, key)
if key == "contents":
data = ContentsFile(pjoin(path, "CONTENTS"), mutable=True)
elif key == "environment":
fp = pjoin(path, key)
if not os.path.exists(fp + ".bz2"):
if not os.path.exists(fp):
# icky.
raise KeyError("environment: no environment file found")
data = data_source.local_source(fp)
else:
data = data_source.bz2_source(fp + ".bz2")
elif key == "ebuild":
fp = pjoin(path, os.path.basename(path.rstrip(os.path.sep)) + ".ebuild")
data = data_source.local_source(fp)
elif key == 'repo':
# try both, for portage/paludis compatibility.
data = readfile(pjoin(path, 'repository'), True)
if data is None:
data = readfile(pjoin(path, 'REPOSITORY'), True)
if data is None:
raise KeyError(key)
else:
data = readfile(pjoin(path, key), True)
if data is None:
raise KeyError((path, key))
return data
开发者ID:neko259,项目名称:pkgcore,代码行数:28,代码来源:ondisk.py
示例2: test_transfer_to_path
def test_transfer_to_path(self):
data = self._mk_data()
reader = self.get_obj(data=data)
writer = data_source.local_source(pjoin(self.dir, 'transfer_to_path'), mutable=True)
reader.transfer_to_path(writer.path)
self.assertContents(reader, writer)
开发者ID:rafaelmartins,项目名称:snakeoil,代码行数:8,代码来源:test_data_source.py
示例3: _path
def _path(self, cpv, eapi_str):
ebuild = pjoin(str(tmpdir), "temp-0.ebuild")
with open(ebuild, 'w') as f:
f.write(textwrap.dedent(f'''\
# Copyright
# License
EAPI={eapi_str}'''))
return local_source(str(ebuild))
开发者ID:radhermit,项目名称:pkgcore,代码行数:9,代码来源:test_ebuild_src.py
示例4: __pull_metadata
def __pull_metadata(self, key):
if key == "contents":
return self.scan_contents(self.image_root)
elif key == "environment":
return local_source(self.environment_path)
else:
try:
return getattr(self.pkg, key)
except AttributeError:
raise_from(KeyError(key))
开发者ID:chutz,项目名称:pkgcore,代码行数:10,代码来源:ebuild_built.py
示例5: get_writable_fsobj
def get_writable_fsobj(self, fsobj, prefer_reuse=True, empty=False):
path = source = None
if fsobj:
source = fsobj.data
if source.mutable:
return fsobj
if self.allow_reuse and prefer_reuse:
path = source.path
# XXX: this should be doing abspath fs intersection probably,
# although the paths generated are from triggers/engine- still.
if path is not None and not path.startswith(self.tempdir):
# the fsobj pathway isn't in temp space; force a transfer.
path = None
if path:
# ok, it's tempspace, and reusable.
obj = data_source.local_source(path, True,
encoding=source.encoding)
if empty:
obj.bytes_fileobj(True).truncate(0)
return obj
# clone it into tempspace; it's required we control the tempspace,
# so this function is safe in our usage.
fd, path = tempfile.mkstemp(prefix='merge-engine-', dir=self.tempdir)
# XXX: annoying quirk of python, we don't want append mode, so 'a+'
# isn't viable; wr will truncate the file, so data_source uses r+.
# this however doesn't allow us to state "create if missing"
# so we create it ourselves. Annoying, but so it goes.
# just touch the filepath.
open(path, 'w').close()
new_source = data_source.local_source(path, True,
encoding=getattr(fsobj, 'encoding', None))
if source and not empty:
data_source.transfer(source.bytes_fsobj(), new_source.bytes_fsobj(True))
return new_source
开发者ID:floppym,项目名称:pkgcore,代码行数:42,代码来源:engine.py
示例6: test_it
def test_it(self):
src = pjoin(self.dir, "copy_test_src")
dest = pjoin(self.dir, "copy_test_dest")
open(src, "w").writelines("asdf\n" for i in xrange(10))
kwds = {"mtime":10321, "uid":os.getuid(), "gid":os.getgid(),
"mode":0664, "data":local_source(src), "dev":None,
"inode":None}
o = fs.fsFile(dest, **kwds)
self.assertTrue(ops.default_copyfile(o))
self.assertEqual("asdf\n" * 10, open(dest, "r").read())
self.verify(o, kwds, os.stat(o.location))
开发者ID:veelai,项目名称:pkgcore,代码行数:11,代码来源:test_ops.py
示例7: get_obj
def get_obj(self, data="foonani", mutable=False, test_creation=False):
self.fp = pjoin(self.dir, "localsource.test")
mode = None
if not test_creation:
if isinstance(data, bytes):
mode = 'wb'
elif mode is None:
mode = 'w'
with open(self.fp, mode) as f:
f.write(data)
return data_source.local_source(self.fp, mutable=mutable)
开发者ID:radhermit,项目名称:snakeoil,代码行数:11,代码来源:test_data_source.py
示例8: get_obj
def get_obj(self, data="foonani", mutable=False, test_creation=False):
self.fp = os.path.join(self.dir, "localsource.test")
f = None
if not test_creation:
if compatibility.is_py3k:
if isinstance(data, bytes):
f = open(self.fp, 'wb')
if f is None:
f = open(self.fp, "w")
f.write(data)
f.close()
return data_source.local_source(self.fp, mutable=mutable)
开发者ID:rafaelmartins,项目名称:snakeoil,代码行数:12,代码来源:test_data_source.py
示例9: gen_obj
def gen_obj(path, stat=None, chksum_handlers=None, real_location=None,
stat_func=os.lstat, **overrides):
"""
given a fs path, and an optional stat, create an appropriate fs obj.
:param stat: stat object to reuse if available
:param real_location: real path to the object if path is the desired
location, rather then existent location.
:raise KeyError: if no obj type matches the stat checks
:return: :obj:`pkgcore.fs.fs.fsBase` derivative
"""
if real_location is None:
real_location = path
if stat is None:
try:
stat = stat_func(real_location)
except EnvironmentError as e:
if stat_func == os.lstat or e.errno != errno.ENOENT:
raise
stat = os.lstat(real_location)
mode = stat.st_mode
d = {"mtime":stat.st_mtime, "mode":S_IMODE(mode),
"uid":stat.st_uid, "gid":stat.st_gid}
if S_ISREG(mode):
d["size"] = stat.st_size
d["data"] = local_source(real_location)
d["dev"] = stat.st_dev
d["inode"] = stat.st_ino
if chksum_handlers is not None:
d["chf_types"] = chksum_handlers
d.update(overrides)
return fsFile(path, **d)
d.update(overrides)
if S_ISDIR(mode):
return fsDir(path, **d)
elif S_ISLNK(mode):
d["target"] = os.readlink(real_location)
return fsSymlink(path, **d)
elif S_ISFIFO(mode):
return fsFifo(path, **d)
else:
major, minor = get_major_minor(stat)
d["minor"] = minor
d["major"] = major
d["mode"] = mode
return fsDev(path, **d)
开发者ID:den4ix,项目名称:pkgcore,代码行数:49,代码来源:livefs.py
示例10: get_package_bashrcs
def get_package_bashrcs(self, pkg):
for source in self.profile.bashrcs:
yield source
for restrict, source in self.bashrcs:
if restrict.match(pkg):
yield source
if not self.ebuild_hook_dir:
return
# matching portage behaviour... it's whacked.
base = pjoin(self.ebuild_hook_dir, pkg.category)
for fp in (pkg.package, "%s:%s" % (pkg.package, pkg.slot),
getattr(pkg, "P", "nonexistent"), getattr(pkg, "PF", "nonexistent")):
fp = pjoin(base, fp)
if os.path.exists(fp):
yield local_source(fp)
开发者ID:den4ix,项目名称:pkgcore,代码行数:15,代码来源:domain.py
示例11: get_package_bashrcs
def get_package_bashrcs(self, pkg):
for source in self.profile.bashrcs:
yield source
for source in self.bashrcs:
yield source
if not os.path.exists(self.ebuild_hook_dir):
return
# matching portage behavior... it's whacked.
base = pjoin(self.ebuild_hook_dir, pkg.category)
dirs = (
pkg.package,
f"{pkg.package}:{pkg.slot}",
getattr(pkg, "P", None),
getattr(pkg, "PF", None),
)
for fp in filter(None, dirs):
fp = pjoin(base, fp)
if os.path.exists(fp):
yield local_source(fp)
开发者ID:radhermit,项目名称:pkgcore,代码行数:19,代码来源:domain.py
示例12: __init__
def __init__(self, location, chksums=None, data=None, **kwds):
"""
:param chksums: dict of checksums, key chksum_type: val hash val.
See :obj:`snakeoil.chksum`.
"""
assert 'data_source' not in kwds
if data is None:
data = local_source(location)
kwds["data"] = data
if chksums is None:
# this can be problematic offhand if the file is modified
# but chksum not triggered
chf_types = kwds.pop("chf_types", None)
if chf_types is None:
chf_types = tuple(get_handlers())
chksums = _LazyChksums(chf_types, self._chksum_callback)
kwds["chksums"] = chksums
fsBase.__init__(self, location, **kwds)
开发者ID:chutz,项目名称:pkgcore,代码行数:19,代码来源:fs.py
示例13: package_env_splitter
def package_env_splitter(basedir, val):
val = val.split()
return parse_match(val[0]), local_source(pjoin(basedir, val[1]))
开发者ID:den4ix,项目名称:pkgcore,代码行数:3,代码来源:domain.py
示例14: __init__
#.........这里部分代码省略.........
self.arch = self.stable_arch = settings["ARCH"]
self.unstable_arch = "~%s" % self.arch
# ~amd64 -> [amd64, ~amd64]
for x in default_keywords[:]:
if x.startswith("~"):
default_keywords.append(x.lstrip("~"))
default_keywords = unstable_unique(default_keywords + [self.arch])
accept_keywords = pkg_keywords + list(profile.accept_keywords)
vfilters = [self.make_keywords_filter(
self.arch, default_keywords, accept_keywords, profile.keywords,
incremental="package.keywords" in incrementals)]
del default_keywords, accept_keywords
# we can finally close that fricking
# "DISALLOW NON FOSS LICENSES" bug via this >:)
master_license = []
master_license.extend(settings.get('ACCEPT_LICENSE', ()))
if master_license or pkg_licenses:
vfilters.append(self.make_license_filter(master_license, pkg_licenses))
del master_license
# if it's made it this far...
self.root = settings["ROOT"] = root
self.prefix = prefix
self.settings = ProtectedDict(settings)
for data in self.settings.get('bashrc', ()):
source = local_source(data)
# this is currently local-only so a path check is ok
# TODO make this more general
if not os.path.exists(source.path):
raise Failure(
'user-specified bashrc %r does not exist' % (data,))
self.bashrcs.append((packages.AlwaysTrue, source))
# stack use stuff first, then profile.
self.enabled_use = ChunkedDataDict()
self.enabled_use.add_bare_global(*split_negations(self.use))
self.enabled_use.merge(profile.pkg_use)
self.enabled_use.update_from_stream(
chunked_data(k, *split_negations(v)) for k, v in pkg_use)
for attr in ('', 'stable_'):
c = ChunkedDataDict()
c.merge(getattr(profile, attr + 'forced_use'))
c.add_bare_global((), (self.arch,))
setattr(self, attr + 'forced_use', c)
c = ChunkedDataDict()
c.merge(getattr(profile, attr + 'masked_use'))
setattr(self, attr + 'disabled_use', c)
self.repos = []
self.vdb = []
self.repos_configured = {}
self.repos_configured_filtered = {}
rev_names = {repo: name for name, repo in self.repos_raw.iteritems()}
profile_masks = profile._incremental_masks()
开发者ID:den4ix,项目名称:pkgcore,代码行数:67,代码来源:domain.py
示例15: get_eclass
def get_eclass(self, eclass):
o = self.eclasses.get(eclass)
if o is None:
return None
return local_source(o.path)
开发者ID:neko259,项目名称:pkgcore,代码行数:5,代码来源:eclass_cache.py
示例16: test_data_source_check
def test_data_source_check(self):
self.assertEqual(self.chf(local_source(self.fn)), self.expected_long)
self.assertEqual(
self.chf(data_source(fileutils.readfile_ascii(self.fn))), self.expected_long)
开发者ID:chutz,项目名称:snakeoil,代码行数:4,代码来源:test_defaults.py
示例17: bashrcs
def bashrcs(self):
files = sorted_scan(pjoin(self.config_dir, 'bashrc'), follow_symlinks=True)
return tuple(local_source(x) for x in files)
开发者ID:radhermit,项目名称:pkgcore,代码行数:3,代码来源:domain.py
示例18: stat_func
if real_location is None:
real_location = path
if stat is None:
try:
stat = stat_func(real_location)
except EnvironmentError, e:
if stat_func == os.lstat or e.errno != errno.ENOENT:
raise
stat = os.lstat(real_location)
mode = stat.st_mode
d = {"mtime":stat.st_mtime, "mode":S_IMODE(mode),
"uid":stat.st_uid, "gid":stat.st_gid}
if S_ISREG(mode):
d["size"] = stat.st_size
d["data"] = local_source(real_location)
d["dev"] = stat.st_dev
d["inode"] = stat.st_ino
if chksum_handlers is not None:
d["chf_types"] = chksum_handlers
d.update(overrides)
return fsFile(path, **d)
d.update(overrides)
if S_ISDIR(mode):
return fsDir(path, **d)
elif S_ISLNK(mode):
d["target"] = os.readlink(real_location)
return fsSymlink(path, **d)
elif S_ISFIFO(mode):
return fsFifo(path, **d)
开发者ID:veelai,项目名称:pkgcore,代码行数:31,代码来源:livefs.py
注:本文中的snakeoil.data_source.local_source函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论