summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorshoward <showard@592f7852-d20e-0410-864c-8624ca9c26a4>2009-06-08 23:29:54 +0000
committershoward <showard@592f7852-d20e-0410-864c-8624ca9c26a4>2009-06-08 23:29:54 +0000
commit442812554b815827687368a302842f1013a295ac (patch)
treee2353a6fabc0d213fa13e8ddb38bc1a6bc24cc94 /utils
parentf6e0adf11be94295fcc9b8658aa983d37523a97c (diff)
quick script to generate schema diagrams for AFE and TKO. should make it easier to keep the diagrams on the wiki up to date. including the open-source tool modelviz.py.
Signed-off-by: Steve Howard <showard@google.com> git-svn-id: svn://test.kernel.org/autotest/trunk@3231 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'utils')
-rw-r--r--utils/modelviz/common.py8
-rw-r--r--utils/modelviz/generate_schema_diagrams.py51
2 files changed, 59 insertions, 0 deletions
diff --git a/utils/modelviz/common.py b/utils/modelviz/common.py
new file mode 100644
index 00000000..41607e17
--- /dev/null
+++ b/utils/modelviz/common.py
@@ -0,0 +1,8 @@
+import os, sys
+dirname = os.path.dirname(sys.modules[__name__].__file__)
+autotest_dir = os.path.abspath(os.path.join(dirname, "..", ".."))
+client_dir = os.path.join(autotest_dir, "client")
+sys.path.insert(0, client_dir)
+import setup_modules
+sys.path.pop(0)
+setup_modules.setup(base_path=autotest_dir, root_module_name="autotest_lib")
diff --git a/utils/modelviz/generate_schema_diagrams.py b/utils/modelviz/generate_schema_diagrams.py
new file mode 100644
index 00000000..8a4551a4
--- /dev/null
+++ b/utils/modelviz/generate_schema_diagrams.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+
+"""
+Generates schema diagrams for Django apps. Just run the script with no
+arguments. If you don't have them installed, you'll need "dot" from the
+Graphviz package and Django.
+"""
+
+import common
+import os
+
+ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
+PROJECTS = (
+ ('new_tko', 'tko'),
+ ('frontend', 'afe'),
+ )
+
+
+def main():
+ for project, app in PROJECTS:
+ settings = 'autotest_lib.%s.settings' % project
+ os.environ['DJANGO_SETTINGS_MODULE'] = settings
+
+ # import after setting DJANGO_SETTINGS_MODULE
+ from autotest_lib.contrib import modelviz
+
+ # hack to force reload of settings and app list
+ import django.conf
+ from django.db.models import loading
+ reload(django.conf)
+ reload(loading)
+
+ print 'Analyzing', project
+ dot_contents = modelviz.generate_dot([app])
+
+ dot_path = project + '.dot'
+ dotfile = open(dot_path, 'w')
+ dotfile.write(dot_contents)
+ dotfile.close()
+ print 'Wrote', dot_path
+
+ png_path = project + '.png'
+ os.system('dot -Tpng -o %s %s' % (png_path, dot_path))
+ print 'Generated', png_path
+ print
+
+ del os.environ['DJANGO_SETTINGS_MODULE']
+
+
+if __name__ == '__main__':
+ main()