本文整理汇总了Python中util.prepare_filetree函数的典型用法代码示例。如果您正苦于以下问题:Python prepare_filetree函数的具体用法?Python prepare_filetree怎么用?Python prepare_filetree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了prepare_filetree函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rule_file
def test_rule_file(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
filename_sync: 1
filename_not_sync: 2
filename_not_sync_encrypted: 3
''')
dot_folder = os.path.join(self.plain_folder, ".syncrypto")
dot_folder_check = os.path.join(self.plain_folder_check, ".syncrypto")
if not os.path.exists(dot_folder):
os.mkdir(dot_folder)
if not os.path.exists(dot_folder_check):
os.mkdir(dot_folder_check)
with open(os.path.join(dot_folder, "rules"), 'wb') as f:
f.write(b'exclude: name match *_not_sync')
with open(os.path.join(dot_folder_check, "rules"), 'wb') as f:
f.write(b'exclude: name match *_encrypted')
self.cli(["--password-file", self.password_file,
self.encrypted_folder, self.plain_folder])
self.assertTrue(os.path.exists(
os.path.join(self.encrypted_folder, "_syncrypto", "rules")))
self.cli(["--password-file", self.password_file,
self.encrypted_folder, self.plain_folder_check])
self.assertTrue(file_cmp(os.path.join(dot_folder, "rules"),
os.path.join(dot_folder_check, "rules")))
cmp_result = self.tree_cmp(self.plain_folder, self.plain_folder_check)
self.assertEqual(sorted(cmp_result.left_only),
["filename_not_sync", "filename_not_sync_encrypted"])
self.assertEqual(len(cmp_result.right_only), 0)
self.assertEqual(len(cmp_result.diff_files), 0)
示例2: test_conflict_starting
def test_conflict_starting(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
files.txt: text file
folder/no_extension: no extension file
folder/no_conflict1:1
''')
prepare_filetree(self.plain_folder_check, '''
files.txt: different text file!
folder/no_extension: no extension file!
folder/no_conflict2: 2
''')
self.cli(["--password-file", self.password_file, self.encrypted_folder,
self.plain_folder])
self.cli(["--password-file", self.password_file, self.encrypted_folder,
self.plain_folder_check])
cmp_result = self.tree_cmp(self.plain_folder, self.plain_folder_check)
self.assertEqual(cmp_result.left_only, [])
self.assertEqual(sorted(cmp_result.right_only),
["files.conflict.txt",
"folder/no_conflict2",
"folder/no_extension.conflict"])
self.assertEqual(cmp_result.diff_files, [])
self.assertEqual(open(os.path.join(self.plain_folder_check,
"files.conflict.txt")).read(),
"different text file!")
self.assertEqual(open(
os.path.join(self.plain_folder_check,
"folder/no_extension.conflict")).read(),
"no extension file!")
示例3: test_basic_sync
def test_basic_sync(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
simple_file: hello world
file/in/sub/folder: hello world
empty_dir/
''')
self.check_result_after_sync()
示例4: test_encrypted_file_name
def test_encrypted_file_name(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
normal: hello
normal_folder/file: hello
211: 1
117/hello: 2
''')
self.check_result_after_sync()
示例5: test_delete_file
def test_delete_file(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
delete_me: delete me!
file/in/sub/folder/delete_me: oh, please delete me!
''')
self.check_result_after_sync()
self.delete_file(self.plain_folder, "delete_me")
self.delete_file(self.plain_folder, "file/in/sub/folder/delete_me")
self.check_result_after_sync()
示例6: test_pass_wrong_arguments
def test_pass_wrong_arguments(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
test_simple_file: hello
''')
self.check_result_after_sync()
self.assertNotEqual(syncrypto_cli(["--password-file",
self.password_file,
self.plain_folder,
self.encrypted_folder]), 0)
示例7: test_add_folder
def test_add_folder(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
simple_file: simple file
file/in/sub/folder/simple_file: file in the folder!
empty_dir/
''')
self.check_result_after_sync()
self.add_folder(self.plain_folder, "empty_dir/add_folder")
self.add_folder(self.plain_folder, "folder/with/file")
self.add_file(self.plain_folder, "folder/with/file/test", "test\ntest!")
self.check_result_after_sync()
示例8: test_add_file_in_check_folder
def test_add_file_in_check_folder(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
simple_file: simple file
file/in/sub/folder/simple_file: file in the folder!
empty_dir/
''')
self.check_result_after_sync()
self.add_file(self.plain_folder_check, "add_file", "add file")
self.add_file(self.plain_folder_check, "file/in/sub/folder/add_file",
"add file!")
self.check_result_after_sync_from_check_folder()
示例9: test_modify_file
def test_modify_file(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
keep_same: same file
will_modify: modify the file please
file/in/sub/folder/will_modify: modify the file please!
empty_dir/
''')
self.check_result_after_sync()
self.modify_file(self.plain_folder, "will_modify", "it is modified")
self.modify_file(self.plain_folder, "file/in/sub/folder/will_modify",
"it is modified")
self.check_result_after_sync()
示例10: test_walk_tree_with_rule
def test_walk_tree_with_rule(self):
clear_folder(self.directory_path)
prepare_filetree(self.directory_path, '''
ignore/b/c:1
ignore/bb:2
include/d/e: 3
include/dd: 4
whatever_file: 5
''')
rule_set = FileRuleSet()
rule_set.add_rule_by_string("ignore: name eq ignore")
filetree = FileTree.from_fs(self.directory_path, rule_set=rule_set)
self.assertEqual(len(filetree.files()), 3)
self.assertEqual(len(filetree.folders()), 2)
示例11: test_delete_folder
def test_delete_folder(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
file_reserve: test
folder/reserve: lol
empty_folder1/
empty_folder2/in/sub/folder/
non_empty_folder1/file: test 1
non_empty_folder2/in/sub/folder/file: test 2
''')
self.check_result_after_sync()
self.delete_folder(self.plain_folder, "empty_folder1")
self.delete_folder(self.plain_folder, "empty_folder2/in/sub/folder/")
self.delete_folder(self.plain_folder, "non_empty_folder1")
self.delete_folder(self.plain_folder, "non_empty_folder2/in/sub/folder")
self.check_result_after_sync()
示例12: test_rename_file_in_check_folder
def test_rename_file_in_check_folder(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
keep_same: same file
will_rename: rename
will_rename2: rename
file/in/sub/folder/will_rename: rename
empty_dir/
''')
self.check_result_after_sync()
self.rename(self.plain_folder_check, "will_rename", "renamed")
self.rename(self.plain_folder_check, "file/in/sub/folder/will_rename",
"renamed2")
self.rename(self.plain_folder_check, "will_rename2",
"file/in/sub/folder/renamed2")
self.check_result_after_sync_from_check_folder()
示例13: test_not_ascii_arguments
def test_not_ascii_arguments(self):
plain_folder = mkdtemp("中文")
plain_folder_check = mkdtemp("中文")
encrypted_folder = mkdtemp("中文")
prepare_filetree(plain_folder, '''
文件: 你好
''')
self.cli(["--password-file", self.password_file,
encrypted_folder,
plain_folder])
self.cli(["--password-file", self.password_file,
encrypted_folder,
plain_folder_check])
cmp_result = self.tree_cmp(plain_folder, plain_folder_check)
self.assertEqual(cmp_result.left_only, [])
self.assertEqual(cmp_result.right_only, [])
self.assertEqual(cmp_result.diff_files, [])
示例14: setUp
def setUp(self):
self.crypto = Crypto('password')
self.plain_folder = mkdtemp()
self.plain_folder_check = mkdtemp()
self.encrypted_folder = mkdtemp()
prepare_filetree(self.plain_folder, '''
sync_file_modify:hello world
sync_file_delete:delete
sync/file/modify:hello world
empty_dir_delete/
not_empty_dir/dir2/dir3/file
dir2/file2
''')
self.plain_tree = self.plain_tree = FileTree.from_fs(self.plain_folder)
self.plain_tree_check = FileTree()
self.encrypted_tree = FileTree()
self.snapshot_tree = FileTree()
示例15: test_walk_tree
def test_walk_tree(self):
prepare_filetree(self.directory_path, '''
a
b/
c/d/e/f
1/2
''')
filetree = FileTree.from_fs(self.directory_path)
self.assertEqual(filetree.get('a').isdir, False)
self.assertEqual(filetree.get('b').isdir, True)
self.assertEqual(filetree.get('c').isdir, True)
self.assertEqual(filetree.get('c/d').isdir, True)
self.assertEqual(filetree.get('c/d/e').isdir, True)
self.assertEqual(filetree.get('c/d/e/f').isdir, False)
self.assertEqual(filetree.get('1').isdir, True)
self.assertEqual(filetree.get('1/2').isdir, False)
self.assertEqual(len(filetree.files()), 3)
self.assertEqual(len(filetree.folders()), 5)