fix re-indexing and refactor debug output

pull/19/head
deadc0de6 4 years ago
parent 99d29c272f
commit 6e4c3784fb

@ -59,12 +59,14 @@ class Noder:
def get_node(self, top, path, quiet=False): def get_node(self, top, path, quiet=False):
'''get the node by internal tree path''' '''get the node by internal tree path'''
print(path)
r = anytree.resolver.Resolver('name') r = anytree.resolver.Resolver('name')
try: try:
return r.get(top, path) p = os.path.basename(path)
return r.get(top, p)
except anytree.resolver.ChildResolverError: except anytree.resolver.ChildResolverError:
if not quiet: if not quiet:
Logger.err('No node at path \"{}\"'.format(path)) Logger.err('No node at path \"{}\"'.format(p))
return None return None
def get_node_if_changed(self, top, path, treepath): def get_node_if_changed(self, top, path, treepath):
@ -78,26 +80,26 @@ class Noder:
node = self.get_node(top, treepath, quiet=True) node = self.get_node(top, treepath, quiet=True)
# node does not exist # node does not exist
if not node: if not node:
self._debug('change: node does not exist') self._debug('\tchange: node does not exist')
return None, True return None, True
# force re-indexing if no maccess # force re-indexing if no maccess
maccess = os.path.getmtime(path) maccess = os.path.getmtime(path)
if not self._has_attr(node, 'maccess') or \ if not self._has_attr(node, 'maccess') or \
not node.maccess: not node.maccess:
self._debug('change: no maccess found') self._debug('\tchange: no maccess found')
return node, True return node, True
# maccess changed # maccess changed
old_maccess = node.maccess old_maccess = node.maccess
if float(maccess) != float(old_maccess): if float(maccess) != float(old_maccess):
self._debug('change: maccess changed for \"{}\"'.format(path)) self._debug('\tchange: maccess changed for \"{}\"'.format(path))
return node, True return node, True
# test hash # test hash
if self.hash and node.md5: if self.hash and node.md5:
md5 = self._get_hash(path) md5 = self._get_hash(path)
if md5 != node.md5: if md5 != node.md5:
self._debug('change: checksum changed for \"{}\"'.format(path)) self._debug('\tchange: checksum changed for \"{}\"'.format(path))
return node, True return node, True
self._debug('change: no change for \"{}\"'.format(path)) self._debug('\tchange: no change for \"{}\"'.format(path))
return node, False return node, False
def get_meta_node(self, top): def get_meta_node(self, top):

@ -75,7 +75,7 @@ class Walker:
treepath = os.path.join(storagepath, f) treepath = os.path.join(storagepath, f)
reindex, n = self._need_reindex(parent, sub, treepath) reindex, n = self._need_reindex(parent, sub, treepath)
if not reindex: if not reindex:
self._debug('\tignore file {}'.format(sub)) self._debug('\tskip file {}'.format(sub))
self.noder.flag(n) self.noder.flag(n)
continue continue
self._debug('\tre-index file {}'.format(sub)) self._debug('\tre-index file {}'.format(sub))
@ -114,18 +114,18 @@ class Walker:
''' '''
cnode, changed = self.noder.get_node_if_changed(top, path, treepath) cnode, changed = self.noder.get_node_if_changed(top, path, treepath)
if not cnode: if not cnode:
self._debug('{} does not exist'.format(path)) self._debug('\t{} does not exist'.format(path))
return True, cnode return True, cnode
if cnode and not changed: if cnode and not changed:
# ignore this node # ignore this node
self._debug('{} has not changed'.format(path)) self._debug('\t{} has not changed'.format(path))
return False, cnode return False, cnode
if cnode and changed: if cnode and changed:
# remove this node and re-add # remove this node and re-add
self._debug('{} has changed'.format(path)) self._debug('\t{} has changed'.format(path))
self._debug('removing node {} for {}'.format(cnode, path)) self._debug('\tremoving node {} for {}'.format(cnode, path))
cnode.parent = None cnode.parent = None
self._debug('{} is to be re-indexed'.format(path)) self._debug('\t{} is to be re-indexed'.format(path))
return True, cnode return True, cnode
def _debug(self, string): def _debug(self, string):

Loading…
Cancel
Save