本文整理汇总了Python中util.prepare_filetree函数的典型用法代码示例。如果您正苦于以下问题:Python prepare_filetree函数的具体用法?Python prepare_filetree怎么用?Python prepare_filetree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了prepare_filetree函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:liangqing,项目名称:syncrypto,代码行数:30,代码来源:test_cli.py
示例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!")
开发者ID:liangqing,项目名称:syncrypto,代码行数:30,代码来源:test_cli.py
示例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()
开发者ID:liangqing,项目名称:syncrypto,代码行数:8,代码来源:test_cli.py
示例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()
开发者ID:liangqing,项目名称:syncrypto,代码行数:9,代码来源:test_cli.py
示例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()
开发者ID:liangqing,项目名称:syncrypto,代码行数:10,代码来源:test_cli.py
示例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)
开发者ID:liangqing,项目名称:syncrypto,代码行数:10,代码来源:test_cli.py
示例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()
开发者ID:liangqing,项目名称:syncrypto,代码行数:12,代码来源:test_cli.py
示例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()
开发者ID:liangqing,项目名称:syncrypto,代码行数:12,代码来源:test_cli.py
示例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()
开发者ID:liangqing,项目名称:syncrypto,代码行数:13,代码来源:test_cli.py
示例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)
开发者ID:malongge,项目名称:syncrypto,代码行数:14,代码来源:test_filetree.py
示例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()
开发者ID:liangqing,项目名称:syncrypto,代码行数:16,代码来源:test_cli.py
示例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()
开发者ID:liangqing,项目名称:syncrypto,代码行数:16,代码来源:test_cli.py
示例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, [])
开发者ID:pmphxs,项目名称:syncrypto,代码行数:17,代码来源:test_cli.py
示例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()
开发者ID:pmphxs,项目名称:syncrypto,代码行数:17,代码来源:test_sync.py
示例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)
开发者ID:malongge,项目名称:syncrypto,代码行数:18,代码来源:test_filetree.py
示例16: test_conflict_after_syncing
def test_conflict_after_syncing(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
files.txt: text file
folder/no_extension: no extension file
folder/no_conflict1:1
''')
self.check_result_after_sync()
self.modify_file(self.plain_folder, "files.txt", "modified")
self.modify_file(self.plain_folder_check, "files.txt", "modified 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"])
开发者ID:liangqing,项目名称:syncrypto,代码行数:18,代码来源:test_cli.py
示例17: test_rule_set
def test_rule_set(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
filename_sync: 1
filename_not_sync: 2
filename_not_sync_encrypted: 3
''')
self.cli(["--password-file", self.password_file,
"--rule",
"exclude: name match *_not_sync",
self.encrypted_folder, self.plain_folder])
self.cli(["--password-file", self.password_file,
"--rule",
"exclude: name match *_encrypted",
self.encrypted_folder, self.plain_folder_check])
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)
开发者ID:liangqing,项目名称:syncrypto,代码行数:20,代码来源:test_cli.py
示例18: test_encrypt_file_given_out_file
def test_encrypt_file_given_out_file(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
test_simple_file: hello
''')
self.cli(["--password-file", self.password_file, "--encrypt-file",
os.path.join(self.plain_folder, "test_simple_file")])
self.assertTrue(os.path.exists(
os.path.join(self.plain_folder, "test_simple_file.encrypted")))
self.cli([
"--password-file", self.password_file,
"--decrypt-file",
os.path.join(self.plain_folder, "test_simple_file.encrypted"),
"--out-file",
os.path.join(self.plain_folder, "test_simple_file_decrypted")
])
self.assertTrue(
file_cmp(
os.path.join(self.plain_folder, "test_simple_file_decrypted"),
os.path.join(self.plain_folder, "test_simple_file"), False))
开发者ID:liangqing,项目名称:syncrypto,代码行数:20,代码来源:test_cli.py
示例19: test_decrypt_file_no_out_file
def test_decrypt_file_no_out_file(self):
self.clear_folders()
prepare_filetree(self.plain_folder, '''
test_simple_file: hello
''')
self.cli(["--password-file", self.password_file, self.encrypted_folder,
self.plain_folder])
encrypted_path = None
for name in os.listdir(self.encrypted_folder):
if name.startswith(".") or name.startswith('_'):
continue
encrypted_path = name
self.assertFalse(encrypted_path is None)
origin = os.getcwd()
os.chdir(self.plain_folder_check)
self.cli(["--password-file", self.password_file, "--decrypt-file",
os.path.join(self.encrypted_folder, encrypted_path)])
self.assertTrue(os.path.exists("test_simple_file"))
with open("test_simple_file") as f:
self.assertEqual(f.read(), "hello")
os.chdir(origin)
开发者ID:liangqing,项目名称:syncrypto,代码行数:21,代码来源:test_cli.py
注:本文中的util.prepare_filetree函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论