當前位置: 首頁>>代碼示例>>Python>>正文


Python File.resolve_relative_path方法代碼示例

本文整理匯總了Python中gio.File.resolve_relative_path方法的典型用法代碼示例。如果您正苦於以下問題:Python File.resolve_relative_path方法的具體用法?Python File.resolve_relative_path怎麽用?Python File.resolve_relative_path使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gio.File的用法示例。


在下文中一共展示了File.resolve_relative_path方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Folder

# 需要導入模塊: from gio import File [as 別名]
# 或者: from gio.File import resolve_relative_path [as 別名]
class Folder(object):

    def __init__(self, obj=None):
        if obj is None:
            self._folder = None
        elif type(obj) is str:
            self._folder = File(obj)
        elif isinstance(obj, File):
            self._folder = obj
        else:
            raise ValueError, 'unexpected obj "%s"' % obj


    ############################
    # Private API
    ############################
    def _get_g_file(self, uri):
        if type(uri) is not str:
            raise TypeError, 'unexpected "%s"' % repr(uri)

        # Resolve or not ?

        # Your folder is None => new File
        if self._folder is None:
            g_file = File(uri)
        else:
            # Split the uri
            scheme, authority, path, query, fragment = urlsplit(uri)

            # A scheme or an authority => new File
            # XXX This is not truly exact:
            #     we can have a scheme and a relative path.
            if scheme or authority:
                g_file = File(uri)
            else:
                # Else we resolve the path
                g_file = self._folder.resolve_relative_path(uri)

        # Automount a ftp server ?
        if g_file.get_uri_scheme () == 'ftp':
            # Mount the server
            AnonymousConnection(g_file)

        return g_file


    def _get_xtime(self, uri, attribut):
        g_file = self._get_g_file(uri)
        info = g_file.query_info(attribut)
        uint64 = info.get_attribute_uint64(attribut)
        return datetime.fromtimestamp(uint64)


    def _can_x(self, uri, attribut):
        g_file = self._get_g_file(uri)
        info = g_file.query_info(attribut)
        return info.get_attribute_boolean(attribut)


    ############################
    # Public API
    ############################
    def exists(self, uri):
        g_file = self._get_g_file(uri)
        return g_file.query_exists()


    def is_file(self, uri):
        g_file = self._get_g_file(uri)
        return _is_file(g_file)


    def is_folder(self, uri):
        g_file = self._get_g_file(uri)
        return _is_folder(g_file)


    def can_read(self, uri):
        return self._can_x(uri, FILE_ATTRIBUTE_ACCESS_CAN_READ)


    def can_write(self, uri):
        return self._can_x(uri, FILE_ATTRIBUTE_ACCESS_CAN_WRITE)


    def make_file(self, uri):
        g_file = self._get_g_file(uri)

        # Make the parent's directory
        _make_directory_with_parents(g_file.get_parent())

        return g_file.create()


    def make_folder(self, uri):
        g_file = self._get_g_file(uri)
        # XXX g_file_make_directory_with_parents is not yet implemented!!
        _make_directory_with_parents(g_file)


#.........這裏部分代碼省略.........
開發者ID:kiniou,項目名稱:blender-smooth-slides,代碼行數:103,代碼來源:vfs.py

示例2: Folder

# 需要導入模塊: from gio import File [as 別名]
# 或者: from gio.File import resolve_relative_path [as 別名]
class Folder(object):

    def __init__(self, obj=None):
        if obj is None:
            self._folder = None
        elif type(obj) is str:
            self._folder = File(obj)
        elif isinstance(obj, File):
            self._folder = obj
        else:
            raise ValueError, 'unexpected obj "%s"' % obj


    ############################
    # Private API
    ############################
    def _get_g_file(self, uri):
        if type(uri) is not str:
            raise TypeError, 'unexpected "%s"' % repr(uri)

        # Your folder is None => new File
        if self._folder is None:
            return File(uri)

        # Your folder is not None, we must resolve the uri
        scheme, authority, path, query, fragment = urlsplit(uri)

        # A scheme or an authority => new File
        # XXX This is not truly exact:
        #     we can have a scheme and a relative path.
        if scheme or authority:
            return File(uri)

        # Else we resolve the path
        return self._folder.resolve_relative_path(uri)


    def _get_xtime(self, uri, attribut):
        g_file = self._get_g_file(uri)
        info = g_file.query_info(attribut)
        uint64 = info.get_attribute_uint64(attribut)
        return datetime.fromtimestamp(uint64)


    def _can_x(self, uri, attribut):
        g_file = self._get_g_file(uri)
        info = g_file.query_info(attribut)
        return info.get_attribute_boolean(attribut)


    #######################################################################
    # Public API
    #######################################################################
    def exists(self, uri):
        g_file = self._get_g_file(uri)
        return g_file.query_exists()


    def is_file(self, uri):
        g_file = self._get_g_file(uri)
        return _is_file(g_file)


    def is_folder(self, uri):
        g_file = self._get_g_file(uri)
        return _is_folder(g_file)


    def can_read(self, uri):
        return self._can_x(uri, FILE_ATTRIBUTE_ACCESS_CAN_READ)


    def can_write(self, uri):
        return self._can_x(uri, FILE_ATTRIBUTE_ACCESS_CAN_WRITE)


    def make_file(self, uri):
        g_file = self._get_g_file(uri)

        # Make the parent's directory
        _make_directory_with_parents(g_file.get_parent())

        return g_file.create()


    def make_folder(self, uri):
        g_file = self._get_g_file(uri)
        _make_directory_with_parents(g_file)


    def get_ctime(self, uri):
        return self._get_xtime(uri, FILE_ATTRIBUTE_TIME_CHANGED)


    def get_mtime(self, uri):
        return self._get_xtime(uri, FILE_ATTRIBUTE_TIME_MODIFIED)


    def get_atime(self, uri):
        return self._get_xtime(uri, FILE_ATTRIBUTE_TIME_ACCESS)
#.........這裏部分代碼省略.........
開發者ID:Nabellaleen,項目名稱:itools,代碼行數:103,代碼來源:vfs.py


注:本文中的gio.File.resolve_relative_path方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。