2
2
import BaseHTTPServer
3
3
import SocketServer
4
4
import mimetypes
5
+ import os
6
+ import pkg_resources
7
+ from rpaths import Path
5
8
import shutil
9
+ import tempfile
6
10
import webbrowser
7
11
8
- import pkg_resources
9
-
12
+ from reprounzip .common import RPZPack
10
13
from reprounzip .unpackers .common import COMPAT_OK
11
-
14
+ from reprounzip . unpackers . graph import generate
12
15
13
16
__version__ = '0.1'
14
17
@@ -21,7 +24,9 @@ def do_GET(self):
21
24
if self .path == '/provenance.json' :
22
25
self .send_response (200 )
23
26
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 )
25
30
else :
26
31
try :
27
32
f = pkg_resources .resource_stream ('reprounzip_vis' ,
@@ -35,30 +40,41 @@ def do_GET(self):
35
40
else :
36
41
ctype = mimetypes .guess_type (self .path )[0 ]
37
42
self .send_header ('Content-Type' , ctype )
43
+ self .end_headers ()
38
44
shutil .copyfileobj (f , self .wfile )
39
45
f .close ()
40
46
41
47
42
48
def show_vis (args ):
43
49
# 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' )
56
51
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 ()
60
76
finally :
61
- httpd . server_close ( )
77
+ os . remove ( json_file )
62
78
63
79
64
80
def setup_vis (parser , ** kwargs ):
0 commit comments