Example #1
0
    def getInfo(self, path = None):
        path = self.getPath(path)

        debug("Fetching local file metadata: %s" % repr(path))

        try:
            # Obtain the file info, following the link
            st_info = os.stat(path)
            dirname, filename = os.path.split(path)

            if os.path.isdir(path):
                mimeType = MimeTypes.FOLDER
            else:
                mimeType = MimeTypes.get(path)

            md5Checksum = None
            if GsyncOptions.checksum:
                md5Checksum = self._md5Checksum(path)

            info = SyncFileInfo(
                None,
                filename,
                datetime.datetime.utcfromtimestamp(
                    st_info.st_mtime
                ).isoformat(),
                mimeType,
                description = st_info,
                fileSize = st_info.st_size,
                md5Checksum = md5Checksum,
                path=path
            )
        except OSError, e:
            debug("File not found: %s" % repr(path))
            return None
Example #2
0
    def getInfo(self, path=None):
        path = self.getPath(path)

        debug("Fetching local file metadata: %s" % repr(path))

        try:
            # Obtain the file info, following the link
            st_info = os.stat(path)
            dirname, filename = os.path.split(path)

            if os.path.isdir(path):
                mimeType = MimeTypes.FOLDER
            else:
                mimeType = MimeTypes.get(path)

            md5Checksum = None
            if GsyncOptions.checksum:
                md5Checksum = self._md5Checksum(path)

            info = SyncFileInfo(None,
                                filename,
                                datetime.datetime.utcfromtimestamp(
                                    st_info.st_mtime).isoformat(),
                                mimeType,
                                description=st_info,
                                fileSize=st_info.st_size,
                                md5Checksum=md5Checksum,
                                path=path)
            debug("Local file = %s" % repr(info), 3)
            debug("Local mtime: %s" % repr(info.modifiedDate))
        except OSError, e:
            debug("File not found: %s" % repr(path))
            return None
Example #3
0
    def test_DriveMimeTypes_get_magic_exception(self):
        try:
            import magic
        except Exception:
            self.skipTest("Module 'magic' not present")
            return

        def func(*args, **kwargs):
            raise Exception("Fake exception")

        magic.from_file = func

        self.assertEqual(MimeTypes.get("/bin/true"), MimeTypes.NONE)
Example #4
0
    def test_DriveMimeTypes_get_magic_exception(self):
        try:
            import magic
        except Exception:
            self.skipTest("Module 'magic' not present")
            return

        def func(*args, **kwargs):
            raise Exception("Fake exception")

        magic.from_file = func

        self.assertEqual(MimeTypes.get("/bin/true"), MimeTypes.NONE)
Example #5
0
    def get_info(self, path=None):
        path = self.get_path(path)

        debug("Fetching local file metadata: %s" % repr(path))

        try:
            # Obtain the file info, following the link
            st_info = os.stat(path)
            filename = os.path.basename(path)

            if os.path.isdir(path):
                mimetype = MimeTypes.FOLDER
            elif os.path.islink(path):
                st_info = os.lstat(path)
                mimetype = MimeTypes.SYMLINK
            else:
                mimetype = MimeTypes.get(path)

            md5_checksum = None
            if GsyncOptions.checksum:
                md5_checksum = self._md5_checksum(path)

            info = SyncFileInfo(
                id=None,
                title=filename,
                modifiedDate=datetime.datetime.utcfromtimestamp(
                    st_info.st_mtime
                    # ).isoformat(),
                    # ).replace(tzinfo=tzutc()).isoformat(),
                ).replace(tzinfo=tzutc()).strftime("%Y-%m-%dT%H:%M:%S.%f%z"),
                mimeType=mimetype,
                description=st_info,
                fileSize=st_info.st_size,
                md5Checksum=md5_checksum,
                path=path
            )
            debug("Local file = %s" % repr(info), 3)
            debug("Local mtime: %s" % repr(info.modifiedDate))

        except OSError:  # pragma: no cover
            debug("File not found: %s" % repr(path))
            return None

        debug("Local mtime: %s" % info.modifiedDate)

        return info
Example #6
0
    def get_info(self, path = None):
        path = self.get_path(path)

        debug("Fetching local file metadata: %s" % repr(path))

        try:
            # Obtain the file info, following the link
            st_info = os.stat(path)
            filename = os.path.basename(path)

            if os.path.isdir(path):
                mimetype = MimeTypes.FOLDER
            elif os.path.islink(path):
                st_info = os.lstat(path)
                mimetype = MimeTypes.SYMLINK
            else:
                mimetype = MimeTypes.get(path)

            md5_checksum = None
            if GsyncOptions.checksum:
                md5_checksum = self._md5_checksum(path)

            info = SyncFileInfo(
                id=None,
                title=filename,
                modifiedDate=datetime.datetime.utcfromtimestamp(
                    st_info.st_mtime
                    #).isoformat(),
                    #).replace(tzinfo=tzutc()).isoformat(),
                    ).replace(tzinfo=tzutc()).strftime("%Y-%m-%dT%H:%M:%S.%f%z"),
                mimeType=mimetype,
                description=st_info,
                fileSize=st_info.st_size,
                md5Checksum=md5_checksum,
                path=path
            )
            debug("Local file = %s" % repr(info), 3)
            debug("Local mtime: %s" % repr(info.modifiedDate))

        except OSError: # pragma: no cover
            debug("File not found: %s" % repr(path))
            return None

        debug("Local mtime: %s" % info.modifiedDate)

        return info
Example #7
0
 def test_DriveMimeTypes_get_folder_mimetype(self):
     self.assertEqual(MimeTypes.get("/bin"), "inode/directory")
Example #8
0
 def test_DriveMimeTypes_get_binary_mimetype(self):
     self.assertEqual(MimeTypes.get("/bin/true"),
                      "application/x-executable")
Example #9
0
 def test_DriveMimeTypes_get_unknown_mimetype(self):
     self.assertEqual(MimeTypes.get("/dev/null"), "inode/chardevice")
Example #10
0
 def test_DriveMimeTypes_get_folder_mimetype(self):
     self.assertEqual(MimeTypes.get("/bin"), "inode/directory")
Example #11
0
 def test_DriveMimeTypes_get_binary_mimetype(self):
     self.assertEqual(
         MimeTypes.get("/bin/true"), "application/x-executable"
     )
Example #12
0
 def test_DriveMimeTypes_get_unknown_mimetype(self):
     self.assertEqual(MimeTypes.get("/dev/null"), "inode/chardevice")