pyreqif 0.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyreqif/__init__.py +9 -0
- pyreqif/create.py +93 -0
- pyreqif/extractOleData.py +41 -0
- pyreqif/html.py +91 -0
- pyreqif/ole2rtf.py +16 -0
- pyreqif/pyreqif.py +729 -0
- pyreqif/reqif.py +410 -0
- pyreqif/rif.py +702 -0
- pyreqif/xlsx.py +126 -0
- pyreqif-0.9.data/scripts/reqif2html.py +11 -0
- pyreqif-0.9.data/scripts/reqif2xlsx.py +11 -0
- pyreqif-0.9.data/scripts/xlsx2reqif.py +236 -0
- pyreqif-0.9.dist-info/METADATA +50 -0
- pyreqif-0.9.dist-info/RECORD +17 -0
- pyreqif-0.9.dist-info/WHEEL +5 -0
- pyreqif-0.9.dist-info/licenses/LICENSE +25 -0
- pyreqif-0.9.dist-info/top_level.txt +1 -0
pyreqif/__init__.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
try:
|
|
2
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
3
|
+
except ImportError: # Python < 3.8
|
|
4
|
+
from importlib_metadata import version, PackageNotFoundError
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
__version__ = version("pyreqif")
|
|
8
|
+
except PackageNotFoundError:
|
|
9
|
+
__version__ = "unknown"
|
pyreqif/create.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
import datetime
|
|
4
|
+
import pyreqif.pyreqif
|
|
5
|
+
import pyreqif.rif
|
|
6
|
+
import uuid
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def createDocument(id, title="title", comment="created by pyreqif"):
|
|
10
|
+
mydoc = pyreqif.pyreqif.doc()
|
|
11
|
+
mydoc.addHeader({"identifier": id, "sourceToolId": "pyreqif", "comment": comment, "title": title,
|
|
12
|
+
"creationTime": datetime.datetime.today().isoformat("T", "seconds")})
|
|
13
|
+
return mydoc
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def addDocType(id, mydoc, lastChange=datetime.datetime.today().isoformat("T", "seconds"), longName="doc_type"):
|
|
17
|
+
mydoc.specificationTypes.add({"identifier": id, "lastChange": lastChange, "longName": longName})
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def addDatatype(id, mydoc, type="document", lastChange=datetime.datetime.today().isoformat("T", "seconds"),
|
|
21
|
+
longName="xhtml", values=None):
|
|
22
|
+
if values is None:
|
|
23
|
+
mydoc.addDatatype({"identifier": id, "type": type, "lastChange": lastChange, "longName": longName})
|
|
24
|
+
else:
|
|
25
|
+
mydoc.addDatatype(
|
|
26
|
+
{"identifier": id, "type": type, "lastChange": lastChange, "longName": longName, "values": values})
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def addSpecRelationType(id, mydoc, longName, lastChange=datetime.datetime.today().isoformat("T", "seconds")):
|
|
30
|
+
mydoc.addSpecRelationType({"identifier": id, "longName": longName, "lastChange": lastChange})
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def addSpecRelationGroup(mydoc, id, sourceDoc, targetDoc, longName, longNameOfType, specRelationRefs,
|
|
34
|
+
lastChange=datetime.datetime.today().isoformat("T", "seconds")):
|
|
35
|
+
mydoc.addSpecRelationGroup({"identifier": id, "longName": longName, "sourceDoc": sourceDoc,
|
|
36
|
+
"targetDoc": targetDoc, "lastChange": lastChange,
|
|
37
|
+
"longNameOfType": longNameOfType, "specRelationRefs": specRelationRefs})
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def addReqType(specObjId, specObjLongName, specAttribId, collumName, typeRef, mydoc, type="complex",
|
|
41
|
+
lastChange=datetime.datetime.today().isoformat("T", "seconds"), multiValued=False):
|
|
42
|
+
mydoc.addRequirementType({"identifier": specObjId, "longName": specObjLongName, "lastChange": lastChange,
|
|
43
|
+
specAttribId: {"identifier": specAttribId, "typeRef": typeRef, "type": type,
|
|
44
|
+
"lastChange": lastChange, "longName": collumName,
|
|
45
|
+
"multiValued": multiValued}})
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def addReq(id, specType, content, reqTypeRef, mydoc, longName=None, contentRef=None,
|
|
49
|
+
lastChange=datetime.datetime.today().isoformat("T", "seconds")):
|
|
50
|
+
value = {"attributeRef": reqTypeRef}
|
|
51
|
+
if contentRef is not None:
|
|
52
|
+
value["type"] = "enum"
|
|
53
|
+
value["contentRef"] = contentRef
|
|
54
|
+
else:
|
|
55
|
+
value["content"] = content
|
|
56
|
+
value["type"] = "embeddedDoc"
|
|
57
|
+
req = {"typeRef": specType, "identifier": id, "lastChange": lastChange,
|
|
58
|
+
"values": {id: value}}
|
|
59
|
+
if longName is not None:
|
|
60
|
+
req["longName"] = longName
|
|
61
|
+
mydoc.addRequirement(req)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def addRelation(sourceId, targetId, mydoc, id, type, longName=None,
|
|
65
|
+
lastChange=datetime.datetime.today().isoformat("T", "seconds")):
|
|
66
|
+
relation = {"identifier": id, "lastChange": lastChange}
|
|
67
|
+
relation["sourceRef"] = sourceId
|
|
68
|
+
relation["targetRef"] = targetId
|
|
69
|
+
relation["typeRef"] = type
|
|
70
|
+
if longName is not None:
|
|
71
|
+
relation["longName"] = longName
|
|
72
|
+
mydoc.addRelation(relation)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def creatUUID(itemId=None):
|
|
76
|
+
if itemId is not None:
|
|
77
|
+
return "_" + str(uuid.uuid1(int(itemId)))
|
|
78
|
+
else:
|
|
79
|
+
return "_" + str(uuid.uuid1())
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def createHierarchHead(longName, typeRef, id=None, lastChange=datetime.datetime.today().isoformat("T", "seconds")):
|
|
83
|
+
if id is None:
|
|
84
|
+
id = creatUUID()
|
|
85
|
+
return pyreqif.pyreqif.hierarchy(
|
|
86
|
+
**pyreqif.rif.reqif2py({"identifier": id, "longName": longName, "typeRef": typeRef, "lastChange": lastChange}))
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def createHierarchElement(reqid, id=None, lastChange=datetime.datetime.today().isoformat("T", "seconds")):
|
|
90
|
+
if id is None:
|
|
91
|
+
id = creatUUID()
|
|
92
|
+
return pyreqif.pyreqif.hierarchy(
|
|
93
|
+
**pyreqif.rif.reqif2py({"identifier": id, "lastChange": lastChange, "objectRef": reqid}))
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env python2
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
import os.path
|
|
4
|
+
from oletools import rtfobj
|
|
5
|
+
|
|
6
|
+
def extractOleData(rtfFilename):
|
|
7
|
+
createdFiles = []
|
|
8
|
+
rtfData = open(rtfFilename, 'rb').read()
|
|
9
|
+
rtfp = rtfobj.RtfObjParser(rtfData)
|
|
10
|
+
rtfp.parse()
|
|
11
|
+
for obj in rtfp.objects:
|
|
12
|
+
if b'Acro' in obj.class_name: # PDF
|
|
13
|
+
outfileName = os.path.splitext(rtfFilename)[0] + ".pdf"
|
|
14
|
+
outfileData = obj.oledata[obj.oledata.find(b"%PDF-1."):]
|
|
15
|
+
|
|
16
|
+
elif b'Package' == obj.class_name:
|
|
17
|
+
outfileName = os.path.join(os.path.dirname(rtfFilename), obj.filename)
|
|
18
|
+
outfileData = obj.olepkgdata
|
|
19
|
+
elif b'Word' in obj.class_name:
|
|
20
|
+
# if "PK\03\04" in obj.oledata:
|
|
21
|
+
# outfileData = obj.oledata[obj.oledata.find("PK\03\04"):]
|
|
22
|
+
# outfileName = os.path.splitext(rtfFilename)[0] + ".docx"
|
|
23
|
+
# else:
|
|
24
|
+
outfileName = os.path.splitext(rtfFilename)[0] + ".doc"
|
|
25
|
+
outfileData = obj.oledata
|
|
26
|
+
elif b'Excel' in obj.class_name:
|
|
27
|
+
if b"PK\03\04" in obj.oledata:
|
|
28
|
+
outfileData = obj.oledata[obj.oledata.find("PK\03\04"):]
|
|
29
|
+
outfileName = os.path.splitext(rtfFilename)[0] + ".xlsx"
|
|
30
|
+
else:
|
|
31
|
+
outfileData = obj.oledata
|
|
32
|
+
outfileName = os.path.splitext(rtfFilename)[0] + ".xls"
|
|
33
|
+
else:
|
|
34
|
+
pass
|
|
35
|
+
createdFiles.append(outfileName)
|
|
36
|
+
|
|
37
|
+
outfile = open(outfileName, "wb")
|
|
38
|
+
outfile.write(outfileData)
|
|
39
|
+
outfile.close()
|
|
40
|
+
|
|
41
|
+
return createdFiles
|
pyreqif/html.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env python2
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
import io
|
|
5
|
+
import os.path
|
|
6
|
+
import pyreqif.ole2rtf
|
|
7
|
+
from lxml import etree
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# reload(sys)
|
|
12
|
+
# sys.setdefaultencoding('utf8')
|
|
13
|
+
|
|
14
|
+
def create_html(item, cols, depth, basepath):
|
|
15
|
+
tempReq = {}
|
|
16
|
+
htmlOutput = "<td>"
|
|
17
|
+
htmlOutput += "+" * depth
|
|
18
|
+
|
|
19
|
+
for col, value in item.items():
|
|
20
|
+
if col not in cols:
|
|
21
|
+
continue
|
|
22
|
+
if type(value) is not bytes:
|
|
23
|
+
value = value.encode("utf8")
|
|
24
|
+
if value is not None:
|
|
25
|
+
if b"<" in value and b">" in value:
|
|
26
|
+
try:
|
|
27
|
+
tree = etree.parse(io.BytesIO(value))
|
|
28
|
+
root = tree.getroot()
|
|
29
|
+
for element in root.iter("object"):
|
|
30
|
+
rtfFilename = os.path.join(basepath, element.attrib["data"])
|
|
31
|
+
files = pyreqif.ole2rtf.ole2rtf(rtfFilename)
|
|
32
|
+
if rtfFilename.endswith("ole"):
|
|
33
|
+
if len(files) > 0:
|
|
34
|
+
if "name" in element.attrib:
|
|
35
|
+
name = element.attrib["name"]
|
|
36
|
+
else:
|
|
37
|
+
name = ""
|
|
38
|
+
|
|
39
|
+
for key in element.attrib:
|
|
40
|
+
del element.attrib[key]
|
|
41
|
+
element.tag = "a"
|
|
42
|
+
element.set("href", files[0])
|
|
43
|
+
element.text = name
|
|
44
|
+
imgElement = etree.Element("img")
|
|
45
|
+
imgElement.set("src", os.path.splitext(files[0])[0] + ".png")
|
|
46
|
+
element.append(imgElement)
|
|
47
|
+
else:
|
|
48
|
+
element.tag = "div"
|
|
49
|
+
else:
|
|
50
|
+
element.tag = "div"
|
|
51
|
+
value = etree.tostring(root)
|
|
52
|
+
value = value.encode("utf8")
|
|
53
|
+
except:
|
|
54
|
+
pass
|
|
55
|
+
tempReq[col] = value
|
|
56
|
+
for col in cols:
|
|
57
|
+
htmlOutput += "<td>"
|
|
58
|
+
if col in tempReq:
|
|
59
|
+
if tempReq[col] is not None:
|
|
60
|
+
htmlOutput += tempReq[col].decode("utf8")
|
|
61
|
+
else:
|
|
62
|
+
htmlOutput += ""
|
|
63
|
+
htmlOutput += "</tr><tr>"
|
|
64
|
+
return htmlOutput
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def dump(myDoc, outfile, basepath=None):
|
|
68
|
+
if basepath is None:
|
|
69
|
+
basepath = os.path.dirname(outfile)
|
|
70
|
+
|
|
71
|
+
for specification in myDoc.specificationList:
|
|
72
|
+
htmlOutput = u"<table border=1><tr><td>"
|
|
73
|
+
cols = myDoc.fields
|
|
74
|
+
|
|
75
|
+
colNr = 0
|
|
76
|
+
for col in cols:
|
|
77
|
+
htmlOutput += u"<td>" + col
|
|
78
|
+
colNr += 1
|
|
79
|
+
|
|
80
|
+
htmlOutput += u"</tr><tr>"
|
|
81
|
+
|
|
82
|
+
for child in myDoc.hierarchy:
|
|
83
|
+
for item, depth in myDoc.hierach_iterator(child, cols):
|
|
84
|
+
htmlOutput += create_html(item, cols, depth, basepath)
|
|
85
|
+
# for req in specification:
|
|
86
|
+
# reqObj = myDoc.getReqById(req)
|
|
87
|
+
# htmlOutput += create_html(myDoc.flatReq(reqObj, html=True), cols, 0, basepath)
|
|
88
|
+
htmlOutput += "</table>"
|
|
89
|
+
fp = open(outfile, "wb")
|
|
90
|
+
fp.write(bytes(htmlOutput, "utf8"))
|
|
91
|
+
fp.close()
|
pyreqif/ole2rtf.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env python2
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
import os.path
|
|
4
|
+
|
|
5
|
+
def ole2rtf(oleFilename):
|
|
6
|
+
if not oleFilename.endswith("ole"):
|
|
7
|
+
return []
|
|
8
|
+
targetFile = os.path.splitext(oleFilename)[0] + ".rtf"
|
|
9
|
+
fileContent = open(oleFilename, "rb").read()
|
|
10
|
+
outFile = open(targetFile, "wb")
|
|
11
|
+
outFile.write("{\\rtf1\\ansi\\deff3\\adeflang1025\n")
|
|
12
|
+
outFile.write(fileContent)
|
|
13
|
+
outFile.write("\n}")
|
|
14
|
+
outFile.close()
|
|
15
|
+
return [targetFile]
|
|
16
|
+
# outFile = open()
|