def test_memoryfs_text(): """ write and read text file :return: """ mem = MemoryFS() data_path = 'a.txt' for i in range(10): mem.appendtext(data_path, str(i)) for line in mem.readtext(data_path): print('read:{}'.format(line.strip()))
def test_garbage_collection(self): log_file = self.get_resource('crashplan_backup_files.log') new_file = u'foo.txt' newer_file = u'/my/crashplan/backups/vms/finn/finn-2018-08-15_00-09-00/finn-5-s004.vmdk' older_file = u'/my/crashplan/backups/vms/gabarolas/gabarolas-2018-08-02_16-07-17/gabarolas-s067.vmdk' with CrashPlanFS(log_file=log_file.strpath) as fs: assert not fs.exists(new_file) assert fs.exists(newer_file) assert fs.exists(older_file) older_file_remote_mtime = fs.getdetails(older_file).modified # Create a mock transfer area from fs.memoryfs import MemoryFS transfer_area = MemoryFS() # Populate the transfer area transfer_area.appendtext(new_file, u'This file is new') transfer_area.makedirs(os.path.split(newer_file)[0]) transfer_area.appendtext(newer_file, u'This file has been modified locally') transfer_area.makedirs(os.path.split(older_file)[0]) transfer_area.appendtext(older_file, u'This file is up-to-date') transfer_area.settimes(older_file, modified=older_file_remote_mtime) assert transfer_area.getdetails( older_file).modified <= older_file_remote_mtime # Pass the transfer area to crashplanfs fs = CrashPlanFS(log_file=log_file.strpath, transfer_area=transfer_area) # The new file should not be listed, as it only exists in the transfer area assert not fs.exists(new_file) # The newer file should be listed, with the remote modification time assert fs.exists(newer_file) assert transfer_area.getdetails(new_file).modified > fs.getdetails( newer_file).modified # The older file should be deleted from the transfer area assert not transfer_area.exists(older_file)
path = relpath(normpath(path)) path = path.replace("__colon__", ":") if not self.allow_autorun: if path.lower().startswith("autorun."): path = "_" + path return path if __name__ == "__main__": import os.path import tempfile from fs.osfs import OSFS from fs.memoryfs import MemoryFS from shutil import rmtree from six import b path = tempfile.mkdtemp() try: #fs = OSFS(path) fs = MemoryFS() fs.create('test.txt') fs.appendtext('test.txt', 'this is a test', encoding=u'utf-8', errors=None, newline=u'') flags = DOKAN_OPTION_DEBUG | DOKAN_OPTION_STDERR | DOKAN_OPTION_REMOVABLE mount(fs, "Q:\\", foreground=True, numthreads=1, flags=flags) fs.close() finally: rmtree(path)
import dokanmount import os.path import tempfile from fs.osfs import OSFS from fs.memoryfs import MemoryFS from shutil import rmtree from six import b path = tempfile.mkdtemp() try: #fs = OSFS(path) fs = MemoryFS() fs.create('test.txt') fs.appendtext('test.txt', 'This is a test file', encoding=u'utf-8', errors=None, newline=u'') fs.makedir("TestDir") fs.create('TestDir/subtest.txt') fs.appendtext('TestDir/subtest.txt', 'This is a test file in a subfolder', encoding=u'utf-8', errors=None, newline=u'') flags = dokanmount.DOKAN_OPTION_DEBUG | dokanmount.DOKAN_OPTION_STDERR | dokanmount.DOKAN_OPTION_REMOVABLE a = dokanmount.mount(fs, "Q:\\", foreground=True, numthreads=2, flags=flags) #fs.close()
import dokanmount import os.path import tempfile from fs.osfs import OSFS from fs.memoryfs import MemoryFS from shutil import rmtree from six import b fs = MemoryFS() fs.create('test.txt') fs.appendtext('test.txt', 'This is a test file', encoding=u'utf-8', errors=None, newline=u'') fs.makedir("TestDir") fs.create('TestDir/subtest.txt') fs.appendtext('TestDir/subtest.txt', 'This is a test file in a subfolder', encoding=u'utf-8', errors=None, newline=u'') #flags = dokanmount.DOKAN_OPTION_DEBUG | dokanmount.DOKAN_OPTION_STDERR | dokanmount.DOKAN_OPTION_REMOVABLE flags = dokanmount.DOKAN_OPTION_REMOVABLE dm = dokanmount.mount(fs, "Q:\\", foreground=False, numthreads=2, flags=flags) print("Memory FS is now mounted!") input("Press any key to create file...") fs.create('PostMountCreatedFile.txt') fs.appendtext('PostMountCreatedFile.txt', 'This is a file was populated after Dokan mounted', encoding=u'utf-8',