~ubuntu-branches/debian/jessie/web2py/jessie

« back to all changes in this revision

Viewing changes to gluon/shell.py

  • Committer: Package Import Robot
  • Author(s): José L. Redrejo Rodríguez
  • Date: 2011-11-04 10:12:01 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20111104101201-ym8q3030ik8sc10u
Tags: 1.99.2.1-1
* Updated upstream sources with real 1.99.2 version
* Ensure python-gtk2 is not needed to run web2py, fixing 
  debian/patches/gtk_gui (Closes: #646931)
* Refreshed debian/patches/avoid_updating patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import re
18
18
import optparse
19
19
import glob
20
 
 
 
20
import traceback
21
21
import fileutils
22
22
import settings
23
23
from utils import web2py_uuid
26
26
from globals import Request, Response, Session
27
27
from storage import Storage
28
28
from admin import w2p_unpack
 
29
from dal import BaseAdapter
29
30
 
30
31
 
31
32
logger = logging.getLogger("web2py")
50
51
 
51
52
    """
52
53
 
53
 
    if request==None: request = Request()
54
 
    if response==None: response = Response()
55
 
    if session==None: session = Session()
 
54
    if request is None: request = Request()
 
55
    if response is None: response = Response()
 
56
    if session is None: session = Session()
56
57
 
57
58
    if request.folder is None:
58
59
        mo = re.match(r'(|.*/)applications/(?P<appname>[^/]+)', pyfile)
150
151
    plain=False,
151
152
    import_models=False,
152
153
    startfile=None,
153
 
    bpython=False
 
154
    bpython=False,
 
155
    python_code=False
154
156
    ):
155
157
    """
156
158
    Start interactive shell or run Python script (startfile) in web2py
202
204
        exec_pythonrc()
203
205
        try:
204
206
            execfile(startfile, _env)
205
 
        except RestrictedError, e:
206
 
            print e.traceback
 
207
            if import_models: BaseAdapter.close_all_instances('commit')
 
208
        except Exception, e:
 
209
            print traceback.format_exc()
 
210
            if import_models: BaseAdapter.close_all_instances('rollback')
 
211
    elif python_code:
 
212
        exec_pythonrc()
 
213
        try:
 
214
            exec(python_code, _env)
 
215
            if import_models: BaseAdapter.close_all_instances('commit')
 
216
        except Exception, e:
 
217
            print traceback.format_exc()
 
218
            if import_models: BaseAdapter.close_all_instances('rollback')
207
219
    else:
208
220
        if not plain:
209
221
            if bpython:
217
229
            else:
218
230
                try:
219
231
                    import IPython
220
 
                    # following 2 lines fix a problem with IPython; thanks Michael Toomim
221
 
                    if '__builtins__' in _env:
222
 
                        del _env['__builtins__']
223
 
                    shell = IPython.Shell.IPShell(argv=[], user_ns=_env)
224
 
                    shell.mainloop()
225
 
                    return
 
232
                    if IPython.__version__ >= '0.11':
 
233
                        from IPython.frontend.terminal.embed import InteractiveShellEmbed
 
234
                        shell = InteractiveShellEmbed(user_ns=_env)
 
235
                        shell()
 
236
                        return
 
237
                    else:
 
238
                        # following 2 lines fix a problem with
 
239
                        # IPython; thanks Michael Toomim
 
240
                        if '__builtins__' in _env:
 
241
                            del _env['__builtins__']
 
242
                        shell = IPython.Shell.IPShell(argv=[],user_ns=_env)
 
243
                        shell.mainloop()
 
244
                        return
226
245
                except:
227
246
                    logger.warning(
228
247
                        'import IPython error; use default python shell')
398
417
if __name__ == '__main__':
399
418
    execute_from_command_line()
400
419
 
 
420
 
 
421