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

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

Loading…
Cancel
Save