Esempio n. 1
0
    def parseFileAttrs(self, attributes):
        '''list(str) -> File
        Retrieves data from the attribute lines and creates File DO.
        @raise ValueError: retrieved line count differs from required attribute count or attribute value is invalid
        '''

        name = self._getFileAttr(attributes, FileAttrs.NAME)
        path = self._getFileAttr(attributes, FileAttrs.PATH)
        isDirectory = self._getFileAttr(attributes, FileAttrs.IS_DIRECTORY)
        isDirectory = isDirectory and isDirectory.isdigit() and int(isDirectory)

        perms = self._getFileAttr(attributes, FileAttrs.PERMS)
        #Cutting parent directory path
        parentPath = path and name and path.endswith(name) and path[:len(path) - (len(name) + 1)]
        size = self._getFileAttr(attributes, FileAttrs.SIZE)
        owner = self._getFileAttr(attributes, FileAttrs.OWNER)

        lastModificationTime = self._getFileAttr(attributes, FileAttrs.LAST_MODIFICATION_TIME)
        lastModificationTime = lastModificationTime and self._parseTimeInMls(lastModificationTime)

        creationTime = self._getFileAttr(attributes, FileAttrs.CREATION_TIME)
        creationTime = creationTime and self._parseTimeInMls(creationTime)

        version = self._getFileAttr(attributes, FileAttrs.VERSION)
        version = version and self._parseVersion(version)
        content = self._getFileAttr(attributes, FileAttrs.CONTENT)

        file_ = File(name, isDirectory)
        file_.path = path
        file_.parent = parentPath
        file_.owner = owner
        file_.content = content
        if version:
            file_.version = version
        size and file_.setSizeInBytes(size)
        perms and file_.setPermissionsInOctal(perms)
        lastModificationTime and file_.setLastModificationTimeInMls(lastModificationTime)
        creationTime and file_.setCreateTimeInMls(creationTime)
        return file_