Exemplo n.º 1
0
def dispatch(request):
    log = logger.logger("wavemoldb.api")

    if request.method != "POST":
        log.info("Invalid import request from " + str(request.get_host()) +
                 " : not POST request")
        return http.HttpResponseBadRequest("Accepting POST")
    try:
        xml = request.POST["xml"]
    except:
        log.info("Invalid import request from " + str(request.get_host()) +
                 " : xml parameter missing")
        return http.HttpResponseBadRequest("xml parameter missing")

    g = rdflib.ConjunctiveGraph()
    g.parse(StringIO.StringIO(xml))

    fs = filestorage.FileStorage("importer",
                                 web_accessible=False,
                                 settings=settings.filestorage_settings)
    identifier = str(uuid.uuid4())
    path = fs.path(identifier + ".rdf")
    f = open(path, "w")
    f.write(g.serialize())
    f.close()

    q = models.QueuedTask(type="import",
                          parameters=identifier,
                          status="QUEUED")
    q.save()
    log.info("Accepted submission " + str(identifier) + " from " +
             str(request.get_host()))

    return http.HttpResponse(status=202)
Exemplo n.º 2
0
 def testReadable(self):
     shutil.rmtree(os.path.join(os.path.dirname(__file__), "web", "foo"))
     settings = {
         "WEB_CACHE_BASE_DIR":
         os.path.join(os.path.dirname(__file__), "web"),
         "LOCAL_CACHE_BASE_DIR":
         os.path.join(os.path.dirname(__file__), "local"),
         "WEB_CACHE_WEB_BASE_URL":
         "/foox",
     }
     f = filestorage.FileStorage("foo", True, settings)
     self.assertEqual(f.readable("bar"), False)
Exemplo n.º 3
0
 def testInitLocal(self):
     shutil.rmtree(os.path.join(os.path.dirname(__file__), "local", "foo"))
     settings = {
         "WEB_CACHE_BASE_DIR":
         os.path.join(os.path.dirname(__file__), "web"),
         "LOCAL_CACHE_BASE_DIR":
         os.path.join(os.path.dirname(__file__), "local"),
         "WEB_CACHE_WEB_BASE_URL":
         "/foo",
     }
     f = filestorage.FileStorage("foo", False, settings)
     self.assertNotEqual(f, None)
     self.assertEqual(
         os.path.exists(
             os.path.join(os.path.dirname(__file__), "local", "foo")), True)
    def _getOptions(self, argv):
        opts, args = getopt.getopt(argv[1:], "i:s:h",
                                   ["id=", "sys-id=", "help"])

        for opt in opts:
            if opt[0] in ["-i", "--id"]:
                self.submission_uuid = str(uuid.UUID(opt[1]))
            if opt[0] in ["-s", "--sys-id"]:
                self.system_uuid = str(uuid.UUID(opt[1]))
            if opt[0] in ["-h", "--help"]:
                _usage()
                sys.exit(1)

        fs = filestorage.FileStorage("importer",
                                     web_accessible=False,
                                     settings=settings.filestorage_settings)
        self.submission_file = fs.path(self.submission_uuid + ".rdf")