diff --git a/README.md b/README.md index a722f3a..425f251 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # YunoHost apps directory + ![roundcube](https://yunohost.org/images/roundcube.png) ![ttrss](https://yunohost.org/images/ttrss.png) ![wordpress](https://yunohost.org/images/wordpress.png) ![transmission](https://yunohost.org/images/transmission.png) ![jappix](https://yunohost.org/images/jappix.png) - @@ -41,26 +41,19 @@ sudo yunohost app fetchlist -n community -u https://yunohost.org/community.json * Fork and edit the [community list](https://github.com/YunoHost/apps/tree/master/community.json) * Add your app's ID and git information at the right alphabetical place -* Indicate the app's functioning state: `notworking`, `inprogress`, or `ready` +* Indicate the app's functioning state: `notworking`, `inprogress`, or `working` * Send a [Pull Request](https://github.com/YunoHost/apps/pulls/) -An example app addition: +App example addition: ```json "wallabag": { "branch": "master", "revision": "c2fc62438ac5c9503e3f4ebfdc425ec03a0ec0c0", "url": "https://github.com/abeudin/wallabag_ynh.git", - "state": "ready" + "state": "working" } ``` -#### How to add an app to the official list - -Same steps than above, but on the `official.json` list with the status `validated`. -The integration will be discussed on the Pull Request. - -**Important**: You will have to find a maintainer willing to take care of the package while published if you want your app to be validated. - #### Helper script You can use the add_or_update.py python script to add or update @@ -69,7 +62,7 @@ your app from one of the 2 json files. Usage: ```bash -python ./add_or_update.py [community.json OR official.json] [github url [github url [github url ...]]] +./add_or_update.py [community.json OR official.json] [github url OR app name [github url OR app name [github url OR app name ...]]] ``` #### More information on [yunohost.org/packaging_apps](https://yunohost.org/packaging_apps) diff --git a/list_builder.py b/list_builder.py index 09470f4..47c4b38 100755 --- a/list_builder.py +++ b/list_builder.py @@ -11,7 +11,7 @@ import requests from dateutil.parser import parse -## Regular expression patterns +# Regular expression patterns """GitHub repository URL.""" re_github_repo = re.compile( @@ -24,7 +24,7 @@ re_commit_author = re.compile( ) -## Helpers +# Helpers def fail(msg, retcode=1): """Show failure message and exit.""" @@ -32,7 +32,37 @@ def fail(msg, retcode=1): sys.exit(retcode) -## Main +def include_translations_in_manifest(app_name, manifest): + for i in os.listdir("locales"): + if not i.endswith("json"): + continue + + if i == "en.json": + continue + + current_lang = i.split(".")[0] + translations = json.load(open(os.path.join("locales", i), "r")) + + key = "%s_manifest_description" % app_name + if key in translations and translations[key]: + manifest["description"][current_lang] = translations[key] + + for category, questions in manifest["arguments"].items(): + for question in questions: + key = "%s_manifest_arguments_%s_%s" % (app_name, category, question["name"]) + if key in translations and translations[key]: + print "[ask]", current_lang, key + question["ask"][current_lang] = translations[key] + + key = "%s_manifest_arguments_%s_help_%s" % (app_name, category, question["name"]) + if key in translations and translations[key]: + print "[help]", current_lang, key + question["help"][current_lang] = translations[key] + + return manifest + + +# Main # Create argument parser parser = argparse.ArgumentParser(description='Process YunoHost application list.') @@ -60,6 +90,13 @@ print(":: Building %s list..." % list_name) if not args.output: args.output = '%s-build.json' % list_name +already_built_file = {} +if os.path.exists(args.output): + try: + already_built_file = json.load(open(args.output)) + except Exception as e: + print("Error while trying to load already built file: %s" % e) + # GitHub credentials if args.github: token = (args.github.split(':')[0], args.github.split(':')[1]) @@ -74,18 +111,41 @@ for app, info in apps_list.items(): # Store usefull values app_url = info['url'] app_rev = info['revision'] + app_state = info["state"] + app_level = info.get("level") + + previous_state = already_built_file.get(app, {}).get("state", {}) manifest = {} timestamp = None - ## Hosted on GitHub + previous_rev = already_built_file.get(app, {}).get("git", {}).get("revision", None) + previous_url = already_built_file.get(app, {}).get("git", {}).get("url") + previous_level = already_built_file.get(app, {}).get("level") + + if previous_rev == app_rev and previous_url == app_url: + print("%s[%s] is already up to date in target output, ignore" % (app, app_rev)) + result_dict[app] = already_built_file[app] + if previous_state != app_state: + result_dict[app]["state"] = app_state + print("... but has changed of state, updating it from '%s' to '%s'" % (previous_state, app_state)) + if previous_level != app_level or app_level is None: + result_dict[app]["level"] = app_level + print("... but has changed of level, updating it from '%s' to '%s'" % (previous_level, app_level)) + + print "update translations but don't download anything" + result_dict[app]['manifest'] = include_translations_in_manifest(app, result_dict[app]['manifest']) + + continue + + # Hosted on GitHub github_repo = re_github_repo.match(app_url) if github_repo: owner = github_repo.group('owner') repo = github_repo.group('repo') raw_url = 'https://raw.githubusercontent.com/%s/%s/%s/manifest.json' % ( - owner, repo, app_rev + owner, repo, app_rev ) try: # Retrieve and load manifest @@ -100,7 +160,7 @@ for app, info in apps_list.items(): continue api_url = 'https://api.github.com/repos/%s/%s/commits/%s' % ( - owner, repo, app_rev + owner, repo, app_rev ) try: # Retrieve last commit information @@ -116,7 +176,8 @@ for app, info in apps_list.items(): else: commit_date = parse(info2['commit']['author']['date']) timestamp = int(time.mktime(commit_date.timetuple())) - ## Git repository with HTTP/HTTPS (Gogs, GitLab, ...) + + # Git repository with HTTP/HTTPS (Gogs, GitLab, ...) elif app_url.startswith('http') and app_url.endswith('.git'): raw_url = '%s/raw/%s/manifest.json' % (app_url[:-4], app_rev) try: @@ -132,7 +193,7 @@ for app, info in apps_list.items(): continue obj_url = '%s/objects/%s/%s' % ( - app_url, app_rev[0:2], app_rev[2:] + app_url, app_rev[0:2], app_rev[2:] ) try: # Retrieve last commit information @@ -179,15 +240,16 @@ for app, info in apps_list.items(): 'url': app_url }, 'lastUpdate': timestamp, - 'manifest': manifest, - 'state': info['state'] + 'manifest': include_translations_in_manifest(manifest['id'], manifest), + 'state': info['state'], + 'level': info.get('level', '?') } except KeyError as e: print("-> Error: invalid app info or manifest, %s" % e) continue # Write resulting file -with open(args.output , 'w') as f: +with open(args.output, 'w') as f: f.write(json.dumps(result_dict, sort_keys=True)) print("\nDone! Written in %s" % args.output)