root/gaphor/trunk/examples/list_classes.py

Revision 2282, 0.9 kB (checked in by wrobe..@pld-linux.org, 8 months ago)

- added an examples to list classes from UML model

  • Property svn:executable set to *
Line 
1 #!/usr/bin/python
2
3 """
4 This script list classes and optionally attributes from UML model created
5 with Gaphor.
6 """
7
8 import gaphor
9 from gaphor.storage import storage
10 import gaphor.UML as UML
11
12 import optparse
13 import sys
14
15 usage = 'usage: %prog [options] file.gaphor'
16
17 parser = optparse.OptionParser(usage=usage)
18
19 parser.add_option('-a', '--attributes', dest='attrs', action='store_true',
20     help='print classes attributes')
21
22 (options, args) = parser.parse_args()
23
24 if len(args) != 1:
25     parser.print_help()
26     sys.exit(1)
27
28 model = args[0]
29
30 # create UML object factory
31 factory = UML.ElementFactory()
32
33 # load model from file
34 storage.load(model, factory)
35
36 # find all classes using factory
37 for cls in factory.select(lambda e: e.isKindOf(UML.Class)):
38     print 'found class %s' % cls.name
39     if options.attrs:
40         for attr in cls.ownedAttribute:
41             print ' attr: %s' % attr.name
42
43 # vim:sw=4:et:ai
Note: See TracBrowser for help on using the browser.