本文整理汇总了Python中libgsync.drive.Drive类的典型用法代码示例。如果您正苦于以下问题:Python Drive类的具体用法?Python Drive怎么用?Python Drive使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Drive类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_open_for_read_and_read_data
def test_open_for_read_and_read_data(self):
drive = Drive()
f = drive.open("drive://unittest/open_for_read.txt", "r")
contents = f.read()
self.assertIsNotNone(contents)
self.assertNotEqual(contents, "")
示例2: test_revisions
def test_revisions(self):
drive = Drive()
num_revisions = 6
info = drive.create("drive://gsync_unittest/revision_test", {
"description": "revision-0"
})
self.assertEqual(info['description'], "revision-0")
for revision in range(1, num_revisions):
description = "revision-%d" % revision
info = drive.update("drive://gsync_unittest/revision_test", {
"description": description
},
media_body=MediaFileUpload("tests/data/open_for_read.txt",
mimetype=MimeTypes.BINARY_FILE, resumable=True
)
)
self.assertEqual(info['description'], description)
f = drive.open("drive://gsync_unittest/revision_test", "r")
revisions = f.revisions()
self.assertEqual(len(revisions), num_revisions)
self.assertEqual(int(revisions[0]['fileSize']), 0)
self.assertNotEqual(int(revisions[-1]['fileSize']), 0)
示例3: test_Drive_pathlist
def test_Drive_pathlist(self):
drive = Drive()
paths = [
"drive://",
"drive://unittest",
"drive://unittest/",
"drive://unittest/a/b/c",
"drive://unittest/a/b/c/.",
"drive://unittest/a/b/c/..",
]
expected_paths = [
[ "drive://" ],
[ "drive://", "unittest" ],
[ "drive://", "unittest" ],
[ "drive://", "unittest", "a", "b", "c" ],
[ "drive://", "unittest", "a", "b", "c" ],
[ "drive://", "unittest", "a", "b" ],
]
for i in xrange(0, len(paths)):
expected = str(expected_paths[i])
actual = str(drive.pathlist(paths[i]))
self.assertEqual(expected, actual,
"From %s expected %s but got %s" % (
paths[i], expected, actual
)
)
示例4: test_Drive_strippath
def test_Drive_strippath(self):
drive = Drive()
paths = [
"drive:",
"drive:/",
"drive://",
"drive://unittest",
"drive://unittest/",
"drive://unittest/a/b/c",
"drive://unittest/a/b/c/.",
"drive://unittest/a/b/c/..",
]
expected_paths = [
"/",
"/",
"/",
"/unittest",
"/unittest",
"/unittest/a/b/c",
"/unittest/a/b/c",
"/unittest/a/b",
]
for i in xrange(0, len(paths)):
expected = str(expected_paths[i])
actual = str(drive.strippath(paths[i]))
self.assertEqual(expected, actual,
"From %s expected %s but got %s" % (
paths[i], expected, actual
)
)
示例5: _update_data
def _update_data(self, path, src):
debug("Updating remote file: %s" % repr(path))
total_bytes_written = self.bytes_written
bytes_written = 0
info = src.get_info()
def __callback(status):
bytes_written = int(status.resumable_progress)
self.bytes_written = total_bytes_written + bytes_written
progress = Progress(GsyncOptions.progress, __callback)
if GsyncOptions.dry_run:
bytes_written = info.fileSize
progress(MediaUploadProgress(bytes_written, bytes_written))
else:
progress.bytesTotal = info.fileSize
drive = Drive()
info = drive.update(
path, info, media_body=src.get_uploader(),
progress_callback=progress
)
if info is not None:
bytes_written = long(info.get('fileSize', '0'))
debug("Final file size: %d" % bytes_written)
else:
debug("Update failed")
progress.complete(bytes_written)
self.bytes_written = total_bytes_written + bytes_written
示例6: _updateFile
def _updateFile(self, path, src):
debug("Updating remote file: %s" % repr(path))
totalBytesWritten = self.bytesWritten
bytesWritten = 0
info = src.getInfo()
def _callback(status):
bytesWritten = int(status.resumable_progress)
self.bytesWritten = totalBytesWritten + bytesWritten
progress = Progress(GsyncOptions.progress, _callback)
if GsyncOptions.dry_run:
bytesWritten = info.fileSize
progress(MediaUploadProgress(bytesWritten, bytesWritten))
else:
drive = Drive()
info = drive.update(path, info, src.getUploader(), progress)
if info is not None:
bytesWritten = long(info.get('fileSize', '0'))
else:
debug("Update failed")
progress.complete(bytesWritten)
self.bytesWritten = totalBytesWritten + bytesWritten
示例7: test_open_for_read_and_seek
def test_open_for_read_and_seek(self):
drive = Drive()
f = drive.open("drive://gsync_unittest/open_for_read.txt", "r")
self.assertNotEqual(int(f._info.fileSize), 0)
f.seek(0, os.SEEK_END)
self.assertNotEqual(f.tell(), 0)
示例8: test_mkdir
def test_mkdir(self):
drive = Drive()
info = drive.mkdir("drive://gsync_unittest/test_mkdir/a/b/c/d/e/f/g")
self.assertIsNotNone(info)
self.assertEqual(info.title, "g")
drive.delete("drive://gsync_unittest/test_mkdir", skip_trash=True)
示例9: test_mkdir
def test_mkdir(self):
self.skipTest("slow")
drive = Drive()
info = drive.mkdir("drive://unittest/test_mkdir/a/b/c/d/e/f/g")
self.assertIsNotNone(info)
self.assertEqual(info.title, "g")
drive.rm("drive://unittest/test_mkdir", recursive=True)
示例10: test_listdir
def test_listdir(self):
drive = Drive()
info = drive.create("drive://gsync_unittest/a_file_to_list", {})
self.assertIsNotNone(info)
items = drive.listdir("drive://gsync_unittest/")
self.assertTrue(isinstance(items, list))
self.assertTrue("a_file_to_list" in items)
示例11: test_mimetypes
def test_mimetypes(self):
drive = Drive()
drive.mkdir("drive://gsync_unittest/mimetype_test_dir")
f = drive.open("drive://gsync_unittest/mimetype_test_dir", "r")
self.assertEqual(f.mimetype(), MimeTypes.FOLDER)
f.mimetype(MimeTypes.BINARY_FILE)
self.assertEqual(f.mimetype(), MimeTypes.BINARY_FILE)
示例12: _createFile
def _createFile(self, path, src):
debug("Creating remote file: %s" % repr(path))
if GsyncOptions.dry_run: return
drive = Drive()
info = drive.create(path, src.getInfo())
if info is None:
debug("Creation failed")
示例13: test_stat
def test_stat(self):
drive = Drive()
info = drive.stat("drive://")
self.assertIsNotNone(info)
self.assertEqual("root", info.id)
info = drive.stat("drive://unittest/")
self.assertIsNotNone(info)
self.assertIsNotNone(info.id)
self.assertEqual(info.title, "unittest")
示例14: get_uploader
def get_uploader(self, path = None):
info = self.get_info(path)
if info is None:
raise Exception("Could not obtain file information: %s" % path)
path = self.get_path(path)
drive = Drive()
debug("Opening remote file for reading: %s" % repr(path))
fd = drive.open(path, "r")
if fd is None:
raise Exception("Open failed: %s" % path)
return MediaIoBaseUpload(fd, info.mimeType, resumable=True)
示例15: test_close
def test_close(self):
drive = Drive()
f = drive.open("drive://gsync_unittest/open_for_read.txt", "r")
contents = f.read()
self.assertNotEqual(contents, None)
f.close()
self.assertTrue(f.closed)
try:
f.seek(0)
self.assertEqual("Expected IOError for seek on closed file", None)
except IOError:
pass