当前位置: 首页>>代码示例>>Python>>正文


Python FilePath.getPermissions方法代码示例

本文整理汇总了Python中twisted.python.filepath.FilePath.getPermissions方法的典型用法代码示例。如果您正苦于以下问题:Python FilePath.getPermissions方法的具体用法?Python FilePath.getPermissions怎么用?Python FilePath.getPermissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.python.filepath.FilePath的用法示例。


在下文中一共展示了FilePath.getPermissions方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Fs

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getPermissions [as 别名]
class Fs(CrawlJob):
    def __init__(self, cfg, db_pool, data):
        super(Fs, self).__init__(cfg, db_pool, data)
        self.cfg = cfg
        self.data = data

        self.protocol = 'filesystem'

        self.creator = None

        self.fs = None
        self.connection_closed = False

    def create(self, path=None):
        self.fs = FilePath(path)
        try:
            return self.fs.getPermissions()
        except:
            return False

    @defer.inlineCallbacks
    def getDirectory(self, path='/'):

        self.fs = yield FilePath(path)

        if not self.fs.getPermissions():
            defer.returnValue(False)

        files = []

        for f in self.fs.listdir():
            if f == '/':
                continue

            fp = path+f
            fs = FilePath(fp)

            # dont follow symlinks
            if fs.realpath().path != fp:
                continue

            perm = None
            isdir = fs.isdir()
            size = fs.getsize()
            modified = datetime.utcfromtimestamp(fs.getModificationTime())

            df = DiscoveredFile(
                resource_id=self.data['resource_id'],
                file_path=path,
                file_name=f,
                file_isdir=isdir,
                file_size=size,
                file_modified=modified,
                file_perm=perm
            )

            print '[%s] LIST %s.' % (self.data['resource_name'], fp if not fp.endswith('.') else fp)
            files.append(df)

        defer.returnValue(files)
开发者ID:pombredanne,项目名称:findex-crawl,代码行数:62,代码来源:filesystem.py

示例2: inspect

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getPermissions [as 别名]
def inspect(doc):
    data = json.loads(doc)
    path = FilePath(data['path'])
    ret = {'kind': 'file', 'path': path.path, 'exists': path.exists()}
    if not ret['exists']:
        return ret
    
    if path.isdir():
        ret['filetype'] = 'dir'
    elif path.isfile():
        ret['filetype'] = 'file'
        ret['size'] = path.statinfo.st_size
        h = sha1()
        fh = open(path.path, 'r')
        while True:
            data = fh.read(4096)
            if not data:
                break
            h.update(data)
        ret['sha1'] = h.hexdigest()

    ret['owner'] = pwd.getpwuid(path.getUserID()).pw_name
    ret['group'] = grp.getgrgid(path.getGroupID()).gr_name
    ret['perms'] = permsString(path.getPermissions())
    ret['ctime'] = int(path.statinfo.st_ctime)
    ret['mtime'] = int(path.statinfo.st_mtime)
    ret['atime'] = int(path.statinfo.st_atime)
    return ret
开发者ID:hagna,项目名称:mold,代码行数:30,代码来源:file.py

示例3: test_permissions

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getPermissions [as 别名]
 def test_permissions(self):
     """
     The directory is created with restrictive permissions.
     """
     path = FilePath(self.mktemp())
     DockerPluginScript()._create_listening_directory(path)
     path.restat()
     self.assertEqual(path.getPermissions().shorthand(), "rwx------")
开发者ID:sysuwbs,项目名称:flocker,代码行数:10,代码来源:test_script.py

示例4: wrapper

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getPermissions [as 别名]
 def wrapper(case, *args, **kwargs):
     test_file = FilePath(case.mktemp())
     test_file.touch()
     test_file.chmod(0o000)
     permissions = test_file.getPermissions()
     test_file.chmod(0o777)
     if permissions != Permissions(0o000):
         raise SkipTest("Can't run test on filesystem with broken permissions.")
     return test_method(case, *args, **kwargs)
开发者ID:WUMUXIAN,项目名称:flocker,代码行数:11,代码来源:__init__.py

示例5: test_reverse_config_file_is_world_readable

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getPermissions [as 别名]
 def test_reverse_config_file_is_world_readable(self):
     self.patch(DNSReverseZoneConfig, 'target_dir', self.make_dir())
     dns_zone_config = DNSReverseZoneConfig(
         factory.getRandomString(), serial=random.randint(1, 100),
         dns_ip=factory.getRandomIPAddress(),
         network=factory.getRandomNetwork())
     dns_zone_config.write_config()
     filepath = FilePath(dns_zone_config.target_path)
     self.assertTrue(filepath.getPermissions().other.read)
开发者ID:cloudbase,项目名称:maas,代码行数:11,代码来源:test_config.py

示例6: test_install_dir_normalises_permissions

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getPermissions [as 别名]
 def test_install_dir_normalises_permissions(self):
     # install_dir() normalises directory permissions to 0755 and file
     # permissions to 0644.
     target_dir = FilePath(self.make_dir())
     new_dir = FilePath(self.make_dir())
     new_dir.chmod(0700)
     new_image = new_dir.child("image")
     new_image.touch()
     new_image.chmod(0600)
     install_dir(new_dir.path, target_dir.path)
     self.assertEqual(
         "rwxr-xr-x",
         target_dir.getPermissions().shorthand())
     self.assertEqual(
         "rw-r--r--",
         target_dir.child("image").getPermissions().shorthand())
开发者ID:deepakhajare,项目名称:maas,代码行数:18,代码来源:test_install_image.py

示例7: test_write_config_makes_config_world_readable

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getPermissions [as 别名]
 def test_write_config_makes_config_world_readable(self):
     target_dir = self.make_dir()
     self.patch(DNSConfig, 'target_dir', target_dir)
     DNSConfig().write_config()
     config_file = FilePath(os.path.join(target_dir, MAAS_NAMED_CONF_NAME))
     self.assertTrue(config_file.getPermissions().other.read)
开发者ID:cloudbase,项目名称:maas,代码行数:8,代码来源:test_config.py


注:本文中的twisted.python.filepath.FilePath.getPermissions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。