コード例 #1
0
ファイル: watcher.py プロジェクト: Queens-Hacks/CaaS
    def serve_forever(self):
        """Watch the specified directory"""
        while not self.stop.is_set():
            if self.watch():
                print ("{0}: Files changed, recompiling...".format(self.name_))
                stream = tar_paths(self.conf['input'])
                if stream is None:
                    print ("{0}: ERROR: Failed to pack files".format(self.name_))
                else:
                    self.lock.acquire()
                    self.service.process(self.conf, stream, self.unlock)

                    # Wait until the job is processed before continuing
                    self.lock.acquire()
                    self.lock.release()
            time.sleep(2)
コード例 #2
0
def get_service(processor):
    """routes subdomains to the right service"""

    if not account.User.collection.find_one(
        {"key": request.args.get("key", "")}):
        return Response(
            "You must create an account and supply a valid API key to use this service",
            status=403)

    if processor not in processors:
        return Response(
            "Invalid compiler '{0}'. Valid compilers are: {1}".format(
                processor, ", ".join(processors)),
            status=400)

    elif request.files is None:
        return Response("No files recieved, should be 1", status=400)

    elif len(request.files) != 1:
        return Response("Should send 1 file, sent {0} instead".format(
            len(request.files)),
                        status=400)

    elif request.files['data'] is None:
        return Response("Form key should be 'data'", status=400)

    in_dir = tempfile.mkdtemp()
    out_dir = tempfile.mkdtemp()

    comp_result = False

    try:
        untar_to_path(request.files['data'], in_dir)

        # Compile the code
        comp_result = (processors[processor])(in_dir, out_dir)

        stream = tar_paths(out_dir)
    finally:
        rmrf(in_dir)
        rmrf(out_dir)

    r = Response(stream, mimetype="application/gzip")
    if not comp_result:
        r.headers.add('warning', "Compilation reported a failure")

    return r
コード例 #3
0
    def serve_forever(self):
        """Watch the specified directory"""
        while not self.stop.is_set():
            if self.watch():
                print("{0}: Files changed, recompiling...".format(self.name_))
                stream = tar_paths(self.conf['input'])
                if stream is None:
                    print("{0}: ERROR: Failed to pack files".format(
                        self.name_))
                else:
                    self.lock.acquire()
                    self.service.process(self.conf, stream, self.unlock)

                    # Wait until the job is processed before continuing
                    self.lock.acquire()
                    self.lock.release()
            time.sleep(2)
コード例 #4
0
ファイル: __init__.py プロジェクト: Queens-Hacks/CaaS
def get_service(processor):
    """routes subdomains to the right service"""

    if not account.User.collection.find_one({"key": request.args.get("key", "")}):
        return Response ("You must create an account and supply a valid API key to use this service", status=403)

    if processor not in processors:
        return Response ("Invalid compiler '{0}'. Valid compilers are: {1}".format(processor, ", ".join(processors)), status=400)

    elif request.files is None:
        return Response ("No files recieved, should be 1", status=400)

    elif len(request.files) != 1:
        return Response ("Should send 1 file, sent {0} instead".format(len(request.files)), status=400)

    elif request.files['data'] is None:
        return Response ("Form key should be 'data'", status=400)

    in_dir = tempfile.mkdtemp()
    out_dir = tempfile.mkdtemp()

    comp_result = False

    try:
        untar_to_path(request.files['data'], in_dir)

        # Compile the code
        comp_result = (processors[processor])(in_dir, out_dir)

        stream = tar_paths(out_dir)
    finally:
        rmrf(in_dir)
        rmrf(out_dir)

    r = Response(stream, mimetype="application/gzip")
    if not comp_result:
        r.headers.add('warning', "Compilation reported a failure")

    return r