Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyrasite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
pyrasite
Commits
0c62da64
Commit
0c62da64
authored
Feb 14, 2012
by
Luke Macken
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6 from ralphbean/feature/sparklines
Feature/sparklines I'm an idiot.
parents
2002fae9
26bb63d7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
12 deletions
+38
-12
pyrasite/reverse.py
pyrasite/reverse.py
+7
-1
pyrasite/tools/gui.py
pyrasite/tools/gui.py
+9
-11
pyrasite/utils.py
pyrasite/utils.py
+22
-0
No files found.
pyrasite/reverse.py
View file @
0c62da64
...
...
@@ -27,13 +27,16 @@ from StringIO import StringIO
from
pyrasite.ipc
import
PyrasiteIPC
class
ReverseConnection
(
threading
.
Thread
,
PyrasiteIPC
):
"""A payload that connects to a given host:port and receives commands"""
host
=
'127.0.0.1'
port
=
9001
def
__init__
(
self
,
port
=
None
):
def
__init__
(
self
,
host
=
None
,
port
=
None
):
super
(
ReverseConnection
,
self
).
__init__
()
self
.
sock
=
None
if
host
:
self
.
host
=
host
if
port
:
self
.
port
=
port
...
...
@@ -64,7 +67,10 @@ class ReverseConnection(threading.Thread, PyrasiteIPC):
class
ReversePythonConnection
(
ReverseConnection
):
"""A reverse Python connection payload.
Executes Python commands and returns the output.
"""
def
on_command
(
self
,
cmd
):
buffer
=
StringIO
()
sys
.
stdout
=
buffer
...
...
pyrasite/tools/gui.py
View file @
0c62da64
...
...
@@ -33,7 +33,7 @@ from meliae import loader
from
gi.repository
import
GLib
,
GObject
,
Pango
,
Gtk
,
WebKit
import
pyrasite
from
pyrasite.utils
import
setup_logger
,
run
from
pyrasite.utils
import
setup_logger
,
run
,
humanize_bytes
log
=
logging
.
getLogger
(
'pyrasite'
)
...
...
@@ -321,12 +321,12 @@ class PyrasiteWindow(Gtk.Window):
cpu_user
=
cputimes
.
user
,
cpu_sys
=
cputimes
.
system
,
mem
=
p
.
get_memory_percent
(),
mem_rss
=
meminfo
.
rss
,
mem_vms
=
meminfo
.
vms
,
mem_rss
=
humanize_bytes
(
meminfo
.
rss
)
,
mem_vms
=
humanize_bytes
(
meminfo
.
vms
)
,
read_count
=
io
.
read_count
,
read_bytes
=
io
.
read_bytes
,
read_bytes
=
humanize_bytes
(
io
.
read_bytes
)
,
write_count
=
io
.
write_count
,
write_bytes
=
io
.
write_bytes
,
write_bytes
=
humanize_bytes
(
io
.
write_bytes
)
,
)
open_files
=
p
.
get_open_files
()
...
...
@@ -417,19 +417,17 @@ class PyrasiteWindow(Gtk.Window):
def
test
():
# Inject jQuery
jquery
=
file
(
'jquery-1.7.1.min.js'
)
self
.
details
_view
.
execute_script
(
jquery
.
read
())
self
.
info
_view
.
execute_script
(
jquery
.
read
())
jquery
.
close
()
# Inject Sparkline
sparkline
=
file
(
'jquery.sparkline.min.js'
)
self
.
details
_view
.
execute_script
(
sparkline
.
read
())
self
.
info
_view
.
execute_script
(
sparkline
.
read
())
sparkline
.
close
()
# FIXME: alert works, sparkline does not...
self
.
details_view
.
execute_script
(
"""
self
.
info_view
.
execute_script
(
"""
jQuery(document).ready(function() {
jQuery('#cpu_graph').sparkline();
alert('FOO');
jQuery('#cpu_graph').sparkline([10,8,3,7,4,4,1]);
});
"""
)
...
...
pyrasite/utils.py
View file @
0c62da64
# http://code.activestate.com/recipes/577081-humanized-representation-of-a-number-of-bytes/
from
__future__
import
division
def
humanize_bytes
(
bytes
,
precision
=
1
):
"""Return a humanized string representation of a number of bytes."""
abbrevs
=
(
(
1
<<
50L
,
'PB'
),
(
1
<<
40L
,
'TB'
),
(
1
<<
30L
,
'GB'
),
(
1
<<
20L
,
'MB'
),
(
1
<<
10L
,
'kB'
),
(
1
,
'bytes'
)
)
if
bytes
==
1
:
return
'1 byte'
for
factor
,
suffix
in
abbrevs
:
if
bytes
>=
factor
:
break
return
'%.*f %s'
%
(
precision
,
bytes
/
factor
,
suffix
)
# Some useful functions based on code from Will Maier's 'ideal Python script'
# https://github.com/wcmaier/python-script
#
...
...
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