Skip to content

Commit

Permalink
[ADD] module-graph.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KangOl committed Apr 30, 2021
1 parent f1372b7 commit 32fef87
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions module-graph.py
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("}")

0 comments on commit 32fef87

Please sign in to comment.