Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Addons autoin…
Browse files Browse the repository at this point in the history
…staller and env-based filter
  • Loading branch information
yajo committed Oct 2, 2017
1 parent 9c3df09 commit 4d36380
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
26 changes: 17 additions & 9 deletions lib/odoobaselib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
CUSTOM_DIR = "/opt/odoo/custom"
SRC_DIR = os.path.join(CUSTOM_DIR, 'src')
ADDONS_YAML = os.path.join(SRC_DIR, 'addons')
if os.path.isfile('%s.yaml' % ADDONS_YAML):
ADDONS_YAML = '%s.yaml' % ADDONS_YAML
else:
ADDONS_YAML = '%s.yml' % ADDONS_YAML
ADDONS_DIR = "/opt/odoo/auto/addons"
CLEAN = os.environ.get("CLEAN") == "true"
LOG_LEVELS = ("DEBUG", "INFO", "WARNING", "ERROR")
Expand All @@ -20,11 +24,6 @@
PRIVATE_DIR = os.path.join(SRC_DIR, PRIVATE)
CORE_DIR = os.path.join(SRC_DIR, CORE)

if os.path.isfile('%s.yaml' % ADDONS_YAML):
ADDONS_YAML = '%s.yaml' % ADDONS_YAML
else:
ADDONS_YAML = '%s.yml' % ADDONS_YAML

# Customize logging for build
logging.root.name = "docker-odoo-base"
_log_level = os.environ.get("LOG_LEVEL", "")
Expand All @@ -48,33 +47,40 @@ def addons_config():
with open(ADDONS_YAML) as addons_file:
for doc in yaml.load_all(addons_file):
# Skip sections with ONLY and that don't match
for key, values in doc.get("ONLY", dict()).items():
if os.environ.get(key) not in values:
continue
if any(os.environ.get(key) not in values
for key, values in doc.get("ONLY", dict()).items()):
logging.debug("Skipping section with ONLY %s", doc["ONLY"])
continue
# Flatten all sections in a single dict
for repo, addons in doc.items():
if repo == PRIVATE:
private_done = True
elif repo == CORE:
core_done = True
logging.debug("Processing %s repo", repo)
for glob in addons:
logging.debug("Expanding glob %s", glob)
for addon in iglob(os.path.join(SRC_DIR, repo, glob)):
logging.debug("Registering addon %s", addon)
addon = os.path.basename(addon)
config.setdefault(addon, set())
config[addon].add(repo)
except IOError:
logging.debug('Could not find addons configuration yml.')
# By default, all private and core addons are enabled
if not private_done:
logging.debug("Auto-adding all private repo addons")
config.update({
os.path.basename(addon): {PRIVATE}
for addon in iglob(os.path.join(SRC_DIR, PRIVATE, "*"))
})
if not core_done:
logging.debug("Auto-adding all core repo addons")
config.update({
os.path.basename(addon): {CORE}
for addon in iglob(os.path.join(SRC_DIR, CORE, "*"))
})
logging.debug("Resulting configuration: %r", config)
for addon, repos in config.items():
# Private addons are most important
if PRIVATE in repos:
Expand All @@ -83,6 +89,8 @@ def addons_config():
elif repos == {CORE}:
yield addon, CORE
# Other addons fall in between
elif len(repos) != 1:
logging.error("Addon %s defined in several repos %s", addon, repos)
raise Exception
else:
repos.discard(CORE)
yield addon, repos.pop()
20 changes: 10 additions & 10 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,36 +98,36 @@ def compose_test(self, workdir, sub_env, *commands):
def test_addons_filtered(self):
"""Test addons filtering with ``ONLY`` keyword in ``addons.yaml``."""
project_dir = join(SCAFFOLDINGS_DIR, "dotd")
for sub_env in matrix():
for sub_env in matrix(odoo={"10.0"}):
self.compose_test(
project_dir,
dict(sub_env, DBNAME="prod"),
("test", "-e", "auto/addons/website"),
("test", "-e", "auto/addons/dummy_addon"),
("test", "-e", "auto/addons/private_addon"),
("sh", "-c", 'test "$(addons-install -lp)" == private_addon'),
("sh", "-c", 'test "$(addons-install -le)" == dummy_addon'),
("sh", "-c", 'addons-install -lc | grep ,crm,'),
("bash", "-c", 'test "$(addons-install -lp)" == private_addon'),
("bash", "-c", 'test "$(addons-install -le)" == dummy_addon'),
("bash", "-c", 'addons-install -lc | 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"),
("sh", "-c", '[ -z "$(addons-install -lp)" ]'),
("sh", "-c", '[ "$(addons-install -le)" == dummy_addon ]'),
("sh", "-c", 'addons-install -lc | grep ,crm,'),
("bash", "-c", 'test -z "$(addons-install -lp)"'),
("bash", "-c", 'test "$(addons-install -le)" == dummy_addon'),
("bash", "-c", 'addons-install -lc | 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"),
("sh", "-c", '[ -z "$(addons-install -lp)" ]'),
("sh", "-c", '[ "$(addons-install -le)" == dummy_addon ]'),
("sh", "-c", '[ "$(addons-install -lc)" == crm,sale ]'),
("bash", "-c", 'test -z "$(addons-install -lp)"'),
("bash", "-c", 'test "$(addons-install -le)" == dummy_addon'),
("bash", "-c", 'test "$(addons-install -lc)" == crm,sale'),
)

def test_smallest(self):
Expand Down

0 comments on commit 4d36380

Please sign in to comment.