예제 #1
0
 def OnTimer(self, event):
     stats = self.torrentCreator.getStats()
     processed, total = scaleInt(10000, stats['processedFileSize'], stats['totalFileSize'])
     self.totalProgressBar.SetRange(total)
     self.totalProgressBar.SetValue(processed)
     self.totalProgressText.SetLabel('%s/%s' % (dataAmountToString(stats['processedFileSize']).strip(), dataAmountToString(stats['totalFileSize'])))
     self.currentProgressBar.SetValue(round(stats['currentFileProgress']*10000, 0))
     self.currentProgressText.SetLabel('%.2f' % (round(stats['currentFileProgress']*100, 2))+'%')
     self.currentFileName.SetLabel(stats['currentFileName'])
     self.currentFileProgress.SetLabel('%i/%i Files' % (stats['currentFileNumber'], stats['amountOfFiles']))
     self.Update()
     self.progressBoxSizer.Layout()
     
     self._updatePieceEstimates(stats['totalFileSize'])
     
     if not self.torrentCreator.isRunning():
         #finished
         self.createButton.SetLabel(u'Create')
         self.pieceBoxUpdateButton.Enable()
         self.Update()
         self.progressBoxSizer.Layout()
         self.updateTimer.Stop()
         
         lastError = self.torrentCreator.getLastError()
         if lastError is None:
             #creation succeeded
             showInfoMessage(self, u'The torrent was successfuly created.')
         else:
             #creation failed
             showErrorMessage(self, u'The creation of the torrent failed:\n%s', lastError.reason)
         self.torrentCreator.reset()
예제 #2
0
파일: Gui.py 프로젝트: kytvi2p/i2p.pybit
 def OnAddFromUrl(self, event):
     #torrentpath
     downloadDefaultDir = self.config.get('paths','downloadFolder')
     
     #let user enter a url
     diag = wx.TextEntryDialog(self, message='Please enter the http url of the torrent file:', caption='Enter url', defaultValue='http://')
     
     if diag.ShowModal() == wx.ID_OK:
         #user did select something
         torrentUrl = diag.GetValue()
         
         #directory in which the download data should be stored
         saveDiag = wx.DirDialog(self, message='Select the directory in which the downloaded data should be stored',\
                                 defaultPath=downloadDefaultDir, style=wx.DD_NEW_DIR_BUTTON)
         if saveDiag.ShowModal() == wx.ID_OK:
             #user selected something
             savePath = saveDiag.GetPath()
             
             #load torrents one by one
             self.log.info('Adding torrent with data path "%s"', savePath)
             try:
                 self.torrentList.addTorrentByUrl(torrentUrl, savePath)
             except MultiBtException, e:
                 self.log.error('Failed to add torrent, reason: %s', e.reason)
                 showErrorMessage(self, '%s.', e.reason)
             except Exception, e:
                 self.log.critical('Internal error while adding torrent:\n%s', logTraceback())
                 showErrorMessage(self, 'Internal error, torrent not added.\n%s.', logTraceback())
예제 #3
0
 def OnCreateButton(self, event):
     if self.createButton.GetLabel() == u'Abort':
         #currently creating a torrent, abort
         self._abort()
         
     else:
         #not creating a torrent, create one
         if self.dataPath.GetValue() == u'':
             showErrorMessage(self, u'The path to the file or directory, for which a torrent should be created, is not set! (field "Files>File")')
             
         elif self.torrentPath.GetValue() == u'':
             showErrorMessage(self, u'The filepath for the torrent, which should be created, is not set! (field "Files>Torrent")')
             
         elif self.pieceSize.GetValue() == u'':
             showErrorMessage(self, u'There is no piece size selected! (field "Piece size > Piece size")')
             
         elif self.trackerList.GetCount() == 0:
             showErrorMessage(self, u'There is no tracker configured but at least one is required! (box "Tracker")')
             
         else:
             #everything ok or at least useable, get values
             torrentPath = self.torrentPath.GetValue()
             dataPath = self.dataPath.GetValue()
             pieceSize = self.pieceSizeMapper[self.pieceSize.GetValue()]
             mainTracker = self.trackerList.GetString(0)
             
             if self.trackerList.GetCount() > 1:
                 trackerList = [[trackerUrl] for trackerUrl in self.trackerList.GetStrings()]
             else:
                 trackerList = None
                 
             if self.creationDate.GetValue() == True:
                 creationDate = int(round(time(),0))
             else:
                 creationDate = None
             
             createdBy = self.createdBy.GetValue()
             if createdBy == '':
                 createdBy = None
                 
             comment = self.comment.GetValue()
             if comment == '':
                 comment = None
             
             #start torrent creation
             self.torrentCreator.create(torrentPath, dataPath, pieceSize, mainTracker, trackerList, creationDate, comment, createdBy)
             
             #disable update button
             self.pieceBoxUpdateButton.Disable()
             
             #adjust button label
             self.createButton.SetLabel(u'Abort')
             self.Update()
             self.progressBoxSizer.Layout()
             
             #start timer
             self.updateTimer.Start(250)
예제 #4
0
 def OnTrackerMoveToGroup(self):
     trackerIdx = self.trackerUrlList.GetFirstSelected()
     if trackerIdx == -1:
         #no tracker selected
         showErrorMessage(self, 'You need to select a tracker, before you can move it to a different group!')
     else:
         #a tracker was selected
         diag = wx.SingleChoiceDialog(self, message='Please select the new group for this tracker:', caption='Select group', choices=[tier['groupName'] for tier in self.trackerInfo]) 
         if diag.ShowModal() == wx.ID_OK:
             #user did hit ok
             newGroupIdx = diag.GetSelection()
             if not newGroupIdx == self.selectedGroup:
                 #not the current one
                 tracker = self.trackerInfo[self.selectedGroup]['groupTracker'][trackerIdx]
                 del self.trackerInfo[self.selectedGroup]['groupTracker'][trackerIdx]
                 self.trackerInfo[newGroupIdx]['groupTracker'].append(tracker)
                 
                 #move selection
                 self.trackerGroupList.Select(self.selectedGroup, on=0)
                 self.trackerGroupList.Select(newGroupIdx, on=1)
예제 #5
0
 def OnTrackerChangeUrl(self):
     trackerIdx = self.trackerUrlList.GetFirstSelected()
     if trackerIdx == -1:
         #no tracker selected
         showErrorMessage(self, 'You need to select a tracker, before you can change its url!')
     else:
         #a tracker was selected
         tracker = self.trackerInfo[self.selectedGroup]['groupTracker'][trackerIdx]
         diag = wx.TextEntryDialog(self, message='Please enter the new url for this tracker:', caption='Enter url', defaultValue=tracker['trackerUrl'])
     
         if diag.ShowModal() == wx.ID_OK:
             #user did hit ok
             trackerUrl = diag.GetValue()
             if i2pHttpUrlRegexObj.match(trackerUrl) is None:
                 #invalid url
                 showErrorMessage(self, 'The url "%s" is not a valid i2p http url!', trackerUrl)
             else:
                 #valid
                 tracker['trackerUrl'] = trackerUrl
                 self.trackerUrlList.dataUpdate()
예제 #6
0
 def OnTrackerAdd(self, event):
     if self.selectedGroup is None:
         #no group selected
         showErrorMessage(self, 'You need to select a tracker group, before you can add a tracker!')
     else:
         #group selected, go on
         tier = self.trackerInfo[self.selectedGroup]['groupTracker']
         trackerUrl = self.trackerAnnounceUrl.GetValue()
         if i2pHttpUrlRegexObj.match(trackerUrl) is None:
             #invalid url
             showErrorMessage(self, 'The url "%s" is not a valid i2p http url!', trackerUrl)
         else:
             #valid
             trackerPos = self.trackerUrlList.GetFirstSelected()
             if trackerPos == -1:
                 trackerPos = 0
             else:
                 trackerPos += 1
                 
             tier.insert(trackerPos, {'tier':self.selectedGroup + 1,
                                      'tierPos':trackerPos + 1,
                                      'trackerUrl':trackerUrl,
                                      'trackerId':self.nextTrackerId,
                                      'active':False,
                                      'announceTryCount':None,
                                      'announceTryTime':None,
                                      'announceSuccessCount':None,
                                      'announceSuccessTime':None,
                                      'lastAnnounceResult':'None',
                                      'scrapeTryCount':None,
                                      'scrapeTryTime':None,
                                      'scrapeSuccessCount':None,
                                      'scrapeSuccessTime':None,
                                      'seeds':None,
                                      'leeches':None,
                                      'downloads':None})
             self.nextTrackerId += 1
             
             self.trackerUrlList.dataUpdate()
예제 #7
0
 def OnPieceStatUpdateButton(self, event):
     if self.dataPath.GetValue() == u'':
         showErrorMessage(self, u'The path to the file or directory, for which a torrent should be created, is not set! (field "Files>File")')
         
     elif self.pieceSize.GetValue() == u'':
         showErrorMessage(self, u'There is no piece size selected! (field "Piece size > Piece size")')
         
     else:
         try:
             self.torrentCreator.getFiles(self.dataPath.GetValue())
             stats = self.torrentCreator.getStats()
             self._updatePieceEstimates(stats['totalFileSize'])
             
         except TorrentCreatorException, tce:
             showErrorMessage(self, u'%s', tce.reason)
예제 #8
0
파일: Gui.py 프로젝트: kytvi2p/i2p.pybit
 def OnAddFromFile(self, event):
     #torrentpath
     torrentDefaultDir = self.config.get('paths','torrentFolder')
     downloadDefaultDir = self.config.get('paths','downloadFolder')
     
     #let user select a torrent
     diag = wx.FileDialog(self, message='Select the torrent to open',defaultDir=torrentDefaultDir,\
                          wildcard='Torrent files (*.torrent)|*.torrent|All files (*.*)|*.*',\
                          style=wx.OPEN | wx.MULTIPLE)
     
     if diag.ShowModal() == wx.ID_OK:
         #user did select something
         torrentPaths = diag.GetPaths()
         
         #directory in which the download data should be stored
         saveDiag = wx.DirDialog(self, message='Select the directory in which the downloaded data should be stored',\
                                 defaultPath=downloadDefaultDir,style=wx.DD_NEW_DIR_BUTTON)
         if saveDiag.ShowModal() == wx.ID_OK:
             #user selected something
             savePath = saveDiag.GetPath()
             
             #load torrents one by one
             for torrentPath in torrentPaths:
                 self.log.info('Trying to read torrent file from "%s"', torrentPath)
                 try:
                     fl = open(torrentPath, 'rb')
                     with fl:
                         data = fl.read()
                 except (IOError, OSError):
                     data = None
                 
                 if data is None:
                     #failed to read file
                     self.log.error('Failed to read torrent file from "%s", torrent not added', torrentPath)
                     showErrorMessage(self, 'Failed to read torrent file from "%s".', torrentPath)
                 else:
                     #worked
                     self.log.info('Adding torrent with data path "%s"', savePath)
                     try:
                         self.torrentList.addTorrentByFile(data, savePath)
                     except MultiBtException, e:
                         self.log.error('Failed to add torrent, reason: %s', e.reason)
                         showErrorMessage(self, '%s.', e.reason)
                     except Exception, e:
                         self.log.critical('Internal error while adding torrent:\n%s', logTraceback())
                         showErrorMessage(self, 'Internal error, torrent not added.\n%s.', logTraceback())