def execute_from_command_line(argv=None): if argv is None: argv = sys.argv parser = OptionParser(usage=get_usage()) parser.add_option('-p', '--plain', action='store_true', help='Default python shell, not to use IPython.') parser.add_option('-M', '--nomodel', action='store_true', help='Not auto load model files.') options, args = parser.parse_args(argv[1:]) if len(args) != 1: parser.print_help() sys.exit(0) from gluon.fileutils import untar appname = args[0] path = os.path.join('applications', appname) if not os.access(path, os.F_OK): if raw_input('application %s does not exit, create (y/n)?' % appname).lower() in ['y', 'yes']: os.mkdir(path) untar('welcome.tar', path) else: return run(appname, options)
def execute_from_command_line(argv=None): if argv is None: argv = sys.argv parser = OptionParser(usage=get_usage()) parser.add_option('-p', '--plain', action='store_true', help='Default python shell, not to use IPython.') parser.add_option('-M', '--nomodel', action='store_true', help='Not auto load model files.') options, args = parser.parse_args(argv[1:]) if len(args) != 1: parser.print_help() sys.exit(0) from gluon.fileutils import untar appname=args[0] path=os.path.join('applications',appname) if not os.access(path,os.F_OK): if raw_input('application %s does not exit, create (y/n)?' % appname).lower() in ['y','yes']: os.mkdir(path) untar('welcome.tar',path) else: return run(appname, options)
def execute_from_command_line(argv=None): if argv is None: argv = sys.argv parser = OptionParser(usage=get_usage()) parser.add_option("-p", "--plain", action="store_true", help="Default python shell, not to use IPython.") parser.add_option("-M", "--nomodel", action="store_true", help="Not auto load model files.") options, args = parser.parse_args(argv[1:]) if len(args) != 1: parser.print_help() sys.exit(0) from gluon.fileutils import untar appname = args[0] path = os.path.join("applications", appname) if not os.access(path, os.F_OK): if raw_input("application %s does not exit, create (y/n)?" % appname).lower() in ["y", "yes"]: os.mkdir(path) untar("welcome.tar", path) else: return run(appname, options)
def site(): """ Site handler """ myversion = request.env.web2py_version # Shortcut to make the elif statements more # legible file_or_appurl = request.vars.has_key('file') or \ request.vars.has_key('appurl') if request.vars.filename and not request.vars.has_key('file'): try: appname = cleanpath(request.vars.filename).replace('.', '_') path = apath(appname) os.mkdir(path) untar('welcome.tar', path) response.flash = T('new application "%(appname)s" created', dict(appname=appname)) except Exception: response.flash = \ T('unable to create new application "%(appname)s"', dict(appname=request.vars.filename)) elif file_or_appurl and not request.vars.filename: msg = 'you must specify a name for the uploaded application' response.flash = T(msg) elif file_or_appurl and request.vars.filename: mkdir = False try: appname = cleanpath(request.vars.filename).replace('.', '_') tarname = apath('../deposit/%s.tar' % appname) if request.vars.appurl is not '': tarfile = urllib.urlopen(request.vars.appurl).read() elif request.vars.file is not '': tarfile = request.vars.file.file.read() open(tarname, 'wb').write(tarfile) path = apath(appname) os.mkdir(path) mkdir = True untar(tarname, path) fix_newlines(path) msg = 'application %(appname)s installed with md5sum: %(digest)s' response.flash = T(msg, dict(appname=appname, digest=md5_hash(tarfile))) except Exception: if mkdir: shutil.rmtree(path) msg = 'unable to install application "%(appname)s"' response.flash = T(msg, dict(appname=request.vars.filename)) regex = re.compile('^\w+$') apps = sorted([(file.upper(), file) for file in os.listdir(apath()) if regex.match(file)]) apps = [item[1] for item in apps] return dict(app=None, apps=apps, myversion=myversion)
def console(): """ Defines the behaviour 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='the ip address of the server (127.0.0.1)') parser.add_option('-p', '--port', default='8000', dest='port', type='int', help='the port for of server (8000)') msg = 'the 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('-u', '--upgrade', default='no', dest='upgrade', help='upgrade applications') 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 where to store the pid of the server') parser.add_option('-l', '--log_filename', default='httpserver.log', dest='log_filename', help='file where 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='the 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') parser.add_option('-z', '--shutdown_timeout', default='5', type='int', dest='shutdown_timeout', help='timeout on shutdown of server') parser.add_option('-f', '--folder', default=os.getcwd(), dest='folder', help='the folder where 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)') (options, args) = parser.parse_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 we have the applications package or if we should upgrade have_applications = os.path.exists('applications/__init__.py') should_upgrade = options.upgrade == 'yes' if not have_applications or should_upgrade: print 'unpacking apps, this may take a few minutes...' if not os.path.exists('applications/admin'): os.mkdir('applications/admin') untar('admin.tar', 'applications/admin/') if not os.path.exists('applications/welcome'): os.mkdir('applications/welcome') untar('welcome.tar', 'applications/welcome/') if not os.path.exists('applications/examples'): os.mkdir('applications/examples') untar('examples.tar', 'applications/examples/') open('applications/__init__.py', 'w').write('') print 'default applications are now installed' else: print 'default applications appear to be installed already' return (options, args)