diff --git a/gluon/compileapp.py b/gluon/compileapp.py index caef15ee..679732c3 100644 --- a/gluon/compileapp.py +++ b/gluon/compileapp.py @@ -18,7 +18,7 @@ import fnmatch import os import copy import random -from gluon._compat import builtin +from gluon._compat import builtin, PY2 from gluon.storage import Storage, List from gluon.template import parse_template from gluon.restricted import restricted, compile2 @@ -548,10 +548,17 @@ def run_models_in(environment): path = pjoin(folder, 'models') cpath = pjoin(folder, 'compiled') compiled = os.path.exists(cpath) - if compiled: - models = sorted(listdir(cpath, '^models[_.][\w.]+\.pyc$', 0), model_cmp) + if PY2: + if compiled: + models = sorted(listdir(cpath, '^models[_.][\w.]+\.pyc$', 0), model_cmp) + else: + models = sorted(listdir(path, '^\w+\.py$', 0, sort=False), model_cmp_sep) else: - models = sorted(listdir(path, '^\w+\.py$', 0, sort=False), model_cmp_sep) + if compiled: + models = sorted(listdir(cpath, '^models[_.][\w.]+\.pyc$', 0), key=lambda f: '{0:03d}'.format(f.count('.')) + f) + else: + models = sorted(listdir(path, '^\w+\.py$', 0, sort=False), key=lambda f: '{0:03d}'.format(f.count(os.path.sep)) + f) + models_to_run = None for model in models: if response.models_to_run != models_to_run: diff --git a/gluon/contrib/redis_scheduler.py b/gluon/contrib/redis_scheduler.py index 7bd3ffb5..251f42f2 100644 --- a/gluon/contrib/redis_scheduler.py +++ b/gluon/contrib/redis_scheduler.py @@ -31,7 +31,7 @@ from gluon.contrib.redis_utils import RConn from gluon.contrib.redis_scheduler import RScheduler def demo1(*args,**vars): - print 'you passed args=%s and vars=%s' % (args, vars) + print('you passed args=%s and vars=%s') % (args, vars) return 'done!' def demo2(): diff --git a/gluon/globals.py b/gluon/globals.py index 6ef72393..c3ae7b9e 100644 --- a/gluon/globals.py +++ b/gluon/globals.py @@ -418,7 +418,7 @@ class Response(Storage): self.body.write(to_native(xmlescape(data))) def render(self, *a, **b): - from compileapp import run_view_in + from gluon.compileapp import run_view_in if len(a) > 2: raise SyntaxError( 'Response.render can be called with two arguments, at most') diff --git a/gluon/languages.py b/gluon/languages.py index 67574064..7c536399 100644 --- a/gluon/languages.py +++ b/gluon/languages.py @@ -164,7 +164,7 @@ def clear_cache(filename): def read_dict_aux(filename): - lang_text = read_locked(filename).replace('\r\n', '\n') + lang_text = read_locked(filename).replace(b'\r\n', b'\n') clear_cache(filename) try: return safe_eval(lang_text) or {} @@ -287,7 +287,7 @@ def read_possible_languages(langpath): def read_plural_dict_aux(filename): - lang_text = read_locked(filename).replace('\r\n', '\n') + lang_text = read_locked(filename).replace(b'\r\n', b'\n') try: return eval(lang_text) or {} except Exception: diff --git a/gluon/portalocker.py b/gluon/portalocker.py index d9a88d4e..095c66b7 100644 --- a/gluon/portalocker.py +++ b/gluon/portalocker.py @@ -148,14 +148,14 @@ class LockedFile(object): def read_locked(filename): - fp = LockedFile(filename, 'r') + fp = LockedFile(filename, 'rb') data = fp.read() fp.close() return data def write_locked(filename, data): - fp = LockedFile(filename, 'w') + fp = LockedFile(filename, 'wb') data = fp.write(data) fp.close() diff --git a/gluon/scheduler.py b/gluon/scheduler.py index ebf6182d..4aacbd4a 100644 --- a/gluon/scheduler.py +++ b/gluon/scheduler.py @@ -41,7 +41,7 @@ Create File: app/models/scheduler.py ====== from gluon.scheduler import Scheduler def demo1(*args,**vars): - print 'you passed args=%s and vars=%s' % (args, vars) + print('you passed args=%s and vars=%s') % (args, vars) return 'done!' def demo2(): diff --git a/gluon/tests/test_scheduler.py b/gluon/tests/test_scheduler.py index 8565b71c..107579e7 100644 --- a/gluon/tests/test_scheduler.py +++ b/gluon/tests/test_scheduler.py @@ -309,12 +309,12 @@ class TestsForSchedulerRunner(testForSchedulerRunnerBase): self.db.commit() self.writefunction(r""" def demo1(*args,**vars): - print 'you passed args=%s and vars=%s' % (args, vars) + print('you passed args=%s and vars=%s') % (args, vars) return args[0] def demo4(): time.sleep(15) - print "I'm printing something" + print("I'm printing something") return dict(a=1, b=2) """) ret = self.exec_sched() @@ -359,24 +359,24 @@ def demo4(): self.writefunction(r""" def demo3(): time.sleep(15) - print 1/0 + print(1/0) return None def demo4(): time.sleep(15) - print "I'm printing something" + print("I'm printing something") return dict(a=1, b=2) def demo5(): time.sleep(15) - print "I'm printing something" + print("I'm printing something") rtn = dict(a=1, b=2) def demo6(): time.sleep(5) - print '50%' + print('50%') time.sleep(5) - print '!clear!100%' + print('!clear!100%') return 1 """) ret = self.exec_sched() @@ -417,12 +417,12 @@ def demo6(): self.db.commit() self.writefunction(r""" def demo1(*args,**vars): - print 'you passed args=%s and vars=%s' % (args, vars) + print('you passed args=%s and vars=%s' % (args, vars)) return args[0] import random def demo7(): time.sleep(random.randint(1,5)) - print W2P_TASK, request.now + print(W2P_TASK, request.now) return W2P_TASK.id, W2P_TASK.uuid, W2P_TASK.run_id """) ret = self.exec_sched() @@ -466,7 +466,7 @@ def demo8(): num_of_lines = 0 with open(placeholder) as f: num_of_lines = len([a for a in f.read().split('\n') if a]) - print 'number of lines', num_of_lines + print('number of lines', num_of_lines) if num_of_lines <= 2: 1/0 else: diff --git a/gluon/widget.py b/gluon/widget.py index 17203388..ceccf068 100644 --- a/gluon/widget.py +++ b/gluon/widget.py @@ -25,10 +25,10 @@ import logging import getpass from gluon import main, newcron -from .fileutils import read_file, write_file, create_welcome_w2p -from .settings import global_settings -from .shell import run, test -from .utils import is_valid_ip_address, is_loopback_ip_address, getipaddrinfo +from gluon.fileutils import read_file, write_file, create_welcome_w2p +from gluon.settings import global_settings +from gluon.shell import run, test +from gluon.utils import is_valid_ip_address, is_loopback_ip_address, getipaddrinfo ProgramName = 'web2py Web Framework'