mirror of
https://github.com/YunoHost/package_linter.git
synced 2024-09-03 20:06:12 +02:00
Merge pull request #39 from Jibec/dependencies_consistency
Add dependencies consistency check
This commit is contained in:
commit
d37eaae1e2
1 changed files with 51 additions and 0 deletions
|
@ -30,6 +30,8 @@ def header(app_path):
|
|||
"YUNOHOST APP PACKAGE LINTER\n", c.END,
|
||||
"App packaging documentation: https://yunohost.org/#/packaging_apps\n",
|
||||
"App package example: https://github.com/YunoHost/example_ynh\n",
|
||||
"Official helpers: https://yunohost.org/#/packaging_apps_helpers_en\n",
|
||||
"Experimental helpers: https://github.com/YunoHost-Apps/Experimental_helpers\n"
|
||||
"Checking " + c.BOLD + app_path + c.END + " package\n")
|
||||
|
||||
|
||||
|
@ -253,6 +255,9 @@ def check_script(path, script_name, script_nbr):
|
|||
if script_nbr < 5:
|
||||
check_verifications_done_before_modifying_system(read_file(script_path))
|
||||
check_set_usage(script_name, read_file(script_path))
|
||||
check_helper_usage_dependencies(script_path, script_name)
|
||||
check_helper_usage_unix(script_path, script_name)
|
||||
check_helper_consistency(script_path, script_name)
|
||||
#check_arg_retrieval(script.copy())
|
||||
|
||||
|
||||
|
@ -354,6 +359,52 @@ def check_arg_retrieval(script):
|
|||
print_wrong("Argument retrieval from manifest with $1 is deprecated. You may use $YNH_APP_ARG_*")
|
||||
print_wrong("For more details see: https://yunohost.org/#/packaging_apps_arguments_management_en")
|
||||
|
||||
def check_helper_usage_dependencies(path, script_name):
|
||||
"""
|
||||
Detect usage of ynh_package_* & apt-get *
|
||||
and suggest herlpers ynh_install_app_dependencies and ynh_remove_app_dependencies
|
||||
"""
|
||||
script = read_file(path)
|
||||
|
||||
if "ynh_package_install" in script or "apt-get install" in script:
|
||||
print_warning("You should not use `ynh_package_install` or `apt-get install`, use `ynh_install_app_dependencies` instead")
|
||||
|
||||
if "ynh_package_remove" in script or "apt-get remove" in script:
|
||||
print_warning("You should not use `ynh_package_remove` or `apt-get removeè, use `ynh_remove_app_dependencies` instead")
|
||||
|
||||
def check_helper_usage_unix(path, script_name):
|
||||
"""
|
||||
Detect usage of unix commands with helper equivalents:
|
||||
- sudo → ynh_exec_as
|
||||
- rm → ynh_secure_remove
|
||||
- sed -i → ynh_replace_string
|
||||
"""
|
||||
script = read_file(path)
|
||||
|
||||
if "rm -rf" in script or "rm -Rf" in script:
|
||||
print_wrong("[YEP-2.12] You should avoid using `rm -rf`, please use `ynh_secure_remove` instead")
|
||||
|
||||
if "sed -i" in script:
|
||||
print_warning("[YEP-2.12] You should avoid using `sed -i`, please use `ynh_replace_string` instead")
|
||||
|
||||
if "sudo " in script:
|
||||
print_warning("[YEP-2.12] You should not need to use `sudo`, the script is being run as root. (If you need to run a command using a specific user, use `ynh_exec_as`)")
|
||||
|
||||
def check_helper_consistency(path, script_name):
|
||||
"""
|
||||
check if ynh_install_app_dependencies is present in install/upgrade/restore
|
||||
so dependencies are up to date after restoration or upgrade
|
||||
"""
|
||||
script = read_file(path)
|
||||
|
||||
if script_name == "install" and "ynh_install_app_dependencies" in script:
|
||||
for name in ["upgrade", "restore"]:
|
||||
try:
|
||||
script2 = read_file(os.path.dirname(path) + "/" + name)
|
||||
if not "ynh_install_app_dependencies" in script2:
|
||||
print_warning("ynh_install_app_dependencies should also be in %s script" % name)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) != 2:
|
||||
|
|
Loading…
Reference in a new issue