From 28911accee7216b34d6a43416c32786c3a924a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Balzarotti?= Date: Mon, 20 Aug 2018 11:27:32 +0200 Subject: [PATCH] first running version --- src/run.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/run.py diff --git a/src/run.py b/src/run.py new file mode 100644 index 0000000..943c06c --- /dev/null +++ b/src/run.py @@ -0,0 +1,30 @@ +import os +import config + + +def scan(path: str, ignore_excluded: bool = False): + path = os.path.expanduser(path) + if config.verbosity > 0: + print("Scanning: " + path) + for root, subdirs, files in os.walk(path): + if (not ignore_excluded) and isexcluded(root): + if config.verbosity > 1: + print("Ignoring: " + root) + continue + if len(files) > config.maxmimum_file_number: + if config.verbosity > 0: + print("Too many " + "(" + str(len(files)) + ")" + + " files in: " + root) + return True + + +def isexcluded(path: str): + dirname = os.path.basename(path) in config.excluded_dir_names + dirnameinside = any(map(lambda x: "/" + x + "/" in path, + config.excluded_dir_names)) + fullname = any(map(lambda l: path.startswith(l), excluded)) + return dirname or fullname or dirnameinside + + +excluded = list(map(os.path.expanduser, config.excluded_dirs)) +list(map(scan, config.watched_dirs))