Move general checks as methods of App class

This commit is contained in:
Alexandre Aubin 2019-03-02 01:43:29 +01:00
parent a0e435c271
commit 0c4e86d098

View file

@ -93,7 +93,18 @@ class App():
self.scripts = { f: Script(self.path, f) for f in scripts }
def misc_file_checks(app_path):
def analyze(self):
self.misc_file_checks()
self.check_source_management()
self.check_manifest()
for script in self.scripts.values():
if script.exists:
script.analyze()
def misc_file_checks(self):
print_header("MISC FILE CHECKS")
@ -108,7 +119,7 @@ def misc_file_checks(app_path):
non_mandatory = ("script/backup", "script/restore")
for filename in filenames:
if file_exists(app_path + "/" + filename):
if file_exists(self.path + "/" + filename):
continue
elif filename in non_mandatory:
print_warning("Consider adding a file %s" % filename)
@ -119,26 +130,26 @@ def misc_file_checks(app_path):
# Deprecated php-fpm.ini thing
#
if file_exists(app_path + "/conf/php-fpm.ini"):
if file_exists(self.path + "/conf/php-fpm.ini"):
print_warning("Using a separate php-fpm.ini file is deprecated. Please merge your php-fpm directives directly in the pool file. (c.f. https://github.com/YunoHost-Apps/nextcloud_ynh/issues/138 )")
#
# Deprecated usage of 'add_header' in nginx conf
#
for filename in os.listdir(app_path + "/conf"):
for filename in os.listdir(self.path + "/conf"):
if not os.path.isfile(filename):
continue
content = open(app_path + "/conf/" + filename).read()
content = open(self.path + "/conf/" + filename).read()
if "location" in content and "add_header" in content:
print_warning("Do not use 'add_header' in the nginx conf. Use 'more_set_headers' instead. (See https://www.peterbe.com/plog/be-very-careful-with-your-add_header-in-nginx and https://github.com/openresty/headers-more-nginx-module#more_set_headers )")
def check_source_management(app_path):
def check_source_management(self):
print_header("SOURCES MANAGEMENT")
DIR = os.path.join(app_path, "sources")
DIR = os.path.join(self.path, "sources")
# Check if there is more than six files on 'sources' folder
if os.path.exists(os.path.join(app_path, "sources")) \
if os.path.exists(os.path.join(self.path, "sources")) \
and len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) > 5:
print_warning("[YEP-3.3] Upstream app sources shouldn't be stored on this "
"'sources' folder of this git repository as a copy/paste."
@ -148,8 +159,8 @@ def check_source_management(app_path):
"https://github.com/YunoHost/issues/issues/201#issuecomment-391549262")
def check_manifest(path):
manifest = os.path.join(path, 'manifest.json')
def check_manifest(self):
manifest = os.path.join(self.path, 'manifest.json')
if not os.path.exists(manifest):
return
print_header("MANIFEST")
@ -205,7 +216,7 @@ def check_manifest(path):
print_warning("[YEP-1.2] This app is not registered in official or community applications")
# YEP 1.3 License
def license_mentionned_in_readme(path):
def license_mentionned_in_readme():
readme_path = os.path.join(path, 'README.md')
if os.path.isfile(readme_path):
return "LICENSE" in open(readme_path).read()
@ -220,7 +231,7 @@ def check_manifest(path):
" field is 'non-free' and not 'nonfree'")
license = "non-free"
if license in ["free", "non-free", "dep-non-free"]:
if not license_mentionned_in_readme(path):
if not license_mentionned_in_readme(self.path):
print_warning("[YEP-1.3] The use of '%s' in license field implies to "
"write something about the license in your "
"README.md" % (license))
@ -469,18 +480,7 @@ def main():
app_path = sys.argv[1]
header(app_path)
# Global checks
app = App(app_path)
misc_file_checks(app_path)
check_source_management(app_path)
check_manifest(app_path)
# Scripts checks
for script in app.scripts.values():
if script.exists:
script.analyze()
App(app_path).analyze()
sys.exit(return_code)