From 4af351d1448e974e46c5ef8bbce014545a8325e7 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sat, 28 Mar 2020 15:14:23 +0100 Subject: [PATCH] doc --- catcli/catcli.py | 8 ++++---- catcli/noder.py | 10 +++++++++- catcli/walker.py | 20 +++++++++++++------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/catcli/catcli.py b/catcli/catcli.py index c8fe56c..7aa6a98 100755 --- a/catcli/catcli.py +++ b/catcli/catcli.py @@ -71,7 +71,7 @@ Options: def cmd_index(args, noder, catalog, top, debug=False): path = args[''] name = args[''] - nohash = not args['--hash'] + hash = args['--hash'] subsize = not args['--no-subsize'] if not os.path.exists(path): Logger.err('\"{}\" does not exist'.format(path)) @@ -87,7 +87,7 @@ def cmd_index(args, noder, catalog, top, debug=False): node = noder.get_storage_node(top, name) node.parent = None start = datetime.datetime.now() - walker = Walker(noder, nohash=nohash, debug=debug) + walker = Walker(noder, hash=hash, debug=debug) attr = noder.format_storage_attr(args['--meta']) root = noder.storage_node(name, path, parent=top, attr=attr) _, cnt = walker.index(path, root, name) @@ -102,7 +102,7 @@ def cmd_index(args, noder, catalog, top, debug=False): def cmd_update(args, noder, catalog, top, debug=False): path = args[''] name = args[''] - nohash = not args['--hash'] + hash = args['--hash'] subsize = not args['--no-subsize'] if not os.path.exists(path): Logger.err('\"{}\" does not exist'.format(path)) @@ -112,7 +112,7 @@ def cmd_update(args, noder, catalog, top, debug=False): Logger.err('storage named \"{}\" does not exist'.format(name)) return start = datetime.datetime.now() - walker = Walker(noder, nohash=nohash, debug=debug) + walker = Walker(noder, hash=hash, debug=debug) cnt = walker.reindex(path, root, top) if subsize: noder.rec_size(root) diff --git a/catcli/noder.py b/catcli/noder.py index e931682..5677c7a 100644 --- a/catcli/noder.py +++ b/catcli/noder.py @@ -37,6 +37,11 @@ class Noder: TYPE_META = 'meta' def __init__(self, debug=False, sortsize=False, arc=False): + ''' + @debug: debug mode + @sortsize: sort nodes by size + @arch: handle archive + ''' self.hash = True self.debug = debug self.sortsize = sortsize @@ -222,6 +227,7 @@ class Noder: return cnt def flag(self, node): + '''flag a node''' node.flag = True def _clean(self, node): @@ -416,7 +422,7 @@ class Noder: return found ############################################################### - # tree creationg + # tree creation ############################################################### def _add_entry(self, name, top, resolv): '''add an entry to the tree''' @@ -449,6 +455,7 @@ class Noder: return sorted(items, key=self._sort, reverse=self.sortsize) def _sort(self, x): + '''sort a list''' if self.sortsize: return self._sort_size(x) return self._sort_fs(x) @@ -487,6 +494,7 @@ class Noder: return utils.md5sum(path) def _debug(self, string): + '''print debug''' if not self.debug: return Logger.debug(string) diff --git a/catcli/walker.py b/catcli/walker.py index df738a9..45f0bad 100644 --- a/catcli/walker.py +++ b/catcli/walker.py @@ -15,10 +15,15 @@ class Walker: MAXLINE = 80 - 15 - def __init__(self, noder, nohash=False, debug=False): + def __init__(self, noder, hash=True, debug=False): + ''' + @noder: the noder to use + @hash: calculate hash of nodes + @debug: debug mode + ''' self.noder = noder - self.nohash = nohash - self.noder.set_hashing(not self.nohash) + self.hash = hash + self.noder.set_hashing(self.hash) self.debug = debug def index(self, path, parent, name, storagepath=''): @@ -32,7 +37,7 @@ class Walker: for f in files: self._debug('found file {} under {}'.format(f, path)) sub = os.path.join(root, f) - self._log(f) + self._progress(f) self._debug('index file {}'.format(sub)) self.noder.file_node(os.path.basename(f), sub, parent, storagepath) @@ -50,7 +55,7 @@ class Walker: _, cnt2 = self.index(sub, dummy, base, nstoragepath) cnt += cnt2 break - self._log(None) + self._progress(None) return parent, cnt def reindex(self, path, parent, top): @@ -101,7 +106,6 @@ class Walker: cnt2 = self._reindex(sub, dummy, top, nstoragepath) cnt += cnt2 break - self._log(None) return cnt def _need_reindex(self, top, path, treepath): @@ -127,11 +131,13 @@ class Walker: return True, cnode def _debug(self, string): + '''print to debug''' if not self.debug: return Logger.debug(string) - def _log(self, string): + def _progress(self, string): + '''print progress''' if self.debug: return if not string: