本文整理汇总了Python中pmaker.models.FileObjectFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python FileObjectFactory.create方法的具体用法?Python FileObjectFactory.create怎么用?Python FileObjectFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pmaker.models.FileObjectFactory
的用法示例。
在下文中一共展示了FileObjectFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_02_list__multi_generated_file
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def test_02_list__multi_generated_file(self):
listfile = os.path.join(self.workdir, "file.list")
listfile2 = os.path.join(self.workdir, "file2.list")
config = init_config(listfile)
line = "%s/file*.list\n" % self.workdir
open(listfile, "w").write(line)
open(listfile2, "w").write(line)
collector = FilelistCollector(listfile, config)
fos = collector.list(listfile)
fos_ref = [Factory.create(listfile), Factory.create(listfile2)]
self.assertEquals(sorted(fos), sorted(fos_ref))
示例2: test_copy__exists
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def test_copy__exists(self):
fo = Factory.create(self.testfile1)
dest = self.testfile1 + ".2"
FileOps.copy(fo, dest)
self.assertFalse(FileOps.copy(fo, dest))
示例3: test_update
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def test_update(self):
modifier = RpmAttributeModifier()
f = F.create("/bin/bash")
new_f = modifier.update(f)
self.assertTrue(getattr(new_f, "rpm_attr", False))
示例4: test_pred__not_exist
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def test_pred__not_exist(self):
filter = NotExistFilter()
path = "/bin/sh"
assert os.path.exists(path)
fo = Factory.create(path)
self.assertFalse(filter.pred(fo))
示例5: test_copy_impl_and_remove
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def test_copy_impl_and_remove(self):
fo = Factory.create(self.testfile1)
dest = self.testfile1 + ".2"
FileOps.copy_impl(fo, dest)
self.assertTrue(os.path.exists(dest))
FileOps.remove(dest)
self.assertFalse(os.path.exists(dest))
示例6: test__create_wo_attrs
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def test__create_wo_attrs(self):
fo = Factory.create(self.path)
self.assertTrue(isinstance(fo, FO.DirObject))
self.assertEquals(fo.mode, fo.defaults.mode)
self.assertEquals(fo.uid, fo.defaults.uid)
self.assertEquals(fo.gid, fo.defaults.gid)
self.assertEquals(fo.checksum, fo.defaults.checksum)
self.assertEquals(fo.path, self.path)
示例7: test_pred__unsupported__fileobjects
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def test_pred__unsupported__fileobjects(self):
username = pwd.getpwuid(os.getuid()).pw_name
paths = ["/dev/null", "/dev/zero"] + glob.glob("/tmp/orbit-%s/linc-*" % username)[:3] # device files # socket
paths = [p for p in paths if os.path.exists(p)]
for p in paths:
fo = Factory.create(p)
self.assertTrue(self.filter.pred(fo))
示例8: test_pred__permitted_to_read
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def test_pred__permitted_to_read(self):
filter = ReadAccessFilter()
pred = lambda f: os.path.exists(f) and os.access(f, os.R_OK)
path = random.choice([p for p in ("/etc/hosts", "/etc/resolv.conf",
"/etc/sysctl.conf")
if pred(p)])
fo = Factory.create(path)
self.assertFalse(filter.pred(fo))
示例9: test__create_w_filetype_symlink
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def test__create_w_filetype_symlink(self):
filetype = FO.typestr_to_type("symlink")
fo = Factory.create(self.path, filetype=filetype)
self.assertTrue(isinstance(fo, FO.SymlinkObject))
self.assertEquals(fo.type(), G.TYPE_SYMLINK)
self.assertEquals(fo.path, self.path)
self.assertEquals(fo.mode, fo.defaults.mode)
self.assertEquals(fo.uid, fo.defaults.uid)
self.assertEquals(fo.gid, fo.defaults.gid)
self.assertEquals(fo.checksum, fo.defaults.checksum)
示例10: test__create_w_content
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def test__create_w_content(self):
content = "Hello, world\n"
fo = Factory.create(self.path, content=content)
self.assertTrue(isinstance(fo, FO.FileObject))
self.assertEquals(fo.path, self.path)
self.assertEquals(fo.mode, fo.defaults.mode)
self.assertEquals(fo.uid, fo.defaults.uid)
self.assertEquals(fo.gid, fo.defaults.gid)
self.assertEquals(fo.checksum, fo.defaults.checksum)
self.assertEquals(fo.content, content)
示例11: test__create_w_src
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def test__create_w_src(self):
src = "/etc/hosts"
fo = Factory.create(self.path, src=src)
self.assertTrue(isinstance(fo, FO.FileObject))
self.assertEquals(fo.path, self.path)
self.assertEquals(fo.mode, fo.defaults.mode)
self.assertEquals(fo.uid, fo.defaults.uid)
self.assertEquals(fo.gid, fo.defaults.gid)
self.assertEquals(fo.checksum, fo.defaults.checksum)
self.assertEquals(fo.src, src)
示例12: test__create_w_linkto
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def test__create_w_linkto(self):
linkto = "/etc/hosts"
fo = Factory.create(self.path, linkto=linkto)
self.assertTrue(isinstance(fo, FO.SymlinkObject))
self.assertEquals(fo.path, self.path)
self.assertEquals(fo.mode, fo.defaults.mode)
self.assertEquals(fo.uid, fo.defaults.uid)
self.assertEquals(fo.gid, fo.defaults.gid)
self.assertEquals(fo.checksum, fo.defaults.checksum)
self.assertEquals(fo.linkto, linkto)
示例13: test__create_w_filetype_dir
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def test__create_w_filetype_dir(self):
filetype = FO.typestr_to_type("dir")
fo = Factory.create(self.path, filetype=filetype)
self.assertTrue(isinstance(fo, FO.DirObject))
self.assertEquals(fo.type(), G.TYPE_DIR)
self.assertEquals(fo.path, self.path)
self.assertEquals(fo.mode, fo.defaults.mode)
self.assertEquals(fo.uid, fo.defaults.uid)
self.assertEquals(fo.gid, fo.defaults.gid)
self.assertEquals(fo.checksum, fo.defaults.checksum)
示例14: test_pred__supported__fileobjects
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def test_pred__supported__fileobjects(self):
paths = [
"/etc/resolv.conf", "/etc/hosts", # normal files
"/etc", # dirs
"/etc/rc", "/etc/init.d", "/etc/grub.conf" # symlinks
]
paths = [p for p in paths if os.path.exists(p)]
for p in paths:
fo = Factory.create(p)
self.assertFalse(self.filter.pred(fo))
示例15: _parse
# 需要导入模块: from pmaker.models import FileObjectFactory [as 别名]
# 或者: from pmaker.models.FileObjectFactory import create [as 别名]
def _parse(self, bobj):
"""
:param bobj: A Bunch object holds path and attrs (metadata) of files.
"""
path = bobj.get("path", False)
if not path or path.startswith("#"):
return []
else:
paths = "*" in path and glob.glob(path) or [path]
attrs = bobj.get("attrs", dict())
return [Factory.create(p, self.use_rpmdb, **attrs) for p in paths]