Exemplo n.º 1
0
def ingest(request):
    """ View to ingest a browse report delivered via HTTP-POST. The XML file is
        expected to be included within the POST data.
    """
    
    try:
        status = get_status()
        if not status.running:
            raise IngestionException("Ingest is not possible if the state of "
                                     "the server is not 'RUNNING'.",
                                     "InvalidState")

        if request.method != "POST":
            raise IngestionException("Method '%s' is not allowed, use 'POST' "
                                     "only." % request.method.upper(),
                                     "MethodNotAllowed")
        
        try:
            document = etree.parse(request)
        except etree.XMLSyntaxError, e: 
            raise IngestionException("Could not parse request XML. Error was: "
                                     "'%s'." % str(e),
                                     "InvalidRequest")
        try:
            parsed_browse_report = decode_browse_report(document.getroot())
            results = ingest_browse_report(parsed_browse_report)

        # unify exception code for some exception types
        except (XMLDecodeError, DecodingException), e:
            raise IngestionException(str(e), "InvalidRequest")
Exemplo n.º 2
0
    def _handle_file(self, filename, create_result, config):
        logger.info("Processing input file '%s'." % filename)

        # parse the xml file and obtain its data structures as a
        # parsed browse report.
        logger.info("Parsing XML file '%s'." % filename)
        document = etree.parse(filename)
        parsed_browse_report = decode_browse_report(document.getroot())

        # ingest the parsed browse report
        logger.info("Ingesting browse report with %d browse%s." %
                    (len(parsed_browse_report),
                     "s" if len(parsed_browse_report) > 1 else ""))

        results = ingest_browse_report(parsed_browse_report, config=config)

        if create_result:
            # print ingest result
            print(
                render_to_string("control/ingest_response.xml",
                                 {"results": results}))

        logger.info(
            "%d browse%s handled, %d successfully replaced "
            "and %d successfully inserted." %
            (results.to_be_replaced,
             "s have been" if results.to_be_replaced > 1 else " has been",
             results.actually_replaced, results.actually_inserted))
Exemplo n.º 3
0
def ingest(request):
    """ View to ingest a browse report delivered via HTTP-POST. The XML file is
        expected to be included within the POST data.
    """

    try:
        status = get_status()
        if not status.running:
            raise IngestionException(
                "Ingest is not possible if the state of "
                "the server is not 'RUNNING'.", "InvalidState")

        if request.method != "POST":
            raise IngestionException(
                "Method '%s' is not allowed, use 'POST' "
                "only." % request.method.upper(), "MethodNotAllowed")

        try:
            document = etree.parse(request)
        except etree.XMLSyntaxError, e:
            raise IngestionException(
                "Could not parse request XML. Error was: "
                "'%s'." % str(e), "InvalidRequest")
        try:
            parsed_browse_report = decode_browse_report(document.getroot())
            results = ingest_browse_report(parsed_browse_report)

        # unify exception code for some exception types
        except (XMLDecodeError, DecodingException), e:
            raise IngestionException(str(e), "InvalidRequest")
Exemplo n.º 4
0
 def _handle_file(self, filename, create_result, config):
     logger.info("Processing input file '%s'." % filename)
     
     # parse the xml file and obtain its data structures as a 
     # parsed browse report.
     self.print_msg("Parsing XML file '%s'." % filename, 1)
     document = etree.parse(filename)
     parsed_browse_report = decode_browse_report(document.getroot())
     
     # ingest the parsed browse report
     self.print_msg("Ingesting browse report with %d browse%s."
                    % (len(parsed_browse_report), 
                       "s" if len(parsed_browse_report) > 1 else ""))
     
     results = ingest_browse_report(parsed_browse_report, config=config)
     
     if create_result:
         # print ingest result
         print(render_to_string("control/ingest_response.xml",
                                {"results": results}))
     
     self.print_msg("%d browses have been handled whereof %d have been "
                     "successfully replaced and %d successfully inserted."
                     % (results.to_be_replaced, results.actually_replaced,
                         results.actually_inserted))