def _write_to_collected(self, filename):
     #calculate root-hash
     sdef = SwiftDef()
     sdef.add_content(filename)
     sdef.finalize(self.session.get_swift_path(), destdir = self.session.get_torrent_collecting_dir())
     
     mfpath = os.path.join(self.session.get_torrent_collecting_dir(),sdef.get_roothash_as_hex())
     if not os.path.exists(mfpath):
         if os.path.exists(mfpath + ".mhash"): #indicating active swift download
             download = self.session.get_download(sdef.get_roothash())
             if download:
                 self.session.remove_download(download, removestate = True)
                 sleep(1)
             else:
                 os.remove(mfpath + ".mhash")
         
         try:
             shutil.copy(filename, mfpath)
             shutil.move(filename+'.mhash', mfpath+'.mhash')
             shutil.move(filename+'.mbinmap', mfpath+'.mbinmap')
             
         except:
             print_exc()
     
     return sdef, mfpath
Exemplo n.º 2
0
    def _write_to_collected(self, filename):
        #calculate root-hash
        sdef = SwiftDef()
        sdef.add_content(filename)
        sdef.finalize(self.session.get_swift_path(),
                      destdir=self.session.get_torrent_collecting_dir())

        mfpath = os.path.join(self.session.get_torrent_collecting_dir(),
                              sdef.get_roothash_as_hex())
        if not os.path.exists(mfpath):
            download = self.session.get_download(sdef.get_roothash())
            if download:
                self.session.remove_download(download, removestate=True)
                sleep(1)
            elif os.path.exists(mfpath +
                                ".mhash"):  #indicating failed swift download
                os.remove(mfpath + ".mhash")

            try:
                shutil.copy(filename, mfpath)
                shutil.move(filename + '.mhash', mfpath + '.mhash')
                shutil.move(filename + '.mbinmap', mfpath + '.mbinmap')

            except:
                print_exc()

        return sdef, mfpath
Exemplo n.º 3
0
    def notify_possible_torrent_roothash(self, roothash):
        keys = self.callbacks.keys()
        for key in keys:
            if key[1] == roothash:
                handle_lambda = lambda key=key: self._handleCallback(key, True)
                self.scheduletask(handle_lambda)

        sdef = SwiftDef(roothash)
        swiftpath = os.path.join(self.session.get_torrent_collecting_dir(),
                                 sdef.get_roothash_as_hex())
        if os.path.exists(swiftpath):
            tdef = TorrentDef.load(swiftpath)

            if self.torrent_db.hasTorrent(tdef.get_infohash()):
                self.torrent_db.updateTorrent(
                    tdef.get_infohash(),
                    swift_torrent_hash=sdef.get_roothash(),
                    torrent_file_name=swiftpath)
            else:
                self.torrent_db._addTorrentToDB(tdef,
                                                source="SWIFT",
                                                extra_info={
                                                    'filename': swiftpath,
                                                    'swift_torrent_hash':
                                                    roothash,
                                                    'status': 'good'
                                                },
                                                commit=True)
Exemplo n.º 4
0
    def __torrentdef_retrieved(self, tdef):
        infohash = tdef.get_infohash()
        if DEBUG:
            print >> sys.stderr, 'magnetrequester: received torrent', bin2str(
                infohash)

        #remove from requested list
        if infohash in self.requestedInfohashes:
            self.requestedInfohashes.remove(infohash)

            #save torrent
            torrent = self.torrent_db.getTorrent(infohash,
                                                 ['torrent_file_name'],
                                                 include_mypref=False)
            if torrent and torrent.get(
                    'torrent_file_name',
                    False) and not os.path.isabs(torrent['torrent_file_name']):
                torrent_filename = os.path.join(
                    self.metadatahandler.torrent_dir,
                    torrent['torrent_file_name'])
            else:
                torrent_filename = os.path.join(
                    self.metadatahandler.torrent_dir,
                    get_collected_torrent_filename(infohash))
            tdef.save(torrent_filename)

            #calculate root-hash
            sdef = SwiftDef()
            sdef.add_content(torrent_filename)
            sdef.finalize(self.session.get_swift_path())

            #add this new torrent to db
            self.torrent_db.addExternalTorrent(tdef,
                                               extra_info={
                                                   'swift_torrent_hash':
                                                   bin2str(sdef.get_roothash())
                                               })

            #notify all
            self.remoteTorrentHandler.metadatahandler_got_torrent(
                infohash, tdef, torrent_filename)
            self.overlay_bridge.add_task(self.__requestMagnet,
                                         self.REQUEST_INTERVAL)
 def notify_possible_torrent_roothash(self, roothash):
     keys = self.callbacks.keys()
     for key in keys:
         if key[1] == roothash:
             handle_lambda = lambda key=key: self._handleCallback(key, True)
             self.scheduletask(handle_lambda)
     
     sdef = SwiftDef(roothash)
     swiftpath = os.path.join(self.session.get_torrent_collecting_dir(),sdef.get_roothash_as_hex())
     if os.path.exists(swiftpath):
         tdef = TorrentDef.load(swiftpath)
     
         if self.torrent_db.hasTorrent(tdef.get_infohash()):
             self.torrent_db.updateTorrent(tdef.get_infohash(), swift_torrent_hash = sdef.get_roothash(), torrent_file_name = swiftpath)
         else:
             self.torrent_db._addTorrentToDB(tdef, source = "SWIFT", extra_info = {'filename': swiftpath, 'swift_torrent_hash':roothash, 'status':'good'}, commit = True)
Exemplo n.º 6
0
    def __torrentdef_retrieved(self, tdef):
        infohash = tdef.get_infohash()
        if DEBUG:
            print >>sys.stderr, "magnetrequester: received torrent", bin2str(infohash)

        # remove from requested list
        if infohash in self.requestedInfohashes:
            self.requestedInfohashes.remove(infohash)

            # save torrent
            torrent = self.torrent_db.getTorrent(infohash, ["torrent_file_name"], include_mypref=False)
            if torrent and torrent.get("torrent_file_name", False) and not os.path.isabs(torrent["torrent_file_name"]):
                torrent_filename = os.path.join(self.metadatahandler.torrent_dir, torrent["torrent_file_name"])
            else:
                torrent_filename = os.path.join(
                    self.metadatahandler.torrent_dir, get_collected_torrent_filename(infohash)
                )
            tdef.save(torrent_filename)

            # calculate root-hash
            sdef = SwiftDef()
            sdef.add_content(torrent_filename)
            sdef.finalize(self.session.get_swift_path())

            # add this new torrent to db
            self.torrent_db.addExternalTorrent(tdef, extra_info={"swift_torrent_hash": bin2str(sdef.get_roothash())})

            # notify all
            self.remoteTorrentHandler.metadatahandler_got_torrent(infohash, tdef, torrent_filename)
            self.overlay_bridge.add_task(self.__requestMagnet, self.REQUEST_INTERVAL)