Exemple #1
0
 def on_download_file_completed(self, task):
     """
     Called when the target file is fully downloaded.
     
     This method retrieve the stored data and loop while all the metadata
     have not been retrieved. That means that a file's matadata can be stored
     in many chunks, the same way files are stored in vodstok.
     """
     if self.__state == DownTask.SUMMARY:
         filename, self.__chunks = self.__file.read().split('|')
         if filename == 'metadata':
             self.__file = MemoryStream('', key=self.__key)
             self.__task = DownloadFileTask(self, self.__chunks.split(','), self.__file)
         else:
             self.__state = DownTask.RECVING
             self.filename = clean_filename(os.path.join(self.__dst_prefix, filename))
             self.__file = FileStream(
                 open(self.filename, 'wb'), key=self.__key
             )
             self.__task = DownloadFileTask(
                 self, self.__chunks.split(','), self.__file
             )
         if self.__manager is not None:
             self.__manager.queue_task(self.__task)
     elif self.__state == DownTask.RECVING:
         self.__state = DownTask.DONE
         self.__file.close()
         if self.__manager is not None:
             # notify manager of new servers
             for chunk in self.__chunks.split(','):
                 server,alias = chunk.split('?')
                 self.__manager.on_server_discovered(Server(server))
             self.__manager.on_task_done(self)
Exemple #2
0
 def __init__(self, manager=None, filename='unk.bin'):
     try:
         self.uuid = uuid.uuid1()
         self.__manager = manager
         self.__filename = clean_filename(filename)
         self.__file = FileStream(open(filename, 'rb'))
         self.__key = self.__file.get_key()
         self.__state = UpTask.INIT
         self.__task = UploadFileTask(self, self.__file)
         self.__alias = None
     except IOError:
         raise IncorrectParameterError
 def __init__(self, manager=None, filename='unk.bin'):
     try:
         self.uuid = uuid.uuid1()
         self.__manager = manager
         self.__filename = clean_filename(filename)
         self.__file = FileStream(open(filename, 'rb'))
         self.__key = self.__file.get_key()
         self.__state = UpTask.INIT
         self.__task = UploadFileTask(self, self.__file)
         self.__alias = None
     except IOError:
         raise IncorrectParameterError
    def on_download_file_completed(self, task):
        """
        Called when the target file is fully downloaded.

        This method retrieve the stored data and loop while all the metadata
        have not been retrieved. That means that a file's matadata can be stored
        in many chunks, the same way files are stored in vodstok.
        """
        if self.__state == DownTask.SUMMARY:
            file_content = self.__file.read()
            # Is it an old version of chunk ?
            if (file_content.count('|') == 1):
                filename, self.__chunks = file_content.split('|')
            elif (file_content.count('|') == 2):
                filename, version, self.__chunks = self.__file.read().split(
                    '|')
                # Check version
                # If version is greater than our version, raise an error.
                if VersionStr(version) > Settings.version:
                    raise VersionError()
                if filename == 'metadata':
                    self.__file = MemoryStream('', key=self.__key)
                    self.__task = DownloadFileTask(self,
                                                   self.__chunks.split(','),
                                                   self.__file)
                else:
                    self.__state = DownTask.RECVING
                    self.filename = clean_filename(
                        os.path.join(self.__dst_prefix, filename))
                    self.__file = FileStream(open(self.filename, 'wb'),
                                             key=self.__key)
                    self.__task = DownloadFileTask(self,
                                                   self.__chunks.split(','),
                                                   self.__file)
                if self.__manager is not None:
                    self.__manager.queue_task(self.__task)
        elif self.__state == DownTask.RECVING:
            self.__state = DownTask.DONE
            self.__file.close()
            if self.__manager is not None:
                # notify manager of new servers
                for chunk in self.__chunks.split(','):
                    server, alias = chunk.split('?')
                    self.__manager.on_server_discovered(Server(server))
                self.__manager.on_task_done(self)
Exemple #5
0
    def on_download_file_completed(self, task):
        """
        Called when the target file is fully downloaded.

        This method retrieve the stored data and loop while all the metadata
        have not been retrieved. That means that a file's matadata can be stored
        in many chunks, the same way files are stored in vodstok.
        """
        if self.__state == DownTask.SUMMARY:
            file_content = self.__file.read()
            # Is it an old version of chunk ?
            if (file_content.count('|') == 1):
                filename, self.__chunks = file_content.split('|')
            elif (file_content.count('|') == 2):
                filename, version, self.__chunks = self.__file.read().split('|')
                # Check version
                # If version is greater than our version, raise an error.
                if VersionStr(version) > Settings.version:
                    raise VersionError()
                if filename == 'metadata':
                    self.__file = MemoryStream('', key=self.__key)
                    self.__task = DownloadFileTask(self, self.__chunks.split(','), self.__file)
                else:
                    self.__state = DownTask.RECVING
                    self.filename = clean_filename(os.path.join(self.__dst_prefix, filename))
                    self.__file = FileStream(
                        open(self.filename, 'wb'), key=self.__key
                    )
                    self.__task = DownloadFileTask(
                        self, self.__chunks.split(','), self.__file
                    )
                if self.__manager is not None:
                    self.__manager.queue_task(self.__task)
        elif self.__state == DownTask.RECVING:
            self.__state = DownTask.DONE
            self.__file.close()
            if self.__manager is not None:
                # notify manager of new servers
                for chunk in self.__chunks.split(','):
                    server, alias = chunk.split('?')
                    self.__manager.on_server_discovered(Server(server))
                self.__manager.on_task_done(self)