1
1
# Copyright 2010 Twitter, Inc.
2
2
# Copyright 2010 Larry Gadea <[email protected] >
3
+ # Copyright 2010 Matt Freels <[email protected] >
3
4
#
4
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
6
# not use this file except in compliance with the License. You may obtain
27
28
psyco .full ()
28
29
except :
29
30
pass
30
-
31
+
31
32
from BitTornado .download_bt1 import BT1Download , defaults , parse_params , get_usage , get_response
32
33
from BitTornado .RawServer import RawServer , UPnP_ERROR
33
34
from random import seed
@@ -91,17 +92,17 @@ def __init__(self):
91
92
92
93
def finished (self ):
93
94
global doneFlag
94
-
95
+
95
96
self .done = True
96
97
self .percentDone = '100'
97
98
self .timeEst = 'Download Succeeded!'
98
99
self .downRate = ''
99
100
#self.display()
100
-
101
+
101
102
global isPeer
102
-
103
+
103
104
print "done and done"
104
-
105
+
105
106
if isPeer :
106
107
if os .fork ():
107
108
os ._exit (0 )
@@ -118,7 +119,7 @@ def finished(self):
118
119
119
120
t = threading .Timer (30.0 , ok_close_now )
120
121
t .start ()
121
-
122
+
122
123
def failed (self ):
123
124
self .done = True
124
125
self .percentDone = '0'
@@ -135,12 +136,12 @@ def error(self, errormsg):
135
136
print errormsg
136
137
doneFlag .set ()
137
138
138
- def display (self , dpflag = Event (), fractionDone = None , timeEst = None ,
139
+ def display (self , dpflag = Event (), fractionDone = None , timeEst = None ,
139
140
downRate = None , upRate = None , activity = None ,
140
141
statistics = None , ** kws ):
141
142
if self .last_update_time + 0.1 > clock () and fractionDone not in (0.0 , 1.0 ) and activity is not None :
142
143
return
143
- self .last_update_time = clock ()
144
+ self .last_update_time = clock ()
144
145
if fractionDone is not None :
145
146
self .percentDone = str (float (int (fractionDone * 1000 )) / 10 )
146
147
if timeEst is not None :
@@ -174,7 +175,7 @@ def display(self, dpflag = Event(), fractionDone = None, timeEst = None,
174
175
#print 'seed status: ', self.seedStatus
175
176
#print 'peer status: ', self.peerStatus
176
177
#stdout.flush()
177
- dpflag .set ()
178
+ dpflag .set ()
178
179
179
180
def chooseFile (self , default , size , saveas , dir ):
180
181
self .file = '%s (%.1f MB)' % (default , float (size ) / (1 << 20 ))
@@ -212,7 +213,7 @@ def run(params):
212
213
213
214
myid = createPeerID ()
214
215
seed (myid )
215
-
216
+
216
217
global doneFlag
217
218
doneFlag = Event ()
218
219
def disp_exception (text ):
@@ -245,7 +246,7 @@ def disp_exception(text):
245
246
dow = BT1Download (h .display , h .finished , h .error , disp_exception , doneFlag ,
246
247
config , response , infohash , myid , rawserver , listen_port ,
247
248
configdir )
248
-
249
+
249
250
if not dow .saveAs (h .chooseFile , h .newpath ):
250
251
break
251
252
@@ -283,9 +284,9 @@ def disp_exception(text):
283
284
sys .exit (1 )
284
285
285
286
argv = ["--responsefile" , sys .argv [2 ],
286
- "--saveas" , sys .argv [3 ],
287
+ "--saveas" , sys .argv [3 ],
287
288
"--ip" , sys .argv [4 ]]
288
-
289
+
289
290
isPeer = sys .argv [1 ] == "peer"
290
-
291
+
291
292
run (argv [1 :])
0 commit comments