check_helper_consistency is now an app method instead of script

This commit is contained in:
Alexandre Aubin 2019-03-02 02:24:13 +01:00
parent 1c8bc4abc4
commit 1ccebdbab3

View file

@ -90,12 +90,12 @@ class App():
self.path = path self.path = path
scripts = ["install", "remove", "upgrade", "backup", "restore"] scripts = ["install", "remove", "upgrade", "backup", "restore"]
self.scripts = { f: Script(self.path, f) for f in scripts } self.scripts = {f: Script(self.path, f) for f in scripts}
def analyze(self): def analyze(self):
self.misc_file_checks() self.misc_file_checks()
self.check_helper_consistency()
self.check_source_management() self.check_source_management()
self.check_manifest() self.check_manifest()
@ -103,7 +103,6 @@ class App():
if script.exists: if script.exists:
script.analyze() script.analyze()
def misc_file_checks(self): def misc_file_checks(self):
print_header("MISC FILE CHECKS") print_header("MISC FILE CHECKS")
@ -152,6 +151,25 @@ class App():
"and https://github.com/openresty/headers-more-nginx-module#more_set_headers )" "and https://github.com/openresty/headers-more-nginx-module#more_set_headers )"
) )
def check_helper_consistency(self):
"""
check if ynh_install_app_dependencies is present in install/upgrade/restore
so dependencies are up to date after restoration or upgrade
"""
install_script = self.scripts["install"]
if install_script.exists:
if install_script.contains("ynh_install_app_dependencies"):
for name in ["upgrade", "restore"]:
if self.scripts[name].exists and not self.scripts[name].contains("ynh_install_app_dependencies"):
print_warning("ynh_install_app_dependencies should also be in %s script" % name)
if install_script.contains("yunohost service add"):
if self.scripts["remove"].exists and not self.scripts["remove"].contains("yunohost service remove"):
print_error(
"You used 'yunohost service add' in the install script, "
"but not 'yunohost service remove' in the remove script."
)
def check_source_management(self): def check_source_management(self):
print_header("SOURCES MANAGEMENT") print_header("SOURCES MANAGEMENT")
@ -167,7 +185,6 @@ class App():
"https://github.com/YunoHost/issues/issues/201#issuecomment-391549262" "https://github.com/YunoHost/issues/issues/201#issuecomment-391549262"
) )
def check_manifest(self): def check_manifest(self):
manifest = os.path.join(self.path, 'manifest.json') manifest = os.path.join(self.path, 'manifest.json')
if not os.path.exists(manifest): if not os.path.exists(manifest):
@ -224,7 +241,7 @@ class App():
print_warning("[YEP-1.2] This app is not registered in official or community applications") print_warning("[YEP-1.2] This app is not registered in official or community applications")
# YEP 1.3 License # YEP 1.3 License
def license_mentionned_in_readme(): def license_mentionned_in_readme(path):
readme_path = os.path.join(path, 'README.md') readme_path = os.path.join(path, 'README.md')
if os.path.isfile(readme_path): if os.path.isfile(readme_path):
return "LICENSE" in open(readme_path).read() return "LICENSE" in open(readme_path).read()
@ -368,7 +385,6 @@ class Script():
except Exception as e: except Exception as e:
print_warning("%s : Could not parse this line (%s) : %s" % (self.path, e, line)) print_warning("%s : Could not parse this line (%s) : %s" % (self.path, e, line))
def contains(self, command): def contains(self, command):
""" """
Iterate on lines to check if command is contained in line Iterate on lines to check if command is contained in line
@ -378,17 +394,14 @@ class Script():
return any(command in line return any(command in line
for line in [ ' '.join(line) for line in self.lines]) for line in [ ' '.join(line) for line in self.lines])
def analyze(self): def analyze(self):
print_header(self.name.upper() + " SCRIPT") print_header(self.name.upper() + " SCRIPT")
check_verifications_done_before_modifying_system(self) self.check_verifications_done_before_modifying_system()
check_set_usage(self) self.check_set_usage()
check_helper_usage_dependencies(self) self.check_helper_usage_dependencies()
check_helper_consistency(self) self.check_deprecated_practices()
check_deprecated_practices(self)
def check_verifications_done_before_modifying_system(self): def check_verifications_done_before_modifying_system(self):
""" """
@ -421,7 +434,6 @@ class Script():
) )
return return
def check_set_usage(self): def check_set_usage(self):
present = False present = False
@ -445,7 +457,6 @@ class Script():
"look at https://github.com/YunoHost/issues/issues/419" "look at https://github.com/YunoHost/issues/issues/419"
) )
def check_helper_usage_dependencies(self): def check_helper_usage_dependencies(self):
""" """
Detect usage of ynh_package_* & apt-get * Detect usage of ynh_package_* & apt-get *
@ -464,29 +475,6 @@ class Script():
"use `ynh_remove_app_dependencies` instead" "use `ynh_remove_app_dependencies` instead"
) )
def check_helper_consistency(self):
"""
check if ynh_install_app_dependencies is present in install/upgrade/restore
so dependencies are up to date after restoration or upgrade
"""
if self.name == "install" and self.contains("ynh_install_app_dependencies"):
for name in ["upgrade", "restore"]:
script2 = Script(name, os.path.dirname(self.path))
if script2.exists and not script2.contains("ynh_install_app_dependencies"):
print_warning("ynh_install_app_dependencies should also be in %s script" % name)
if self.name == "install" and script.contains("yunohost service add"):
srcipt2 = Script("remove", os.path.dirname(self.path))
if script2.exists and not script2.contains("yunohost service remove"):
print_error(
"You used 'yunohost service add' in the install script, "
"but not 'yunohost service remove' in the remove script."
)
def check_deprecated_practices(self): def check_deprecated_practices(self):
if self.contains("yunohost app setting"): if self.contains("yunohost app setting"):
@ -529,6 +517,7 @@ class Script():
"You can use 'ynh_print_info' or 'ynh_script_progression' for this." "You can use 'ynh_print_info' or 'ynh_script_progression' for this."
) )
def main(): def main():
if len(sys.argv) != 2: if len(sys.argv) != 2:
print("Give one app package path.") print("Give one app package path.")