3 import pytx
, traceback
, sys
, logging
5 from tord
.pyro
import *
6 from tord
.common
import *
13 def __init__(self
, flags
=0, size
=5):
14 pytx
.List
.__init
__(self
, flags
)
20 self
.add(self
.count
, text
)
26 def size_cb(self
, s
, d
):
29 class Status(pytx
.List
):
30 def __init__(self
, core
, flags
= 0):
31 pytx
.List
.__init
__(self
, flags
)
34 self
.keys
= ["download_rate", "download_limit", "upload_rate", "upload_limit", "num_peers", "dht"]
35 self
.format
= [fspeed
, fspeed
, fspeed
, fspeed
, fpeers
, lambda x
: x
<0 and "off" or fpeers(x
)]
39 data
= self
.core
.get_session_status(self
.keys
)
40 status
= [f(v
) for k
, f
, v
in zip(self
.keys
, self
.format
, data
)]
41 text
= "Download[%6s|%6s] Upload[%6s|%6s] Peers[%3s] DHT[%3s]" % tuple(status
)
46 def size_cb(self
, s
, d
):
56 self
.config
= Config("torc.conf", DEFAULT_PREFS
)
57 self
.core
= self
.get_core()
60 l
= Views(pytx
.FOCUS|pytx
.SCROLL|pytx
.SEPARATOR|pytx
.TITLES|pytx
.HIGHLIGHT
, 6)
61 l
.view_add(Torrents(self
.core
))
62 l
.view_add(Files(self
.core
))
63 l
.view_add(Peers(self
.core
))
65 b
= pytx
.Box(pytx
.VERT
, pytx
.ROOT|pytx
.BORDER
)
69 b
.add(l
); b
.add(m
); b
.add(s
)
72 stream
=FakeIO(m
.msg
, m
.draw
)
73 logging
.root
.handlers
[0].stream
= stream
77 l
.refresh(update
=True)
80 "update": lambda c
,i
,m
: l
.refresh(update
=True, sort
=False, args
=(c
,i
)),
81 "sort": lambda c
,i
,m
: l
.refresh(update
=True, sort
=True, args
=(c
,i
)),
82 "remove": lambda c
,i
,m
: l
.refresh(remove
=i
),
89 def message(self
, msg
):
94 try: self
.events
[subject
](self
.get_core(), *alert
)
95 except: log
.info("%-20s %s" % (str(subject
)+':', alert
[1]))
100 logging
.root
.handlers
[0].stream
= sys
.stderr
104 if len(sys
.argv
) == 2: host
= sys
.argv
[1]
106 PyroClient(TXTor
, host
)