def save_backup(self, data: Optional[str]) -> None: if config.local_copy_dir is not None: try: safe_write(self.local_copy_fn, data, True) except IOError as ex: log.warning("unable to save backup copy of {}: {}".format( self.url, ex))
def publish(req, *opts): """ Publish the working document in XML form. :param req: The request :param opts: Options (unused) :return: None Publish takes one argument: path to a file where the document tree will be written. **Examples** .. code-block:: yaml - publish: /tmp/idp.xml """ if req.t is None: raise PipeException("Empty document submitted for publication") if req.args is None: raise PipeException("publish must specify output") try: validate_document(req.t) except DocumentInvalid as ex: log.error(ex.error_log) raise PipeException("XML schema validation failed") output_file = None if type(req.args) is dict: output_file = req.args.get("output", None) else: output_file = req.args[0] if output_file is not None: output_file = output_file.strip() log.debug("publish {}".format(output_file)) resource_name = output_file m = re.match(FILESPEC_REGEX, output_file) if m: output_file = m.group(1) resource_name = m.group(2) log.debug("output_file={}, resource_name={}".format( output_file, resource_name)) out = output_file if os.path.isdir(output_file): out = "{}.xml".format(os.path.join(output_file, req.id)) safe_write(out, dumptree(req.t)) req.md.store.update( req.t, tid=resource_name ) # TODO maybe this is not the right thing to do anymore return req.t
def store(req, *opts): """ Save the working document as separate files :param req: The request :param opts: Options (unused) :return: always returns the unmodified working document Split the working document into EntityDescriptor-parts and save in directory/sha1(@entityID).xml. Note that this does not erase files that may already be in the directory. If you want a "clean" directory, remove it before you call store. """ if req.t is None: raise PipeException("Your pipeline is missing a select statement.") if not req.args: raise PipeException("store requires an argument") target_dir = None if type(req.args) is dict: target_dir = req.args.get('directory', None) else: target_dir = req.args[0] if target_dir is not None: if not os.path.isdir(target_dir): os.makedirs(target_dir) for e in iter_entities(req.t): eid = e.get('entityID') if eid is None or len(eid) == 0: raise PipeException("Missing entityID in %s" % e) m = hashlib.sha1() m.update(eid) d = m.hexdigest() safe_write("%s.xml" % os.path.join(target_dir, d), dumptree(e, pretty_print=True)) return req.t
output_file = req.args.get("output", None) else: output_file = req.args[0] if output_file is not None: output_file = output_file.strip() log.debug("publish %s" % output_file) resource_name = output_file m = re.match(FILESPEC_REGEX, output_file) if m: output_file = m.group(1) resource_name = m.group(2) log.debug("output_file=%s, resource_name=%s" % (output_file, resource_name)) out = output_file if os.path.isdir(output_file): out = "%s.xml" % os.path.join(output_file, req.id) safe_write(out, dumptree(req.t)) req.md.store.update(req.t, tid=resource_name) # TODO maybe this is not the right thing to do anymore return req.t @pipe def loadstats(req, *opts): """ Log (INFO) information about the result of the last call to load :param req: The request :param opts: Options: (none) :return: None """ from stats import metadata _stats = None try: if 'json' in opts: