-
Notifications
You must be signed in to change notification settings - Fork 7
/
edsbreakerdemo v1.5.2.py
208 lines (172 loc) · 5.98 KB
/
edsbreakerdemo v1.5.2.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# edsbreaker v1.5.2
# programmed by Nathan Zuzow, 9/6/18-9/11/18
import datetime
import glob
import os
import re
import shutil
import sys
import time
import zipfile
from xml.etree import ElementTree as et
from pathlib import Path
version = 'demo v1.5.2'
# setting the base path
basePath = os.path.dirname(os.path.realpath(__file__))
# wildcard searching .eds
edsWildcard = '*.eds'
edsTarget = os.path.join(basePath, edsWildcard)
allEds = glob.glob(edsTarget)
listEds = list(allEds)
lenlistEds = str(len(listEds))
edsParsed = '.eds Files Parsed:'
eds = " ".join([edsParsed, lenlistEds])
print(eds)
# wildcard searching .sds
sdsWildcard = '*.sds'
sdsTarget = os.path.join(basePath, sdsWildcard)
allSds = glob.glob(sdsTarget)
listSds = list(allSds)
lenlistSds = str(len(listSds))
sdsParsed = '.sds Files Parsed:'
sds = " ".join([sdsParsed, lenlistSds])
print(sds)
# merging all data
allData = allEds + allSds
listData = list(allData)
# batch .zip generation
extPath = os.path.join(basePath, 'ext')
extpathTest = Path(extPath)
if extpathTest.is_dir():
pass
else:
os.mkdir(extPath)
for filePath in allData:
fileName = os.path.basename(filePath)
noExt = fileName[:-4]
zipPath = os.path.join(extPath, noExt + '.zip')
shutil.copyfile(filePath, zipPath)
# wildcard searching .zips
zipWildcard = '*.zip'
zipTarget = os.path.join(extPath, zipWildcard)
allZips = glob.glob(zipTarget)
listZips = list(allZips)
zips = print(".zip Files Created:", len(listZips), '\n')
# extract zips to individual folders in ext
for zipFile in allZips:
filePath = os.path.join(extPath, zipFile)
fileDest = os.path.join(extPath, zipFile[:-4])
filedestTest = Path(fileDest)
if filedestTest.is_dir():
pass
else:
os.mkdir(fileDest)
unzipMe = zipfile.ZipFile(filePath)
unzipMe.extractall(fileDest)
unzipMe.close()
# parse the xml and text for each data file
for filePath in allData:
fileName = os.path.basename(filePath)
noExt = fileName[:-4]
dataFolder = os.path.join(extPath, noExt)
xmlfileLoc = os.path.join(dataFolder, "apldbio\\sds")
os.chdir(xmlfileLoc)
# establishing text path
textPath = os.path.join(basePath, noExt + '.txt')
textFile = open(textPath, 'a', encoding = 'utf-8')
# converting manifest and messages to .txt
maniPath = os.path.join(xmlfileLoc, 'manifest.mf')
maniDest = os.path.join(xmlfileLoc, 'manifest.txt')
shutil.copy(maniPath, maniDest)
messPath = os.path.join(xmlfileLoc, 'messages.log')
messDest = os.path.join(xmlfileLoc, 'messages.txt')
# establishing xml element
tree = et.parse('experiment.xml')
root = tree.getroot()
# printout
textFile.write('This file was generated by edsbreaker ' + version + ' on ' + str(datetime.datetime.now()) + '\n')
textFile.write(eds + '\n' + sds + '\n' + '\n')
for element in root.iter('FileName'):
title = 'Filename:'
elementStr = str(element.text)
joinString = " ".join([title, elementStr])
print(joinString)
textFile.write(joinString + '\n')
for element in root.iter('InstrumentTypeId'):
title = 'Instrument:'
elementStr = str(element.text)
joinString = " ".join([title, elementStr])
print(joinString)
textFile.write(joinString + '\n')
for element in root.findall('.//*[@key="softwareVersion"]/String'):
title = 'Software Version:'
elementStr = str(element.text)
joinString = " ".join([title, elementStr])
print(joinString)
textFile.write(joinString + '\n')
manifest = open('manifest.txt', 'r', encoding = 'utf-8')
for line in manifest:
if re.match("(.*)(I|i)mplementation-Version(.*)", line):
newline = 'Software Version:' + line[24:]
# newline = newline.rstrip('\n')
print(newline)
textFile.write(newline)
manifest.close()
try:
shutil.copy(messPath, messDest)
messages = open('messages.txt', 'r', encoding = 'utf-8')
messages.close()
except FileNotFoundError:
pass
# print('**No messages.txt file available.**')
for element in root.findall('.//*[@key="RUNTITLE"]/String'):
title = 'Instrument Serial:'
elementStr = str(element.text)
joinString = " ".join([title, elementStr])
print(joinString[0:28])
textFile.write(joinString + '\n')
for element in root.findall('.//*[@key="instrumentSerialNumber"]/String'):
title = 'Instrument Serial:'
elementStr = str(element.text)
joinString = " ".join([title, elementStr])
print(joinString)
textFile.write(joinString + '\n')
for element in root.findall('.//*[@key="blockSerialNumber"]/String'):
title = 'Block Serial:'
elementStr = str(element.text)
joinString = " ".join([title, elementStr])
print(joinString)
textFile.write(joinString + '\n')
for element in root.findall("./Type/Name"):
title = 'Experiment Type:'
elementStr = (element.text)
joinString = " ".join([title, elementStr])
print(joinString)
textFile.write((joinString) + '\n')
for element in root.findall("./ChemistryType"):
title = 'Chemistry:'
elementStr = str(element.text)
joinString = " ".join([title, elementStr])
print(joinString)
textFile.write(joinString + '\n')
for element in root.findall("./RunState"):
title = 'Run State:'
elementStr = str(element.text)
joinString = " ".join([title, elementStr])
print(joinString)
textFile.write(joinString + '\n')
print('\n' + '\n')
textFile.close()
# remove the ext directory
os.chdir(basePath)
shutil.rmtree('ext')
# text cleanout for troubleshooting
##txtWildcard = '*.txt'
##txtTarget = os.path.join(basePath, txtWildcard)
##allTxt = glob.glob(txtTarget)
##listTxt = list(allTxt)
##print(listTxt)
##
##for textFile in listTxt:
## os.remove(textFile)
# WIP: compile to .exe