-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
import os | ||
import optparse | ||
import glob | ||
|
||
MANIFEST_FILES = ["__manifest__.py", "__openerp__.py", "__terp__.py"] | ||
|
||
|
||
def load_information_from_description_file(module): | ||
""" | ||
:param module: The name of the module (sale, purchase, ...) | ||
""" | ||
for filename in MANIFEST_FILES: | ||
description_file = os.path.join(module, filename) | ||
if os.path.isfile(description_file): | ||
return eval(open(description_file).read()) | ||
|
||
return {} | ||
|
||
|
||
def get_valid_path(paths, module): | ||
for path in paths: | ||
full = os.path.join(path, module) | ||
if os.path.exists(full): | ||
return full | ||
return None | ||
|
||
|
||
parser = optparse.OptionParser(usage="%prog [options] [module1 [module2 ...]]") | ||
parser.add_option( | ||
"-p", "--addons-path", dest="path", help="addons directory", action="append" | ||
) | ||
(opt, args) = parser.parse_args() | ||
|
||
if not opt.path: | ||
opt.path = ["."] | ||
|
||
if not args: | ||
modules = { | ||
os.path.dirname(f) | ||
for p in opt.path | ||
for m in MANIFEST_FILES | ||
for f in glob.glob(os.path.join(p, "*", m)) | ||
} | ||
else: | ||
modules = {vp for module in args for vp in [get_valid_path(opt.path, module)] if vp} | ||
|
||
all_modules = set(map(os.path.basename, modules)) | ||
|
||
print("digraph G {") | ||
|
||
while modules: | ||
f = modules.pop() | ||
module_name = os.path.basename(f) | ||
all_modules.add(module_name) | ||
info = load_information_from_description_file(f) | ||
if info.get("installable", True): | ||
for name in info.get("depends", []): | ||
valid_path = get_valid_path(opt.path, name) | ||
if name not in all_modules: | ||
if valid_path: | ||
modules.add(valid_path) | ||
else: | ||
all_modules.add(name) | ||
print(f"\t{name} [color=red]") | ||
print("\t%s -> %s;" % (module_name, name)) | ||
|
||
print("}") |