diff --git a/package_linter.py b/package_linter.py index 2883784..88ad7bc 100755 --- a/package_linter.py +++ b/package_linter.py @@ -402,6 +402,7 @@ class Script(): self.check_set_usage() self.check_helper_usage_dependencies() self.check_deprecated_practices() + self.check_source_common() def check_verifications_done_before_modifying_system(self): """ @@ -518,6 +519,26 @@ class Script(): ) + def check_source_common(self): + #test for standard execution + if script["name"] in ["install","upgrade","remove"]: + count_common=len(re.findall("^source _common.sh",script["raw"],flags=re.MULTILINE)) + if count_common == 0: + print_warning("Calling _common.sh seams not present in this script, please add \"source _common.sh\"") + elif count_common > 1: + print_warning("Duplicates calls to _common.sh, please clean your code") + + #test for "save" files + else: + count_common=len(re.findall("^source _common.sh",script["raw"],flags=re.MULTILINE)) + count_common_save=len(re.findall("^source ../settings/scripts/_common.sh",script["raw"],flags=re.MULTILINE)) + if count_common > 0 and count_common_save == 0: + print_error("You must call _common.sh with \"source ../settings/scripts/_common.sh\" in this script to respect context execution") + elif count_common == 0 and count_common_save == 0: + print_warning("Calling _common.sh seams not present in this script, please add \"source ../settings/scripts/_common.sh\" in this script to respect context execution") + elif count_common_save > 1: + print_warning("Duplicates calls to _common.sh, please clean your code") + def main(): if len(sys.argv) != 2: print("Give one app package path.") @@ -526,6 +547,7 @@ def main(): app_path = sys.argv[1] header(app_path) App(app_path).analyze() + sys.exit(return_code)