-
-
Notifications
You must be signed in to change notification settings - Fork 460
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
etobella
wants to merge
1
commit into
OCA:master
Choose a base branch
from
dixmit:banner
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
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() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yajo I think we should be able to put custom banners for modules. Same as icons.
There was a problem hiding this comment.
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