Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
re6stnet
Commits
373d35f1
Commit
373d35f1
authored
Apr 08, 2016
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
demo: update graph without reloading the whole page
parent
0bb9d147
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
11 deletions
+28
-11
demo/demo
demo/demo
+28
-11
No files found.
demo/demo
View file @
373d35f1
...
@@ -306,13 +306,14 @@ if len(sys.argv) > 1:
...
@@ -306,13 +306,14 @@ if len(sys.argv) > 1:
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
_path_match = re.compile('/(.+)\.
html
$').match
_path_match = re.compile('/(.+)\.
(html|svg)
$').match
pages = 'ipv6', 'ipv4', 'tunnels'
pages = 'ipv6', 'ipv4', 'tunnels'
def do_GET(self):
def do_GET(self):
svg = None
svg = None
try:
try:
page = self.pages.index(self._path_match(self.path).group(1))
name, ext = self._path_match(self.path).groups()
page = self.pages.index(name)
except AttributeError, ValueError:
except AttributeError, ValueError:
if self.path == '/':
if self.path == '/':
self.send_response(302)
self.send_response(302)
...
@@ -322,7 +323,7 @@ if len(sys.argv) > 1:
...
@@ -322,7 +323,7 @@ if len(sys.argv) > 1:
self.send_error(404)
self.send_error(404)
return
return
if page
<
2:
if page
<
2:
svg
=
route_svg(page)
body
=
route_svg(page)
else:
else:
gv =
registry.Popen(('python',
'
-c
',
r
"""
if
1:
gv =
registry.Popen(('python',
'
-c
',
r
"""
if
1:
import
math
,
json
import
math
,
json
...
@@ -349,22 +350,38 @@ if len(sys.argv) > 1:
...
@@ -349,22 +350,38 @@ if len(sys.argv) > 1:
print '}'
print '}'
"""), stdout=subprocess.PIPE, cwd="..").communicate()[0]
"""), stdout=subprocess.PIPE, cwd="..").communicate()[0]
if gv:
if gv:
svg
= subprocess.Popen(('neato', '-Tsvg'),
body
= subprocess.Popen(('neato', '-Tsvg'),
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
).communicate(gv)[0]
).communicate(gv)[0]
if not
svg
:
if not
body
:
self.send_error(500)
self.send_error(500)
return
return
if ext == 'svg':
mt = 'image/svg+xml'
else:
mt = 'text/html'
mt = 'text/html'
body = """
<html>
body = """
<html>
<head><meta
http-equiv=
"refresh"
content=
"10"
/></head>
<head><script>
function
refresh
()
{
<body><span
style=
"position: absolute"
>
%s
</span>
var
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
'
GET
'
,
'
%s.svg
'
,
true
);
xhr
.
addEventListener
(
"
load
"
,
function
(
e
)
{
if
(
e
.
target
.
status
==
200
)
document
.
getElementsByTagName
(
"
svg
"
)[
0
].
outerHTML
=
e
.
target
.
responseXML
.
documentElement
.
outerHTML
;
});
xhr
.
addEventListener
(
"
error
"
,
function
(
e
)
{
clearTimeout
(
refresh_timer
);
});
xhr
.
send
();
}
</script></head>
<body
onload=
"refresh_timer = setInterval(refresh, 10000)"
>
<span
style=
"position: absolute"
>
%s
</span>
%s
%s
</body>
</body>
</html>
""" % (' '.join(x if i == page else
</html>
""" % (
name,
' '.join(x if i == page else
'
<a
href=
"%s.html"
>
%s
</a>
' % (x, x)
'
<a
href=
"%s.html"
>
%s
</a>
' % (x, x)
for i, x in enumerate(self.pages)),
for i, x in enumerate(self.pages)),
svg[svg
.find('
<svg
')
:
])
body[body
.find('
<svg
')
:
])
self
.
send_response
(
200
)
self
.
send_response
(
200
)
self
.
send_header
('
Content-Length
',
len
(
body
))
self
.
send_header
('
Content-Length
',
len
(
body
))
self
.
send_header
('
Content-type
',
mt
+
';
charset=
utf-8')
self
.
send_header
('
Content-type
',
mt
+
';
charset=
utf-8')
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment