Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] oca-gen-addon-banner: Proof of concept #593

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
license="AGPL3",
packages=["tools"],
include_package_data=True,
package_data={
"tools": ["*.png"],
},
zip_safe=False,
use_scm_version=True,
setup_requires=[
Expand Down Expand Up @@ -44,6 +47,7 @@
"pyproject_dependencies ; python_version>='3.7'",
"setuptools-odoo", # for oca-gen-external-dependencies
"whool", # for oca-gen-external-dependencies
"Pillow", # For oca-gen-addon-banner
],
python_requires=">=3.6",
classifiers=[
Expand All @@ -69,6 +73,7 @@
"oca-migrate-branch-empty = tools.migrate_branch_empty:main",
"oca-publish-modules = tools.publish_modules:main",
"oca-gen-addon-readme = tools.gen_addon_readme:gen_addon_readme",
"oca-gen-addon-banner = tools.gen_addon_banner:gen_addon_banner",
"oca-gen-addon-icon = tools.gen_addon_icon:gen_addon_icon",
"oca-gen-external-dependencies = tools.gen_external_dependencies:main",
"oca-gen-metapackage = tools.gen_metapackage:main",
Expand Down
Binary file added tools/gen_addon_banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions tools/gen_addon_banner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# License AGPLv3 (https://www.gnu.org/licenses/agpl-3.0-standalone.html)
# Copyright (c) 2018 ACSONE SA/NV
# Copyright (c) 2018 GRAP (http://www.grap.coop)

import os
import click
from .manifest import read_manifest, find_addons, NoManifestFound
from .gitutils import commit_if_needed
from PIL import Image


def gen_one_addon_banner(addon_name, addon_dir, manifest, background, font):
# It would be cleaner to modify the readme, but it is easier
image = Image.open(background)
# TODO:Maybe we could add the title of the addon...
modified = []
for path in manifest["images"]:
image.save("%s/%s" % (addon_dir, path))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really make sense to save one copy of this banner in every OCA module? Isn't it easier just to modify the README template (contained in this repo too) to include it from this maintainer-tools github repo directly?

Even more taking into account OCA/oca-addons-repo-template#190 (comment).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really make sense to save one copy of this banner in every OCA module? Isn't it easier just to modify the README template (contained in this repo too) to include it from this maintainer-tools github repo directly?

Even more taking into account OCA/oca-addons-repo-template#190 (comment).

@yajo I think we should be able to put custom banners for modules. Same as icons.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but if it isn't custom, do we really need to replicate this image thousands of times?

For the icon, we do need it, because Odoo expects the icon to exist in a specific place. But the banner only appears on the compiled readme/index

modified.append("%s/%s" % (addon_dir, path))
return modified


@click.command()
@click.option(
"--background",
type=click.Path(dir_okay=False, file_okay=True, exists=True),
default=os.path.join(
os.path.dirname(__file__),
"gen_addon_banner.png",
),
help="Path of the Background to use",
)
@click.option(
"--font",
type=click.Path(dir_okay=True, file_okay=False, exists=True),
help="Path of the Font to use",
)
@click.option(
"--addon-dir",
"addon_dirs",
type=click.Path(dir_okay=True, file_okay=False, exists=True),
multiple=True,
help="Directory where addon manifest is located. This option " "may be repeated.",
)
@click.option(
"--addons-dir",
type=click.Path(dir_okay=True, file_okay=False, exists=True),
help="Directory containing several addons, the README will be "
"generated for all installable addons found there.",
)
@click.option(
"--commit/--no-commit",
help="git commit changes to README.rst and index.html, if any.",
)
def gen_addon_banner(
background,
font,
addon_dirs,
addons_dir,
commit,
):
addons = []
if addons_dir:
addons.extend(find_addons(addons_dir))
for addon_dir in addon_dirs:
addon_name = os.path.basename(os.path.abspath(addon_dir))
try:
manifest = read_manifest(addon_dir)
except NoManifestFound:
continue
addons.append((addon_name, os.path.abspath(addon_dir), manifest))
modified = []
for addon_name, addon_dir, manifest in addons:
print(addon_dir)
if "images" not in manifest:
continue
modified += gen_one_addon_banner(
addon_name, addon_dir, manifest, background, font
)
if commit:
commit_if_needed(modified, "[UPD] banners")


if __name__ == "__main__":
gen_addon_banner()
Loading