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()))
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
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
def signal_startup(cls, config): log.info("got startup signal") log.info("config sections: " + dict2json(config))
def signal_disconnect(self): log.info("got disconnect signal")
def signal_process(self): self.tmpfile_path = None self.extracted1_path = None self.extracted2_path = None log.info("got process signal")
def signal_destruct(self): log.info("got destruct signal")
def signal_connect(self): log.info("got connect signal")
def signal_termination(cls): log.info("got termination signal")
def signal_init(self): log.info("got init signal")