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
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
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)
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
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
def test_DriveMimeTypes_get_folder_mimetype(self): self.assertEqual(MimeTypes.get("/bin"), "inode/directory")
def test_DriveMimeTypes_get_binary_mimetype(self): self.assertEqual(MimeTypes.get("/bin/true"), "application/x-executable")
def test_DriveMimeTypes_get_unknown_mimetype(self): self.assertEqual(MimeTypes.get("/dev/null"), "inode/chardevice")
def test_DriveMimeTypes_get_binary_mimetype(self): self.assertEqual( MimeTypes.get("/bin/true"), "application/x-executable" )