Убрал ненужные запчасти

sandbox1
inpos 2016-03-10 20:45:10 +03:00
parent 39417e8e93
commit bdd454f049
1 changed files with 7 additions and 73 deletions

View File

@ -3,7 +3,7 @@
import sys, os import sys, os
import json import json
import chardet import chardet
STANDALONE = False
try: try:
from python_libtorrent import get_libtorrent from python_libtorrent import get_libtorrent
lt=get_libtorrent() lt=get_libtorrent()
@ -15,10 +15,7 @@ except Exception, e:
except Exception as e: except Exception as e:
strerror = e.args strerror = e.args
print(strerror) print(strerror)
if STANDALONE: raise
sys.exit(1)
else:
raise
from random import SystemRandom from random import SystemRandom
import time import time
@ -154,11 +151,9 @@ class TorrentFile(object):
self.index = index self.index = index
self.piece_length = int(self.pieceLength()) self.piece_length = int(self.pieceLength())
self.startPiece, self.endPiece = self.Pieces() self.startPiece, self.endPiece = self.Pieces()
self.pieces_deadlined = [False for x in range(self.endPiece - self.startPiece)] self.pieces_deadlined = [False] * (self.endPiece - self.startPiece)
self.offset = self.Offset() self.offset = self.Offset()
self.size = self.Size() self.size = self.Size()
def Index(self):
return tf.index
def Downloaded(self): def Downloaded(self):
return self.downloaded return self.downloaded
def Progress(self): def Progress(self):
@ -265,26 +260,6 @@ class TorrentFile(object):
return self.fileEntry.size return self.fileEntry.size
def IsComplete(self): def IsComplete(self):
return self.downloaded == self.size return self.downloaded == self.size
#######################################################################################
class TorrentDir(object):
tfs = None
entriesRead = int()
def __init__(self, tfs):
self.tfs = tfs
def Readdir(self, count):
info = self.tfs.TorrentInfo()
totalFiles = info.num_files()
read = self.entriesRead
toRead = totalFiles - read
if count >= 0 and count < toRead:
toRead = count
files = [None for x in range(toRead)]
for i in range(toRead):
files[i] = self.tfs.FileAt(read)
read += 1
return files
####################################################################################### #######################################################################################
@ -390,8 +365,6 @@ class TorrentFS(object):
def Open(self, name): def Open(self, name):
if self.shuttingDown or not self.HasTorrentInfo(): if self.shuttingDown or not self.HasTorrentInfo():
raise IOError raise IOError
if name == '/':
return TorrentDir(self)
return self.OpenFile(name) return self.OpenFile(name)
def checkPriorities(self): def checkPriorities(self):
for index, priority in enumerate(self.priorities): for index, priority in enumerate(self.priorities):
@ -655,10 +628,7 @@ class Pyrrent2http(object):
except Exception as e: except Exception as e:
strerror = e.args strerror = e.args
logging.error('Build torrent params error is (%s)' % (strerror,)) logging.error('Build torrent params error is (%s)' % (strerror,))
if STANDALONE: raise
sys.exit(1)
else:
raise
torrentParams['ti'] = torrent_info torrentParams['ti'] = torrent_info
else: else:
logging.info('Will fetch: %s' % (uri,)) logging.info('Will fetch: %s' % (uri,))
@ -668,10 +638,7 @@ class Pyrrent2http(object):
except Exception as e: except Exception as e:
strerror = e.args strerror = e.args
logging.error(strerror) logging.error(strerror)
if STANDALONE: raise
sys.exit(1)
else:
raise
torrentParams['ti'] = torrent_info torrentParams['ti'] = torrent_info
logging.info('Setting save path: %s' % (self.config.downloadPath,)) logging.info('Setting save path: %s' % (self.config.downloadPath,))
torrentParams['save_path'] = self.config.downloadPath torrentParams['save_path'] = self.config.downloadPath
@ -800,10 +767,7 @@ class Pyrrent2http(object):
except IOError as e: except IOError as e:
strerror = e.args strerror = e.args
logging.error(strerror) logging.error(strerror)
if STANDALONE: raise
sys.exit(1)
else:
raise
settings = self.session.get_settings() settings = self.session.get_settings()
if self.config.userAgent != '': if self.config.userAgent != '':
@ -832,10 +796,7 @@ class Pyrrent2http(object):
except ValueError as e: except ValueError as e:
strerror = e.args strerror = e.args
logging.error(strerror) logging.error(strerror)
if STANDALONE: raise
sys.exit(1)
else:
raise
self.session.add_dht_router(host, port) self.session.add_dht_router(host, port)
logging.info('Added DHT router: %s:%d' % (host, port)) logging.info('Added DHT router: %s:%d' % (host, port))
logging.info('Setting encryption settings') logging.info('Setting encryption settings')
@ -954,9 +915,6 @@ class Pyrrent2http(object):
def loop(self): def loop(self):
def sigterm_handler(_signo, _stack_frame): def sigterm_handler(_signo, _stack_frame):
self.forceShutdown = True self.forceShutdown = True
if STANDALONE:
import signal
signal.signal(signal.SIGTERM, sigterm_handler)
self.statsTicker = Ticker(30) self.statsTicker = Ticker(30)
self.saveResumeDataTicker = Ticker(5) self.saveResumeDataTicker = Ticker(5)
time_start = time.time() time_start = time.time()
@ -1066,27 +1024,3 @@ class Pyrrent2http(object):
logging.info('Aborting the session') logging.info('Aborting the session')
del self.session del self.session
logging.info('Bye bye') logging.info('Bye bye')
if STANDALONE:
sys.exit(0)
else:
return
if __name__ == '__main__':
STANDALONE = True
try:
import logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
pyrrent2http = Pyrrent2http()
pyrrent2http.parseFlags()
pyrrent2http.startSession()
pyrrent2http.startServices()
pyrrent2http.addTorrent()
pyrrent2http.startHTTP()
pyrrent2http.loop()
pyrrent2http.shutdown()
except KeyboardInterrupt:
pyrrent2http.shutdown()