Exemple #1
0
    def signal_processed(self, was_error):
        if self.tmpfile_path is not None:
            os.remove(self.tmpfile_path)

        if self.extracted1_path is not None:
            shutil.rmtree(self.extracted1_path)

        if self.extracted2_path is not None:
            shutil.rmtree(self.extracted2_path)

        log.info("got processed signal")
Exemple #2
0
    def signal_processed(self, was_error):
        if self.tmpfile_path is not None:
            os.remove(self.tmpfile_path)

        if self.extracted1_path is not None:
            shutil.rmtree(self.extracted1_path)

        if self.extracted2_path is not None:
            shutil.rmtree(self.extracted2_path)

        log.info("got processed signal")
    def on_startup(cls, config, system_json):
        # TODO: config is not accessible when local
        cls._system = System(config, system_json, service=True)
        cls._config = config
        cls._lock = Lock()

        cls.tmp_dir = config.get('tmp-dir', DEFAULT_TMP_DIR)

        if not os.path.isdir(cls.tmp_dir):
            log.info("Creating tree dir '%s'" % cls.tmp_dir)
            os.mkdir(cls.tmp_dir)
        log.info("Using temporary dir '%s'" % cls.tmp_dir)

        cls.signal_startup(config.get(cls.get_service_name()))
Exemple #4
0
    def on_startup(cls, config, system_json):
        # TODO: config is not accessible when local
        cls._system = System(config, system_json, service=True)
        cls._config = config
        cls._lock = Lock()

        cls.tmp_dir = config.get('tmp-dir', DEFAULT_TMP_DIR)

        if not os.path.isdir(cls.tmp_dir):
            log.info("Creating tree dir '%s'" % cls.tmp_dir)
            os.mkdir(cls.tmp_dir)
        log.info("Using temporary dir '%s'" % cls.tmp_dir)

        cls.signal_startup(config.get(cls.get_service_name()))
Exemple #5
0
    def download(self, file_id):
        '''
        Download a file
        @param file_id: a file to be downloaded
        @return: file content
        '''
        # avoid getting files from the local system
        if not file_id.get_service_name() == self.get_service_name():
            raise ValueError("File not from this service")

        filename = os.path.basename(file_id.get_raw()['identifier'])
        file_path = os.path.join(self.upload_dir, filename)

        with self.get_lock():
            log.info("downloading '%s'" % str(file_path))
            with open(file_path, 'rb') as f:
                content = f.read()

        return content
Exemple #6
0
    def upload(self, blob):
        '''
        Upload file to the system
        @param blob: a file content to be store
        @return: file id
        '''
        res = ServiceResult()
        log.info("uploading")
        h = blob_hash(blob)
        dst = os.path.join(self.upload_dir, h)

        with self.get_lock():
            with open(dst, 'wb') as f:
                f.write(blob)

        creation_time = datetime_parse(time.ctime(os.path.getctime(dst)))
        # TODO: remove, use dircache instead
        valid_until = creation_time + self.file_lifetime

        res.result = FileId.construct(self, dst, h)
        return res
Exemple #7
0
 def signal_startup(cls, config):
     log.info("got startup signal")
     log.info("config sections: " + dict2json(config))
Exemple #8
0
 def signal_disconnect(self):
     log.info("got disconnect signal")
Exemple #9
0
 def signal_process(self):
     self.tmpfile_path = None
     self.extracted1_path = None
     self.extracted2_path = None
     log.info("got process signal")
Exemple #10
0
 def signal_destruct(self):
     log.info("got destruct signal")
Exemple #11
0
 def signal_connect(self):
     log.info("got connect signal")
Exemple #12
0
 def signal_termination(cls):
     log.info("got termination signal")
Exemple #13
0
 def signal_init(self):
     log.info("got init signal")
Exemple #14
0
 def signal_init(self):
     log.info("got init signal")
Exemple #15
0
 def signal_startup(cls, config):
     log.info("got startup signal")
     log.info("config sections: " + dict2json(config))
Exemple #16
0
 def signal_termination(cls):
     log.info("got termination signal")
Exemple #17
0
 def signal_destruct(self):
     log.info("got destruct signal")
Exemple #18
0
 def signal_connect(self):
     log.info("got connect signal")
Exemple #19
0
 def signal_disconnect(self):
     log.info("got disconnect signal")
Exemple #20
0
 def signal_process(self):
     self.tmpfile_path = None
     self.extracted1_path = None
     self.extracted2_path = None
     log.info("got process signal")