Example #1
0
    def init(self, parser, opts, args):
        if opts.paste:
            app_name = "main"
            path = opts.paste
            if "#" in path:
                path, app_name = path.split("#")
            path = os.path.abspath(
                os.path.normpath(os.path.join(util.getcwd(), path)))

            if not os.path.exists(path):
                raise ConfigError("%r not found" % path)

            # paste application, load the config
            self.cfgurl = "config:%s#%s" % (path, app_name)
            self.relpath = os.path.dirname(path)

            from .pasterapp import paste_config

            return paste_config(self.cfg, self.cfgurl, self.relpath)

        if len(args) < 1:
            parser.error("No application module specified.")

        self.cfg.set("default_proc_name", args[0])
        self.app_uri = args[0]
Example #2
0
def make_default_env(cfg):
    if cfg.django_settings:
        os.environ['DJANGO_SETTINGS_MODULE'] = cfg.django_settings

    if cfg.pythonpath and cfg.pythonpath is not None:
        paths = cfg.pythonpath.split(",")
        for path in paths:
            pythonpath = os.path.abspath(cfg.pythonpath)
            if pythonpath not in sys.path:
                sys.path.insert(0, pythonpath)

    try:
        os.environ['DJANGO_SETTINGS_MODULE']
    except KeyError:
        # not settings env set, try to build one.
        cwd = util.getcwd()
        project_path, settings_name = find_settings_module(cwd)

        if not project_path:
            raise RuntimeError("django project not found")

        pythonpath, project_name = os.path.split(project_path)
        os.environ['DJANGO_SETTINGS_MODULE'] = "%s.%s" % (project_name,
                                                          settings_name)
        if pythonpath not in sys.path:
            sys.path.insert(0, pythonpath)

        if project_path not in sys.path:
            sys.path.insert(0, project_path)
Example #3
0
    def __init__(self, app):
        os.environ["SERVER_SOFTWARE"] = SERVER_SOFTWARE

        self._num_workers = None
        self._last_logged_active_worker_count = None
        self.log = None

        self.setup(app)

        self.pidfile = None
        self.worker_age = 0
        self.reexec_pid = 0
        self.master_pid = 0
        self.master_name = "Master"

        cwd = util.getcwd()

        args = sys.argv[:]
        args.insert(0, sys.executable)

        # init start context
        self.START_CTX = {
            "args": args,
            "cwd": cwd,
            0: sys.executable
        }
def make_default_env(cfg):
    if cfg.django_settings:
        os.environ['DJANGO_SETTINGS_MODULE'] = cfg.django_settings

    if cfg.pythonpath and cfg.pythonpath is not None:
        paths = cfg.pythonpath.split(",")
        for path in paths:
            pythonpath = os.path.abspath(cfg.pythonpath)
            if pythonpath not in sys.path:
                sys.path.insert(0, pythonpath)

    try:
        os.environ['DJANGO_SETTINGS_MODULE']
    except KeyError:
        # not settings env set, try to build one.
        cwd = util.getcwd()
        project_path, settings_name = find_settings_module(cwd)

        if not project_path:
            raise RuntimeError("django project not found")

        pythonpath, project_name = os.path.split(project_path)
        os.environ['DJANGO_SETTINGS_MODULE'] = "%s.%s" % (project_name,
                settings_name)
        if pythonpath not in sys.path:
            sys.path.insert(0, pythonpath)

        if project_path not in sys.path:
            sys.path.insert(0, project_path)
Example #5
0
class Chdir(Setting):
    name = "chdir"
    section = "Server Mechanics"
    cli = ["--chdir"]
    validator = validate_chdir
    default = util.getcwd()
    desc = """\
Example #6
0
    def __init__(self, app):
        os.environ["SERVER_SOFTWARE"] = SERVER_SOFTWARE

        self._num_workers = None
        self.setup(app)

        self.pidfile = None
        self.worker_age = 0
        self.reexec_pid = 0
        self.master_name = "Master"

        cwd = util.getcwd()

        args = sys.argv[:]
        args.insert(0, sys.executable)

        # init start context
        self.START_CTX = {
            "args": args,
            "cwd": cwd,
            0: sys.executable
        }

        # Instrumentation
        self.last_usr_t = 0  # store time used by children
Example #7
0
    def __init__(self, app):
        os.environ["SERVER_SOFTWARE"] = SERVER_SOFTWARE

        self._num_workers = None
        self._last_logged_active_worker_count = None
        self.log = None

        self.setup(app)

        self.pidfile = None
        self.worker_age = 0
        self.reexec_pid = 0
        self.master_name = "Master"

        cwd = util.getcwd()

        args = sys.argv[:]
        args.insert(0, sys.executable)

        # init start context
        self.START_CTX = {
            "args": args,
            "cwd": cwd,
            0: sys.executable
        }
Example #8
0
    def __init__(self, app):
        os.environ["SERVER_SOFTWARE"] = SERVER_SOFTWARE

        self._num_workers = None
        self._last_logged_active_worker_count = None
        self.log = None

        # 一下属性会在 setup 中赋值
        self.app = None
        self.cfg = None
        self.worker_class = None
        self.address = None
        self.timeout = None
        self.proc_name = None
        self.setup(app)

        self.pid = None         # 在 start 中赋值
        self.pidfile = None
        self.systemd = False
        self.worker_age = 0
        self.reexec_pid = 0
        self.master_pid = 0
        self.master_name = "Master"

        args = sys.argv[:]
        args.insert(0, sys.executable)

        # init start context
        self.START_CTX = {
            # e.g. ['python3.7', 'gunicorn', '-w', '1', 'app:app']
            "args": args,
            "cwd": util.getcwd(),
            0: sys.executable       # e.g. python3.7
        }
        self._log('START_CTX: %s' % self.START_CTX)
Example #9
0
    def init(self, parser, opts, args):
        if len(args) != 1:
            parser.error("No application module specified.")

        self.cfg.set("default_proc_name", args[0])
        self.app_uri = args[0]

        cwd = util.getcwd()

        sys.path.insert(0, cwd)
Example #10
0
    def init(self, parser, opts, args):
        if len(args) != 1:
            parser.error("No application module specified.")

        self.cfg.set("default_proc_name", args[0])
        self.app_uri = args[0]

        cwd = util.getcwd()

        sys.path.insert(0, cwd)
Example #11
0
def validate_chdir(val):
    # valid if the value is a string
    val = validate_string(val)

    # transform relative paths
    path = os.path.abspath(os.path.normpath(os.path.join(util.getcwd(), val)))

    # test if the path exists
    if not os.path.exists(path):
        raise ConfigError("can't chdir to %r" % val)

    return path
Example #12
0
def validate_chdir(val):
    # valid if the value is a string
    val = validate_string(val)

    # transform relative paths
    path = os.path.abspath(os.path.normpath(os.path.join(util.getcwd(), val)))

    # test if the path exists
    if not os.path.exists(path):
        raise ConfigError("can't chdir to %r" % val)

    return path
Example #13
0
def validate_file(val):
    if val is None:
        return None

    # valid if the value is a string
    val = validate_string(val)

    # transform relative paths
    path = os.path.abspath(os.path.normpath(os.path.join(util.getcwd(), val)))

    # test if the path exists
    if not os.path.exists(path):
        raise ConfigError("%r not found" % val)

    return path
Example #14
0
def validate_config_dir(val):
    if val is None:
        return val
    else:
        # valid if the value is a string
        val = validate_string(val)

        # transform relative paths
        path = os.path.abspath(os.path.normpath(os.path.join(util.getcwd(), val)))

        # test if the path exists
        if not os.path.exists(path):
            raise ConfigError("can't find a config directory in %r" % val)

        return path
Example #15
0
def validate_file(val):
    if val is None:
        return None

    # valid if the value is a string
    val = validate_string(val)

    # transform relative paths
    path = os.path.abspath(os.path.normpath(os.path.join(util.getcwd(), val)))

    # test if the path exists
    if not os.path.exists(path):
        raise ConfigError("%r not found" % val)

    return path
Example #16
0
    def init(self, parser, opts, args):
        if len(args) != 1:
            parser.error("No application name specified.")

        cwd = util.getcwd()
        cfgfname = os.path.normpath(os.path.join(cwd, args[0]))
        cfgfname = os.path.abspath(cfgfname)
        if not os.path.exists(cfgfname):
            parser.error("Config file not found: %s" % cfgfname)

        self.cfgurl = 'config:%s' % cfgfname
        self.relpath = os.path.dirname(cfgfname)
        self.cfgfname = cfgfname

        sys.path.insert(0, self.relpath)
        pkg_resources.working_set.add_entry(self.relpath)

        return self.app_config()
Example #17
0
    def init(self, parser, opts, args):
        if len(args) != 1:
            parser.error("No application name specified.")

        cwd = util.getcwd()
        cfgfname = os.path.normpath(os.path.join(cwd, args[0]))
        cfgfname = os.path.abspath(cfgfname)
        if not os.path.exists(cfgfname):
            parser.error("Config file not found: %s" % cfgfname)

        self.cfgurl = 'config:%s' % cfgfname
        self.relpath = os.path.dirname(cfgfname)
        self.cfgfname = cfgfname

        sys.path.insert(0, self.relpath)
        pkg_resources.working_set.add_entry(self.relpath)

        return self.app_config()
Example #18
0
    def init(self, parser, opts, args):
        if opts.paste and opts.paste is not None:
            app_name = 'main'
            path = opts.paste
            if '#' in path:
                path, app_name = path.split('#')
            path = os.path.abspath(
                os.path.normpath(os.path.join(getcwd(), path)))

            if not os.path.exists(path):
                raise ConfigError("%r not found" % path)

            # paste application, load the config
            self.cfgurl = 'config:%s#%s' % (path, app_name)
            self.relpath = os.path.dirname(path)

        self.cfg.set("default_proc_name", FLASK_APP.__dict__.get('name', ''))
        self.app_uri = FLASK_APP
Example #19
0
    def init(self, parser, opts, args):
        if opts.paste and opts.paste is not None:
            path = os.path.abspath(os.path.normpath(
                os.path.join(util.getcwd(), opts.paste)))

            if not os.path.exists(path):
                raise ConfigError("%r not found" % val)

            # paste application, load the config
            self.cfgurl = 'config:%s' % path
            self.relpath = os.path.dirname(path)

            from .pasterapp import paste_config
            return paste_config(self.cfg, self.cfgurl, self.relpath)

        if len(args) != 1:
            parser.error("No application module specified.")

        self.cfg.set("default_proc_name", args[0])
        self.app_uri = args[0]
Example #20
0
    def init(self, parser, opts, args):
        if opts.paste and opts.paste is not None:
            path = os.path.abspath(
                os.path.normpath(os.path.join(util.getcwd(), opts.paste)))

            if not os.path.exists(path):
                raise ConfigError("%r not found" % val)

            # paste application, load the config
            self.cfgurl = 'config:%s' % path
            self.relpath = os.path.dirname(path)

            from .pasterapp import paste_config
            return paste_config(self.cfg, self.cfgurl, self.relpath)

        if len(args) != 1:
            parser.error("No application module specified.")

        self.cfg.set("default_proc_name", args[0])
        self.app_uri = args[0]
Example #21
0
    def init(self, parser, opts, args):
        if opts.paste:
            app_name = 'main'
            path = opts.paste
            if '#' in path:
                path, app_name = path.split('#')
            path = os.path.abspath(os.path.normpath(
                os.path.join(util.getcwd(), path)))

            if not os.path.exists(path):
                raise ConfigError("%r not found" % path)

            # paste application, load the config
            self.cfgurl = 'config:%s#%s' % (path, app_name)
            self.relpath = os.path.dirname(path)

            from .pasterapp import paste_config
            return paste_config(self.cfg, self.cfgurl, self.relpath)

        if len(args) < 1:
            parser.error("No application module specified.")

        self.cfg.set("default_proc_name", args[0])
        self.app_uri = args[0]
Example #22
0
 def __init__(self, filename, settings=None):
     self.relpath = util.getcwd()
     self.cfgpath = abspath(normpath(join(self.relpath, filename)))
     self.cfgurl = 'config:' + self.cfgpath
     self.settings = settings
     super(Application, self).__init__()
Example #23
0
File: script.py Project: ercchy/h
 def __init__(self, filename, settings=None):
     self.relpath = util.getcwd()
     self.cfgpath = abspath(normpath(join(self.relpath, filename)))
     self.cfgurl = 'config:' + self.cfgpath
     self.settings = settings
     super(Application, self).__init__()