本文整理汇总了Python中status.Status.checkForFile方法的典型用法代码示例。如果您正苦于以下问题:Python Status.checkForFile方法的具体用法?Python Status.checkForFile怎么用?Python Status.checkForFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类status.Status
的用法示例。
在下文中一共展示了Status.checkForFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Peer
# 需要导入模块: from status import Status [as 别名]
# 或者: from status.Status import checkForFile [as 别名]
class Peer( threading.Thread ):
"""
Peer is the iplementation the interface defined in the provided peer.h file.
Peers run as their own thread, working through a queue of requests (rQueue)
"""
# ----------------
# PUBLIC INTERFACE
# ----------------
def join( self ):
"""
Notifies all peers that this peer is joining in the network.
"""
if self.joined:
return
logging.info( 'Joining BitTorrent network' )
self.joined = True
self.peerTCPServer = PeerTCPServer()
self.peerTCPServer.init( self.host, self.port, self )
connectSucess = False
for p in self.peers:
result = self.sendStatus( p , True )
connectSucess = connectSucess or result
if connectSucess:
return RETURNCODES['errOk']
else:
return RETURNCODES['errNoPeersFound']
def leave( self ):
"""
Notifies all peers that this peer no longer in the network.
"""
if not self.joined:
return
logging.info( 'Submitting request to leave network' )
package = { 'packageType': 'command',
'command': 'leave' }
self.rQueue.put( package )
return RETURNCODES['errOk']
def query( self, status ):
"""
Copies this peer's status into the given status.
Returns this peer's status (for good measure).
"""
self.status.copyStatus( status )
localStatus = self.status.getStatus()
print '---PEER STATUS----'
for f in localStatus:
print f['filename']
print f
print ''
return RETURNCODES['errOk']
def insert( self, filename ):
"""
Inserts the provided filename into the bittorent network.
"""
try:
filepath = os.path.join( os.getcwd(), self.filesDir, filename )
if not os.path.isfile( filepath ):
logging.error( 'File Invalid or does not exist: ' + filename )
return RETURNCODES['errUnknownWarning']
else:
logging.info( 'Submitting request to insert file: ' + filename )
filesize = os.path.getsize( filepath )
package = { 'packageType': 'command',
'command': 'insert',
'filename': filename,
'filepath': filepath,
'filesize': filesize }
self.rQueue.put( package )
return RETURNCODES['errOk']
except Exception as inst:
logging.error ( 'Exception while inserting file: ' + str( type( inst ) ) )
def remove( self, filename ):
"""Remove specified file from the network"""
if not self.status.checkForFile( filename ):
return RETURNCODES['errUnknownWarning']
package = { 'packageType': 'command',
'command': 'remove',
'filename': filename }
self.rQueue.put( package )
return RETURNCODES['errOk']
# --------------------------------
# PRIVATE METHODS (IMPLEMENTATION)
# --------------------------------
def run( self ):
#.........这里部分代码省略.........