File: list_classes.py

package info (click to toggle)
gaphor 0.13.0-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,692 kB
  • ctags: 2,971
  • sloc: python: 19,981; xml: 247; makefile: 54; sh: 40
file content (43 lines) | stat: -rwxr-xr-x 904 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python

"""
This script list classes and optionally attributes from UML model created
with Gaphor.
"""

import gaphor
from gaphor.storage import storage
import gaphor.UML as UML

import optparse
import sys

usage = 'usage: %prog [options] file.gaphor'

parser = optparse.OptionParser(usage=usage)

parser.add_option('-a', '--attributes', dest='attrs', action='store_true',
    help='print classes attributes')

(options, args) = parser.parse_args()

if len(args) != 1:
    parser.print_help()
    sys.exit(1)

model = args[0]

# create UML object factory
factory = UML.ElementFactory()

# load model from file
storage.load(model, factory)

# find all classes using factory
for cls in factory.select(lambda e: e.isKindOf(UML.Class)):
    print 'found class %s' % cls.name
    if options.attrs:
        for attr in cls.ownedAttribute:
            print ' attr: %s' % attr.name

# vim:sw=4:et:ai