def test14_remove_folder(self): # Create hierarchy vfs.make_folder('tests/folder') vfs.make_folder('tests/folder/a') vfs.make_file('tests/folder/a/hello.txt') # Remove and test vfs.remove('tests/folder') self.assertEqual(vfs.exists('tests/folder'), False)
def test20_append(self): # Initialize file = vfs.make_file('tests/toto.txt') try: file.write('hello\n') finally: file.close() # Test file = vfs.open('tests/toto.txt', APPEND) try: file.write('bye\n') finally: file.close() self.assertEqual(open('tests/toto.txt').read(), 'hello\nbye\n') # Remove temporary file vfs.remove('tests/toto.txt')
def test21_write_and_truncate(self): # Initialize file = vfs.make_file('tests/toto.txt') try: file.write('hello\n') finally: file.close() # Test file = vfs.open('tests/toto.txt', WRITE) try: file.write('bye\n') finally: file.close() self.assertEqual(open('tests/toto.txt').read(), 'bye\n') # Remove temporary file vfs.remove('tests/toto.txt')
def GET(self, resource, context): items = self.get_items(resource, context) issues = self.sort_and_batch(resource, context, items) # Get path of all attachment to add in zip dirname = '%s/zip' % mkdtemp('zip', 'ikaaro') zip = ZipFile(dirname, 'w') for issue in issues: attachment_name = issue.issue_last_attachment attachment = resource.get_resource('%s/%s' % (issue.name, attachment_name)) attachment_uri = attachment.handler.uri[7:] # Get extension mimetype = attachment.get_content_type() ext = guess_extension(mimetype)[1:] #attachment_name = 'issue_%s_%s' % (issue.name, get_uri_name(attachment_uri)) attachment_name = '%s_%s.%s' % (issue.name, issue.title, ext) #print attachment_name, attachment_uri zip.write(attachment_uri, attachment_name) zip.close() # Create zip # Build zipname name = "LastAttachedImages" now = strftime("%y%d%m%H%M") #pprint("%s" % now) zipname = "%s_%s_%s.zip" % (resource.name, name, now) file = open(dirname) try: data = file.read() finally: file.close() vfs.remove(dirname) # Return the zip response = context.response response.set_header('Content-Type', 'application/zip') response.set_header('Content-Disposition', 'attachment; filename=%s' % zipname) return data
def test18_get_names(self): self.assertEqual('hello.txt.old' in vfs.get_names('tests'), True) # Remove temporary file vfs.remove('tests/hello.txt.old')
def test13_remove_empty_folder(self): vfs.remove('tests/folder') self.assertEqual(vfs.exists('tests/folder'), False)
def test12_remove_file(self): vfs.remove('tests/file') self.assertEqual(vfs.exists('tests/file'), False)
def tearDown(self): if vfs.exists('tmp'): vfs.remove('tmp')
def tearDown(self): if vfs.exists('tests/toto.txt'): vfs.remove('tests/toto.txt')
def safe_remove(self, reference): if self.database is None: return vfs.remove(reference) return self.database.safe_remove(reference)
def tearDown(self): if vfs.exists('sandbox'): vfs.remove('sandbox')