-
Notifications
You must be signed in to change notification settings - Fork 15
/
example.py
executable file
·73 lines (61 loc) · 1.82 KB
/
example.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
from __future__ import print_function
import os.path
import pyreqif.reqif
import pyreqif.rif
import sys
#
# command line parsing
#
if len(sys.argv) < 2:
print("Usage {} some_reqif_file.reqif\n".format(sys.argv[0]))
print("prints Text and Chapter Information and also exports a RIF file")
sys.exit()
filename = sys.argv[1]
#
# calculate base path of reqif-document for extracting attachments
#
basepath = os.path.dirname(filename)
#
# load reqif/rif file
#
myDoc = pyreqif.reqif.load(filename)
#
# example rif export:
#
f = open(os.path.splitext(filename)[0] + "_pyreqif_export.xml", "wb")
pyreqif.rif.dump(myDoc,f)
#
# example ascii console 'flat' dump, without hierarchie
#
print ("Specification Requirements (flat):")
specs = myDoc.asDict()
for spec in specs:
for req in spec:
for key,value in req.items():
print ("{} : {}".format(key, value), end=" ")
print("")
#
# example ascii console 'hierarchy' dump, using hierach_iterator
#
print ("Specification Requirements (hierarchical):")
cols = myDoc.fields
for spec in specs:
for child in myDoc.hierarchy:
for item, depth in myDoc.hierach_iterator(child, cols):
#
# iterator gives every element and its hierachical depth
# do some ascii printing of Text and Chapter
print(" " * depth, end="")
for key, value in req.items():
print("{} : {}".format(key, value), end=" ")
print("")
# print (item["ReqIF.ChapterName"], end="")
# print (item["ReqIF.Text"])
#
# print some info, if attachement is found
#
if "attachments" in item:
for attachment in item["attachments"]:
absPath = os.path.abspath(attachment)
print (absPath)