From 7402117dbc87bf5f0f611e9ba4e89760f127e1b7 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Sat, 26 May 2018 20:27:24 +0200 Subject: [PATCH 01/10] Add check for dependencies helpers --- package_linter.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/package_linter.py b/package_linter.py index 0bd6277..6878e53 100755 --- a/package_linter.py +++ b/package_linter.py @@ -253,6 +253,7 @@ 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) #check_arg_retrieval(script.copy()) @@ -354,6 +355,25 @@ 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(script_name): + """ + detects usage of ynh_package_* & apt-get * and suggest usage of + ynh_remove_app_dependencies and ynh_remove_app_dependencies + """ + script = open(script_name).read() + + present = False + + present = "ynh_package_install" in script or "apt-get install" in script + + if present: + print_warning("You should not use ynh_package_install or apt-get install, use ynh_install_app_dependencies instead") + + present = False + present = "ynh_package_remove" in script or "apt-get remove" in script + + if present: + print_warning("You should not use ynh_package_remove or apt-get remove, use ynh_remove_app_dependencies instead") if __name__ == '__main__': if len(sys.argv) != 2: From 29ac976ba0d8b55266a26569ed9c052cc496f87e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Sat, 26 May 2018 20:40:27 +0200 Subject: [PATCH 02/10] Add basic unix command detection --- package_linter.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/package_linter.py b/package_linter.py index 6878e53..da3454f 100755 --- a/package_linter.py +++ b/package_linter.py @@ -254,6 +254,7 @@ def check_script(path, script_name, script_nbr): 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) + check_helper_usage_unix(script_path) #check_arg_retrieval(script.copy()) @@ -375,6 +376,21 @@ def check_helper_usage_dependencies(script_name): if present: print_warning("You should not use ynh_package_remove or apt-get remove, use ynh_remove_app_dependencies instead") +def check_helper_usage_unix(script_name): + """ + detects usage of sudo, rm and sed + """ + script = open(script_name).read() + + if "rm -rf" in script: + print_warning("You should not use `rm -rf`, use ynh_secure_remove instead") + + if "sed -i" in script: + print_warning("You should not have to use `sed -i`, use ynh_replace_string or one of the helper") + + if "sudo " in script: + print_warning("You should not have to use `sudo`, the script is run as root") + if __name__ == '__main__': if len(sys.argv) != 2: print("Give one app package path.") From 834ac35b960843a8d4edae752d6adfdca483af73 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Sat, 26 May 2018 20:42:14 +0200 Subject: [PATCH 03/10] Add link to official and experimental helpers --- package_linter.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package_linter.py b/package_linter.py index da3454f..efcb2ec 100755 --- a/package_linter.py +++ b/package_linter.py @@ -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://helpers.yunohost.org\n", + "Experimental helpers: https://github.com/YunoHost-Apps/Experimental_helpers\n" "Checking " + c.BOLD + app_path + c.END + " package\n") From e3f689441e613e962896daf15a7d96297fa9cd55 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Sun, 27 May 2018 11:54:28 +0200 Subject: [PATCH 04/10] Add consistency check for dependencies --- package_linter.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/package_linter.py b/package_linter.py index efcb2ec..27e6cc2 100755 --- a/package_linter.py +++ b/package_linter.py @@ -257,6 +257,7 @@ def check_script(path, script_name, script_nbr): check_set_usage(script_name, read_file(script_path)) check_helper_usage_dependencies(script_path) check_helper_usage_unix(script_path) + check_helper_consistency(path, script_name, script_path) #check_arg_retrieval(script.copy()) @@ -393,6 +394,22 @@ def check_helper_usage_unix(script_name): if "sudo " in script: print_warning("You should not have to use `sudo`, the script is run as root") +def check_helper_consistency(path, script_name, script_path): + """ + check if ynh_install_app_dependencies is present in install/upgrade/restore + so dependencies are up to date after restoration or upgrade + """ + script = open(script_path).read() + + if script_name == "install" and "ynh_install_app_dependencies" in script: + for name in ["upgrade", "restore"]: + try: + script2 = open(path + "/scripts/" + name).read() + 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: print("Give one app package path.") From 0d181969492806c3f603d9f40b5afdaecbeb457b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Sun, 27 May 2018 12:01:38 +0200 Subject: [PATCH 05/10] Improve text and code style --- package_linter.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/package_linter.py b/package_linter.py index efcb2ec..878f0de 100755 --- a/package_linter.py +++ b/package_linter.py @@ -360,27 +360,23 @@ def check_arg_retrieval(script): def check_helper_usage_dependencies(script_name): """ - detects usage of ynh_package_* & apt-get * and suggest usage of - ynh_remove_app_dependencies and ynh_remove_app_dependencies + Detect usage of ynh_package_* & apt-get * + and suggest herlpers ynh_install_app_dependencies and ynh_remove_app_dependencies """ script = open(script_name).read() - present = False + 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") - present = "ynh_package_install" in script or "apt-get install" in script - - if present: - print_warning("You should not use ynh_package_install or apt-get install, use ynh_install_app_dependencies instead") - - present = False - present = "ynh_package_remove" in script or "apt-get remove" in script - - if present: - print_warning("You should not use ynh_package_remove or apt-get remove, use ynh_remove_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(script_name): """ - detects usage of sudo, rm and sed + Detect usage of unix commands with helper equivalents: + - sudo → nothing + - rm → ynh_secure_remove + - sed -i → ynh_replace_string """ script = open(script_name).read() From 21cb506419b53ddbf8b1156e08ee6e74ce04f37e Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 2 Dec 2018 17:54:54 +0100 Subject: [PATCH 06/10] Update url for official helpers doc --- package_linter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package_linter.py b/package_linter.py index 1550ba0..881efd5 100755 --- a/package_linter.py +++ b/package_linter.py @@ -30,7 +30,7 @@ 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://helpers.yunohost.org\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") From 4a68c76089007ffeef5480065760516e101440ef Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 2 Dec 2018 17:56:45 +0100 Subject: [PATCH 07/10] Use read_file() to get file content without comments --- package_linter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package_linter.py b/package_linter.py index 881efd5..5ccbd81 100755 --- a/package_linter.py +++ b/package_linter.py @@ -364,7 +364,7 @@ def check_helper_usage_dependencies(script_name): Detect usage of ynh_package_* & apt-get * and suggest herlpers ynh_install_app_dependencies and ynh_remove_app_dependencies """ - script = open(script_name).read() + script = read_file(script_name) 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") @@ -379,7 +379,7 @@ def check_helper_usage_unix(script_name): - rm → ynh_secure_remove - sed -i → ynh_replace_string """ - script = open(script_name).read() + script = read_file(script_name) if "rm -rf" in script: print_warning("You should not use `rm -rf`, use ynh_secure_remove instead") @@ -395,7 +395,7 @@ def check_helper_consistency(path, script_name, script_path): check if ynh_install_app_dependencies is present in install/upgrade/restore so dependencies are up to date after restoration or upgrade """ - script = open(script_path).read() + script = read_file(script_name) if script_name == "install" and "ynh_install_app_dependencies" in script: for name in ["upgrade", "restore"]: From 29d647ce2056d5c21504483b039eff46e75b5353 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 2 Dec 2018 17:59:45 +0100 Subject: [PATCH 08/10] Update advice about 'sudo' and others --- package_linter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package_linter.py b/package_linter.py index 5ccbd81..3d5e418 100755 --- a/package_linter.py +++ b/package_linter.py @@ -375,20 +375,20 @@ def check_helper_usage_dependencies(script_name): def check_helper_usage_unix(script_name): """ Detect usage of unix commands with helper equivalents: - - sudo → nothing + - sudo → ynh_exec_as - rm → ynh_secure_remove - sed -i → ynh_replace_string """ script = read_file(script_name) if "rm -rf" in script: - print_warning("You should not use `rm -rf`, use ynh_secure_remove instead") + print_warning("You should avoid using `rm -rf`, please use `ynh_secure_remove` instead") if "sed -i" in script: - print_warning("You should not have to use `sed -i`, use ynh_replace_string or one of the helper") + print_warning("You should avoid using `sed -i`, please use `ynh_replace_string` instead") if "sudo " in script: - print_warning("You should not have to use `sudo`, the script is run as root") + print_warning("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, script_path): """ From 132ee456e0c91c8d6c652d56459855a0675fb238 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 13 Dec 2018 20:47:49 +0100 Subject: [PATCH 09/10] Misc fixes for confusion between full path, script name, and content --- package_linter.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/package_linter.py b/package_linter.py index 3d5e418..6fa3a4d 100755 --- a/package_linter.py +++ b/package_linter.py @@ -255,9 +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) - check_helper_usage_unix(script_path) - check_helper_consistency(path, script_name, 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()) @@ -359,12 +359,12 @@ 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(script_name): +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(script_name) + 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") @@ -372,14 +372,14 @@ def check_helper_usage_dependencies(script_name): 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(script_name): +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(script_name) + script = read_file(path) if "rm -rf" in script: print_warning("You should avoid using `rm -rf`, please use `ynh_secure_remove` instead") @@ -390,17 +390,17 @@ def check_helper_usage_unix(script_name): if "sudo " in script: print_warning("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, script_path): +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(script_name) + script = read_file(path) if script_name == "install" and "ynh_install_app_dependencies" in script: for name in ["upgrade", "restore"]: try: - script2 = open(path + "/scripts/" + name).read() + 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: From 48075f80e3e163f22f9ca80b4349220b126aa094 Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Thu, 13 Dec 2018 22:48:49 +0100 Subject: [PATCH 10/10] [enh] Check fail if rm -rf --- package_linter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package_linter.py b/package_linter.py index 6fa3a4d..a76e4a1 100755 --- a/package_linter.py +++ b/package_linter.py @@ -381,14 +381,14 @@ def check_helper_usage_unix(path, script_name): """ script = read_file(path) - if "rm -rf" in script: - print_warning("You should avoid using `rm -rf`, please use `ynh_secure_remove` instead") + 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("You should avoid using `sed -i`, please use `ynh_replace_string` instead") + print_warning("[YEP-2.12] You should avoid using `sed -i`, please use `ynh_replace_string` instead") if "sudo " in script: - print_warning("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`)") + 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): """