-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphScript.py
More file actions
53 lines (42 loc) · 1.56 KB
/
Copy pathgraphScript.py
File metadata and controls
53 lines (42 loc) · 1.56 KB
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
#!/usr/bin/python
#import everything needed
from optparse import OptionParser
import xml.etree.ElementTree as ET
import subprocess
import sys
import os
#parse args
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename",
help = "xml file to read in", type="string", action="store")
parser.add_option("-g", "--gnuplot", action="store_false", dest="R")
parser.add_option("-r", "--R", action="store_true", dest="R")
(option, args) = parser.parse_args()
if(len(option.filename) <= 0):
sys.exit(0)
R = False;
if(option.R):
R = True;
#set up xml tree
tree = ET.parse(option.filename)
root = tree.getroot()
#create directory to dump images and files into
directory = 'graphs'
if not os.path.exists(directory):
os.makedirs(directory)
for child in root:
with open(directory+'/'+child.get('name'), 'w') as output:
arr = child.text.split()
rows = int(child.get('rows'))
columns = int(child.get('columns'))
for x in range(0, len(arr)):
temp = str(x/columns) + ' ' + arr[x] + '\n'
output.write(temp)
output.close()
if(R):
command = 'r '+directory+'/'+child.get('name')+' '+directory+'/'+child.get('name')+'.png < rScript.R'
else:
command = 'gnuplot -e \"filename=\''+directory+'/'+child.get('name')+'\'; outputname=\''+directory+'/'+child.get('name')+'.png\'\" gnuplotScript.cfg'
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
tempOutput = process.communicate()[0]
os.remove(directory+'/'+child.get('name'))