(config, gtk_proc, opencv)
| 35 | self.gtk_proc.stdin.flush() |
| 36 | |
| 37 | def execute(config, gtk_proc, opencv): |
| 38 | verbose = config.getboolean("debug", "verbose_stamps", fallback=False) |
| 39 | dir_path = os.path.dirname(os.path.realpath(__file__)) |
| 40 | installed_stamps = [] |
| 41 | |
| 42 | # Go through each file in the rubberstamp folder |
| 43 | for filename in os.listdir(dir_path): |
| 44 | # Remove non-readable file or directories |
| 45 | if not os.path.isfile(dir_path + "/" + filename): |
| 46 | continue |
| 47 | |
| 48 | # Remove meta files |
| 49 | if filename in ["__init__.py", ".gitignore"]: |
| 50 | continue |
| 51 | |
| 52 | # Add the found file to the list of enabled rubberstamps |
| 53 | installed_stamps.append(filename.split(".")[0]) |
| 54 | |
| 55 | if verbose: print("Installed rubberstamps: " + ", ".join(installed_stamps)) |
| 56 | |
| 57 | # Get the rules defined in the config |
| 58 | raw_rules = config.get("rubberstamps", "stamp_rules") |
| 59 | rules = raw_rules.split("\n") |
| 60 | |
| 61 | # Go through the rules one by one |
| 62 | for rule in rules: |
| 63 | rule = rule.strip() |
| 64 | |
| 65 | if len(rule) <= 1: |
| 66 | continue |
| 67 | |
| 68 | # Parse the rule with regex |
| 69 | regex_result = re.search("^(\w+)\s+([\w\.]+)\s+([a-z]+)(.*)?$", rule, re.IGNORECASE) |
| 70 | |
| 71 | # Error out if the regex did not match (invalid line) |
| 72 | if not regex_result: |
| 73 | print(_("Error parsing rubberstamp rule: {}").format(rule)) |
| 74 | continue |
| 75 | |
| 76 | type = regex_result.group(1) |
| 77 | |
| 78 | # Error out if the stamp name in the rule is not a file |
| 79 | if type not in installed_stamps: |
| 80 | print(_("Stamp not installed: {}").format(type)) |
| 81 | continue |
| 82 | |
| 83 | # Load the module from file |
| 84 | module = SourceFileLoader(type, dir_path + "/" + type + ".py").load_module() |
| 85 | |
| 86 | # Try to get the class with the same name |
| 87 | try: |
| 88 | constructor = getattr(module, type) |
| 89 | except AttributeError: |
| 90 | print(_("Stamp error: Class {} not found").format(type)) |
| 91 | continue |
| 92 | |
| 93 | # Init the class and set common values |
| 94 | instance = constructor() |
nothing calls this directly
no test coverage detected
searching dependent graphs…