Heres my patched gluon/widget.py
Web2py is running!!

But have Internal Error (cannot see debug due to internal error on admin
page too) lets see.




On Sat, Jan 10, 2009 at 3:30 PM, Phyo Arkar <[email protected]>wrote:

> There!
>
> Jython2.5b1 is really cool! improved much from 2.5b0!
> Pydev Works Well with Jython2.5b1 , (not when it was 2.5b0!)
>
> Got some prob tho , i will remove browser module and try.
> v...@v3ssbox-2 /opt/web2py $ ~/jython2.5b1/jython web2py.py
> WARNING:root:no file locking
> WARNING:root:unable to import dbhash
> Traceback (most recent call last):
>   File "web2py.py", line 4, in <module>
>     from gluon.widget import start
>   File "/opt/web2py/gluon/widget.py", line 38, in <module>
>     import time, webbrowser, thread, re, cStringIO, os, stat, socket,
> signal, math
>
>
>
> On Sat, Jan 10, 2009 at 3:10 AM, Massimo Di Pierro <
> [email protected]> wrote:
>
>> perhaps it is time to again to run web2py to jython! who wants to take the
>> lead on this?
>> Massimo
>>
>> Begin forwarded message:
>>
>> *From: *Frank Wierzbicki <[email protected]>
>> *Date: *January 9, 2009 3:37:38 PM CST
>> *To: *Jython Developers <[email protected]>, userJython <
>> [email protected]>, "[email protected]" <
>> [email protected]>
>> *Subject: **Jython 2.5 Beta1 Released!*
>> *Reply-To: *"[email protected]" <[email protected]>
>>
>> On behalf of the Jython development team, I'm pleased to announce that
>> Jython 2.5b1 is available for download:
>> http://downloads.sourceforge.net/jython/jython_installer-2.5b1.jar.
>> See the installation instructions here:
>> http://www.jython.org/Project/installation.html.
>>
>> Jython 2.5 Beta1 continues a code cooling period where the number of
>> new features should significantly slow as we concentrate on
>> solidifying Jython 2.5 for an eventual release.  I would guess that we
>> will put out about two more betas before we start pushing out release
>> candidates, hopefully in February.
>>
>> This is a beta release so be careful.
>>
>> -Frank
>> --
>> http://mail.python.org/mailman/listinfo/python-announce-list
>>
>>         Support the Python Software Foundation:
>>         http://www.python.org/psf/donations.html
>>
>>
>>
>> >>
>>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

#!/bin/python2.5

"""
This file is part of the web2py Web Framework (Copyrighted, 2007-2008)
Developed in Python by Massimo Di Pierro <[email protected]>
"""

import sys, cStringIO
if not sys.version[:3] in ['2.5','2.6']:
    sys.stderr.write('Warning: web2py requires Python 2.5 or 2.6 but you are running:\n%s' % sys.version)

ProgramName="web2py Enterprise Web Framework"
ProgramAuthor='Created by Massimo Di Pierro, Copyright 2007-2008'
ProgramVersion=open('VERSION','r').read().strip()

class IO(object):
    def __init__(self):
        self.buffer=cStringIO.StringIO()
    def write(self,data):
        sys.__stdout__.write(data)       
        if hasattr(self,'callback'): self.callback(data)
        else: self.buffer.write(data)

try: 
    import tkMessageBox, Tkinter
    havetk=True
except:
    havetk=False
    
from gluon.main import HttpServer, save_password
from gluon.fileutils import tar, untar
from optparse import *
from gluon.shell import run, test
try:
    from gluon.winservice import web2py_windows_service_handler
except: pass

try:
	import time, webbrowser, thread, re, cStringIO, os, stat, socket, signal, math
except: 
	import time, thread, re, StringIO, os, stat, socket, signal, math
def try_start_browser(url):
    #try: webbrowser.open(url)
    #except: 
    print 'warning: unable to detect your browser'

def start_browser(ip,port):
    print 'please visit:'
    print '\thttp://%s:%s' % (ip,port)
    print 'starting browser...in 5 seconds'
    time.sleep(5)
    try_start_browser('http://%s:%s'%(ip,port))

def presentation(root):
        root.withdraw()
        dx=root.winfo_screenwidth()
        dy=root.winfo_screenheight()
        dialog=Tkinter.Toplevel(root)
        dialog.geometry('%ix%i+%i+%i' % (500,300,dx/2-200, dy/2-150))
        dialog.overrideredirect(1)
        dialog.focus_force()
        canvas=Tkinter.Canvas(dialog, background='white', width=500, height=300)
        canvas.pack()      
        root.update()  
        for counter in xrange(5):            
            if counter is 0:
                canvas.create_text(250,50, text='Welcome to ...',
                                        font=('Helvetica',12),
                                        anchor=Tkinter.CENTER, fill='#195866')
            elif counter is 1:
               canvas.create_text(250,130, text=ProgramName,
                                        font=('Helvetica',18),
                                        anchor=Tkinter.CENTER, fill='#FF5C1F')
            elif counter is 2:
                canvas.create_text(250,170,
                                        text=ProgramAuthor,
                                        font=('Helvetica',12),
                                        anchor=Tkinter.CENTER, fill='#195866')
            elif counter is 3:
                canvas.create_text(250,250, text=ProgramVersion,
                                        font=('Helvetica',12),
                                        anchor=Tkinter.CENTER, fill='#195866')
            else:
                dialog.destroy()
                return
            root.update()
            time.sleep(1.5)
        return root

class web2pyDialog(object):
    def __init__(self,root,options):
        root.title('web2py server')
        self.root=Tkinter.Toplevel(root)
        self.options=options
        self.menu=Tkinter.Menu(self.root)
        servermenu = Tkinter.Menu(self.menu,tearoff=0)
        httplog=os.path.join(os.getcwd(),'httpserver.log')
        servermenu.add_command(label='View httpserver.log', 
           command=lambda:try_start_browser(httplog))
        servermenu.add_command(label='Quit (pid:%i)' % os.getpid(),
           command=self.quit)
        self.menu.add_cascade(label="Server", menu=servermenu)

        self.pagesmenu = Tkinter.Menu(self.menu,tearoff=0)  
        self.menu.add_cascade(label="Pages", menu=self.pagesmenu)

        helpmenu = Tkinter.Menu(self.menu,tearoff=0)
        helpmenu.add_command(label="Home Page", command=lambda: try_start_browser('http://www.web2py.com'))
        helpmenu.add_command(label="About", command=lambda:tkMessageBox.showinfo('About web2py','%s\n%s\n%s'%(ProgramName,ProgramAuthor,ProgramVersion)))
        self.menu.add_cascade(label="Info", menu=helpmenu)

        self.root.config(menu=self.menu)
        if options.taskbar: self.root.protocol("WM_DELETE_WINDOW", lambda: self.quit(True))
        else: self.root.protocol("WM_DELETE_WINDOW", self.quit)
        sticky=Tkinter.NW
        Tkinter.Label(self.root, text="Choose a password:",justify=Tkinter.LEFT).grid(row=0,column=0,sticky=sticky)
        self.password = Tkinter.Entry(self.root,show='*')
        self.password.grid(row=0, column=1,sticky=sticky)
        Tkinter.Label(self.root, text="Running from host:",justify=Tkinter.LEFT).grid(row=1,column=0,sticky=sticky)
        self.ip = Tkinter.Entry(self.root)
        self.ip.insert(Tkinter.END,'127.0.0.1')
        self.ip.grid(row=1, column=1,sticky=sticky)
        Tkinter.Label(self.root, text="Running from port:",justify=Tkinter.LEFT).grid(row=2,column=0,sticky=sticky)
        self.port_number = Tkinter.Entry(self.root)
        self.port_number.insert(Tkinter.END,'8000')
        self.port_number.grid(row=2, column=1,sticky=sticky)
        self.canvas=Tkinter.Canvas(self.root,width=300,height=100,bg='black')
        self.canvas.grid(row=3,column=0,columnspan=2)
        self.canvas.after(1000,self.update_canvas)
        frame=Tkinter.Frame(self.root)
        frame.grid(row=4,column=0,columnspan=2)
        self.button_start=Tkinter.Button(frame,text='start server',command=self.start)
        self.button_start.grid(row=0, column=0)
        self.button_stop=Tkinter.Button(frame,text='stop server',command=self.stop)
        self.button_stop.grid(row=0, column=1)
        self.button_stop.configure(state='disabled')
        if options.taskbar:
            import contrib.taskbar_widget
            self.tb=contrib.taskbar_widget.TaskBarIcon()
            self.checkTaskBar()
            if options.password != '<ask>':
                self.password.insert(0,options.password)
                self.start()               
                self.root.withdraw()
        else: self.tb = None   
    def checkTaskBar(self):
        if self.tb.status:            
            if self.tb.status[0] == self.tb.EnumStatus.QUIT:
                self.quit()
            elif self.tb.status[0] ==self.tb.EnumStatus.TOGGLE:
                if self.root.state() == "withdrawn":
                    self.root.deiconify()
                else:
                    self.root.withdraw()
            elif self.tb.status[0] == self.tb.EnumStatus.STOP:
                self.stop()
            elif self.tb.status[0] == self.tb.EnumStatus.START:
                self.start()            
            elif self.tb.status[0] == self.tb.EnumStatus.RESTART:
                self.stop()
                self.start()
            del self.tb.status[0]
        self.root.after(1000,self.checkTaskBar)
    def update(self,text):
        try:
            self.text.configure(state='normal')
            self.text.insert('end',text)
            self.text.configure(state='disabled')
        except: pass ### this should only happen in case app is destroyed
    def connect_pages(self):
        for file in os.listdir('applications/'):
            if os.path.exists('applications/%s/__init__.py' % file):
                url=self.url+'/'+file
                self.pagesmenu.add_command(label=url, command=lambda u=url:try_start_browser(u))
    def quit(self,justHide=False):
        if justHide:
            self.root.withdraw() 
        else:
            try: self.server.stop()
            except: pass
            try: self.tb.Destroy()
            except: pass
            self.root.destroy()
            sys.exit()
    def error(self,message):
        tkMessageBox.showerror("web2py start server",message)
        return
    def start(self):         
        password=self.password.get()
        if not password:
            self.error('no password, no web admin interface')
        ip=self.ip.get()
        if ip and not re.compile('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}').match(ip):
            return self.error('invalid host ip address')
        try: port=int(self.port_number.get())
        except: 
            return self.error('invalid port number')
        self.url='http://%s:%s' % (ip,port)
        self.connect_pages()
        self.button_start.configure(state='disabled')
        try:
            options=self.options
            self.server=HttpServer(ip,port,password,
                pid_filename=options.pid_filename,
                log_filename=options.log_filename,
                ssl_certificate=options.ssl_certificate,
                ssl_private_key=options.ssl_private_key,
	        numthreads=options.numthreads,
                server_name=options.server_name,
                request_queue_size=options.request_queue_size, 
                timeout=options.timeout, 
                shutdown_timeout=options.shutdown_timeout,
                path=options.folder)
            thread.start_new_thread(self.server.start,())            
        except Exception, e:
            self.button_start.configure(state='normal')
            return self.error(str(e))
        self.button_stop.configure(state='normal')
        if not options.taskbar:
            thread.start_new_thread(start_browser,(ip,port))
        self.password.configure(state='readonly')
        self.ip.configure(state='readonly')
        self.port_number.configure(state='readonly')
        if self.tb:
            self.tb.SetServerRunning()   
    def stop(self):
        self.button_start.configure(state='normal')
        self.button_stop.configure(state='disabled')
        self.password.configure(state='normal')
        self.ip.configure(state='normal')
        self.port_number.configure(state='normal')
        self.server.stop()
        if self.tb:
            self.tb.SetServerStopped()
    def update_canvas(self):
        try:
            t1=os.stat('httpserver.log')[stat.ST_SIZE]
        except:
            self.canvas.after(1000, self.update_canvas ) 
            return
        try:
            file=open('httpserver.log','r')
            file.seek(self.t0)
            data=file.read(t1-self.t0)
            self.p0=self.p0[1:]+[10+90.0/math.sqrt(1+data.count('\n'))]
            for i in xrange(len(self.p0)-1):
                c=self.canvas.coords(self.q0[i])
                self.canvas.coords(self.q0[i],
                                   (c[0],self.p0[i],c[2],self.p0[i+1]))
            self.t0=t1
        except BaseException, e:
            self.t0=time.time()
            self.t0=t1
            self.p0=[100]*300
            self.q0=[self.canvas.create_line(i,100,i+1,100,fill='green') for i in xrange(len(self.p0)-1)]
        self.canvas.after(1000, self.update_canvas ) 

def console():
    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."""
    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)')
    parser.add_option('-a','--password',default='<ask>',dest='password',
                  help='the password to be used for administration'+\
                       "(use -a '<recycle>' to reuse the last password)")
    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')
    parser.add_option('-q','--request_queue_size',default='5', type='int',
                  dest='request_queue_size',
                  help='max number of queued requests when server unavailable')
    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')
    parser.add_option('-D', '--debug', 
                  dest='debuglevel', default=30, type='int',
                  help='set debug output level (0-100, 0 means all, 100 means none, default is 30)')
    parser.add_option('-S', '--shell',
                  dest='shell', metavar='APPNAME',
                  help='run web2py in interactive shell or IPython(if installed) with specified appname')
    parser.add_option('-P', '--plain', action='store_true', default=False,
                  dest='plain', 
                  help='only use plain python shell, should be used with --shell option')
    parser.add_option('-M', '--import_models', action='store_true', default=False,
                  dest='import_models', 
                  help='auto import model files, default is False, should be used with --shell option')
    parser.add_option('-R', '--run', dest='run', metavar='PYTHON_FILE', default='',
                  help='run PYTHON_FILE in web2py environment, should be used with --shell option')
    parser.add_option('-T', '--test', dest='test', metavar='TEST_PATH', default=None,
                  help='run doctests in web2py environment, TEST_PATH like a/c/f (c,f optional)')
    parser.add_option('-W', '--winservice', dest='winservice', default='',
                  help='-W install|start|stop as windows service')
    parser.add_option('-L', '--config', dest='config', default='',
                  help='Config file')
    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()

    import logging
    if options.quiet:
        import StringIO
        capture = StringIO.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('applications/__init__.py') or options.upgrade=='yes':
        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

def start():
    ### get command line arguments
    options,args=console()
    print ProgramName
    print ProgramAuthor
    print ProgramVersion

    from gluon.sql import drivers
    print "Database drivers available: %s" % ", ".join(drivers)
    ### if -W install/start/stop web2py as service
    if options.winservice:
        if os.name=='nt': 
            web2py_windows_service_handler(['', options.winservice], options.config)
        else: 
            print 'Error: windows services not supported on this platform'
            sys.exit(1)
        return
    ### if -T run doctests
    if options.test:
        test(options.test, verbose=options.verbose)
        return
    ### if -S start interactive shell
    if options.shell:
        run(options.shell, plain=options.plain,
            import_models=options.import_models, startfile=options.run)
        return
    ### if -L load options from options.config file
    if options.config:
        try:
            options = __import__(options.config, [], [], '')
        except Exception:
            print "Cannot import config file [%s]" % options.config
            sys.exit(1)
    ### if no password provided and havetk start Tk interface
    ### or start interface if we want to put in taskbar (system tray)
    try: options.taskbar
    except: options.taskbar = False
    if options.taskbar and os.name != 'nt':
        print 'Error: taskbar not supported on this platform'
        sys.exit(1)
    root=None
    if (options.password=='<ask>' and havetk) or (options.taskbar and havetk):
        try: root=Tkinter.Tk()
        except: pass
    if root:
        root.focus_force()
        presentation(root)
        master=web2pyDialog(root,options)
        signal.signal(signal.SIGTERM,lambda a,b: master.quit())
        try: root.mainloop()
        except: master.quit()
        sys.exit()
    ### if no tk and no password, ask for a password
    if not root and options.password=='<ask>':
        options.password=raw_input('choose a password:')
    if not options.password: 
        print 'no password, no admin interface'     
    ### start server
    ip,port=options.ip,int(options.port)
    print 'please visit:'
    print '\thttp://%s:%s' % (ip,port)
    print 'use "kill -SIGTERM %i" to shutdown the web2py server'  % os.getpid()
    server=HttpServer(ip=ip,port=port,password=options.password,
                      pid_filename=options.pid_filename,
                      log_filename=options.log_filename,
                      ssl_certificate=options.ssl_certificate,
                      ssl_private_key=options.ssl_private_key,
                      numthreads=options.numthreads,
                      server_name=options.server_name,
                      request_queue_size=options.request_queue_size,
                      timeout=options.timeout,
                      shutdown_timeout=options.shutdown_timeout,
                      path=options.folder)
    try: server.start()
    except KeyboardInterrupt: server.stop()

Reply via email to