本文整理汇总了Python中amo.utils.LocalFileStorage类的典型用法代码示例。如果您正苦于以下问题:Python LocalFileStorage类的具体用法?Python LocalFileStorage怎么用?Python LocalFileStorage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LocalFileStorage类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reject_rereview
def reject_rereview(theme):
"""Delete pending theme from filesystem."""
storage = LocalFileStorage()
rereview = theme.rereviewqueuetheme_set.all()
reupload = rereview[0]
storage.delete(reupload.header_path)
storage.delete(reupload.footer_path)
rereview.delete()
示例2: setUp
def setUp(self):
self.tmp = tempfile.mkdtemp()
self.stor = LocalFileStorage()
示例3: TestLocalFileStorage
class TestLocalFileStorage(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.mkdtemp()
self.stor = LocalFileStorage()
def tearDown(self):
shutil.rmtree(self.tmp)
def test_read_write(self):
fn = os.path.join(self.tmp, 'somefile.txt')
with self.stor.open(fn, 'w') as fd:
fd.write('stuff')
with self.stor.open(fn, 'r') as fd:
eq_(fd.read(), 'stuff')
def test_non_ascii_filename(self):
fn = os.path.join(self.tmp, u'Ivan Krsti\u0107.txt')
with self.stor.open(fn, 'w') as fd:
fd.write('stuff')
with self.stor.open(fn, 'r') as fd:
eq_(fd.read(), 'stuff')
def test_non_ascii_content(self):
fn = os.path.join(self.tmp, 'somefile.txt')
with self.stor.open(fn, 'w') as fd:
fd.write(u'Ivan Krsti\u0107.txt'.encode('utf8'))
with self.stor.open(fn, 'r') as fd:
eq_(fd.read().decode('utf8'), u'Ivan Krsti\u0107.txt')
def test_make_file_dirs(self):
dp = os.path.join(self.tmp, 'path', 'to')
self.stor.open(os.path.join(dp, 'file.txt'), 'w').close()
assert os.path.exists(self.stor.path(dp)), (
'Directory not created: %r' % dp)
def test_do_not_make_file_dirs_when_reading(self):
fpath = os.path.join(self.tmp, 'file.txt')
with open(fpath, 'w') as fp:
fp.write('content')
# Make sure this doesn't raise an exception.
self.stor.open(fpath, 'r').close()
def test_make_dirs_only_once(self):
dp = os.path.join(self.tmp, 'path', 'to')
with self.stor.open(os.path.join(dp, 'file.txt'), 'w') as fd:
fd.write('stuff')
# Make sure it doesn't try to make the dir twice
with self.stor.open(os.path.join(dp, 'file.txt'), 'w') as fd:
fd.write('stuff')
with self.stor.open(os.path.join(dp, 'file.txt'), 'r') as fd:
eq_(fd.read(), 'stuff')
示例4: TestLocalFileStorage
class TestLocalFileStorage(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.mkdtemp()
self.stor = LocalFileStorage()
def tearDown(self):
rm_local_tmp_dir(self.tmp)
def test_read_write(self):
fn = os.path.join(self.tmp, "somefile.txt")
with self.stor.open(fn, "w") as fd:
fd.write("stuff")
with self.stor.open(fn, "r") as fd:
eq_(fd.read(), "stuff")
def test_non_ascii_filename(self):
fn = os.path.join(self.tmp, u"Ivan Krsti\u0107.txt")
with self.stor.open(fn, "w") as fd:
fd.write("stuff")
with self.stor.open(fn, "r") as fd:
eq_(fd.read(), "stuff")
def test_non_ascii_content(self):
fn = os.path.join(self.tmp, "somefile.txt")
with self.stor.open(fn, "w") as fd:
fd.write(u"Ivan Krsti\u0107.txt".encode("utf8"))
with self.stor.open(fn, "r") as fd:
eq_(fd.read().decode("utf8"), u"Ivan Krsti\u0107.txt")
def test_make_file_dirs(self):
dp = os.path.join(self.tmp, "path", "to")
self.stor.open(os.path.join(dp, "file.txt"), "w").close()
assert os.path.exists(self.stor.path(dp)), "Directory not created: %r" % dp
def test_do_not_make_file_dirs_when_reading(self):
fpath = os.path.join(self.tmp, "file.txt")
with open(fpath, "w") as fp:
fp.write("content")
# Make sure this doesn't raise an exception.
self.stor.open(fpath, "r").close()
def test_make_dirs_only_once(self):
dp = os.path.join(self.tmp, "path", "to")
with self.stor.open(os.path.join(dp, "file.txt"), "w") as fd:
fd.write("stuff")
# Make sure it doesn't try to make the dir twice
with self.stor.open(os.path.join(dp, "file.txt"), "w") as fd:
fd.write("stuff")
with self.stor.open(os.path.join(dp, "file.txt"), "r") as fd:
eq_(fd.read(), "stuff")
def test_delete_empty_dir(self):
dp = os.path.join(self.tmp, "path")
os.mkdir(dp)
self.stor.delete(dp)
eq_(os.path.exists(dp), False)
@raises(OSError)
def test_cannot_delete_non_empty_dir(self):
dp = os.path.join(self.tmp, "path")
with self.stor.open(os.path.join(dp, "file.txt"), "w") as fp:
fp.write("stuff")
self.stor.delete(dp)
def test_delete_file(self):
dp = os.path.join(self.tmp, "path")
fn = os.path.join(dp, "file.txt")
with self.stor.open(fn, "w") as fp:
fp.write("stuff")
self.stor.delete(fn)
eq_(os.path.exists(fn), False)
eq_(os.path.exists(dp), True)
示例5: make_checksum
def make_checksum(header_path, footer_path):
ls = LocalFileStorage()
raw_checksum = ls._open(header_path).read() + ls._open(footer_path).read()
return hashlib.sha224(raw_checksum).hexdigest()
示例6: setUp
def setUp(self):
super(TestLocalFileStorage, self).setUp()
self.tmp = tempfile.mkdtemp()
self.stor = LocalFileStorage()
示例7: TestLocalFileStorage
class TestLocalFileStorage(BaseTestCase):
def setUp(self):
super(TestLocalFileStorage, self).setUp()
self.tmp = tempfile.mkdtemp()
self.stor = LocalFileStorage()
def tearDown(self):
rm_local_tmp_dir(self.tmp)
super(TestLocalFileStorage, self).tearDown()
def test_read_write(self):
fn = os.path.join(self.tmp, 'somefile.txt')
with self.stor.open(fn, 'w') as fd:
fd.write('stuff')
with self.stor.open(fn, 'r') as fd:
eq_(fd.read(), 'stuff')
def test_non_ascii_filename(self):
fn = os.path.join(self.tmp, u'Ivan Krsti\u0107.txt')
with self.stor.open(fn, 'w') as fd:
fd.write('stuff')
with self.stor.open(fn, 'r') as fd:
eq_(fd.read(), 'stuff')
def test_non_ascii_content(self):
fn = os.path.join(self.tmp, 'somefile.txt')
with self.stor.open(fn, 'w') as fd:
fd.write(u'Ivan Krsti\u0107.txt'.encode('utf8'))
with self.stor.open(fn, 'r') as fd:
eq_(fd.read().decode('utf8'), u'Ivan Krsti\u0107.txt')
def test_make_file_dirs(self):
dp = os.path.join(self.tmp, 'path', 'to')
self.stor.open(os.path.join(dp, 'file.txt'), 'w').close()
assert os.path.exists(self.stor.path(dp)), (
'Directory not created: %r' % dp)
def test_do_not_make_file_dirs_when_reading(self):
fpath = os.path.join(self.tmp, 'file.txt')
with open(fpath, 'w') as fp:
fp.write('content')
# Make sure this doesn't raise an exception.
self.stor.open(fpath, 'r').close()
def test_make_dirs_only_once(self):
dp = os.path.join(self.tmp, 'path', 'to')
with self.stor.open(os.path.join(dp, 'file.txt'), 'w') as fd:
fd.write('stuff')
# Make sure it doesn't try to make the dir twice
with self.stor.open(os.path.join(dp, 'file.txt'), 'w') as fd:
fd.write('stuff')
with self.stor.open(os.path.join(dp, 'file.txt'), 'r') as fd:
eq_(fd.read(), 'stuff')
def test_delete_empty_dir(self):
dp = os.path.join(self.tmp, 'path')
os.mkdir(dp)
self.stor.delete(dp)
eq_(os.path.exists(dp), False)
@raises(OSError)
def test_cannot_delete_non_empty_dir(self):
dp = os.path.join(self.tmp, 'path')
with self.stor.open(os.path.join(dp, 'file.txt'), 'w') as fp:
fp.write('stuff')
self.stor.delete(dp)
def test_delete_file(self):
dp = os.path.join(self.tmp, 'path')
fn = os.path.join(dp, 'file.txt')
with self.stor.open(fn, 'w') as fp:
fp.write('stuff')
self.stor.delete(fn)
eq_(os.path.exists(fn), False)
eq_(os.path.exists(dp), True)