Home | History | Annotate | Download | only in modelviz
      1 #!/usr/bin/env python
      2 
      3 """
      4 Generates schema diagrams for Django apps.  Just run the script with no
      5 arguments.  If you don't have them installed, you'll need "dot" from the
      6 Graphviz package and Django.
      7 """
      8 
      9 import common
     10 import os
     11 
     12 ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
     13 PROJECTS = (
     14         ('frontend', 'tko'),
     15         ('frontend', 'afe'),
     16     )
     17 
     18 
     19 def main():
     20     for project, app in PROJECTS:
     21         settings = 'autotest_lib.%s.settings' % project
     22         os.environ['DJANGO_SETTINGS_MODULE'] = settings
     23 
     24         # import after setting DJANGO_SETTINGS_MODULE
     25         from autotest_lib.contrib import modelviz
     26 
     27         # hack to force reload of settings and app list
     28         import django.conf
     29         from django.db.models import loading
     30         reload(django.conf)
     31         reload(loading)
     32 
     33         print 'Analyzing', project
     34         dot_contents = modelviz.generate_dot([app])
     35 
     36         dot_path = project + '.dot'
     37         dotfile = open(dot_path, 'w')
     38         dotfile.write(dot_contents)
     39         dotfile.close()
     40         print 'Wrote', dot_path
     41 
     42         png_path = project + '.png'
     43         os.system('dot -Tpng -o %s %s' % (png_path, dot_path))
     44         print 'Generated', png_path
     45         print
     46 
     47         del os.environ['DJANGO_SETTINGS_MODULE']
     48 
     49 
     50 if __name__ == '__main__':
     51     main()
     52