예제 #1
0
def main(argv):
    usage = "usage: %prog [options]"

    redirect_port_args = {
        "redirectport": {
            "flags": ["--redirectport"],
            "default": PORT,
            "help": "Port to use for redirect server (default: %s)" % PORT,
        },
    }

    opts = utils.parse(argv, redirect_port_args, ".splunkrc", usage=usage)

    args = [("scheme", opts.kwargs["scheme"]), ("host", opts.kwargs["host"]),
            ("port", opts.kwargs["port"]), ("redirecthost", "localhost"),
            ("redirectport", opts.kwargs["redirectport"]),
            ("username", opts.kwargs["username"]),
            ("password", opts.kwargs["password"])]
    if 'app' in opts.kwargs.keys():
        args.append(('app', opts.kwargs['app']))
    if 'owner' in opts.kwargs.keys():
        args.append(('owner', opts.kwargs['owner']))

    # Encode these arguments
    args = urllib.urlencode(args)

    # Launch the browser
    webbrowser.open("file://%s" %
                    os.path.join(os.getcwd(), "explorer.html?%s" % args))

    # And server the files
    server.serve(opts.kwargs["redirectport"])
예제 #2
0
def main(argv):
    usage = "usage: %prog [options]"

    redirect_port_args = {
        "redirectport": {
            "flags": ["--redirectport"],
            "default": PORT,
            "help": "Port to use for redirect server (default: %s)" % PORT,
        },
    }

    opts = utils.parse(argv, redirect_port_args, ".splunkrc", usage=usage)

    args = [("scheme", opts.kwargs["scheme"]),
            ("host", opts.kwargs["host"]),
            ("port", opts.kwargs["port"]),
            ("redirecthost", "localhost"),
            ("redirectport", opts.kwargs["redirectport"]),
            ("username", opts.kwargs["username"]),
            ("password", opts.kwargs["password"])]
    if 'app' in opts.kwargs.keys():
        args.append(('app', opts.kwargs['app']))
    if 'owner' in opts.kwargs.keys():
        args.append(('owner', opts.kwargs['owner']))

    # Encode these arguments
    args = urllib.urlencode(args)

    # Launch the browser
    webbrowser.open("file://%s" % os.path.join(os.getcwd(), "explorer.html?%s" % args))

    # And server the files
    server.serve(opts.kwargs["redirectport"])
예제 #3
0
def main(argv):
    usage = "usage: %prog [options]"

    redirect_port_args = {
        "redirectport": {
            "flags": ["--redirectport"],
            "default": PORT,
            "help": "Port to use for redirect server (default: %s)" % PORT,
        },
    }

    opts = utils.parse(argv, redirect_port_args, ".splunkrc", usage=usage)

    # We have to provide a sensible value for namespace
    namespace = opts.kwargs["namespace"]
    namespace = namespace if namespace else "-"

    # Encode these arguments
    args = urllib.urlencode([
            ("scheme", opts.kwargs["scheme"]),
            ("host", opts.kwargs["host"]),
            ("port", opts.kwargs["port"]),
            ("redirecthost", "localhost"),
            ("redirectport", opts.kwargs["redirectport"]),
            ("username", opts.kwargs["username"]),
            ("password", opts.kwargs["password"]),
            ("namespace", namespace)
        ]),

    # Launch the browser
    webbrowser.open("file://%s" % os.path.join(os.getcwd(), "explorer.html?%s" % args))

    # And server the files
    server.serve(opts.kwargs["redirectport"])
예제 #4
0
def cli():
    help_text = """
    commands:
        help:                 prints this help text
        get_coords [address]: gets the coordinates for given address
        serve:                starts a server to listen for requests
    """
    
    incorrect_command_text = "incorrect command"

    num_args = len(sys.argv)

    if num_args > 1:
        command = sys.argv[1]
        if command == "help":
            print(help_text)
            return 0
        elif command == "get_coords" and num_args > 2:
            address = " ".join(sys.argv[2:])
            print(address_to_coords(address))
            return 0
        elif command == "serve":
            serve()
            return 0

    print(incorrect_command_text)
    print(help_text)
    return 1
def server_wrapper():
    import server
    if len(sys.argv) < 5:
        server.serve(0, {})
    else:
        voter_id = int(sys.argv[2])
        friend_id = int(sys.argv[3])
        friend_ip = sys.argv[4]
        friend_port = int(sys.argv[5])
        server.serve(voter_id, {friend_id: (friend_ip, friend_port)})
예제 #6
0
파일: lavavu.py 프로젝트: ah548455/LavaVu
 def serve(self):
     if not self.control: return
     try:
         import server
         os.chdir(control.htmlpath)
         server.serve(self)
     except Exception, e:
         print "LavaVu error: " + str(e)
         print "Web Server failed to run"
         import traceback
         traceback.print_exc()
         pass
예제 #7
0
def main(dareFiles, port=1337):
    # register ctrl+c for exit
    signal.signal(signal.SIGINT, signal_handler)

    for file in dareFiles:
        logick.loadTaskList()

    games = {}
    server.root["new"] = (newGameHadler, games)
    server.root["games"] = games

    print("serving at port", port)
    server.serve(port)
예제 #8
0
def main():
    """
    Parse command-line arguments and invoke server.
    """
    parser = ArgumentParser()
    parser.add_argument('-p', '--port', action='store', type=int,
                        dest='port', default=5001)
    parser.add_argument('-u', '--universe', action='store_true',
                        dest='universe')
    parser.add_argument('-s', '--setup', action='store', type=str,
                        dest='setup_code')
    options = parser.parse_args()
    server.serve(**vars(options))
예제 #9
0
파일: jsonapp.py 프로젝트: thinxer/jsonapp
def test():
    application = JsonApplication()
    api = application.decorator()

    @api
    def add(x, y):
        return x + y

    @api('o')
    def mul(x, y):
        return x * y

    from server import serve
    serve(application)
예제 #10
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('command')
    parser.add_argument('command_arg')
    args = parser.parse_args()

    if args.command == 'compile':
        config = cf.load_config(args.command_arg)
        compileblog.compile_all(config)

    elif args.command == 'wpimport':
        import wpimport
        wpimport.main(args.command_arg)

    elif args.command == 'refresh':
        config = cf.load_config(args.command_arg)

        import twitter
        twitter.refresh_tweets(config)

    elif args.command == 'newpost':
        title = args.command_arg
        slug = utils.title_to_slug(title)
        now = datetime.utcnow()
        fname = 'drafts/{}-{}.md'.format(now.strftime('%Y-%m-%d-%H-%M'), slug)
        with open(fname, 'w') as f:
            f.write('---\ntitle: "')
            f.write(title)
            f.write('"\n---\n')

        import subprocess
        subprocess.call(['open', fname])

    elif args.command == 'edit' or args.command == 'editpost':
        # TODO
        pass
    elif args.command == 'publish':
        # TODO
        pass


    elif args.command == 'serve':
        config = cf.load_config(args.command_arg)
        config.is_dynamic = True
        server.serve(config)

    else:
        print("Unknown command " + args.command)
        sys.exit(1)
예제 #11
0
def main():
    router = Router()
    router.add_route(Route(r"^/$", index_handler))
    router.add_route(Route(r"^/create_link$", create_new_link_handler))
    router.add_route(Route(r"^/static", serve("./static", "/static")))
    server = Server(router=router, addr=("localhost", 9999))
    server.start_loop()
예제 #12
0
def main():
    router = Router()
    router.add_route(Route(r"^/$", index_view_v2))
    router.add_route(Route(r"^/about/?$", about_view))
    router.add_route(Route(r"^/static", serve("./static", "/static")))
    server = Server(router=router, addr=("localhost", 9999))
    server.start_loop()
예제 #13
0
파일: main.py 프로젝트: wichovw/tca-gt
def main(argv):
    server_ip = 'localhost'
    server_port = 5555
    if len(argv) >= 1:
        if argv[0] in ('serve', 'host'):
            server_ip = get_host(get_name())
        elif argv[0] in ('0', 'localhost'):
            server_ip = 'localhost'
        else:
            exit("<server ip> must be 'host' or 'localhost'")
    if len(argv) >= 2:
        try:
            server_port = int(argv[1])
        except ValueError:
            exit("<server port> must be integer")
    serve(server_ip, server_port)
예제 #14
0
def main():
    router = Router()
    router.add_route(
        Route(r"^/(?P<code>[a-zA-Z0-9]{6,8})/?$", redirect_to_link))
    router.add_route(Route(r"^/create_link$", create_link_view))
    router.add_route(Route(r"^/$", index_view))
    router.add_route(Route(r"^/static", serve("./static", "/static")))
    server = Server(router=router, addr=("localhost", 9999))
    server.start_loop()
예제 #15
0
    def __init__(self, mode):
        self.mode = mode
        # start connection
        if mode == "client":
            self.sock = connect()
        if mode == "server":
            self.sock = serve()

        #initise class wide variables
        self.packets = {}
        self._queue = []
        self.temp_id = 0
예제 #16
0
    def run_brat_direct(self):
        """Execute brat server directly."""

        remote_addr = self.client_address[0]
        remote_host = self.address_string()
        cookie_data = ', '.join(filter(None,
                                       self.headers.getheaders('cookie')))

        query_string = ''
        i = self.path.find('?')
        if i != -1:
            query_string = self.path[i + 1:]

        saved = sys.stdin, sys.stdout, sys.stderr
        sys.stdin, sys.stdout = self.rfile, self.wfile

        # set env to get FieldStorage to read params
        env = {}
        env['REQUEST_METHOD'] = self.command
        content_length = self.headers.getheader('content-length')
        if content_length:
            env['CONTENT_LENGTH'] = content_length
        if query_string:
            env['QUERY_STRING'] = query_string
        os.environ.update(env)
        params = FieldStorage()

        # Call main server
        cookie_hdrs, response_data = serve(params, remote_addr, remote_host,
                                           cookie_data)

        sys.stdin, sys.stdout, sys.stderr = saved

        # Package and send response
        if cookie_hdrs is not None:
            response_hdrs = [hdr for hdr in cookie_hdrs]
        else:
            response_hdrs = []
        response_hdrs.extend(response_data[0])

        self.send_response(200)
        self.wfile.write('\n'.join('%s: %s' % (k, v)
                                   for k, v in response_hdrs))
        self.wfile.write('\n')
        self.wfile.write('\n')
        # Hack to support binary data and general Unicode for SVGs and JSON
        if isinstance(response_data[1], unicode):
            self.wfile.write(response_data[1].encode('utf-8'))
        else:
            self.wfile.write(response_data[1])
        return 0
예제 #17
0
파일: standalone.py 프로젝트: a-tsioh/brat
    def run_brat_direct(self):
        """Execute brat server directly."""

        remote_addr = self.client_address[0]
        remote_host = self.address_string()
        cookie_data = ', '.join(
            [_f for _f in self.headers.get('cookie', []) if _f])

        query_string = ''
        i = self.path.find('?')
        if i != -1:
            query_string = self.path[i + 1:]

        saved = sys.stdin, sys.stdout, sys.stderr
        sys.stdin, sys.stdout = self.rfile, self.wfile

        # set env to get FieldStorage to read params
        env = {}
        env['REQUEST_METHOD'] = self.command
        content_length = self.headers.get('content-length')
        if content_length:
            env['CONTENT_LENGTH'] = content_length
        if query_string:
            env['QUERY_STRING'] = query_string
        os.environ.update(env)
        params = FieldStorage(fp=self.rfile)

        # Call main server
        cookie_hdrs, response_data = serve(params, remote_addr, remote_host,
                                           cookie_data)

        sys.stdin, sys.stdout, sys.stderr = saved

        # Package and send response
        if cookie_hdrs is not None:
            response_hdrs = [hdr for hdr in cookie_hdrs]
        else:
            response_hdrs = []
        response_hdrs.extend(response_data[0])

        self.send_response(200)
        for k, v in response_hdrs:
            self.send_header(k, v)
        self.end_headers()

        # Hack to support binary data and general Unicode for SVGs and JSON
        if isinstance(response_data[1], str):
            self.wfile.write(response_data[1].encode('utf-8'))
        else:
            self.wfile.write(response_data[1])
        return 0
예제 #18
0
def main():
    # Setup signal handlers
    signal.signal(signal.SIGTERM, atexit_function)
    signal.signal(signal.SIGHUP, atexit_function)
    signal.signal(signal.SIGINT, atexit_function)

    parser = argparse.ArgumentParser(
        description='Pulsar Functions Python Instance')
    parser.add_argument('--function_classname',
                        required=True,
                        help='Function Class Name')
    parser.add_argument('--py',
                        required=True,
                        help='Full Path of Function Code File')
    parser.add_argument('--name', required=True, help='Function Name')
    parser.add_argument('--tenant', required=True, help='Tenant Name')
    parser.add_argument('--namespace', required=True, help='Namespace name')
    parser.add_argument('--instance_id', required=True, help='Instance Id')
    parser.add_argument('--function_id', required=True, help='Function Id')
    parser.add_argument('--function_version',
                        required=True,
                        help='Function Version')
    parser.add_argument('--processing_guarantees',
                        required=True,
                        help='Processing Guarantees')
    parser.add_argument('--pulsar_serviceurl',
                        required=True,
                        help='Pulsar Service Url')
    parser.add_argument('--client_auth_plugin',
                        required=False,
                        help='Client authentication plugin')
    parser.add_argument('--client_auth_params',
                        required=False,
                        help='Client authentication params')
    parser.add_argument('--use_tls', required=False, help='Use tls')
    parser.add_argument('--tls_allow_insecure_connection',
                        required=False,
                        help='Tls allow insecure connection')
    parser.add_argument('--hostname_verification_enabled',
                        required=False,
                        help='Enable hostname verification')
    parser.add_argument('--tls_trust_cert_path',
                        required=False,
                        help='Tls trust cert file path')
    parser.add_argument('--port',
                        required=True,
                        help='Instance Port',
                        type=int)
    parser.add_argument('--max_buffered_tuples',
                        required=True,
                        help='Maximum number of Buffered tuples')
    parser.add_argument('--user_config', required=False, help='User Config')
    parser.add_argument('--logging_directory',
                        required=True,
                        help='Logging Directory')
    parser.add_argument('--logging_file', required=True, help='Log file name')
    parser.add_argument('--auto_ack', required=True, help='Enable Autoacking?')
    parser.add_argument('--log_topic',
                        required=False,
                        help='Topic to send Log Messages')
    parser.add_argument('--source_subscription_type',
                        required=True,
                        help='Subscription Type')
    parser.add_argument('--source_topics_serde_classname',
                        required=True,
                        help='A mapping of Input topics to SerDe')
    parser.add_argument(
        '--topics_pattern',
        required=False,
        help=
        'TopicsPattern to consume from list of topics under a namespace that match the pattern (not supported)'
    )
    parser.add_argument('--source_timeout_ms',
                        required=False,
                        help='Source message timeout in milliseconds')
    parser.add_argument('--sink_topic', required=False, help='Sink Topic')
    parser.add_argument('--sink_serde_classname',
                        required=False,
                        help='Sink SerDe classname')

    args = parser.parse_args()
    log_file = os.path.join(
        args.logging_directory,
        util.getFullyQualifiedFunctionName(args.tenant, args.namespace,
                                           args.name),
        "%s-%s.log" % (args.logging_file, args.instance_id))
    log.init_rotating_logger(level=logging.INFO,
                             logfile=log_file,
                             max_files=5,
                             max_bytes=10 * 1024 * 1024)

    Log.info("Starting Python instance with %s" % str(args))

    function_details = Function_pb2.FunctionDetails()
    function_details.tenant = args.tenant
    function_details.namespace = args.namespace
    function_details.name = args.name
    function_details.className = args.function_classname

    if args.topics_pattern:
        raise ValueError('topics_pattern is not supported by python client')
    sourceSpec = Function_pb2.SourceSpec()
    sourceSpec.subscriptionType = Function_pb2.SubscriptionType.Value(
        args.source_subscription_type)
    try:
        source_topics_serde_classname_dict = json.loads(
            args.source_topics_serde_classname)
    except ValueError:
        Log.critical(
            "Cannot decode source_topics_serde_classname.  This argument must be specifed as a JSON"
        )
        sys.exit(1)
    if not source_topics_serde_classname_dict:
        Log.critical("source_topics_serde_classname cannot be empty")
    for topics, serde_classname in source_topics_serde_classname_dict.items():
        sourceSpec.topicsToSerDeClassName[topics] = serde_classname
    if args.source_timeout_ms:
        sourceSpec.timeoutMs = long(args.source_timeout_ms)
    function_details.source.MergeFrom(sourceSpec)

    sinkSpec = Function_pb2.SinkSpec()
    if args.sink_topic != None and len(args.sink_topic) != 0:
        sinkSpec.topic = args.sink_topic
    if args.sink_serde_classname != None and len(
            args.sink_serde_classname) != 0:
        sinkSpec.serDeClassName = args.sink_serde_classname
    function_details.sink.MergeFrom(sinkSpec)

    function_details.processingGuarantees = Function_pb2.ProcessingGuarantees.Value(
        args.processing_guarantees)
    if args.auto_ack == "true":
        function_details.autoAck = True
    else:
        function_details.autoAck = False
    if args.user_config != None and len(args.user_config) != 0:
        function_details.userConfig = args.user_config

    authentication = None
    use_tls = False
    tls_allow_insecure_connection = False
    tls_trust_cert_path = None
    if args.client_auth_plugin and args.client_auth_params:
        authentication = pulsar.Authentication(args.client_auth_plugin,
                                               args.client_auth_params)
    if args.use_tls == "true":
        use_tls = True
    if args.tls_allow_insecure_connection == "true":
        tls_allow_insecure_connection = True
    if args.tls_trust_cert_path:
        tls_trust_cert_path = args.tls_trust_cert_path
    pulsar_client = pulsar.Client(args.pulsar_serviceurl, authentication, 30,
                                  1, 1, 50000, None, use_tls,
                                  tls_trust_cert_path,
                                  tls_allow_insecure_connection)
    pyinstance = python_instance.PythonInstance(str(args.instance_id),
                                                str(args.function_id),
                                                str(args.function_version),
                                                function_details,
                                                int(args.max_buffered_tuples),
                                                str(args.py), args.log_topic,
                                                pulsar_client)
    pyinstance.run()
    server_instance = server.serve(args.port, pyinstance)

    global to_run
    while to_run:
        time.sleep(1)

    pyinstance.join()
    sys.exit(1)
예제 #19
0
def main():
    # Setup signal handlers
    signal.signal(signal.SIGTERM, atexit_function)
    signal.signal(signal.SIGHUP, atexit_function)
    signal.signal(signal.SIGINT, atexit_function)

    parser = argparse.ArgumentParser(
        description='Pulsar Functions Python Instance')
    parser.add_argument('--function_details',
                        required=True,
                        help='Function Details Json String')
    parser.add_argument('--py',
                        required=True,
                        help='Full Path of Function Code File')
    parser.add_argument('--instance_id', required=True, help='Instance Id')
    parser.add_argument('--function_id', required=True, help='Function Id')
    parser.add_argument('--function_version',
                        required=True,
                        help='Function Version')
    parser.add_argument('--pulsar_serviceurl',
                        required=True,
                        help='Pulsar Service Url')
    parser.add_argument('--client_auth_plugin',
                        required=False,
                        help='Client authentication plugin')
    parser.add_argument('--client_auth_params',
                        required=False,
                        help='Client authentication params')
    parser.add_argument('--use_tls', required=False, help='Use tls')
    parser.add_argument('--tls_allow_insecure_connection',
                        required=False,
                        help='Tls allow insecure connection')
    parser.add_argument('--hostname_verification_enabled',
                        required=False,
                        help='Enable hostname verification')
    parser.add_argument('--tls_trust_cert_path',
                        required=False,
                        help='Tls trust cert file path')
    parser.add_argument('--port',
                        required=True,
                        help='Instance Port',
                        type=int)
    parser.add_argument('--metrics_port',
                        required=True,
                        help="Port metrics will be exposed on",
                        type=int)
    parser.add_argument('--max_buffered_tuples',
                        required=True,
                        help='Maximum number of Buffered tuples')
    parser.add_argument('--logging_directory',
                        required=True,
                        help='Logging Directory')
    parser.add_argument('--logging_file', required=True, help='Log file name')
    parser.add_argument('--logging_config_file',
                        required=True,
                        help='Config file for logging')
    parser.add_argument('--expected_healthcheck_interval',
                        required=True,
                        help='Expected time in seconds between health checks',
                        type=int)
    parser.add_argument('--secrets_provider',
                        required=False,
                        help='The classname of the secrets provider')
    parser.add_argument(
        '--secrets_provider_config',
        required=False,
        help='The config that needs to be passed to secrets provider')
    parser.add_argument(
        '--install_usercode_dependencies',
        required=False,
        help=
        'For packaged python like wheel files, do we need to install all dependencies',
        type=bool)
    parser.add_argument(
        '--dependency_repository',
        required=False,
        help=
        'For packaged python like wheel files, which repository to pull the dependencies from'
    )
    parser.add_argument(
        '--extra_dependency_repository',
        required=False,
        help=
        'For packaged python like wheel files, any extra repository to pull the dependencies from'
    )
    parser.add_argument('--state_storage_serviceurl',
                        required=False,
                        help='Managed State Storage Service Url')
    parser.add_argument(
        '--cluster_name',
        required=True,
        help='The name of the cluster this instance is running on')

    args = parser.parse_args()
    function_details = Function_pb2.FunctionDetails()
    args.function_details = str(args.function_details)
    if args.function_details[0] == '\'':
        args.function_details = args.function_details[1:]
    if args.function_details[-1] == '\'':
        args.function_details = args.function_details[:-1]
    json_format.Parse(args.function_details, function_details)

    if os.path.splitext(str(args.py))[1] == '.whl':
        if args.install_usercode_dependencies:
            cmd = "pip install -t %s" % os.path.dirname(str(args.py))
            if args.dependency_repository:
                cmd = cmd + " -i %s" % str(args.dependency_repository)
            if args.extra_dependency_repository:
                cmd = cmd + " --extra-index-url %s" % str(
                    args.extra_dependency_repository)
            cmd = cmd + " %s" % str(args.py)
            retval = os.system(cmd)
            if retval != 0:
                print("Could not install user depedencies")
                sys.exit(1)
        else:
            zpfile = zipfile.ZipFile(str(args.py), 'r')
            zpfile.extractall(os.path.dirname(str(args.py)))
        sys.path.insert(0, os.path.dirname(str(args.py)))
    elif os.path.splitext(str(args.py))[1] == '.zip':
        # Assumig zip file with format func.zip
        # extract to folder function
        # internal dir format
        # "func/src"
        # "func/requirements.txt"
        # "func/deps"
        # run pip install to target folder  deps folder
        zpfile = zipfile.ZipFile(str(args.py), 'r')
        zpfile.extractall(os.path.dirname(str(args.py)))
        basename = os.path.splitext(str(args.py))[0]

        deps_dir = os.path.join(os.path.dirname(str(args.py)), basename,
                                "deps")

        if os.path.isdir(deps_dir) and os.listdir(deps_dir):
            # get all wheel files from deps directory
            wheel_file_list = [
                os.path.join(deps_dir, f) for f in os.listdir(deps_dir)
                if os.path.isfile(os.path.join(deps_dir, f))
                and os.path.splitext(f)[1] == '.whl'
            ]
            cmd = "pip install -t %s --no-index --find-links %s %s" % (
                os.path.dirname(str(
                    args.py)), deps_dir, " ".join(wheel_file_list))
            Log.debug("Install python dependencies via cmd: %s" % cmd)
            retval = os.system(cmd)
            if retval != 0:
                print(
                    "Could not install user depedencies specified by the zip file"
                )
                sys.exit(1)
        # add python user src directory to path
        sys.path.insert(
            0, os.path.join(os.path.dirname(str(args.py)), basename, "src"))

    log_file = os.path.join(
        args.logging_directory,
        util.getFullyQualifiedFunctionName(function_details.tenant,
                                           function_details.namespace,
                                           function_details.name),
        "%s-%s.log" % (args.logging_file, args.instance_id))
    log.init_logger(logging.INFO, log_file, args.logging_config_file)

    Log.info("Starting Python instance with %s" % str(args))

    authentication = None
    use_tls = False
    tls_allow_insecure_connection = False
    tls_trust_cert_path = None
    if args.client_auth_plugin and args.client_auth_params:
        authentication = pulsar.Authentication(args.client_auth_plugin,
                                               args.client_auth_params)
    if args.use_tls == "true":
        use_tls = True
    if args.tls_allow_insecure_connection == "true":
        tls_allow_insecure_connection = True
    if args.tls_trust_cert_path:
        tls_trust_cert_path = args.tls_trust_cert_path
    pulsar_client = pulsar.Client(
        args.pulsar_serviceurl,
        authentication=authentication,
        operation_timeout_seconds=30,
        io_threads=1,
        message_listener_threads=1,
        concurrent_lookup_requests=50000,
        log_conf_file_path=None,
        use_tls=use_tls,
        tls_trust_certs_file_path=tls_trust_cert_path,
        tls_allow_insecure_connection=tls_allow_insecure_connection)

    state_storage_serviceurl = None
    if args.state_storage_serviceurl is not None:
        state_storage_serviceurl = str(args.state_storage_serviceurl)

    secrets_provider = None
    if args.secrets_provider is not None:
        secrets_provider = util.import_class(
            os.path.dirname(inspect.getfile(inspect.currentframe())),
            str(args.secrets_provider))
    else:
        secrets_provider = util.import_class(
            os.path.dirname(inspect.getfile(inspect.currentframe())),
            "secretsprovider.ClearTextSecretsProvider")
    secrets_provider = secrets_provider()
    secrets_provider_config = None
    if args.secrets_provider_config is not None:
        args.secrets_provider_config = str(args.secrets_provider_config)
        if args.secrets_provider_config[0] == '\'':
            args.secrets_provider_config = args.secrets_provider_config[1:]
        if args.secrets_provider_config[-1] == '\'':
            args.secrets_provider_config = args.secrets_provider_config[:-1]
        secrets_provider_config = json.loads(str(args.secrets_provider_config))
    secrets_provider.init(secrets_provider_config)

    pyinstance = python_instance.PythonInstance(
        str(args.instance_id), str(args.function_id),
        str(args.function_version), function_details,
        int(args.max_buffered_tuples), int(args.expected_healthcheck_interval),
        str(args.py), pulsar_client, secrets_provider, args.cluster_name,
        state_storage_serviceurl)
    pyinstance.run()
    server_instance = server.serve(args.port, pyinstance)

    # Cannot use latest version of prometheus client because of thread leak
    # prometheus_client.start_http_server(args.metrics_port)
    # Use patched version of prometheus
    # Contains fix from https://github.com/prometheus/client_python/pull/356
    # This can be removed one the fix in is a official prometheus client release
    prometheus_client_fix.start_http_server(args.metrics_port)

    global to_run
    while to_run:
        time.sleep(1)

    pyinstance.join()
    # make sure to close all non-daemon threads before this!
    sys.exit(0)
예제 #20
0
def main():
  # Setup signal handlers
  signal.signal(signal.SIGTERM, atexit_function)
  signal.signal(signal.SIGHUP, atexit_function)
  signal.signal(signal.SIGINT, atexit_function)

  parser = argparse.ArgumentParser(description='Pulsar Functions Python Instance')
  parser.add_argument('--function_details', required=True, help='Function Details Json String')
  parser.add_argument('--py', required=True, help='Full Path of Function Code File')
  parser.add_argument('--instance_id', required=True, help='Instance Id')
  parser.add_argument('--function_id', required=True, help='Function Id')
  parser.add_argument('--function_version', required=True, help='Function Version')
  parser.add_argument('--pulsar_serviceurl', required=True, help='Pulsar Service Url')
  parser.add_argument('--client_auth_plugin', required=False, help='Client authentication plugin')
  parser.add_argument('--client_auth_params', required=False, help='Client authentication params')
  parser.add_argument('--use_tls', required=False, help='Use tls')
  parser.add_argument('--tls_allow_insecure_connection', required=False, help='Tls allow insecure connection')
  parser.add_argument('--hostname_verification_enabled', required=False, help='Enable hostname verification')
  parser.add_argument('--tls_trust_cert_path', required=False, help='Tls trust cert file path')
  parser.add_argument('--port', required=True, help='Instance Port', type=int)
  parser.add_argument('--max_buffered_tuples', required=True, help='Maximum number of Buffered tuples')
  parser.add_argument('--logging_directory', required=True, help='Logging Directory')
  parser.add_argument('--logging_file', required=True, help='Log file name')
  parser.add_argument('--logging_config_file', required=True, help='Config file for logging')
  parser.add_argument('--expected_healthcheck_interval', required=True, help='Expected time in seconds between health checks', type=int)
  parser.add_argument('--secrets_provider', required=False, help='The classname of the secrets provider')
  parser.add_argument('--secrets_provider_config', required=False, help='The config that needs to be passed to secrets provider')
  parser.add_argument('--install_usercode_dependencies', required=False, help='For packaged python like wheel files, do we need to install all dependencies', type=bool)
  parser.add_argument('--dependency_repository', required=False, help='For packaged python like wheel files, which repository to pull the dependencies from')
  parser.add_argument('--extra_dependency_repository', required=False, help='For packaged python like wheel files, any extra repository to pull the dependencies from')

  args = parser.parse_args()
  function_details = Function_pb2.FunctionDetails()
  args.function_details = str(args.function_details)
  if args.function_details[0] == '\'':
    args.function_details = args.function_details[1:]
  if args.function_details[-1] == '\'':
    args.function_details = args.function_details[:-1]
  json_format.Parse(args.function_details, function_details)

  if os.path.splitext(str(args.py))[1] == '.whl':
    if args.install_usercode_dependencies:
      cmd = "pip install -t %s" % os.path.dirname(str(args.py))
      if args.dependency_repository:
        cmd = cmd + " -i %s" % str(args.dependency_repository)
      if args.extra_dependency_repository:
        cmd = cmd + " --extra-index-url %s" % str(args.extra_dependency_repository)
      cmd = cmd + " %s" % str(args.py)
      retval = os.system(cmd)
      if retval != 0:
        print "Could not install user depedencies"
        sys.exit(1)
    else:
      zpfile = zipfile.ZipFile(str(args.py), 'r')
      zpfile.extractall(os.path.dirname(str(args.py)))
    sys.path.insert(0, os.path.dirname(str(args.py)))
  elif os.path.splitext(str(args.py))[1] == '.zip':
    # Assumig zip file with format func.zip
    # extract to folder function
    # internal dir format
    # "func/src"
    # "func/requirements.txt"
    # "func/deps"
    # run pip install to target folder  deps folder
    zpfile = zipfile.ZipFile(str(args.py), 'r')
    zpfile.extractall(os.path.dirname(str(args.py)))
    basename = os.path.splitext(str(args.py))[0]
    requirements_txt_file = os.path.join(os.path.dirname(str(args.py)), basename, "requirements.txt")
    deps_file = os.path.join(os.path.dirname(str(args.py)), basename, "deps")
    cmd = "pip install -t %s -r %s --no-index --find-links %s" % (os.path.dirname(str(args.py)), requirements_txt_file, deps_file)
    retval = os.system(cmd)
    if retval != 0:
      print "Could not install user depedencies specified by the zip file"
      sys.exit(1)
    sys.path.insert(0, os.path.join(os.path.dirname(str(args.py)), basename, "src"))

  log_file = os.path.join(args.logging_directory,
                          util.getFullyQualifiedFunctionName(function_details.tenant, function_details.namespace, function_details.name),
                          "%s-%s.log" % (args.logging_file, args.instance_id))
  log.init_logger(logging.INFO, log_file, args.logging_config_file)

  Log.info("Starting Python instance with %s" % str(args))

  authentication = None
  use_tls = False
  tls_allow_insecure_connection = False
  tls_trust_cert_path = None
  if args.client_auth_plugin and args.client_auth_params:
      authentication = pulsar.Authentication(args.client_auth_plugin, args.client_auth_params)
  if args.use_tls == "true":
    use_tls = True
  if args.tls_allow_insecure_connection == "true":
    tls_allow_insecure_connection = True
  if args.tls_trust_cert_path:
     tls_trust_cert_path =  args.tls_trust_cert_path
  pulsar_client = pulsar.Client(args.pulsar_serviceurl, authentication, 30, 1, 1, 50000, None, use_tls, tls_trust_cert_path, tls_allow_insecure_connection)

  secrets_provider = None
  if args.secrets_provider is not None:
    secrets_provider = util.import_class(os.path.dirname(inspect.getfile(inspect.currentframe())), str(args.secrets_provider))
  else:
    secrets_provider = util.import_class(os.path.dirname(inspect.getfile(inspect.currentframe())), "secretsprovider.ClearTextSecretsProvider")
  secrets_provider = secrets_provider()
  secrets_provider_config = None
  if args.secrets_provider_config is not None:
    secrets_provider_config = json.loads(str(args.secrets_provider_config))
  secrets_provider.init(secrets_provider_config)

  pyinstance = python_instance.PythonInstance(str(args.instance_id), str(args.function_id),
                                              str(args.function_version), function_details,
                                              int(args.max_buffered_tuples),
                                              int(args.expected_healthcheck_interval),
                                              str(args.py), pulsar_client, secrets_provider)
  pyinstance.run()
  server_instance = server.serve(args.port, pyinstance)

  global to_run
  while to_run:
    time.sleep(1)

  pyinstance.join()
  sys.exit(1)
예제 #21
0
   def on_modified(self,event):
      print("File modified ->"+event.src_path)
      self.renderJade()

def startLogger():
   logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s - %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S')   
   event_handler = LoggingEventHandler()
   observer = Observer()
   observer.schedule(event_handler, ".", recursive=True)
   observer.start()
   try:
      while True:
         time.sleep(1)
   except KeyboardInterrupt:
      observer.stop()
   observer.join()

def startRender(path,batfile):
   jade_handler  = JadeHandler(batfile)   
   renderer = Observer()
   renderer.schedule(jade_handler, path, recursive=True)
   renderer.start()

if __name__ == "__main__":
   server.serve()
   startRender("post","rpost.bat")
   startRender("events/14-15","revent.bat")
   startLogger()
예제 #22
0
def main():
    # Setup signal handlers
    signal.signal(signal.SIGTERM, atexit_function)
    signal.signal(signal.SIGHUP, atexit_function)
    signal.signal(signal.SIGINT, atexit_function)

    parser = argparse.ArgumentParser(
        description='Pulsar Functions Python Instance')
    parser.add_argument('--function_details',
                        required=True,
                        help='Function Details Json String')
    parser.add_argument('--py',
                        required=True,
                        help='Full Path of Function Code File')
    parser.add_argument('--instance_id', required=True, help='Instance Id')
    parser.add_argument('--function_id', required=True, help='Function Id')
    parser.add_argument('--function_version',
                        required=True,
                        help='Function Version')
    parser.add_argument('--pulsar_serviceurl',
                        required=True,
                        help='Pulsar Service Url')
    parser.add_argument('--client_auth_plugin',
                        required=False,
                        help='Client authentication plugin')
    parser.add_argument('--client_auth_params',
                        required=False,
                        help='Client authentication params')
    parser.add_argument('--use_tls', required=False, help='Use tls')
    parser.add_argument('--tls_allow_insecure_connection',
                        required=False,
                        help='Tls allow insecure connection')
    parser.add_argument('--hostname_verification_enabled',
                        required=False,
                        help='Enable hostname verification')
    parser.add_argument('--tls_trust_cert_path',
                        required=False,
                        help='Tls trust cert file path')
    parser.add_argument('--port',
                        required=True,
                        help='Instance Port',
                        type=int)
    parser.add_argument('--max_buffered_tuples',
                        required=True,
                        help='Maximum number of Buffered tuples')
    parser.add_argument('--logging_directory',
                        required=True,
                        help='Logging Directory')
    parser.add_argument('--logging_file', required=True, help='Log file name')
    parser.add_argument('--expected_healthcheck_interval',
                        required=True,
                        help='Expected time in seconds between health checks',
                        type=int)
    parser.add_argument(
        '--install_usercode_dependencies',
        required=False,
        help=
        'For packaged python like wheel files, do we need to install all dependencies',
        type=bool)

    args = parser.parse_args()
    function_details = Function_pb2.FunctionDetails()
    args.function_details = str(args.function_details)
    if args.function_details[0] == '\'':
        args.function_details = args.function_details[1:]
    if args.function_details[-1] == '\'':
        args.function_details = args.function_details[:-1]
    json_format.Parse(args.function_details, function_details)

    if os.path.splitext(str(args.py))[1] == '.whl':
        if args.install_usercode_dependencies:
            os.system("pip install -t %s %s" %
                      (os.path.dirname(str(args.py)), str(args.py)))
        else:
            zpfile = zipfile.ZipFile(str(args.py), 'r')
            zpfile.extractall(os.path.dirname(str(args.py)))
        sys.path.insert(0, os.path.dirname(str(args.py)))

    log_file = os.path.join(
        args.logging_directory,
        util.getFullyQualifiedFunctionName(function_details.tenant,
                                           function_details.namespace,
                                           function_details.name),
        "%s-%s.log" % (args.logging_file, args.instance_id))
    log.init_rotating_logger(level=logging.INFO,
                             logfile=log_file,
                             max_files=5,
                             max_bytes=10 * 1024 * 1024)

    Log.info("Starting Python instance with %s" % str(args))

    authentication = None
    use_tls = False
    tls_allow_insecure_connection = False
    tls_trust_cert_path = None
    if args.client_auth_plugin and args.client_auth_params:
        authentication = pulsar.Authentication(args.client_auth_plugin,
                                               args.client_auth_params)
    if args.use_tls == "true":
        use_tls = True
    if args.tls_allow_insecure_connection == "true":
        tls_allow_insecure_connection = True
    if args.tls_trust_cert_path:
        tls_trust_cert_path = args.tls_trust_cert_path
    pulsar_client = pulsar.Client(args.pulsar_serviceurl, authentication, 30,
                                  1, 1, 50000, None, use_tls,
                                  tls_trust_cert_path,
                                  tls_allow_insecure_connection)
    pyinstance = python_instance.PythonInstance(
        str(args.instance_id), str(args.function_id),
        str(args.function_version), function_details,
        int(args.max_buffered_tuples), int(args.expected_healthcheck_interval),
        str(args.py), pulsar_client)
    pyinstance.run()
    server_instance = server.serve(args.port, pyinstance)

    global to_run
    while to_run:
        time.sleep(1)

    pyinstance.join()
    sys.exit(1)
예제 #23
0
def main():
    serve()
예제 #24
0
파일: gluten.py 프로젝트: entd/gitgluten
def main():
	configParser = confparser.ConfigParser(DEFAULT_NAME)
	config = configParser.main_config
	server.serve(config)
예제 #25
0
            xmin = int(round(top_xmin[i] * image.shape[1]))
            ymin = int(round(top_ymin[i] * image.shape[0]))
            xmax = int(round(top_xmax[i] * image.shape[1]))
            ymax = int(round(top_ymax[i] * image.shape[0]))
            xmin = max(1, xmin)
            ymin = max(1, ymin)
            xmax = min(image.shape[1] - 1, xmax)
            ymax = min(image.shape[0] - 1, ymax)
            score = top_conf[i]
            boxes.append({
                'score': float(score),
                'x_min': xmin,
                'x_max': xmax,
                'y_min': ymin,
                'y_max': ymax
            })
            cv2.rectangle(open_cv_image, (xmin, ymin), (xmax, ymax),
                          (255, 191, 0), 2)

    #buf = BytesIO()
    image_nd = cv2.imencode('.jpg', open_cv_image)[1]
    #input_image.save(buf, format='JPEG')
    #buf.seek(0)
    print("Drawing boxes took %.1f ms" % ((time.time() - start_draw) * 1000))
    print("Total processing time: %.1f ms" % ((time.time() - start) * 1000))
    return image_nd.tobytes()


server.serve(identify_boxes, port=os.environ.get('PORT'))
예제 #26
0
파일: main.py 프로젝트: barisser/redmatter
def hostthread():
    server.serve()
예제 #27
0
import subprocess

try:
    import config
    print('[Info] Loading configuration from config.py')
    Server = config.Server
    Dashboard = config.Dashboard
    Worker = config.Worker
except ImportError:
    print('[Warning] No configuration file were found! Using default config settings.')
    print('[Warning] For more info see config.py. example file or README file.')
    Server = None
    Dashboard = None
    Worker = None

if len(sys.argv) < 2:
    sys.exit('Usage: %s component-name (i.e. server, dashboard or worker)' % sys.argv[0])
elif (sys.argv[1] == 'worker'):
    print 'running worker'
    import worker
    worker.serve(Worker)
elif (sys.argv[1] == 'dashboard'):
    print 'running dashboard'
    import dashboard
    dashboard.serve(Dashboard)
elif (sys.argv[1] == 'server'):
    print 'running server'
    import server
    server.serve(Server)
else:
    sys.exit('Usage: %s component-name (i.e. server, dashboard or worker)' % sys.argv[0])
예제 #28
0
def serve(create_db, with_fixtures, port, hot_reload):
    """Serve the application"""
    from server import serve
    serve(create_db, with_fixtures, port, hot_reload)
예제 #29
0
def main():
    # Setup signal handlers
    signal.signal(signal.SIGTERM, atexit_function)
    signal.signal(signal.SIGHUP, atexit_function)
    signal.signal(signal.SIGINT, atexit_function)

    parser = argparse.ArgumentParser(
        description='Pulsar Functions Python Instance')
    parser.add_argument('--function_details',
                        required=True,
                        help='Function Details Json String')
    parser.add_argument('--py',
                        required=True,
                        help='Full Path of Function Code File')
    parser.add_argument('--instance_id', required=True, help='Instance Id')
    parser.add_argument('--function_id', required=True, help='Function Id')
    parser.add_argument('--function_version',
                        required=True,
                        help='Function Version')
    parser.add_argument('--pulsar_serviceurl',
                        required=True,
                        help='Pulsar Service Url')
    parser.add_argument('--client_auth_plugin',
                        required=False,
                        help='Client authentication plugin')
    parser.add_argument('--client_auth_params',
                        required=False,
                        help='Client authentication params')
    parser.add_argument('--use_tls', required=False, help='Use tls')
    parser.add_argument('--tls_allow_insecure_connection',
                        required=False,
                        help='Tls allow insecure connection')
    parser.add_argument('--hostname_verification_enabled',
                        required=False,
                        help='Enable hostname verification')
    parser.add_argument('--tls_trust_cert_path',
                        required=False,
                        help='Tls trust cert file path')
    parser.add_argument('--port',
                        required=True,
                        help='Instance Port',
                        type=int)
    parser.add_argument('--max_buffered_tuples',
                        required=True,
                        help='Maximum number of Buffered tuples')
    parser.add_argument('--logging_directory',
                        required=True,
                        help='Logging Directory')
    parser.add_argument('--logging_file', required=True, help='Log file name')

    args = parser.parse_args()
    function_details = Function_pb2.FunctionDetails()
    json_format.Parse(args.function_details, function_details)
    log_file = os.path.join(
        args.logging_directory,
        util.getFullyQualifiedFunctionName(function_details.tenant,
                                           function_details.namespace,
                                           function_details.name),
        "%s-%s.log" % (args.logging_file, args.instance_id))
    log.init_rotating_logger(level=logging.INFO,
                             logfile=log_file,
                             max_files=5,
                             max_bytes=10 * 1024 * 1024)

    Log.info("Starting Python instance with %s" % str(args))

    authentication = None
    use_tls = False
    tls_allow_insecure_connection = False
    tls_trust_cert_path = None
    if args.client_auth_plugin and args.client_auth_params:
        authentication = pulsar.Authentication(args.client_auth_plugin,
                                               args.client_auth_params)
    if args.use_tls == "true":
        use_tls = True
    if args.tls_allow_insecure_connection == "true":
        tls_allow_insecure_connection = True
    if args.tls_trust_cert_path:
        tls_trust_cert_path = args.tls_trust_cert_path
    pulsar_client = pulsar.Client(args.pulsar_serviceurl, authentication, 30,
                                  1, 1, 50000, None, use_tls,
                                  tls_trust_cert_path,
                                  tls_allow_insecure_connection)
    pyinstance = python_instance.PythonInstance(str(args.instance_id),
                                                str(args.function_id),
                                                str(args.function_version),
                                                function_details,
                                                int(args.max_buffered_tuples),
                                                str(args.py), pulsar_client)
    pyinstance.run()
    server_instance = server.serve(args.port, pyinstance)

    global to_run
    while to_run:
        time.sleep(1)

    pyinstance.join()
    sys.exit(1)
예제 #30
0
파일: uremi.py 프로젝트: pfalcon/uremi
 def serve(self):
     print(EVENT_MAP)
     server.serve(self.http_handler)
예제 #31
0
#!/usr/bin/env python3
import sys
import os.path
import webbrowser

import dependencies
import server

from config import port

if __name__ == "__main__":
	if len(sys.argv) < 2:
		print("Missing argument! %s <annotation directory>" % sys.argv[0], file=sys.stderr)
		sys.exit(1)
	
	server_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
	project_dir = sys.argv[1]
	
	if not dependencies.resolve(server_dir):
		sys.exit(2)
	
	webbrowser.open("http://localhost:%d" % port)
	server.serve(server_dir, project_dir)
	
예제 #32
0
def main():
  # Setup signal handlers
  signal.signal(signal.SIGTERM, atexit_function)
  signal.signal(signal.SIGHUP, atexit_function)
  signal.signal(signal.SIGINT, atexit_function)

  parser = argparse.ArgumentParser(description='Pulsar Functions Python Instance')
  parser.add_argument('--function_classname', required=True, help='Function Class Name')
  parser.add_argument('--py', required=True, help='Full Path of Function Code File')
  parser.add_argument('--name', required=True, help='Function Name')
  parser.add_argument('--tenant', required=True, help='Tenant Name')
  parser.add_argument('--namespace', required=True, help='Namespace name')
  parser.add_argument('--instance_id', required=True, help='Instance Id')
  parser.add_argument('--function_id', required=True, help='Function Id')
  parser.add_argument('--function_version', required=True, help='Function Version')
  parser.add_argument('--processing_guarantees', required=True, help='Processing Guarantees')
  parser.add_argument('--pulsar_serviceurl', required=True, help='Pulsar Service Url')
  parser.add_argument('--port', required=True, help='Instance Port', type=int)
  parser.add_argument('--max_buffered_tuples', required=True, help='Maximum number of Buffered tuples')
  parser.add_argument('--user_config', required=False, help='User Config')
  parser.add_argument('--logging_directory', required=True, help='Logging Directory')
  parser.add_argument('--logging_file', required=True, help='Log file name')
  parser.add_argument('--auto_ack', required=True, help='Enable Autoacking?')
  parser.add_argument('--log_topic', required=False, help='Topic to send Log Messages')
  parser.add_argument('--source_subscription_type', required=True, help='Subscription Type')
  parser.add_argument('--source_topics_serde_classname', required=True, help='A mapping of Input topics to SerDe')
  parser.add_argument('--sink_topic', required=False, help='Sink Topic')
  parser.add_argument('--sink_serde_classname', required=False, help='Sink SerDe classname')

  args = parser.parse_args()
  log_file = os.path.join(args.logging_directory,
                          util.getFullyQualifiedFunctionName(args.tenant, args.namespace, args.name),
                          "%s-%s.log" % (args.logging_file, args.instance_id))
  log.init_rotating_logger(level=logging.INFO, logfile=log_file,
                           max_files=5, max_bytes=10 * 1024 * 1024)

  Log.info("Starting Python instance with %s" % str(args))

  function_details = Function_pb2.FunctionDetails()
  function_details.tenant = args.tenant
  function_details.namespace = args.namespace
  function_details.name = args.name
  function_details.className = args.function_classname

  sourceSpec = Function_pb2.SourceSpec()
  sourceSpec.subscriptionType = Function_pb2.SubscriptionType.Value(args.source_subscription_type)
  try:
    source_topics_serde_classname_dict = json.loads(args.source_topics_serde_classname)
  except ValueError:
    log.critical("Cannot decode source_topics_serde_classname.  This argument must be specifed as a JSON")
    sys.exit(1)
  if not source_topics_serde_classname_dict:
    log.critical("source_topics_serde_classname cannot be empty")
  for topics, serde_classname in source_topics_serde_classname_dict.items():
    sourceSpec.topicsToSerDeClassName[topics] = serde_classname
  function_details.source.MergeFrom(sourceSpec)

  sinkSpec = Function_pb2.SinkSpec()
  if args.sink_topic != None and len(args.sink_topic) != 0:
    sinkSpec.topic = args.sink_topic
  if args.sink_serde_classname != None and len(args.sink_serde_classname) != 0:
    sinkSpec.serDeClassName = args.sink_serde_classname
  function_details.sink.MergeFrom(sinkSpec)

  function_details.processingGuarantees = Function_pb2.ProcessingGuarantees.Value(args.processing_guarantees)
  if args.auto_ack == "true":
    function_details.autoAck = True
  else:
    function_details.autoAck = False
  if args.user_config != None and len(args.user_config) != 0:
    function_details.userConfig = args.user_config

  pulsar_client = pulsar.Client(args.pulsar_serviceurl)
  pyinstance = python_instance.PythonInstance(str(args.instance_id), str(args.function_id),
                                              str(args.function_version), function_details,
                                              int(args.max_buffered_tuples), str(args.py),
                                              args.log_topic, pulsar_client)
  pyinstance.run()
  server_instance = server.serve(args.port, pyinstance)

  global to_run
  while to_run:
    time.sleep(1)

  pyinstance.join()
  sys.exit(1)
예제 #33
0
파일: gluten.py 프로젝트: entd/gitgluten
def main():
    configParser = confparser.ConfigParser(DEFAULT_NAME)
    config = configParser.main_config
    server.serve(config)
예제 #34
0
parser_server.add_argument("--http-username", dest="http_username", help="dhclientlist server username.")
parser_server.add_argument("--http-password", dest="http_password", help="dhclientlist server password.")
parser_server.add_argument("--debug", dest="debug", action="store_true", help="runs the server in debug mode")


args = parser.parse_args()

if args.command == 'list-drivers':
    table = util.texttable.Texttable()
    table.set_deco(util.texttable_deco)
    table.add_rows([["All drivers"]] + [[driver_name.replace('drivers.', '')] for driver_name in util.list_all_drivers()])
    print table.draw()

elif args.command == 'serve':
    server.serve(server.application.build(get, args.address, args.username, args.password,
                                          util.drivername_to_module(args.drivername),
                                          args.http_username, args.http_password),
                 args.port, args.debug)

elif args.command == 'print':
    try:
        result = get(args.address, args.username, args.password, util.drivername_to_module(args.drivername))
    except Exception as ex:
        print >>sys.stderr, ex
        exit(1)

    if len(result):
        if args.format == "json":
            print json.dumps(result)
        elif args.format == "texttable":
            print util.to_texttable(result)
    else:
예제 #35
0
파일: main.py 프로젝트: weleek/grpc-chat
sys.path.append(os.path.abspath(os.path.dirname(__file__)) + "/proto")

from client import start
from server import serve

if __name__ == '__main__':
    c = None
    try:
        logging.basicConfig()

        mode = input("choice running mode.\n[s] server mode.\n[c] client mode.\n> ")
        while True:
            if mode.upper() == 'S':
                print('Server mode select...')
                print("Server running...")
                serve()
                break 
            elif mode.upper() == 'C':
                print('Client mode select...')
                start()
                break
            else:
                mode = input("choice running mode.\n[s] server mode.\n[c] client mode.\n> ")

    except KeyboardInterrupt:
        print ("\nprogram stop...")
    except Exception as err:
        print("[main.py]", err)
        
        
예제 #36
0
파일: main.py 프로젝트: barisser/civserver
def server_process():
    server.serve()
예제 #37
0
def send():

	t = folder_path.get()
	messagebox.showinfo("Information","sending files...")
	serve(t)
예제 #38
0
   def create_new_version(self,dirname,filename):
      print("Creating new file from : \"{0}\" in : \"{1}\"".format(filename, dirname))
      #Non blocking for parallel rendering
      p=Popen(["jade","-P",filename,"--out",dirname],cwd="./",shell=True)
      stdout, stderr = p.communicate() #Shows jade rendering status
      return p

   def generator(self,event):
      if event.src_path.split(".")[-1].lower() in ("jade", "md", "html"): 
         data=self.parse_file_path(event.src_path)
         if(data["type"]!="none"):
            self.remove_older_version(data["outdir"],data["filename"])
            self.create_new_version(data["outdir"],data["full-path"])

   def on_created(self,event):
      self.generator(event)
   def on_modified(self,event):
      self.generator(event)

def startRender():
   jade_handler  = JadeHandler()   
   renderer = Observer()
   renderer.schedule(jade_handler,"./", recursive=True)
   renderer.start()

if __name__ == "__main__":
   print("Started Sentinel")
   startRender()
   print("Launching page")
   server.serve(7000)
def run(ctx):
    serve(ctx.config)
예제 #40
0
def main():
  """
  Do it
  """

  # Parse the command line args
  parser = argparse.ArgumentParser(description="Phone Lookup")
  # What to do
  parser.add_argument("--lookup",   action="store_true", help="Perform phone lookup")
  parser.add_argument("--geocode",  action="store_true", help="Perform geocoding")
  parser.add_argument("--server",   action="store_true", help="Perform reverse address serving")

  # Server params
  parser.add_argument("--server_sid",   type=str, help="sid for server")
  parser.add_argument("--server_token", type=str, help="token for server")

  # Which geocoder to use
  parser.add_argument("--geocoder", type=str, default="mock", help="Which geocoder ('mock' or 'google')")

  # Vendor params
  parser.add_argument("--pce_id",    type=str,            help="PacificEast Account ID/Key")
  parser.add_argument("--pce_env",   type=str,            help="PacificEast environment ('dev' or 'prod')")
  parser.add_argument("--wp_key",    type=str,            help="WhitePages API Key")

  parser.add_argument("--runall",   action="store_true", help="Run all numbers without prompting")
  args = parser.parse_args()

  # Perform actions
  if not (args.lookup or args.geocode or args.server):
    log.warn("No actions specified. Use '--lookup' and/or '--geocode' or '--server' to do something.")
  elif args.server and (args.lookup or args.geocode):
    log.warn("Cannot use '--server' with '--lookup' or '--geocode'.")
  elif args.server:
    # Use normal SIGINT handling
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    # Run the server
    if args.pce_id:
      vendors = [
        Vendor.get("PacificEast", config={"public": False, "account_id": args.pce_id, "env": args.pce_env}),
      ]
    else:
      vendors = [
        Vendor.get("mock", config={}),
      ]

    # Configure and run the Pyramid app
    server.serve(vendors, sid=args.server_sid, token=args.server_token)
    
  else:
    # Load the number data and perform the lookups
    log.debug("Loading numbers.json")
    numbers = load_numbers("numbers.json")

    ############
    # Lookups
    if args.lookup:
      log.info("Performing lookups")

      # Get the waterfall
      waterfall = get_waterfall(
        pce_id=args.pce_id,
        pce_env=args.pce_env,
        whitepages_key=args.wp_key)
  
      do_lookups(numbers, waterfall, "numbers.json", runall=args.runall)

    ############
    # Geocoding
    if args.geocode:
      log.info("Performing geocoding")
      geocoder = Geocoder.get(args.geocoder, config={})
      do_geocoding(numbers, geocoder, "numbers.json", runall=args.runall)
예제 #41
0
파일: lol.py 프로젝트: gitter-badger/lol
def serve(port):
    """Start a server to serve a directory to localhost."""

    server.serve(port)
예제 #42
0
def main():
    # Setup signal handlers
    signal.signal(signal.SIGTERM, atexit_function)
    signal.signal(signal.SIGHUP, atexit_function)
    signal.signal(signal.SIGINT, atexit_function)

    parser = argparse.ArgumentParser(
        description='Pulsar Functions Python Instance')
    parser.add_argument('--function_classname',
                        required=True,
                        help='Function Class Name')
    parser.add_argument('--py',
                        required=True,
                        help='Full Path of Function Code File')
    parser.add_argument('--name', required=True, help='Function Name')
    parser.add_argument('--tenant', required=True, help='Tenant Name')
    parser.add_argument('--namespace', required=True, help='Namespace name')
    parser.add_argument('--custom_serde_input_topics',
                        required=False,
                        help='Input Topics Requiring Custom Deserialization')
    parser.add_argument('--custom_serde_classnames',
                        required=False,
                        help='Input Serde Classnames')
    parser.add_argument('--input_topics',
                        required=False,
                        help='Input topics with default serde')
    parser.add_argument('--output_topic', required=False, help='Output Topic')
    parser.add_argument('--output_serde_classname',
                        required=False,
                        help='Output Serde Classnames')
    parser.add_argument('--instance_id', required=True, help='Instance Id')
    parser.add_argument('--function_id', required=True, help='Function Id')
    parser.add_argument('--function_version',
                        required=True,
                        help='Function Version')
    parser.add_argument('--processing_guarantees',
                        required=True,
                        help='Processing Guarantees')
    parser.add_argument('--pulsar_serviceurl',
                        required=True,
                        help='Pulsar Service Url')
    parser.add_argument('--port',
                        required=True,
                        help='Instance Port',
                        type=int)
    parser.add_argument('--max_buffered_tuples',
                        required=True,
                        help='Maximum number of Buffered tuples')
    parser.add_argument('--user_config', required=False, help='User Config')
    parser.add_argument('--logging_directory',
                        required=True,
                        help='Logging Directory')
    parser.add_argument('--logging_file', required=True, help='Log file name')
    parser.add_argument('--auto_ack', required=True, help='Enable Autoacking?')
    parser.add_argument('--log_topic',
                        required=False,
                        help='Topic to send Log Messages')

    args = parser.parse_args()
    log_file = os.path.join(args.logging_directory,
                            args.logging_file + ".log.0")
    log.init_rotating_logger(level=logging.INFO,
                             logfile=log_file,
                             max_files=5,
                             max_bytes=10 * 1024 * 1024)

    Log.info("Starting Python instance with %s" % str(args))

    function_config = Function_pb2.FunctionConfig()
    function_config.tenant = args.tenant
    function_config.namespace = args.namespace
    function_config.name = args.name
    function_config.className = args.function_classname
    if args.custom_serde_input_topics is None and args.input_topics is None:
        Log.critical("Atleast one input topic must be present")
        sys.exit(1)
    if args.custom_serde_input_topics is not None and args.custom_serde_classnames is not None:
        input_topics = args.custom_serde_input_topics.split(",")
        input_serde = args.custom_serde_classnames.split(",")
        if len(input_topics) != len(input_serde):
            Log.critical(
                "CustomSerde InputTopcis and Serde classnames should match")
            sys.exit(1)
        for i in xrange(len(input_topics)):
            function_config.customSerdeInputs[input_topics[i]] = input_serde[i]
    if args.input_topics is not None:
        for topic in args.input_topics.split(","):
            function_config.inputs.append(topic)
    if args.output_topic != None and len(args.output_topic) != 0:
        function_config.output = args.output_topic
    if args.output_serde_classname != None and len(
            args.output_serde_classname) != 0:
        function_config.outputSerdeClassName = args.output_serde_classname
    function_config.processingGuarantees = Function_pb2.FunctionConfig.ProcessingGuarantees.Value(
        args.processing_guarantees)
    if args.auto_ack == "true":
        function_config.autoAck = True
    else:
        function_config.autoAck = False
    if args.user_config != None and len(args.user_config) != 0:
        user_config = json.loads(args.user_config)
        for (key, value) in user_config.items():
            function_config.userConfig[str(key)] = str(value)

    pulsar_client = pulsar.Client(args.pulsar_serviceurl)
    pyinstance = python_instance.PythonInstance(str(args.instance_id),
                                                str(args.function_id),
                                                str(args.function_version),
                                                function_config,
                                                int(args.max_buffered_tuples),
                                                str(args.py), args.log_topic,
                                                pulsar_client)
    pyinstance.run()
    server_instance = server.serve(args.port, pyinstance)

    global to_run
    while to_run:
        time.sleep(1)

    pyinstance.join()
    sys.exit(1)
예제 #43
0
ap.add_argument('-a',
                type=str,
                nargs=1,
                dest="address",
                default=[''],
                help='TCP address to bind to')
ap.add_argument('actions',
                type=str,
                nargs=1,
                metavar="/path/to/actions",
                help='Path to actions file')

args = ap.parse_args()

actions_path = args.actions[0]
port = args.port[0]
address = args.address[0]

try:
    actions = parser.parse_actions(actions_path)
except Exception as e:
    error("Unable to parse actions file: %s" % str(e))

while True:
    try:
        server.serve(actions, port=port, ip=address)
    except KeyboardInterrupt:
        break
    except Exception as e:
        error("Error in server loop: %s" % str(e))
예제 #44
0
# Copyright 2013 The Servo Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

import webdriver
import server
from ServoProcess import ServoProcess


def handler(self):
    return 200, [('Content-Type', 'text/html')], '<html><body>hi there</body></html>'

with ServoProcess():
    server.serve(handler)
    session = webdriver.Session('127.0.0.1', 7000)
    session.start()
    session.url = "http://localhost:8001"
    try:
        assert session.url == "http://localhost:8001/"
    except AssertionError, e:
        raise Exception("URL don`t match!")
#    session.end()
    server.stop()
예제 #45
0
def server_process():
    server.serve()
예제 #46
0
   def create_new_version(self,dirname,filename):
      print("Creating new file from : \"{0}\" in : \"{1}\"".format(filename, dirname))
      #Non blocking for parallel rendering
      p=Popen(["jade","-P",filename,"--out",dirname],cwd="./",shell=True)
      stdout, stderr = p.communicate() #Shows jade rendering status
      return p

   def generator(self,event):
      if event.src_path.split(".")[-1].lower() in ("jade", "md", "html"): 
         data=self.parse_file_path(event.src_path)
         if(data["type"]!="none"):
            self.remove_older_version(data["outdir"],data["filename"])
            self.create_new_version(data["outdir"],data["full-path"])

   def on_created(self,event):
      self.generator(event)
   def on_modified(self,event):
      self.generator(event)

def startRender():
   jade_handler  = JadeHandler()   
   renderer = Observer()
   renderer.schedule(jade_handler,"./", recursive=True)
   renderer.start()

if __name__ == "__main__":
   print("Started Sentinel")
   startRender()
   print("Launching page")
   server.serve(8000)
예제 #47
0
def main(fullscreen, debug, fps, pixel_size, raspberry, serve_at):

    # RaspberryPi init #
    if raspberry:
        import RPi.GPIO as GPIO
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(GPIO_FEED, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(GPIO_KILL, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    # Game init #
    pygame.init()

    bird = Bird()
    food = None

    size = width, height = 128, 72

    screen = pygame.surface.Surface(size)
    screen.set_alpha(None)
    window = pygame.display.set_mode((width * pixel_size, height * pixel_size))
    if fullscreen:
        pygame.display.toggle_fullscreen()
        pygame.mouse.set_visible(False)

    clock = pygame.time.Clock()
    prog_frame_count = 0
    game_frame_count = 0
    game_frame_time = 0
    button_pressed_count = 0
    font = pygame.font.Font("LiberationMono-Regular.ttf", 20)

    # Game functions #
    def action():
        """To be executed on user input."""
        nonlocal button_pressed_count
        feed()
        button_pressed_count += 1
        if button_pressed_count > 100:
            reset()

    def feed():
        """Drop some food"""
        nonlocal food
        if not food: food = Food()

    def dance():
        """Make the bird dance"""
        nonlocal bird
        bird.dance()

    def reset():
        """Reset the game"""
        nonlocal food, bird
        bird.init()
        food = None

    def kill():
        """Kill the bird."""
        nonlocal bird
        bird.hunger = DEATH_POS_LIMIT

    # OSC Server #
    if serve_at:
        from server import serve
        adress = serve_at, 4242

        try:
            serve(adress, {
                "/feed": feed,
                "/dance": dance,
                "/reset": reset,
                "/kill": kill,
            })
        except Exception:
            pass  # UGLY !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    # Main loop #
    while True:

        # Time #
        clock.tick()
        prog_frame_count += 1
        game_frame_time += clock.get_time()
        if game_frame_time > 1000 / fps:
            game_frame_time = 0
            game_frame_count += 1

        # Events #
        event = pygame.event.poll()
        if event.type == pygame.QUIT:
            pygame.quit()
            return
        pressed = pygame.key.get_pressed()
        if pressed[pygame.K_ESCAPE]:
            pygame.quit()
            return
        elif pressed[pygame.K_r]:
            reset()
        elif pressed[pygame.K_d]:
            dance()
        elif pressed[pygame.K_SPACE]:
            action()
        elif raspberry and not GPIO.input(GPIO_FEED):
            action()
        elif raspberry and not GPIO.input(GPIO_KILL):
            kill()
        else:
            button_pressed_count = 0

        # Update #
        if game_frame_time == 0:
            if food:
                if bird.eat():
                    food = None
                else:
                    food.update()
            bird.update()

        # Draw #
        screen.fill((255, 255, 255))
        pygame.draw.rect(screen, (220, 220, 220),
                         (0, 0, width, height *
                          (bird.hunger - DEATH_NEG_LIMIT) /
                          (DEATH_POS_LIMIT - DEATH_NEG_LIMIT) - 1), 0)
        if food:
            food.draw(screen, (0, -3))
        bird.draw(screen, (0, -3))

        window.blit(
            pygame.transform.scale(screen,
                                   (width * pixel_size, height * pixel_size)),
            (0, 0))

        # Debug #
        if debug:

            def write_line(line, txt):
                label = font.render(txt.upper(), False, (0, 0, 0))
                window.blit(label, (10, 10 + line * 20))

            infos = ("prog fps: {:.2f}".format(clock.get_fps()),
                     "prog frame count: {}".format(prog_frame_count),
                     "game frame count: {}".format(game_frame_count), "",
                     "bird hunger: {}".format(
                         bird.hunger), "bird weight: {}".format(bird.weight),
                     "bird state: {}".format(bird.state), "",
                     "sprite name: {}".format(bird.current_sprite.name),
                     "sprite variation idx: {}".format(
                         bird.current_sprite.variation_index),
                     "sprite frm: {}/{}".format(
                         bird.current_sprite.index,
                         len(bird.current_sprite.frames[
                             bird.current_sprite.variation_index])))
            for line, txt in enumerate(infos):
                write_line(line, txt)

        pygame.display.flip()
예제 #48
0

def startLogger():
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s - %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S')
    event_handler = LoggingEventHandler()
    observer = Observer()
    observer.schedule(event_handler, ".", recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()


def startRender(path, batfile):
    jade_handler = JadeHandler(batfile)
    renderer = Observer()
    renderer.schedule(jade_handler, path, recursive=True)
    renderer.start()


if __name__ == "__main__":
    server.serve()
    startRender("post", "rpost.bat")
    startRender("events/14-15", "revent.bat")
    startLogger()
예제 #49
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
__package__ = __name__

import authentication
import client
from client import create_connection, wrap_socket
import error
from lib import baseserver, conf
import packet
import server
from server import serve, SOCKS5Server

__doc__ = """
a pure-python SOCKS5 library

when executed, runs a configurable SOCKS server (version 5 by default)
"""

if __name__ == "__main__":
    config = conf.Conf()
    config.append(conf.Section())

    #mkconfig

    threaded = baseserver.threaded.Pipelining(nthreads=1)
    serve(threaded, **config[0])
예제 #50
0
        type=int,
        nargs='?',
        help='Port on which server will be run (8888 is the default)'
    )
    parser.add_argument(
        'request',
        type=str,
        help='Request name to run',
        nargs='?'
    )
    parser.add_argument(
        'config',
        type=str,
        help='Config name to use',
        nargs='?'
    )

    args = parser.parse_args()

    if args.server:
        server.serve(port=args.port)
        sys.exit(0)

    request = args.request
    config = args.config

    if request is None or config is None:
        parser.error('request and config must be given together')

    engine.make_request(request, config)
def main():
    port = 14022
    logging.basicConfig(level=logging.INFO)
    classifier.init()
    server.serve(port)