diff --git a/nuvolasdk/__init__.py b/nuvolasdk/__init__.py index d7d873e..811f2a3 100644 --- a/nuvolasdk/__init__.py +++ b/nuvolasdk/__init__.py @@ -2,13 +2,13 @@ Copyright 2016 Jiří Janoušek Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: +modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. + list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -59,7 +59,7 @@ def print_help(prog): print('\nCreate addon data XML') print('====================\n') nuvolasdk.addondata.create_arg_parser(prog + " create-addondata").print_help() - + def run(wd, argv): prog = os.path.basename(argv[0]) if prog.startswith("__main__"): @@ -84,7 +84,7 @@ def run(wd, argv): if cmd in ('-h', '--help', 'help'): print_help(prog) return 0 - + print("Error: Unknown command '%s'.\n" % cmd) print_help(prog) return 2 diff --git a/nuvolasdk/checkproject.py b/nuvolasdk/checkproject.py index 07623e7..b581099 100644 --- a/nuvolasdk/checkproject.py +++ b/nuvolasdk/checkproject.py @@ -2,13 +2,13 @@ Copyright 2016-2018 Jiří Janoušek Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: +modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. + list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -41,14 +41,14 @@ def run(directory, prog, argv): sdk_data = utils.get_sdk_data_dir() pushdir(directory) n_errors = 0 - + if fexists("Makefile"): print("Cleaning the project...") try_run('make clean') print("") - + print("Checking the project...") - + F_METADATA_IN_JSON = "metadata.in.json" F_CONFIGURE = "configure" F_CHANGELOG_MD = "CHANGELOG.md" @@ -56,21 +56,21 @@ def run(directory, prog, argv): F_CONTRIBUTING_MD = "CONTRIBUTING.md" F_INTEGRATE_JS = "integrate.js" F_GITIGNORE = ".gitignore" - + files = ( F_METADATA_IN_JSON, F_INTEGRATE_JS, F_CONFIGURE, F_CHANGELOG_MD, F_README_MD, F_CONTRIBUTING_MD, F_GITIGNORE ) - + for filename in files: if not fexists(filename): print("Error: A file '%s' is missing." % filename) n_errors += 1 - + if not utils.get_license_files(): print("Error: No license files (LICENSE*) have been found.") n_errors += 1 - + METADATA_JSON = "metadata.json" if fexists(F_METADATA_IN_JSON): metadata = readjson(F_METADATA_IN_JSON) @@ -82,7 +82,7 @@ def run(directory, prog, argv): except KeyError: print('Error: metadata.json file must contain the "id" property.') n_errors += 1 - + try: app_name = metadata["name"].strip() if not app_name: @@ -91,7 +91,7 @@ def run(directory, prog, argv): except KeyError: print('Error: metadata.json file must contain the "name" property.') n_errors += 1 - + prop_name = "version_major" try: version_major = metadata[prop_name] @@ -101,7 +101,7 @@ def run(directory, prog, argv): except KeyError: print('Error: metadata.json file must contain the "%s" property.' % prop_name) n_errors += 1 - + prop_name = "version_minor" try: version_minor = metadata[prop_name] @@ -111,7 +111,7 @@ def run(directory, prog, argv): except KeyError: print('Error: metadata.json file must contain the "%s" property.' % prop_name) n_errors += 1 - + prop_name = "api_major" try: api_major = metadata[prop_name] @@ -121,7 +121,7 @@ def run(directory, prog, argv): except KeyError: print('Error: metadata.json file must contain the "%s" property.' % prop_name) n_errors += 1 - + prop_name = "api_minor" try: api_minor = metadata[prop_name] @@ -131,7 +131,7 @@ def run(directory, prog, argv): except KeyError: print('Error: metadata.json file must contain the "%s" property.' % prop_name) n_errors += 1 - + prop_name = "maintainer_link" try: maintainer_link = metadata[prop_name] @@ -141,7 +141,7 @@ def run(directory, prog, argv): except KeyError: print('Error: metadata.json file must contain the "%s" property.' % prop_name) n_errors += 1 - + prop_name = "maintainer_name" try: maintainer_name = metadata[prop_name] @@ -151,7 +151,7 @@ def run(directory, prog, argv): except KeyError: print('Error: metadata.json file must contain the "%s" property.' % prop_name) n_errors += 1 - + prop_name = "license" try: license = metadata[prop_name] @@ -170,11 +170,11 @@ def run(directory, prog, argv): licenses.check_canonical(license) except ValueError as e: print('Warning: "{}" is not a canonical SPDX license name, use "{}" instead.'.format(*e.args)) - + except KeyError: print('Error: metadata.json file must contain the "%s" property.' % prop_name) n_errors += 1 - + prop_name = "categories" try: categories = metadata[prop_name] @@ -184,9 +184,9 @@ def run(directory, prog, argv): except KeyError: print('Error: metadata.json file must contain the "%s" property.' % categories) n_errors += 1 - - - + + + try: build = metadata["build"] try: @@ -237,4 +237,4 @@ def run(directory, prog, argv): print("No errors have been found.") return 0 - + diff --git a/nuvolasdk/convertproject.py b/nuvolasdk/convertproject.py index 226853e..0f6f9a2 100644 --- a/nuvolasdk/convertproject.py +++ b/nuvolasdk/convertproject.py @@ -2,13 +2,13 @@ Copyright 2014-2018 Jiří Janoušek Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: +modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. + list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -36,7 +36,7 @@ def create_arg_parser(prog): description = 'Converts an old-style project to a SDK project.' ) return parser - + def convert_project(directory, prog, argv): args = create_arg_parser(prog).parse_args(argv) sdk_data = utils.get_sdk_data_dir() @@ -44,14 +44,14 @@ def convert_project(directory, prog, argv): build_extra_data = [] todos = [] git_commands = [] - + try: git.set_up_git() except KeyboardInterrupt: return 1 except ExecError as e: print("Error: Failed to set up git. %s" % e) - + MAKEFILE = "Makefile" makefile = joinpath(directory, MAKEFILE) if fexists(makefile) and not fexists(makefile + ".old"): @@ -68,7 +68,7 @@ def convert_project(directory, prog, argv): entry = entry.strip() if entry and entry not in defaults.BASE_INSTALL_FILES: extra_data.append(entry) - + if backup_makefile: build_extra_data.extend(extra_data) print("Making a backup of the Makefile") @@ -77,14 +77,14 @@ def convert_project(directory, prog, argv): todos.append("If the script builds, remove the Makefile.old file.") except FileNotFoundError as e: pass - - + + METADATA_JSON = "metadata.json" metadata_in = "metadata.in.json" if fexists(METADATA_JSON) and not fexists(metadata_in): print("Renaming %s to %s" % (METADATA_JSON, metadata_in)) rename(METADATA_JSON, metadata_in) - + metadata = readjson(metadata_in) metadata_changed = False try: @@ -95,7 +95,7 @@ def convert_project(directory, prog, argv): app_name = metadata["name"] except KeyError: raise ValueError('Error: metadata.json file must contain the "name" property.') - + try: version_major = metadata["version_major"] except KeyError: @@ -112,7 +112,7 @@ def convert_project(directory, prog, argv): maintainer_link = metadata["maintainer_link"] except KeyError: raise ValueError('Error: metadata.json file must contain the "maintainer_link" property.') - + try: license = metadata["license"] except KeyError: @@ -122,7 +122,7 @@ def convert_project(directory, prog, argv): license = input(prompt).strip() metadata["license"] = license metadata_changed = True - + subst = { "maintainer_name": maintainer_name, "year": datetime.date.today().year, @@ -130,7 +130,7 @@ def convert_project(directory, prog, argv): "app_id_dashed": utils.get_dashed_app_id(app_id), "app_name": app_name, } - + try: build = metadata["build"] except KeyError: @@ -139,7 +139,7 @@ def convert_project(directory, prog, argv): metadata["build"]["extra_data"] = build_extra_data print("Adding the build section to metadata.in.json") metadata_changed = True - + if metadata_changed: writejson(metadata_in, metadata) else: @@ -153,7 +153,7 @@ def convert_project(directory, prog, argv): configure = joinpath(directory, "configure") fwrite(configure, defaults.CONFIGURE_SCRIPT) fchmod(configure, fstat(configure).st_mode|0o111) - + F_CHANGELOG_MD = "CHANGELOG.md" if not fexists(F_CHANGELOG_MD): print("Generating", F_CHANGELOG_MD) @@ -166,14 +166,14 @@ def convert_project(directory, prog, argv): changelog.append(" * Ported to use Nuvola SDK.") with open(F_CHANGELOG_MD, "wt", encoding="utf-8") as f: f.write("\n".join(changelog) + "\n") - + F_CONTRIBUTING_MD = "CONTRIBUTING.md" if not fexists(F_CONTRIBUTING_MD): print("Generating", F_CONTRIBUTING_MD) todos.append("Revise the content of the auto-generated file %s." % F_CONTRIBUTING_MD) cp(joinpath(sdk_data, "template", F_CONTRIBUTING_MD), F_CONTRIBUTING_MD) dollar_replace(F_CONTRIBUTING_MD, subst) - + F_README_MD = "README.md" if not fexists(F_README_MD): readme_md_to_substitute = F_README_MD @@ -244,18 +244,18 @@ def convert_project(directory, prog, argv): del(gitignore[-1]) except Exception: gitignore = [] - + expected_rules = set(s for s in utils.get_gitignore_for_app_id(app_id).splitlines() if s) for rule in gitignore: expected_rules.discard(rule) - + if expected_rules: for rule in sorted(expected_rules): gitignore.append(rule) gitignore.append("") print("Updating .gitignore") fwrite(GITIGNORE, "\n".join(gitignore)) - + print("Trying to update git repo") try_run('git add metadata.in.json') try_run('git add configure') @@ -269,7 +269,7 @@ def convert_project(directory, prog, argv): try_run('git rm -f --cached svg-optimize.sh') for cmd in git_commands: try_run(cmd) - + print("Finished!") print("\nTasks to do:\n") for todo in todos: diff --git a/nuvolasdk/shkit.py b/nuvolasdk/shkit.py index a74a2ec..273f4df 100644 --- a/nuvolasdk/shkit.py +++ b/nuvolasdk/shkit.py @@ -1,16 +1,16 @@ """ -shkit.py - Shell Kit - write shell script alternatives easily in Python 3 +shkit.py - Shell Kit - write shell script alternatives easily in Python 3 Copyright 2014-2018 Jiří Janoušek Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: +modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. + list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -92,7 +92,7 @@ def fwrite(path, text, encoding="utf-8"): def fappend(path, text, encoding="utf-8"): with open(str(path), "at", encoding=encoding) as f: f.write(text) - + def rmftree(path): if not fexists(path): return @@ -119,11 +119,11 @@ def purgedir(path): def file_replace(pattern, path, data): with open(path, "r", encoding="utf-8") as f: text = f.read() - + def replace_func(match): key = match.group(1) return str(data.get(key)) - + text = pattern.sub(replace_func, text) fwrite(path, text) diff --git a/nuvolasdk/utils.py b/nuvolasdk/utils.py index e0a3a55..03dc078 100644 --- a/nuvolasdk/utils.py +++ b/nuvolasdk/utils.py @@ -2,13 +2,13 @@ Copyright 2016-2018 Jiří Janoušek Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: +modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. + list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -62,13 +62,13 @@ def get_nuvola_unique_id(genuine): def get_unique_app_id(app_id, genuine): return build_unique_id(get_nuvola_unique_id(genuine), app_id) - + def build_unique_id(base_id, app_id): app_id_unique = [base_id, "App"] for part in app_id.split("_"): app_id_unique.append(part[0].upper()) app_id_unique.append(part[1:].lower()) - return "".join(app_id_unique) + return "".join(app_id_unique) def get_app_dir_name(app_id): return "nuvola-app-" + get_dashed_app_id(app_id) @@ -104,7 +104,7 @@ def check_desktop_categories(categories): audio_video = False audio = False video = False - + for category in categories: if category not in DESKTOP_CATEGORIES: errors.append('The desktop category "%s" is not valid.' % category) @@ -114,13 +114,13 @@ def check_desktop_categories(categories): audio = True elif category == "Video": video = True - + if audio and not audio_video: errors.append('If the desktop category "Audio" is specified, the desktop category AudioVideo must be specified too.') if video and not audio_video: errors.append('If the desktop category "Video" is specified, the desktop category AudioVideo must be specified too.') return errors - + def parse_version(version): return tuple(int(i.strip() or "0") for i in version.strip().split("."))