refactoring

pull/19/head
deadc0de6 4 years ago
parent c2510924b1
commit 09d86f0902

@ -69,10 +69,11 @@ Options:
""".format(BANNER, NAME, CATALOGPATH)
def cmd_index(args, noder, catalog, top, debug=False):
def cmd_index(args, noder, catalog, top):
path = args['<path>']
name = args['<name>']
hash = args['--hash']
debug = args['--verbose']
subsize = not args['--no-subsize']
if not os.path.exists(path):
Logger.err('\"{}\" does not exist'.format(path))
@ -100,11 +101,12 @@ def cmd_index(args, noder, catalog, top, debug=False):
catalog.save(top)
def cmd_update(args, noder, catalog, top, debug=False):
def cmd_update(args, noder, catalog, top):
path = args['<path>']
name = args['<name>']
hash = args['--hash']
logpath = args['--lpath']
debug = args['--verbose']
subsize = not args['--no-subsize']
if not os.path.exists(path):
Logger.err('\"{}\" does not exist'.format(path))
@ -244,14 +246,14 @@ def main():
top = noder.new_top_node()
# handle the meta node
meta = noder.update_metanode(noder.get_meta_node(top))
meta = noder.update_metanode(top)
catalog.set_metanode(meta)
# parse command
if args['index']:
cmd_index(args, noder, catalog, top, debug=args['--verbose'])
cmd_index(args, noder, catalog, top)
if args['update']:
cmd_update(args, noder, catalog, top, debug=args['--verbose'])
cmd_update(args, noder, catalog, top)
elif args['find']:
cmd_find(args, noder, top)
elif args['tree']:

@ -109,14 +109,6 @@ class Noder:
self._debug('\tchange: no change for \"{}\"'.format(path))
return node, False
def get_meta_node(self, top):
'''return the meta node if any'''
try:
return next(filter(lambda x: x.type == self.TYPE_META,
top.children))
except StopIteration:
return None
def _rec_size(self, node, store=True):
'''
recursively traverse tree and return size
@ -169,8 +161,9 @@ class Noder:
'''create a new top node'''
return anytree.AnyNode(name=self.TOPNAME, type=self.TYPE_TOP)
def update_metanode(self, meta):
def update_metanode(self, top):
'''create or update meta node information'''
meta = self._get_meta_node(top)
epoch = int(time.time())
if not meta:
attr = {}
@ -182,6 +175,14 @@ class Noder:
meta.attr['access_version'] = VERSION
return meta
def _get_meta_node(self, top):
'''return the meta node if any'''
try:
return next(filter(lambda x: x.type == self.TYPE_META,
top.children))
except StopIteration:
return None
def file_node(self, name, path, parent, storagepath):
'''create a new node representing a file'''
if not os.path.exists(path):

@ -65,7 +65,7 @@ class TestIndexing(unittest.TestCase):
# 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
@ -114,7 +114,7 @@ class TestIndexing(unittest.TestCase):
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))
@ -185,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)]

Loading…
Cancel
Save