Rework check_source_common

This commit is contained in:
Alexandre Aubin 2019-03-09 17:39:00 +01:00
parent 46e6439233
commit ecb7483694

View file

@ -519,24 +519,10 @@ class Script():
) )
def check_source_common(self): def check_source_common(self):
#test for standard execution
if script["name"] in ["install","upgrade","remove"]:
count_common=len(re.findall("^source _common.sh|^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 if self.name in ["backup", "restore"]:
else: if self.contains("source _common.sh") or self.contains("source ./_common.sh"):
count_common=len(re.findall("^source _common.sh|^source ./_common.sh",script["raw"],flags=re.MULTILINE)) print_error("In the context of backup and restore script, you should load _common.sh with \"source ../settings/scripts/_common.sh\"")
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(): def main():