updated portalocker, few py3 syntax/import fix

This commit is contained in:
ilvalle
2016-06-04 14:07:42 +02:00
parent dcd24cf88c
commit 71ba0e515f
8 changed files with 32 additions and 25 deletions
+11 -4
View File
@@ -18,7 +18,7 @@ import fnmatch
import os import os
import copy import copy
import random import random
from gluon._compat import builtin from gluon._compat import builtin, PY2
from gluon.storage import Storage, List from gluon.storage import Storage, List
from gluon.template import parse_template from gluon.template import parse_template
from gluon.restricted import restricted, compile2 from gluon.restricted import restricted, compile2
@@ -548,10 +548,17 @@ def run_models_in(environment):
path = pjoin(folder, 'models') path = pjoin(folder, 'models')
cpath = pjoin(folder, 'compiled') cpath = pjoin(folder, 'compiled')
compiled = os.path.exists(cpath) compiled = os.path.exists(cpath)
if compiled: if PY2:
models = sorted(listdir(cpath, '^models[_.][\w.]+\.pyc$', 0), model_cmp) 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: 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 models_to_run = None
for model in models: for model in models:
if response.models_to_run != models_to_run: if response.models_to_run != models_to_run:
+1 -1
View File
@@ -31,7 +31,7 @@ from gluon.contrib.redis_utils import RConn
from gluon.contrib.redis_scheduler import RScheduler from gluon.contrib.redis_scheduler import RScheduler
def demo1(*args,**vars): 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!' return 'done!'
def demo2(): def demo2():
+1 -1
View File
@@ -418,7 +418,7 @@ class Response(Storage):
self.body.write(to_native(xmlescape(data))) self.body.write(to_native(xmlescape(data)))
def render(self, *a, **b): def render(self, *a, **b):
from compileapp import run_view_in from gluon.compileapp import run_view_in
if len(a) > 2: if len(a) > 2:
raise SyntaxError( raise SyntaxError(
'Response.render can be called with two arguments, at most') 'Response.render can be called with two arguments, at most')
+2 -2
View File
@@ -164,7 +164,7 @@ def clear_cache(filename):
def read_dict_aux(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) clear_cache(filename)
try: try:
return safe_eval(lang_text) or {} return safe_eval(lang_text) or {}
@@ -287,7 +287,7 @@ def read_possible_languages(langpath):
def read_plural_dict_aux(filename): 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: try:
return eval(lang_text) or {} return eval(lang_text) or {}
except Exception: except Exception:
+2 -2
View File
@@ -148,14 +148,14 @@ class LockedFile(object):
def read_locked(filename): def read_locked(filename):
fp = LockedFile(filename, 'r') fp = LockedFile(filename, 'rb')
data = fp.read() data = fp.read()
fp.close() fp.close()
return data return data
def write_locked(filename, data): def write_locked(filename, data):
fp = LockedFile(filename, 'w') fp = LockedFile(filename, 'wb')
data = fp.write(data) data = fp.write(data)
fp.close() fp.close()
+1 -1
View File
@@ -41,7 +41,7 @@ Create File: app/models/scheduler.py ======
from gluon.scheduler import Scheduler from gluon.scheduler import Scheduler
def demo1(*args,**vars): 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!' return 'done!'
def demo2(): def demo2():
+10 -10
View File
@@ -309,12 +309,12 @@ class TestsForSchedulerRunner(testForSchedulerRunnerBase):
self.db.commit() self.db.commit()
self.writefunction(r""" self.writefunction(r"""
def demo1(*args,**vars): 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] return args[0]
def demo4(): def demo4():
time.sleep(15) time.sleep(15)
print "I'm printing something" print("I'm printing something")
return dict(a=1, b=2) return dict(a=1, b=2)
""") """)
ret = self.exec_sched() ret = self.exec_sched()
@@ -359,24 +359,24 @@ def demo4():
self.writefunction(r""" self.writefunction(r"""
def demo3(): def demo3():
time.sleep(15) time.sleep(15)
print 1/0 print(1/0)
return None return None
def demo4(): def demo4():
time.sleep(15) time.sleep(15)
print "I'm printing something" print("I'm printing something")
return dict(a=1, b=2) return dict(a=1, b=2)
def demo5(): def demo5():
time.sleep(15) time.sleep(15)
print "I'm printing something" print("I'm printing something")
rtn = dict(a=1, b=2) rtn = dict(a=1, b=2)
def demo6(): def demo6():
time.sleep(5) time.sleep(5)
print '50%' print('50%')
time.sleep(5) time.sleep(5)
print '!clear!100%' print('!clear!100%')
return 1 return 1
""") """)
ret = self.exec_sched() ret = self.exec_sched()
@@ -417,12 +417,12 @@ def demo6():
self.db.commit() self.db.commit()
self.writefunction(r""" self.writefunction(r"""
def demo1(*args,**vars): 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] return args[0]
import random import random
def demo7(): def demo7():
time.sleep(random.randint(1,5)) 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 return W2P_TASK.id, W2P_TASK.uuid, W2P_TASK.run_id
""") """)
ret = self.exec_sched() ret = self.exec_sched()
@@ -466,7 +466,7 @@ def demo8():
num_of_lines = 0 num_of_lines = 0
with open(placeholder) as f: with open(placeholder) as f:
num_of_lines = len([a for a in f.read().split('\n') if a]) 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: if num_of_lines <= 2:
1/0 1/0
else: else:
+4 -4
View File
@@ -25,10 +25,10 @@ import logging
import getpass import getpass
from gluon import main, newcron from gluon import main, newcron
from .fileutils import read_file, write_file, create_welcome_w2p from gluon.fileutils import read_file, write_file, create_welcome_w2p
from .settings import global_settings from gluon.settings import global_settings
from .shell import run, test from gluon.shell import run, test
from .utils import is_valid_ip_address, is_loopback_ip_address, getipaddrinfo from gluon.utils import is_valid_ip_address, is_loopback_ip_address, getipaddrinfo
ProgramName = 'web2py Web Framework' ProgramName = 'web2py Web Framework'