Skip to content

Commit

Permalink
Change addons-install for a better CLI experience
Browse files Browse the repository at this point in the history
  • Loading branch information
yajo committed Oct 9, 2017
1 parent cffc52c commit e227b5d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,14 @@ now keep this in mind:

## Bundled tools

### `addons-install`
### `addons`

A handy CLI tool to automate addon management based on the current environment.
It allows you to install, update, test and/or list private, extra and/or core
addons available to current container, based on current [`addons.yaml`][]
configuration.

Call `addons-install --help` for usage instructions.
Call `addons --help` for usage instructions.

### [`nano`][]

Expand Down
34 changes: 14 additions & 20 deletions bin/addons-install → bin/addons
Original file line number Diff line number Diff line change
@@ -1,62 +1,56 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
from argparse import ArgumentParser
from subprocess import check_call
from odoobaselib import addons_config, CORE, PRIVATE, logging
from odoobaselib import addons_config, CORE, PRIVATE, SRC_DIR, logging

# Define CLI options
parser = ArgumentParser(description="Install addons in current environment")
parser.add_argument(
"action", choices=("init", "update", "list"),
help="What to do with the matched addons.")
parser.add_argument(
"-c", "--core", action="store_true",
help="Install all Odoo core addons")
parser.add_argument(
"-e", "--extra", action="store_true",
help="Install all extra addons")
parser.add_argument(
"-l", "--list", action="store_true",
help="Only list addons instead of installing them")
"-f", "--fullpath", action="store_true",
help="Print addon's full path, only useful with list mode")
parser.add_argument(
"-p", "--private", action="store_true",
help="Install all private addons")
parser.add_argument(
"-s", "--separator", type=str, default=",",
help="String that separates addons when using --list")
help="String that separates addons only useful with list mode")
parser.add_argument(
"-t", "--test", action="store_true",
help="Run unit tests for these addons, usually combined with --update")
parser.add_argument(
"-u", "--update", action="store_true",
help="Update addons instead of installing them")

# Check no CLI conflicts
args = parser.parse_args()
if not (args.private or args.core or args.extra):
parser.error("You have to choose an option at least")
if args.list and args.update:
parser.error("Cannot --list and --update together")
if args.separator != "," and not args.list:
parser.error("Cannot use --separator without --list")
help="Run unit tests for these addons, usually combined with update")

# Generate the matching addons set
args = parser.parse_args()
addons = set()
for addon, repo in addons_config():
core_ok = args.core and repo == CORE
extra_ok = args.extra and repo not in {CORE, PRIVATE}
private_ok = args.private and repo == PRIVATE
if private_ok or core_ok or extra_ok:
if args.fullpath and args.action == "list":
addon = os.path.join(SRC_DIR, repo, addon)
addons.add(addon)

# Do the required action
if not addons:
sys.exit("No addons found")
addons = args.separator.join(sorted(addons))
if args.list:
if args.action == "list":
print(addons)
else:
command = ["odoo", "--stop-after-init"]
command = ["odoo", "--stop-after-init", "--{}".format(args.action), addons]
if args.test:
command += ["--test-enable", "--workers", "0"]
command += ["--update" if args.update else "--init", addons]
logging.info("Executing %s", " ".join(command))
check_call(command)
18 changes: 9 additions & 9 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,29 @@ def test_addons_filtered(self):
("test", "-e", "auto/addons/website"),
("test", "-e", "auto/addons/dummy_addon"),
("test", "-e", "auto/addons/private_addon"),
("bash", "-c", 'test "$(addons-install -lp)" == private_addon'),
("bash", "-c", 'test "$(addons-install -le)" == dummy_addon'),
("bash", "-c", 'addons-install -lc | grep ,crm,'),
("bash", "-c", 'test "$(addons list -p)" == private_addon'),
("bash", "-c", 'test "$(addons list -e)" == dummy_addon'),
("bash", "-c", 'addons list -c | grep ,crm,'),
)
self.compose_test(
project_dir,
dict(sub_env, DBNAME="limited_private"),
("test", "-e", "auto/addons/website"),
("test", "-e", "auto/addons/dummy_addon"),
("test", "!", "-e", "auto/addons/private_addon"),
("bash", "-c", 'test -z "$(addons-install -lp)"'),
("bash", "-c", 'test "$(addons-install -le)" == dummy_addon'),
("bash", "-c", 'addons-install -lc | grep ,crm,'),
("bash", "-c", 'test -z "$(addons list -p)"'),
("bash", "-c", 'test "$(addons list -e)" == dummy_addon'),
("bash", "-c", 'addons list -c | grep ,crm,'),
)
self.compose_test(
project_dir,
dict(sub_env, DBNAME="limited_core"),
("test", "!", "-e", "auto/addons/website"),
("test", "-e", "auto/addons/dummy_addon"),
("test", "!", "-e", "auto/addons/private_addon"),
("bash", "-c", 'test -z "$(addons-install -lp)"'),
("bash", "-c", 'test "$(addons-install -le)" == dummy_addon'),
("bash", "-c", 'test "$(addons-install -lc)" == crm,sale'),
("bash", "-c", 'test -z "$(addons list -p)"'),
("bash", "-c", 'test "$(addons list -e)" == dummy_addon'),
("bash", "-c", 'test "$(addons list -c)" == crm,sale'),
)

def test_smallest(self):
Expand Down

0 comments on commit e227b5d

Please sign in to comment.