|
|
|
@ -12,7 +12,7 @@ from catcli.catcli import cmd_index, cmd_update
|
|
|
|
|
from catcli.noder import Noder
|
|
|
|
|
from catcli.catalog import Catalog
|
|
|
|
|
from tests.helpers import create_dir, create_rnd_file, get_tempdir, \
|
|
|
|
|
clean, unix_tree, edit_file, read_from_file
|
|
|
|
|
clean, unix_tree, edit_file, read_from_file, md5sum
|
|
|
|
|
import anytree
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -31,6 +31,7 @@ class TestIndexing(unittest.TestCase):
|
|
|
|
|
f1 = create_rnd_file(dirpath, 'file1')
|
|
|
|
|
f2 = create_rnd_file(dirpath, 'file2')
|
|
|
|
|
f3 = create_rnd_file(dirpath, 'file3')
|
|
|
|
|
f4 = create_rnd_file(dirpath, 'file4')
|
|
|
|
|
|
|
|
|
|
# create 2 directories
|
|
|
|
|
d1 = create_dir(dirpath, 'dir1')
|
|
|
|
@ -40,22 +41,40 @@ class TestIndexing(unittest.TestCase):
|
|
|
|
|
d1f1 = create_rnd_file(d1, 'dir1file1')
|
|
|
|
|
d1f2 = create_rnd_file(d1, 'dir1file2')
|
|
|
|
|
d2f1 = create_rnd_file(d2, 'dir2file1')
|
|
|
|
|
d2f2 = create_rnd_file(d2, 'dir2file2')
|
|
|
|
|
|
|
|
|
|
noder = Noder()
|
|
|
|
|
noder = Noder(debug=True)
|
|
|
|
|
noder.set_hashing(True)
|
|
|
|
|
top = noder.new_top_node()
|
|
|
|
|
catalog = Catalog(catalogpath, force=True, verbose=False)
|
|
|
|
|
catalog = Catalog(catalogpath, force=True, debug=False)
|
|
|
|
|
|
|
|
|
|
# get checksums
|
|
|
|
|
f4_md5 = md5sum(f4)
|
|
|
|
|
self.assertTrue(f4_md5)
|
|
|
|
|
d1f1_md5 = md5sum(d1f1)
|
|
|
|
|
self.assertTrue(d1f1_md5)
|
|
|
|
|
d2f2_md5 = md5sum(d2f2)
|
|
|
|
|
self.assertTrue(d2f2_md5)
|
|
|
|
|
|
|
|
|
|
# create fake args
|
|
|
|
|
tmpdirname = 'tmpdir'
|
|
|
|
|
args = {'<path>': dirpath, '<name>': tmpdirname,
|
|
|
|
|
'--hash': True, '--meta': ['some meta'],
|
|
|
|
|
'--no-subsize': False, '--verbose': True}
|
|
|
|
|
'--no-subsize': False, '--verbose': True,
|
|
|
|
|
'--lpath': None}
|
|
|
|
|
|
|
|
|
|
# index the directory
|
|
|
|
|
unix_tree(dirpath)
|
|
|
|
|
cmd_index(args, noder, catalog, top, debug=True)
|
|
|
|
|
cmd_index(args, noder, catalog, top)
|
|
|
|
|
self.assertTrue(os.stat(catalogpath).st_size != 0)
|
|
|
|
|
|
|
|
|
|
# ensure md5 sum are in
|
|
|
|
|
nods = noder.find_name(top, os.path.basename(f4))
|
|
|
|
|
self.assertTrue(len(nods) == 1)
|
|
|
|
|
nod = nods[0]
|
|
|
|
|
self.assertTrue(nod)
|
|
|
|
|
self.assertTrue(nod.md5 == f4_md5)
|
|
|
|
|
|
|
|
|
|
# print catalog
|
|
|
|
|
noder.print_tree(top)
|
|
|
|
|
|
|
|
|
@ -70,9 +89,32 @@ class TestIndexing(unittest.TestCase):
|
|
|
|
|
# modify files
|
|
|
|
|
EDIT = 'edited'
|
|
|
|
|
edit_file(d1f1, EDIT)
|
|
|
|
|
d1f1_md5_new = md5sum(d1f1)
|
|
|
|
|
self.assertTrue(d1f1_md5_new)
|
|
|
|
|
self.assertTrue(d1f1_md5_new != d1f1_md5)
|
|
|
|
|
|
|
|
|
|
# change file without mtime
|
|
|
|
|
maccess = os.path.getmtime(f4)
|
|
|
|
|
EDIT = 'edited'
|
|
|
|
|
edit_file(f4, EDIT)
|
|
|
|
|
# reset edit time
|
|
|
|
|
os.utime(f4, (maccess, maccess))
|
|
|
|
|
f4_md5_new = md5sum(d1f1)
|
|
|
|
|
self.assertTrue(f4_md5_new)
|
|
|
|
|
self.assertTrue(f4_md5_new != f4_md5)
|
|
|
|
|
|
|
|
|
|
# change file without mtime
|
|
|
|
|
maccess = os.path.getmtime(d2f2)
|
|
|
|
|
EDIT = 'edited'
|
|
|
|
|
edit_file(d2f2, EDIT)
|
|
|
|
|
# reset edit time
|
|
|
|
|
os.utime(d2f2, (maccess, maccess))
|
|
|
|
|
d2f2_md5_new = md5sum(d2f2)
|
|
|
|
|
self.assertTrue(d2f2_md5_new)
|
|
|
|
|
self.assertTrue(d2f2_md5_new != d2f2_md5)
|
|
|
|
|
|
|
|
|
|
# update storage
|
|
|
|
|
cmd_update(args, noder, catalog, top, debug=True)
|
|
|
|
|
cmd_update(args, noder, catalog, top)
|
|
|
|
|
|
|
|
|
|
# print catalog
|
|
|
|
|
# print(read_from_file(catalogpath))
|
|
|
|
@ -81,7 +123,31 @@ class TestIndexing(unittest.TestCase):
|
|
|
|
|
# explore the top node to find all nodes
|
|
|
|
|
self.assertTrue(len(top.children) == 1)
|
|
|
|
|
storage = top.children[0]
|
|
|
|
|
self.assertTrue(len(storage.children) == 7)
|
|
|
|
|
self.assertTrue(len(storage.children) == 8)
|
|
|
|
|
|
|
|
|
|
# ensure d1f1 md5 sum has changed in catalog
|
|
|
|
|
nods = noder.find_name(top, os.path.basename(d1f1))
|
|
|
|
|
self.assertTrue(len(nods) == 1)
|
|
|
|
|
nod = nods[0]
|
|
|
|
|
self.assertTrue(nod)
|
|
|
|
|
self.assertTrue(nod.md5 != d1f1_md5)
|
|
|
|
|
self.assertTrue(nod.md5 == d1f1_md5_new)
|
|
|
|
|
|
|
|
|
|
# ensure f4 md5 sum has changed in catalog
|
|
|
|
|
nods = noder.find_name(top, os.path.basename(f4))
|
|
|
|
|
self.assertTrue(len(nods) == 1)
|
|
|
|
|
nod = nods[0]
|
|
|
|
|
self.assertTrue(nod)
|
|
|
|
|
self.assertTrue(nod.md5 != f4_md5)
|
|
|
|
|
self.assertTrue(nod.md5 == f4_md5_new)
|
|
|
|
|
|
|
|
|
|
# ensure d2f2 md5 sum has changed in catalog
|
|
|
|
|
nods = noder.find_name(top, os.path.basename(d2f2))
|
|
|
|
|
self.assertTrue(len(nods) == 1)
|
|
|
|
|
nod = nods[0]
|
|
|
|
|
self.assertTrue(nod)
|
|
|
|
|
self.assertTrue(nod.md5 != d2f2_md5)
|
|
|
|
|
self.assertTrue(nod.md5 == d2f2_md5_new)
|
|
|
|
|
|
|
|
|
|
# ensures files and directories are in
|
|
|
|
|
names = [node.name for node in anytree.PreOrderIter(storage)]
|
|
|
|
@ -89,6 +155,7 @@ class TestIndexing(unittest.TestCase):
|
|
|
|
|
self.assertTrue(os.path.basename(f1) in names)
|
|
|
|
|
self.assertTrue(os.path.basename(f2) in names)
|
|
|
|
|
self.assertTrue(os.path.basename(f3) in names)
|
|
|
|
|
self.assertTrue(os.path.basename(f4) in names)
|
|
|
|
|
self.assertTrue(os.path.basename(d1) in names)
|
|
|
|
|
self.assertTrue(os.path.basename(d1f1) in names)
|
|
|
|
|
self.assertTrue(os.path.basename(d1f2) in names)
|
|
|
|
@ -104,7 +171,7 @@ class TestIndexing(unittest.TestCase):
|
|
|
|
|
if node.name == os.path.basename(d1):
|
|
|
|
|
self.assertTrue(len(node.children) == 3)
|
|
|
|
|
elif node.name == os.path.basename(d2):
|
|
|
|
|
self.assertTrue(len(node.children) == 2)
|
|
|
|
|
self.assertTrue(len(node.children) == 3)
|
|
|
|
|
elif node.name == os.path.basename(new3):
|
|
|
|
|
self.assertTrue(len(node.children) == 0)
|
|
|
|
|
elif node.name == os.path.basename(new4):
|
|
|
|
@ -118,7 +185,7 @@ class TestIndexing(unittest.TestCase):
|
|
|
|
|
clean(new4)
|
|
|
|
|
|
|
|
|
|
# update storage
|
|
|
|
|
cmd_update(args, noder, catalog, top, debug=True)
|
|
|
|
|
cmd_update(args, noder, catalog, top)
|
|
|
|
|
|
|
|
|
|
# ensures files and directories are (not) in
|
|
|
|
|
names = [node.name for node in anytree.PreOrderIter(storage)]
|
|
|
|
@ -126,11 +193,13 @@ class TestIndexing(unittest.TestCase):
|
|
|
|
|
self.assertTrue(os.path.basename(f1) in names)
|
|
|
|
|
self.assertTrue(os.path.basename(f2) in names)
|
|
|
|
|
self.assertTrue(os.path.basename(f3) in names)
|
|
|
|
|
self.assertTrue(os.path.basename(f4) in names)
|
|
|
|
|
self.assertTrue(os.path.basename(d1) in names)
|
|
|
|
|
self.assertTrue(os.path.basename(d1f1) not in names)
|
|
|
|
|
self.assertTrue(os.path.basename(d1f2) in names)
|
|
|
|
|
self.assertTrue(os.path.basename(d2) not in names)
|
|
|
|
|
self.assertTrue(os.path.basename(d2f1) not in names)
|
|
|
|
|
self.assertTrue(os.path.basename(d2f1) not in names)
|
|
|
|
|
self.assertTrue(os.path.basename(new1) in names)
|
|
|
|
|
self.assertTrue(os.path.basename(new2) not in names)
|
|
|
|
|
self.assertTrue(os.path.basename(new3) in names)
|
|
|
|
|