Skip to content

Commit

Permalink
Merge pull request web2py#1499 from ilvalle/fix-app-admin
Browse files Browse the repository at this point in the history
fix few app admin py3 issues, updated qdb (close web2py#1471)
  • Loading branch information
mdipierro authored Oct 14, 2016
2 parents bc72324 + c1d81a8 commit f9a4187
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 243 deletions.
2 changes: 1 addition & 1 deletion applications/admin/controllers/appadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def GetInHMS(seconds):
disk['oldest'] = value[0]
disk['keys'].append((key, GetInHMS(time.time() - value[0])))

ram_keys = ram.keys() # ['hits', 'objects', 'ratio', 'entries', 'keys', 'oldest', 'bytes', 'misses']
ram_keys = list(ram) # ['hits', 'objects', 'ratio', 'entries', 'keys', 'oldest', 'bytes', 'misses']
ram_keys.remove('ratio')
ram_keys.remove('oldest')
for key in ram_keys:
Expand Down
18 changes: 9 additions & 9 deletions applications/admin/controllers/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import gluon.html
import gluon.validators
import code
from gluon.debug import communicate, web_debugger, qdb_debugger
from gluon.debug import communicate, web_debugger, dbg_debugger
from gluon._compat import thread
import pydoc

Expand Down Expand Up @@ -39,7 +39,7 @@ def reset():
return 'done'


# new implementation using qdb
# new implementation using dbg

def interact():
app = request.args(0) or 'admin'
Expand Down Expand Up @@ -149,7 +149,7 @@ def breakpoints():
if form.accepts(request.vars, session):
filename = os.path.join(request.env['applications_parent'],
'applications', form.vars.filename)
err = qdb_debugger.do_set_breakpoint(filename,
err = dbg_debugger.do_set_breakpoint(filename,
form.vars.lineno,
form.vars.temporary,
form.vars.condition)
Expand All @@ -158,13 +158,13 @@ def breakpoints():

for item in request.vars:
if item[:7] == 'delete_':
qdb_debugger.do_clear(item[7:])
dbg_debugger.do_clear(item[7:])

breakpoints = [{'number': bp[0], 'filename': os.path.basename(bp[1]),
'path': bp[1], 'lineno': bp[2],
'temporary': bp[3], 'enabled': bp[4], 'hits': bp[5],
'condition': bp[6]}
for bp in qdb_debugger.do_list_breakpoint()]
for bp in dbg_debugger.do_list_breakpoint()]

return dict(breakpoints=breakpoints, form=form)

Expand Down Expand Up @@ -193,18 +193,18 @@ def toggle_breakpoint():
else:
lineno = None
if lineno is not None:
for bp in qdb_debugger.do_list_breakpoint():
for bp in dbg_debugger.do_list_breakpoint():
no, bp_filename, bp_lineno, temporary, enabled, hits, cond = bp
# normalize path name: replace slashes, references, etc...
bp_filename = os.path.normpath(os.path.normcase(bp_filename))
if filename == bp_filename and lineno == bp_lineno:
err = qdb_debugger.do_clear_breakpoint(filename, lineno)
err = dbg_debugger.do_clear_breakpoint(filename, lineno)
response.flash = T("Removed Breakpoint on %s at line %s", (
filename, lineno))
ok = False
break
else:
err = qdb_debugger.do_set_breakpoint(filename, lineno)
err = dbg_debugger.do_set_breakpoint(filename, lineno)
response.flash = T("Set Breakpoint on %s at line %s: %s") % (
filename, lineno, err or T('successful'))
ok = True
Expand All @@ -224,7 +224,7 @@ def list_breakpoints():
'applications', request.vars.filename)
# normalize path name: replace slashes, references, etc...
filename = os.path.normpath(os.path.normcase(filename))
for bp in qdb_debugger.do_list_breakpoint():
for bp in dbg_debugger.do_list_breakpoint():
no, bp_filename, bp_lineno, temporary, enabled, hits, cond = bp
# normalize path name: replace slashes, references, etc...
bp_filename = os.path.normpath(os.path.normcase(bp_filename))
Expand Down
36 changes: 18 additions & 18 deletions applications/admin/controllers/webservices.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,44 +81,44 @@ def install(app_name, filename, data, overwrite=True):

@service.jsonrpc
def attach_debugger(host='localhost', port=6000, authkey='secret password'):
import gluon.contrib.qdb as qdb
import gluon.contrib.dbg as dbg
import gluon.debug
from multiprocessing.connection import Listener

if isinstance(authkey, unicode):
authkey = authkey.encode('utf8')

if not hasattr(gluon.debug, 'qdb_listener'):
if not hasattr(gluon.debug, 'dbg_listener'):
# create a remote debugger server and wait for connection
address = (host, port) # family is deduced to be 'AF_INET'
gluon.debug.qdb_listener = Listener(address, authkey=authkey)
gluon.debug.qdb_connection = gluon.debug.qdb_listener.accept()
gluon.debug.dbg_listener = Listener(address, authkey=authkey)
gluon.debug.dbg_connection = gluon.debug.dbg_listener.accept()
# create the backend
gluon.debug.qdb_debugger = qdb.Qdb(gluon.debug.qdb_connection)
gluon.debug.dbg = gluon.debug.qdb_debugger
gluon.debug.dbg_debugger = dbg.Qdb(gluon.debug.dbg_connection)
gluon.debug.dbg = gluon.debug.dbg_debugger
# welcome message (this should be displayed on the frontend)
print('debugger connected to', gluon.debug.qdb_listener.last_accepted)
print('debugger connected to', gluon.debug.dbg_listener.last_accepted)
return True # connection successful!


@service.jsonrpc
def detach_debugger():
import gluon.contrib.qdb as qdb
import gluon.contrib.dbg as dbg
import gluon.debug
# stop current debugger
if gluon.debug.qdb_debugger:
if gluon.debug.dbg_debugger:
try:
gluon.debug.qdb_debugger.do_quit()
gluon.debug.dbg_debugger.do_quit()
except:
pass
if hasattr(gluon.debug, 'qdb_listener'):
if gluon.debug.qdb_connection:
gluon.debug.qdb_connection.close()
del gluon.debug.qdb_connection
if gluon.debug.qdb_listener:
gluon.debug.qdb_listener.close()
del gluon.debug.qdb_listener
gluon.debug.qdb_debugger = None
if hasattr(gluon.debug, 'dbg_listener'):
if gluon.debug.dbg_connection:
gluon.debug.dbg_connection.close()
del gluon.debug.dbg_connection
if gluon.debug.dbg_listener:
gluon.debug.dbg_listener.close()
del gluon.debug.dbg_listener
gluon.debug.dbg_debugger = None
return True


Expand Down
22 changes: 11 additions & 11 deletions applications/admin/controllers/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import urllib
import glob
from gluon.admin import app_create, plugin_install
from gluon.fileutils import abspath, read_file, write_file
from gluon.fileutils import abspath, read_file, write_file, open_file


def reset(session):
Expand Down Expand Up @@ -67,7 +67,7 @@ def index():
'..', app, 'wizard.metadata'))
if os.path.exists(meta):
try:
metafile = open(meta, 'rb')
metafile = open_file(meta, 'rb')
try:
session.app = pickle.load(metafile)
finally:
Expand Down Expand Up @@ -402,7 +402,7 @@ def make_table(table, fields):

def fix_db(filename):
params = dict(session.app['params'])
content = read_file(filename, 'rb')
content = read_file(filename, 'r')
if 'auth_user' in session.app['tables']:
auth_user = make_table('auth_user', session.app['table_auth_user'])
content = content.replace('sqlite://storage.sqlite',
Expand All @@ -424,7 +424,7 @@ def fix_db(filename):
domain = settings.login_config.split(':')[0],
url = "http://%s/%s/default/user/login" % (request.env.http_host,request.application))
"""
write_file(filename, content, 'wb')
write_file(filename, content, 'w')


def make_menu(pages):
Expand Down Expand Up @@ -493,7 +493,7 @@ def create(options):
### save metadata in newapp/wizard.metadata
try:
meta = os.path.join(request.folder, '..', app, 'wizard.metadata')
file = open(meta, 'wb')
file = open_file(meta, 'wb')
pickle.dump(session.app, file)
file.close()
except IOError:
Expand Down Expand Up @@ -521,7 +521,7 @@ def create(options):

### write configuration file into newapp/models/0.py
model = os.path.join(request.folder, '..', app, 'models', '0.py')
file = open(model, 'wb')
file = open_file(model, 'w')
try:
file.write("from gluon.storage import Storage\n")
file.write("settings = Storage()\n\n")
Expand All @@ -534,7 +534,7 @@ def create(options):
### write configuration file into newapp/models/menu.py
if options.generate_menu:
model = os.path.join(request.folder, '..', app, 'models', 'menu.py')
file = open(model, 'wb')
file = open_file(model, 'w')
try:
file.write(make_menu(session.app['pages']))
finally:
Expand All @@ -548,7 +548,7 @@ def create(options):
if options.generate_model:
model = os.path.join(
request.folder, '..', app, 'models', 'db_wizard.py')
file = open(model, 'wb')
file = open_file(model, 'w')
try:
file.write('### we prepend t_ to tablenames and f_ to fieldnames for disambiguity\n\n')
tables = sort_tables(session.app['tables'])
Expand All @@ -564,7 +564,7 @@ def create(options):
if os.path.exists(model):
os.unlink(model)
if options.populate_database and session.app['tables']:
file = open(model, 'wb')
file = open_file(model, 'w')
try:
file.write(populate(session.app['tables']))
finally:
Expand All @@ -574,7 +574,7 @@ def create(options):
if options.generate_controller:
controller = os.path.join(
request.folder, '..', app, 'controllers', 'default.py')
file = open(controller, 'wb')
file = open_file(controller, 'w')
try:
file.write("""# -*- coding: utf-8 -*-
### required - do no delete
Expand All @@ -594,7 +594,7 @@ def call(): return service()
for page in session.app['pages']:
view = os.path.join(
request.folder, '..', app, 'views', 'default', page + '.html')
file = open(view, 'wb')
file = open_file(view, 'w')
try:
file.write(
make_view(page, session.app.get('page_' + page, '')))
Expand Down
2 changes: 1 addition & 1 deletion applications/examples/controllers/appadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def GetInHMS(seconds):
disk['oldest'] = value[0]
disk['keys'].append((key, GetInHMS(time.time() - value[0])))

ram_keys = ram.keys() # ['hits', 'objects', 'ratio', 'entries', 'keys', 'oldest', 'bytes', 'misses']
ram_keys = list(ram) # ['hits', 'objects', 'ratio', 'entries', 'keys', 'oldest', 'bytes', 'misses']
ram_keys.remove('ratio')
ram_keys.remove('oldest')
for key in ram_keys:
Expand Down
2 changes: 1 addition & 1 deletion applications/welcome/controllers/appadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def GetInHMS(seconds):
disk['oldest'] = value[0]
disk['keys'].append((key, GetInHMS(time.time() - value[0])))

ram_keys = ram.keys() # ['hits', 'objects', 'ratio', 'entries', 'keys', 'oldest', 'bytes', 'misses']
ram_keys = list(ram) # ['hits', 'objects', 'ratio', 'entries', 'keys', 'oldest', 'bytes', 'misses']
ram_keys.remove('ratio')
ram_keys.remove('oldest')
for key in ram_keys:
Expand Down
Loading

0 comments on commit f9a4187

Please sign in to comment.