Skip to content

Commit 3a07882

Browse files
committed
Integrated
1 parent f5259d3 commit 3a07882

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

reprounzip-vis/reprounzip_vis/__init__.py

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
import BaseHTTPServer
33
import SocketServer
44
import mimetypes
5+
import os
6+
import pkg_resources
7+
from rpaths import Path
58
import shutil
9+
import tempfile
610
import webbrowser
711

8-
import pkg_resources
9-
12+
from reprounzip.common import RPZPack
1013
from reprounzip.unpackers.common import COMPAT_OK
11-
14+
from reprounzip.unpackers.graph import generate
1215

1316
__version__ = '0.1'
1417

@@ -21,7 +24,9 @@ def do_GET(self):
2124
if self.path == '/provenance.json':
2225
self.send_response(200)
2326
self.send_header('Content-Type', 'application/json')
24-
self.wfile.write(self.provenance_json)
27+
self.end_headers()
28+
with open(self.provenance_json, 'rb') as f:
29+
shutil.copyfileobj(f, self.wfile)
2530
else:
2631
try:
2732
f = pkg_resources.resource_stream('reprounzip_vis',
@@ -35,30 +40,41 @@ def do_GET(self):
3540
else:
3641
ctype = mimetypes.guess_type(self.path)[0]
3742
self.send_header('Content-Type', ctype)
43+
self.end_headers()
3844
shutil.copyfileobj(f, self.wfile)
3945
f.close()
4046

4147

4248
def show_vis(args):
4349
# Extract JSON from package
44-
VisHTTPHandler.provenance_json = '{}' # TODO
45-
46-
# Serve static files and JSON document to browser
47-
port = 8003
48-
49-
httpd = SocketServer.TCPServer(('', port), VisHTTPHandler)
50-
print("serving at port %d" % port)
51-
52-
# Open web browser
53-
webbrowser.open('http://localhost:%d/index.html' % port)
54-
55-
# Serve until killed
50+
fd, json_file = tempfile.mkstemp(prefix='reprounzip_vis_', suffix='.json')
5651
try:
57-
httpd.serve_forever()
58-
except KeyboardInterrupt:
59-
pass
52+
rpz_pack = RPZPack(args.pack)
53+
with rpz_pack.with_config() as config:
54+
with rpz_pack.with_trace() as trace:
55+
generate(Path(json_file), config, trace, graph_format='json')
56+
os.close(fd)
57+
58+
VisHTTPHandler.provenance_json = json_file
59+
60+
# Serve static files and JSON document to browser
61+
port = 8002
62+
63+
httpd = SocketServer.TCPServer(('', port), VisHTTPHandler)
64+
print("serving at port %d" % port)
65+
66+
# Open web browser
67+
webbrowser.open('http://localhost:%d/index.html' % port)
68+
69+
# Serve until killed
70+
try:
71+
httpd.serve_forever()
72+
except KeyboardInterrupt:
73+
pass
74+
finally:
75+
httpd.server_close()
6076
finally:
61-
httpd.server_close()
77+
os.remove(json_file)
6278

6379

6480
def setup_vis(parser, **kwargs):

0 commit comments

Comments
 (0)