def test_read_all(self): res = fileutils.write_to_tempfile(self.content) self.assertTrue(os.path.exists(res)) out, unread_bytes = fileutils.last_bytes(res, 1000) self.assertEqual(b'1234567890', out) self.assertEqual(0, unread_bytes)
def test_truncated(self): res = fileutils.write_to_tempfile(self.content) self.assertTrue(os.path.exists(res)) out, unread_bytes = fileutils.last_bytes(res, 5) self.assertEqual(b'67890', out) self.assertGreater(unread_bytes, 0)
def test_truncated(self): res = fileutils.write_to_tempfile(self.content) self.assertTrue(os.path.exists(res)) out, unread_bytes = fileutils.last_bytes(res, 5) self.assertEqual(b'67890', out) self.assertGreater(unread_bytes, 0)
def test_read_all(self): res = fileutils.write_to_tempfile(self.content) self.assertTrue(os.path.exists(res)) out, unread_bytes = fileutils.last_bytes(res, 1000) self.assertEqual(b'1234567890', out) self.assertEqual(0, unread_bytes)
from oslo_utils import fileutils import os import shutil path = 'path/to/here' fileutils.ensure_tree(path) file = fileutils.write_to_tempfile('hello fileutils', path) print("template file " + file) for n in ['sha1', 'md5', 'sha256']: print( fileutils.compute_file_checksum(file, read_chunksize=65536, algorithm=n)) print(fileutils.last_bytes(file, 1)) print(fileutils.last_bytes(file, 10000)) fileutils.delete_if_exists(file) # any exception will cause the path to be deleted. #fileutils.remove_path_on_error(path) # fileutils have no routine for directory :( shutil.rmtree('path')