def app_pack_compiled(app, request, raise_ex=False): """ Builds a w2p bytecode-compiled package for the application Parameters ---------- app: application name request: the global request object Returns ------- filename: filename of the w2p file or None on error """ try: filename = apath("../deposit/%s.w2p" % app, request) w2p_pack(filename, apath(app, request), compiled=True) return filename except Exception, e: if raise_ex: raise return None
def app_pack_compiled(app, request, raise_ex=False): """ Builds a w2p bytecode-compiled package for the application Parameters ---------- app: application name request: the global request object Returns ------- filename: filename of the w2p file or None on error """ try: filename = apath('../deposit/%s.w2p' % app, request) w2p_pack(filename, apath(app, request), compiled=True) return filename except Exception, e: if raise_ex: raise return None
def app_pack(app, request, raise_ex=False, filenames=None): """ Builds a w2p package for the application Parameters ---------- app: application name request: the global request object Returns ------- filename: filename of the w2p file or None on error """ try: if filenames is None: app_cleanup(app, request) filename = apath("../deposit/web2py.app.%s.w2p" % app, request) w2p_pack(filename, apath(app, request), filenames=filenames) return filename except Exception, e: if raise_ex: raise return False
def app_pack(app, request, raise_ex=False, filenames=None): """ Builds a w2p package for the application Parameters ---------- app: application name request: the global request object Returns ------- filename: filename of the w2p file or None on error """ try: if filenames is None: app_cleanup(app, request) filename = apath('../deposit/web2py.app.%s.w2p' % app, request) w2p_pack(filename, apath(app, request), filenames=filenames) return filename except Exception, e: if raise_ex: raise return False
def app_pack(app, request): """ Builds a w2p package for the application Parameters ---------- app: application name request: the global request object Returns ------- filename: filename of the w2p file or None on error """ try: app_cleanup(app, request) filename = apath('../deposit/%s.w2p' % app, request) w2p_pack(filename, apath(app, request)) return filename except Exception: return False
def console(): """ Defines the behavior of the console web2py execution """ usage = "python web2py.py" description = """\ web2py Web Framework startup script. ATTENTION: unless a password is specified (-a 'passwd') web2py will attempt to run a GUI. In this case command line options are ignored.""" description = dedent(description) parser = OptionParser(usage, None, Option, ProgramVersion) parser.description = description parser.add_option('-i', '--ip', default='127.0.0.1', dest='ip', help='ip address of the server (127.0.0.1)') parser.add_option('-p', '--port', default='8000', dest='port', type='int', help='port of server (8000)') msg = 'password to be used for administration' msg += ' (use -a "<recycle>" to reuse the last password))' parser.add_option('-a', '--password', default='<ask>', dest='password', help=msg) parser.add_option('-c', '--ssl_certificate', default='', dest='ssl_certificate', help='file that contains ssl certificate') parser.add_option('-k', '--ssl_private_key', default='', dest='ssl_private_key', help='file that contains ssl private key') parser.add_option('-d', '--pid_filename', default='httpserver.pid', dest='pid_filename', help='file to store the pid of the server') parser.add_option('-l', '--log_filename', default='httpserver.log', dest='log_filename', help='file to log connections') parser.add_option('-n', '--numthreads', default='10', type='int', dest='numthreads', help='number of threads') parser.add_option('-s', '--server_name', default=socket.gethostname(), dest='server_name', help='server name for the web server') msg = 'max number of queued requests when server unavailable' parser.add_option('-q', '--request_queue_size', default='5', type='int', dest='request_queue_size', help=msg) parser.add_option('-o', '--timeout', default='10', type='int', dest='timeout', help='timeout for individual request (10 seconds)') parser.add_option('-z', '--shutdown_timeout', default='5', type='int', dest='shutdown_timeout', help='timeout on shutdown of server (5 seconds)') parser.add_option('-f', '--folder', default=os.getcwd(), dest='folder', help='folder from which to run web2py') parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False, help='increase --test verbosity') parser.add_option('-Q', '--quiet', action='store_true', dest='quiet', default=False, help='disable all output') msg = 'set debug output level (0-100, 0 means all, 100 means none;' msg += ' default is 30)' parser.add_option('-D', '--debug', dest='debuglevel', default=30, type='int', help=msg) msg = 'run web2py in interactive shell or IPython (if installed) with' msg += ' specified appname (if app does not exist it will be created).' parser.add_option('-S', '--shell', dest='shell', metavar='APPNAME', help=msg) msg = 'only use plain python shell; should be used with --shell option' parser.add_option('-P', '--plain', action='store_true', default=False, dest='plain', help=msg) msg = 'auto import model files; default is False; should be used' msg += ' with --shell option' parser.add_option('-M', '--import_models', action='store_true', default=False, dest='import_models', help=msg) msg = 'run PYTHON_FILE in web2py environment;' msg += ' should be used with --shell option' parser.add_option('-R', '--run', dest='run', metavar='PYTHON_FILE', default='', help=msg) msg = 'run doctests in web2py environment; ' +\ 'TEST_PATH like a/c/f (c,f optional)' parser.add_option('-T', '--test', dest='test', metavar='TEST_PATH', default=None, help=msg) parser.add_option('-W', '--winservice', dest='winservice', default='', help='-W install|start|stop as Windows service') msg = 'trigger a cron run manually; usually invoked from a system crontab' parser.add_option('-C', '--cron', action='store_true', dest='extcron', default=False, help=msg) msg = 'triggers the use of softcron' parser.add_option('--softcron', action='store_true', dest='softcron', default=False, help=msg) parser.add_option('-N', '--no-cron', action='store_true', dest='nocron', default=False, help='do not start cron automatically') parser.add_option('-L', '--config', dest='config', default='', help='config file') parser.add_option('-F', '--profiler', dest='profiler_filename', default=None, help='profiler filename') parser.add_option('-t', '--taskbar', action='store_true', dest='taskbar', default=False, help='use web2py gui and run in taskbar (system tray)') parser.add_option('', '--nogui', action='store_true', default=False, dest='nogui', help='text-only, no GUI') parser.add_option('-A', '--args', action='store', dest='args', default='', help='should be followed by a list of arguments to be passed to script, to be used with -S, -A must be the last option') msg = 'allows multiple interfaces to be served' parser.add_option('--interfaces', action='store', dest='interfaces', default=None, help=msg) if '-A' in sys.argv: k = sys.argv.index('-A') elif '--args' in sys.argv: k = sys.argv.index('--args') else: k=len(sys.argv) sys.argv, other_args = sys.argv[:k], sys.argv[k+1:] (options, args) = parser.parse_args() options.args = [options.run] + other_args if options.quiet: capture = cStringIO.StringIO() sys.stdout = capture logger.setLevel(logging.CRITICAL + 1) else: logger.setLevel(options.debuglevel) if options.config[-3:] == '.py': options.config = options.config[:-3] for path in ('applications', 'deposit', 'site-packages', 'logs'): if not os.path.exists(path): os.mkdir(path) sys.path.append(os.path.join(os.getcwd(),'site-packages')) # If we have the applications package or if we should upgrade if not os.path.exists('applications/__init__.py'): fp = open('applications/__init__.py', 'w') fp.write('') fp.close() if not os.path.exists('welcome.w2p') or os.path.exists('NEWINSTALL'): w2p_pack('welcome.w2p','applications/welcome') os.unlink('NEWINSTALL') return (options, args)
def console(): """ Defines the behavior of the console web2py execution """ import optparse import textwrap usage = "python web2py.py" description = """\ web2py Web Framework startup script. ATTENTION: unless a password is specified (-a 'passwd') web2py will attempt to run a GUI. In this case command line options are ignored.""" description = textwrap.dedent(description) parser = optparse.OptionParser(usage, None, optparse.Option, ProgramVersion) parser.description = description parser.add_option('-i', '--ip', default='127.0.0.1', dest='ip', help='ip address of the server (127.0.0.1)') parser.add_option('-p', '--port', default='8000', dest='port', type='int', help='port of server (8000)') msg = 'password to be used for administration' msg += ' (use -a "<recycle>" to reuse the last password))' parser.add_option('-a', '--password', default='<ask>', dest='password', help=msg) parser.add_option('-c', '--ssl_certificate', default='', dest='ssl_certificate', help='file that contains ssl certificate') parser.add_option('-k', '--ssl_private_key', default='', dest='ssl_private_key', help='file that contains ssl private key') parser.add_option('--ca-cert', action='store', dest='ssl_ca_certificate', default=None, help='Use this file containing the CA certificate to validate X509 certificates from clients') parser.add_option('-d', '--pid_filename', default='httpserver.pid', dest='pid_filename', help='file to store the pid of the server') parser.add_option('-l', '--log_filename', default='httpserver.log', dest='log_filename', help='file to log connections') parser.add_option('-n', '--numthreads', default=None, type='int', dest='numthreads', help='number of threads (deprecated)') parser.add_option('--minthreads', default=None, type='int', dest='minthreads', help='minimum number of server threads') parser.add_option('--maxthreads', default=None, type='int', dest='maxthreads', help='maximum number of server threads') parser.add_option('-s', '--server_name', default=socket.gethostname(), dest='server_name', help='server name for the web server') msg = 'max number of queued requests when server unavailable' parser.add_option('-q', '--request_queue_size', default='5', type='int', dest='request_queue_size', help=msg) parser.add_option('-o', '--timeout', default='10', type='int', dest='timeout', help='timeout for individual request (10 seconds)') parser.add_option('-z', '--shutdown_timeout', default='5', type='int', dest='shutdown_timeout', help='timeout on shutdown of server (5 seconds)') parser.add_option('--socket-timeout', default=5, type='int', dest='socket_timeout', help='timeout for socket (5 second)') parser.add_option('-f', '--folder', default=os.getcwd(), dest='folder', help='folder from which to run web2py') parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False, help='increase --test verbosity') parser.add_option('-Q', '--quiet', action='store_true', dest='quiet', default=False, help='disable all output') msg = 'set debug output level (0-100, 0 means all, 100 means none;' msg += ' default is 30)' parser.add_option('-D', '--debug', dest='debuglevel', default=30, type='int', help=msg) msg = 'run web2py in interactive shell or IPython (if installed) with' msg += ' specified appname (if app does not exist it will be created).' msg += ' APPNAME like a/c/f (c,f optional)' parser.add_option('-S', '--shell', dest='shell', metavar='APPNAME', help=msg) msg = 'run web2py in interactive shell or bpython (if installed) with' msg += ' specified appname (if app does not exist it will be created).' msg += '\n Use combined with --shell' parser.add_option('-B', '--bpython', action='store_true', default=False, dest='bpython', help=msg) msg = 'only use plain python shell; should be used with --shell option' parser.add_option('-P', '--plain', action='store_true', default=False, dest='plain', help=msg) msg = 'auto import model files; default is False; should be used' msg += ' with --shell option' parser.add_option('-M', '--import_models', action='store_true', default=False, dest='import_models', help=msg) msg = 'run PYTHON_FILE in web2py environment;' msg += ' should be used with --shell option' parser.add_option('-R', '--run', dest='run', metavar='PYTHON_FILE', default='', help=msg) msg = 'run scheduled tasks for the specified apps' msg += '-K app1,app2,app3' msg += 'requires a scheduler defined in the models' parser.add_option('-K', '--scheduler', dest='scheduler', default=None, help=msg) msg = 'run schedulers alongside webserver' parser.add_option('-X', '--with-scheduler', action='store_true', default=False, dest='with_scheduler', help=msg) msg = 'run doctests in web2py environment; ' +\ 'TEST_PATH like a/c/f (c,f optional)' parser.add_option('-T', '--test', dest='test', metavar='TEST_PATH', default=None, help=msg) parser.add_option('-W', '--winservice', dest='winservice', default='', help='-W install|start|stop as Windows service') msg = 'trigger a cron run manually; usually invoked from a system crontab' parser.add_option('-C', '--cron', action='store_true', dest='extcron', default=False, help=msg) msg = 'triggers the use of softcron' parser.add_option('--softcron', action='store_true', dest='softcron', default=False, help=msg) parser.add_option('-N', '--no-cron', action='store_true', dest='nocron', default=False, help='do not start cron automatically') parser.add_option('-J', '--cronjob', action='store_true', dest='cronjob', default=False, help='identify cron-initiated command') parser.add_option('-L', '--config', dest='config', default='', help='config file') parser.add_option('-F', '--profiler', dest='profiler_filename', default=None, help='profiler filename') parser.add_option('-t', '--taskbar', action='store_true', dest='taskbar', default=False, help='use web2py gui and run in taskbar (system tray)') parser.add_option('', '--nogui', action='store_true', default=False, dest='nogui', help='text-only, no GUI') parser.add_option('-A', '--args', action='store', dest='args', default=None, help='should be followed by a list of arguments to be passed to script, to be used with -S, -A must be the last option') parser.add_option('--no-banner', action='store_true', default=False, dest='nobanner', help='Do not print header banner') msg = 'listen on multiple addresses: "ip:port:cert:key:ca_cert;ip2:port2:cert2:key2:ca_cert2;..." (:cert:key optional; no spaces)' parser.add_option('--interfaces', action='store', dest='interfaces', default=None, help=msg) msg = 'runs web2py tests' parser.add_option('--run_system_tests', action='store_true', dest='run_system_tests', default=False, help=msg) if '-A' in sys.argv: k = sys.argv.index('-A') elif '--args' in sys.argv: k = sys.argv.index('--args') else: k=len(sys.argv) sys.argv, other_args = sys.argv[:k], sys.argv[k+1:] (options, args) = parser.parse_args() options.args = [options.run] + other_args global_settings.cmd_options = options global_settings.cmd_args = args try: options.ips = [ ip for ip in socket.gethostbyname_ex(socket.getfqdn())[2] if ip!='127.0.0.1'] except socket.gaierror: options.ips = [] if options.run_system_tests: run_system_tests() if options.quiet: capture = cStringIO.StringIO() sys.stdout = capture logger.setLevel(logging.CRITICAL + 1) else: logger.setLevel(options.debuglevel) if options.config[-3:] == '.py': options.config = options.config[:-3] if options.cronjob: global_settings.cronjob = True # tell the world options.nocron = True # don't start cron jobs options.plain = True # cronjobs use a plain shell options.folder = os.path.abspath(options.folder) # accept --interfaces in the form # "ip:port:cert:key;ip2:port2;ip3:port3:cert3:key3" # (no spaces; optional cert:key indicate SSL) if isinstance(options.interfaces, str): options.interfaces = [ interface.split(':') for interface in options.interfaces.split(';')] for interface in options.interfaces: interface[1] = int(interface[1]) # numeric port options.interfaces = [ tuple(interface) for interface in options.interfaces] if options.numthreads is not None and options.minthreads is None: options.minthreads = options.numthreads # legacy if not options.cronjob: # If we have the applications package or if we should upgrade if not os.path.exists('applications/__init__.py'): write_file('applications/__init__.py', '') if not os.path.exists('welcome.w2p') or os.path.exists('NEWINSTALL'): try: w2p_pack('welcome.w2p','applications/welcome') os.unlink('NEWINSTALL') except: msg = "New installation: unable to create welcome.w2p file" sys.stderr.write(msg) return (options, args)
def console(): """ Defines the behavior of the console web2py execution """ import optparse import textwrap usage = "python web2py.py" description = """\ web2py Web Framework startup script. ATTENTION: unless a password is specified (-a 'passwd') web2py will attempt to run a GUI. In this case command line options are ignored.""" description = textwrap.dedent(description) parser = optparse.OptionParser(usage, None, optparse.Option, ProgramVersion) parser.description = description parser.add_option("-i", "--ip", default="127.0.0.1", dest="ip", help="ip address of the server (127.0.0.1)") parser.add_option("-p", "--port", default="8000", dest="port", type="int", help="port of server (8000)") msg = "password to be used for administration" msg += ' (use -a "<recycle>" to reuse the last password))' parser.add_option("-a", "--password", default="<ask>", dest="password", help=msg) parser.add_option( "-c", "--ssl_certificate", default="", dest="ssl_certificate", help="file that contains ssl certificate" ) parser.add_option( "-k", "--ssl_private_key", default="", dest="ssl_private_key", help="file that contains ssl private key" ) parser.add_option( "--ca-cert", action="store", dest="ssl_ca_certificate", default=None, help="Use this file containing the CA certificate to validate X509 certificates from clients", ) parser.add_option( "-d", "--pid_filename", default="httpserver.pid", dest="pid_filename", help="file to store the pid of the server", ) parser.add_option( "-l", "--log_filename", default="httpserver.log", dest="log_filename", help="file to log connections" ) parser.add_option( "-n", "--numthreads", default=None, type="int", dest="numthreads", help="number of threads (deprecated)" ) parser.add_option( "--minthreads", default=None, type="int", dest="minthreads", help="minimum number of server threads" ) parser.add_option( "--maxthreads", default=None, type="int", dest="maxthreads", help="maximum number of server threads" ) parser.add_option( "-s", "--server_name", default=socket.gethostname(), dest="server_name", help="server name for the web server" ) msg = "max number of queued requests when server unavailable" parser.add_option("-q", "--request_queue_size", default="5", type="int", dest="request_queue_size", help=msg) parser.add_option( "-o", "--timeout", default="10", type="int", dest="timeout", help="timeout for individual request (10 seconds)" ) parser.add_option( "-z", "--shutdown_timeout", default="5", type="int", dest="shutdown_timeout", help="timeout on shutdown of server (5 seconds)", ) parser.add_option( "--socket-timeout", default=60, type="int", dest="socket_timeout", help="timeout for socket (60 second)" ) parser.add_option("-f", "--folder", default=os.getcwd(), dest="folder", help="folder from which to run web2py") parser.add_option( "-v", "--verbose", action="store_true", dest="verbose", default=False, help="increase --test verbosity" ) parser.add_option("-Q", "--quiet", action="store_true", dest="quiet", default=False, help="disable all output") msg = "set debug output level (0-100, 0 means all, 100 means none;" msg += " default is 30)" parser.add_option("-D", "--debug", dest="debuglevel", default=30, type="int", help=msg) msg = "run web2py in interactive shell or IPython (if installed) with" msg += " specified appname (if app does not exist it will be created)." msg += " APPNAME like a/c/f (c,f optional)" parser.add_option("-S", "--shell", dest="shell", metavar="APPNAME", help=msg) msg = "run web2py in interactive shell or bpython (if installed) with" msg += " specified appname (if app does not exist it will be created)." msg += "\n Use combined with --shell" parser.add_option("-B", "--bpython", action="store_true", default=False, dest="bpython", help=msg) msg = "only use plain python shell; should be used with --shell option" parser.add_option("-P", "--plain", action="store_true", default=False, dest="plain", help=msg) msg = "auto import model files; default is False; should be used" msg += " with --shell option" parser.add_option("-M", "--import_models", action="store_true", default=False, dest="import_models", help=msg) msg = "run PYTHON_FILE in web2py environment;" msg += " should be used with --shell option" parser.add_option("-R", "--run", dest="run", metavar="PYTHON_FILE", default="", help=msg) msg = "run scheduled tasks for the specified apps" msg += "-K app1,app2,app3" msg += "requires a scheduler defined in the models" parser.add_option("-K", "--scheduler", dest="scheduler", default=None, help=msg) msg = "run doctests in web2py environment; " + "TEST_PATH like a/c/f (c,f optional)" parser.add_option("-T", "--test", dest="test", metavar="TEST_PATH", default=None, help=msg) parser.add_option( "-W", "--winservice", dest="winservice", default="", help="-W install|start|stop as Windows service" ) msg = "trigger a cron run manually; usually invoked from a system crontab" parser.add_option("-C", "--cron", action="store_true", dest="extcron", default=False, help=msg) msg = "triggers the use of softcron" parser.add_option("--softcron", action="store_true", dest="softcron", default=False, help=msg) parser.add_option( "-N", "--no-cron", action="store_true", dest="nocron", default=False, help="do not start cron automatically" ) parser.add_option( "-J", "--cronjob", action="store_true", dest="cronjob", default=False, help="identify cron-initiated command" ) parser.add_option("-L", "--config", dest="config", default="", help="config file") parser.add_option("-F", "--profiler", dest="profiler_filename", default=None, help="profiler filename") parser.add_option( "-t", "--taskbar", action="store_true", dest="taskbar", default=False, help="use web2py gui and run in taskbar (system tray)", ) parser.add_option("", "--nogui", action="store_true", default=False, dest="nogui", help="text-only, no GUI") parser.add_option( "-A", "--args", action="store", dest="args", default=None, help="should be followed by a list of arguments to be passed to script, to be used with -S, -A must be the last option", ) parser.add_option( "--no-banner", action="store_true", default=False, dest="nobanner", help="Do not print header banner" ) msg = 'listen on multiple addresses: "ip:port:cert:key:ca_cert;ip2:port2:cert2:key2:ca_cert2;..." (:cert:key optional; no spaces)' parser.add_option("--interfaces", action="store", dest="interfaces", default=None, help=msg) if "-A" in sys.argv: k = sys.argv.index("-A") elif "--args" in sys.argv: k = sys.argv.index("--args") else: k = len(sys.argv) sys.argv, other_args = sys.argv[:k], sys.argv[k + 1 :] (options, args) = parser.parse_args() options.args = [options.run] + other_args global_settings.cmd_options = options global_settings.cmd_args = args if options.quiet: capture = cStringIO.StringIO() sys.stdout = capture logger.setLevel(logging.CRITICAL + 1) else: logger.setLevel(options.debuglevel) if options.config[-3:] == ".py": options.config = options.config[:-3] if options.cronjob: global_settings.cronjob = True # tell the world options.nocron = True # don't start cron jobs options.plain = True # cronjobs use a plain shell options.folder = os.path.abspath(options.folder) # accept --interfaces in the form # "ip:port:cert:key;ip2:port2;ip3:port3:cert3:key3" # (no spaces; optional cert:key indicate SSL) if isinstance(options.interfaces, str): options.interfaces = [interface.split(":") for interface in options.interfaces.split(";")] for interface in options.interfaces: interface[1] = int(interface[1]) # numeric port options.interfaces = [tuple(interface) for interface in options.interfaces] if options.numthreads is not None and options.minthreads is None: options.minthreads = options.numthreads # legacy if not options.cronjob: # If we have the applications package or if we should upgrade if not os.path.exists("applications/__init__.py"): write_file("applications/__init__.py", "") if not os.path.exists("welcome.w2p") or os.path.exists("NEWINSTALL"): try: w2p_pack("welcome.w2p", "applications/welcome") os.unlink("NEWINSTALL") except: msg = "New installation: unable to create welcome.w2p file" sys.stderr.write(msg) return (options, args)
def console(): """ Defines the behavior of the console web2py execution """ usage = "python web2py.py" description = """\ web2py Web Framework startup script. ATTENTION: unless a password is specified (-a 'passwd') web2py will attempt to run a GUI. In this case command line options are ignored.""" description = dedent(description) parser = OptionParser(usage, None, Option, ProgramVersion) parser.description = description parser.add_option("-i", "--ip", default="127.0.0.1", dest="ip", help="ip address of the server (127.0.0.1)") parser.add_option("-p", "--port", default="8000", dest="port", type="int", help="port of server (8000)") msg = "password to be used for administration" msg += ' (use -a "<recycle>" to reuse the last password))' parser.add_option("-a", "--password", default="<ask>", dest="password", help=msg) parser.add_option( "-c", "--ssl_certificate", default="", dest="ssl_certificate", help="file that contains ssl certificate" ) parser.add_option( "-k", "--ssl_private_key", default="", dest="ssl_private_key", help="file that contains ssl private key" ) parser.add_option( "-d", "--pid_filename", default="httpserver.pid", dest="pid_filename", help="file to store the pid of the server", ) parser.add_option( "-l", "--log_filename", default="httpserver.log", dest="log_filename", help="file to log connections" ) parser.add_option("-n", "--numthreads", default="10", type="int", dest="numthreads", help="number of threads") parser.add_option( "-s", "--server_name", default=socket.gethostname(), dest="server_name", help="server name for the web server" ) msg = "max number of queued requests when server unavailable" parser.add_option("-q", "--request_queue_size", default="5", type="int", dest="request_queue_size", help=msg) parser.add_option( "-o", "--timeout", default="10", type="int", dest="timeout", help="timeout for individual request (10 seconds)" ) parser.add_option( "-z", "--shutdown_timeout", default="5", type="int", dest="shutdown_timeout", help="timeout on shutdown of server (5 seconds)", ) parser.add_option("-f", "--folder", default=os.getcwd(), dest="folder", help="folder from which to run web2py") parser.add_option( "-v", "--verbose", action="store_true", dest="verbose", default=False, help="increase --test verbosity" ) parser.add_option("-Q", "--quiet", action="store_true", dest="quiet", default=False, help="disable all output") msg = "set debug output level (0-100, 0 means all, 100 means none;" msg += " default is 30)" parser.add_option("-D", "--debug", dest="debuglevel", default=30, type="int", help=msg) msg = "run web2py in interactive shell or IPython (if installed) with" msg += " specified appname" parser.add_option("-S", "--shell", dest="shell", metavar="APPNAME", help=msg) msg = "only use plain python shell; should be used with --shell option" parser.add_option("-P", "--plain", action="store_true", default=False, dest="plain", help=msg) msg = "auto import model files; default is False; should be used" msg += " with --shell option" parser.add_option("-M", "--import_models", action="store_true", default=False, dest="import_models", help=msg) msg = "run PYTHON_FILE in web2py environment;" msg += " should be used with --shell option" parser.add_option("-R", "--run", dest="run", metavar="PYTHON_FILE", default="", help=msg) msg = "run doctests in web2py environment; " + "TEST_PATH like a/c/f (c,f optional)" parser.add_option("-T", "--test", dest="test", metavar="TEST_PATH", default=None, help=msg) parser.add_option( "-W", "--winservice", dest="winservice", default="", help="-W install|start|stop as Windows service" ) msg = "trigger a cron run manually; usually invoked from a system crontab" parser.add_option("-C", "--cron", action="store_true", dest="extcron", default=False, help=msg) parser.add_option( "-N", "--no-cron", action="store_true", dest="nocron", default=False, help="do not start cron automatically" ) parser.add_option("-L", "--config", dest="config", default="", help="config file") parser.add_option("-F", "--profiler", dest="profiler_filename", default=None, help="profiler filename") parser.add_option( "-t", "--taskbar", action="store_true", dest="taskbar", default=False, help="use web2py gui and run in taskbar (system tray)", ) parser.add_option("", "--nogui", action="store_true", default=False, dest="nogui", help="text-only, no GUI") parser.add_option( "-A", "--args", action="store", dest="args", default="", help="should be followed by a list of arguments to be passed to script, to be used with -S, -A must be the last option", ) if "-A" in sys.argv: k = sys.argv.index("-A") elif "--args" in sys.argv: k = sys.argv.index("--args") else: k = len(sys.argv) sys.argv, other_args = sys.argv[:k], sys.argv[k + 1 :] (options, args) = parser.parse_args() options.args = [options.run] + other_args if options.quiet: capture = cStringIO.StringIO() sys.stdout = capture logging.getLogger().setLevel(logging.CRITICAL + 1) else: logging.getLogger().setLevel(options.debuglevel) if options.config[-3:] == ".py": options.config = options.config[:-3] if not os.path.exists("applications"): os.mkdir("applications") if not os.path.exists("deposit"): os.mkdir("deposit") if not os.path.exists("site-packages"): os.mkdir("site-packages") sys.path.append(os.path.join(os.getcwd(), "site-packages")) # If we have the applications package or if we should upgrade if not os.path.exists("applications/__init__.py"): fp = open("applications/__init__.py", "w") fp.write("") fp.close() if not os.path.exists("welcome.w2p") or os.path.exists("NEWINSTALL"): w2p_pack("welcome.w2p", "applications/welcome") os.unlink("NEWINSTALL") return (options, args)
def console(): """ Defines the behavior of the console web2py execution """ import optparse import textwrap usage = "python web2py.py" description = """\ web2py Web Framework startup script. ATTENTION: unless a password is specified (-a 'passwd') web2py will attempt to run a GUI. In this case command line options are ignored.""" description = textwrap.dedent(description) parser = optparse.OptionParser(usage, None, optparse.Option, ProgramVersion) parser.description = description parser.add_option('-i', '--ip', default='127.0.0.1', dest='ip', help='ip address of the server (127.0.0.1)') parser.add_option('-p', '--port', default='8000', dest='port', type='int', help='port of server (8000)') msg = 'password to be used for administration' msg += ' (use -a "<recycle>" to reuse the last password))' parser.add_option('-a', '--password', default='<ask>', dest='password', help=msg) parser.add_option('-c', '--ssl_certificate', default='', dest='ssl_certificate', help='file that contains ssl certificate') parser.add_option('-k', '--ssl_private_key', default='', dest='ssl_private_key', help='file that contains ssl private key') parser.add_option('-d', '--pid_filename', default='httpserver.pid', dest='pid_filename', help='file to store the pid of the server') parser.add_option('-l', '--log_filename', default='httpserver.log', dest='log_filename', help='file to log connections') parser.add_option('-n', '--numthreads', default='10', type='int', dest='numthreads', help='number of threads') parser.add_option('-s', '--server_name', default=socket.gethostname(), dest='server_name', help='server name for the web server') msg = 'max number of queued requests when server unavailable' parser.add_option('-q', '--request_queue_size', default='5', type='int', dest='request_queue_size', help=msg) parser.add_option('-o', '--timeout', default='10', type='int', dest='timeout', help='timeout for individual request (10 seconds)') parser.add_option('-z', '--shutdown_timeout', default='5', type='int', dest='shutdown_timeout', help='timeout on shutdown of server (5 seconds)') parser.add_option('-f', '--folder', default=os.getcwd(), dest='folder', help='folder from which to run web2py') parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False, help='increase --test verbosity') parser.add_option('-Q', '--quiet', action='store_true', dest='quiet', default=False, help='disable all output') msg = 'set debug output level (0-100, 0 means all, 100 means none;' msg += ' default is 30)' parser.add_option('-D', '--debug', dest='debuglevel', default=30, type='int', help=msg) msg = 'run web2py in interactive shell or IPython (if installed) with' msg += ' specified appname (if app does not exist it will be created).' parser.add_option('-S', '--shell', dest='shell', metavar='APPNAME', help=msg) msg = 'only use plain python shell; should be used with --shell option' parser.add_option('-P', '--plain', action='store_true', default=False, dest='plain', help=msg) msg = 'auto import model files; default is False; should be used' msg += ' with --shell option' parser.add_option('-M', '--import_models', action='store_true', default=False, dest='import_models', help=msg) msg = 'run PYTHON_FILE in web2py environment;' msg += ' should be used with --shell option' parser.add_option('-R', '--run', dest='run', metavar='PYTHON_FILE', default='', help=msg) msg = 'run doctests in web2py environment; ' +\ 'TEST_PATH like a/c/f (c,f optional)' parser.add_option('-T', '--test', dest='test', metavar='TEST_PATH', default=None, help=msg) parser.add_option('-W', '--winservice', dest='winservice', default='', help='-W install|start|stop as Windows service') msg = 'trigger a cron run manually; usually invoked from a system crontab' parser.add_option('-C', '--cron', action='store_true', dest='extcron', default=False, help=msg) msg = 'triggers the use of softcron' parser.add_option('--softcron', action='store_true', dest='softcron', default=False, help=msg) parser.add_option('-N', '--no-cron', action='store_true', dest='nocron', default=False, help='do not start cron automatically') parser.add_option('-L', '--config', dest='config', default='', help='config file') parser.add_option('-F', '--profiler', dest='profiler_filename', default=None, help='profiler filename') parser.add_option('-t', '--taskbar', action='store_true', dest='taskbar', default=False, help='use web2py gui and run in taskbar (system tray)') parser.add_option('', '--nogui', action='store_true', default=False, dest='nogui', help='text-only, no GUI') parser.add_option( '-A', '--args', action='store', dest='args', default='', help= 'should be followed by a list of arguments to be passed to script, to be used with -S, -A must be the last option' ) msg = 'allows multiple interfaces to be served' parser.add_option('--interfaces', action='store', dest='interfaces', default=None, help=msg) if '-A' in sys.argv: k = sys.argv.index('-A') elif '--args' in sys.argv: k = sys.argv.index('--args') else: k = len(sys.argv) sys.argv, other_args = sys.argv[:k], sys.argv[k + 1:] (options, args) = parser.parse_args() options.args = [options.run] + other_args if options.quiet: capture = cStringIO.StringIO() sys.stdout = capture logger.setLevel(logging.CRITICAL + 1) else: logger.setLevel(options.debuglevel) if options.config[-3:] == '.py': options.config = options.config[:-3] for path in ('applications', 'deposit', 'site-packages', 'logs'): if not os.path.exists(path): os.mkdir(path) sys.path.append(os.path.join(options.folder, 'site-packages')) # If we have the applications package or if we should upgrade if not os.path.exists('applications/__init__.py'): fp = open('applications/__init__.py', 'w') fp.write('') fp.close() if not os.path.exists('welcome.w2p') or os.path.exists('NEWINSTALL'): w2p_pack('welcome.w2p', 'applications/welcome') os.unlink('NEWINSTALL') return (options, args)