Ejemplo n.º 1
0
    def _decomp_templates(self):
        """Decompresses the template buffers from the database.

        Raises:
            FileNotFoundError: If buffer is not found in db.
        """
        templates = self.cf['templates']
        temp_buf = self.db.select('templates', templates.keys())[0]
        if not temp_buf:
            raise FileNotFoundError('Templates not found in DB.')
        else:
            for temp, temp_name in zip(temp_buf, templates.values()):
                if not temp:
                    raise FileNotFoundError(f'{temp_name} not found in DB.')
                else:
                    utils.decompress_buf(temp, temp_name)
Ejemplo n.º 2
0
    def _decomp_files(self):
        '''This decompresses the buffers in the database into files.
        Note: the db connection must be open.

        Raises:
            FileNotFoundError: If unable to find input buffers in database.
            Or unable to find checkpoint buffers.
        '''

        inp = self.six_cfg["input_files"]
        input_files = json.loads(inp)
        inputs = list(input_files.values())

        input_buf = self.db.select('preprocess_task',
                                   inputs,
                                   f'task_id={self.pre_task_id}')
        if not input_buf:
            raise FileNotFoundError("The required files were not found!")

        input_buf = list(input_buf[0])

        cr_inputs = []
        if self.first_turn is not None:
            cr_inputs = self.cr_files
            where = f'wu_id={self.wu_id} and last_turn={self.first_turn-1}'
            cr_task_ids = self.db.select('sixtrack_wu', ['task_id'],
                                         where=where)
            cr_task_id = cr_task_ids[0][0]
            cr_input_buf = self.db.select('sixtrack_task', cr_inputs,
                                          where=f'task_id={cr_task_id}')
            if (not cr_input_buf) or (cr_input_buf[0][0] is None):
                raise FileNotFoundError("checkpoint files were not found!")

            inputs += cr_inputs
            input_buf += cr_input_buf[0]

        for infile in inputs:
            i = inputs.index(infile)
            buf = input_buf[i]

            utils.decompress_buf(buf, infile, des='file')

        return cr_inputs
Ejemplo n.º 3
0
 def test_compress_buf(self):
     # with strings
     in_str = 'qwertyuiopasdfghjklzxcvbnm_-./'
     in_str_comp = utils.compress_buf(in_str, source='str')
     in_str_decomp = utils.decompress_buf(in_str_comp, None, des='buf')
     self.assertEqual(in_str, in_str_decomp)