From a40b55d8d4403f370bc6f76cc45aee2671e288c9 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Wed, 29 Aug 2012 15:09:08 -0500 Subject: [PATCH] fixed some problems with admin no GAE, still readonly --- VERSION | 2 +- applications/admin/controllers/default.py | 12 +++++++----- applications/admin/models/access.py | 5 ++++- gluon/cfs.py | 6 ++++-- gluon/dal.py | 2 +- gluon/languages.py | 5 ++++- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index b25e0bdd..c09cf1c7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.00.1 (2012-08-29 10:27:58) rc4 +Version 2.00.1 (2012-08-29 15:09:03) rc4 diff --git a/applications/admin/controllers/default.py b/applications/admin/controllers/default.py index 1fb8cf9e..ccc36121 100644 --- a/applications/admin/controllers/default.py +++ b/applications/admin/controllers/default.py @@ -51,12 +51,12 @@ def log_progress(app,mode='EDIT',filename=None,progress=0): progress_file = os.path.join(apath(app, r=request), 'progress.log') now = str(request.now)[:19] if not os.path.exists(progress_file): - open(progress_file,'w').write('[%s] START\n' % now) + safe_open(progress_file,'w').write('[%s] START\n' % now) if filename: - open(progress_file,'a').write('[%s] %s %s: %s\n' % (now,mode,filename,progress)) + safe_open(progress_file,'a').write('[%s] %s %s: %s\n' % (now,mode,filename,progress)) def safe_open(a,b): - if DEMO_MODE and 'w' in b: + if DEMO_MODE and ('w' in b or 'a' in b): class tmp: def write(self,data): pass return tmp() @@ -455,11 +455,13 @@ def delete(): def enable(): app = get_app() filename = os.path.join(apath(app, r=request),'DISABLED') - if os.path.exists(filename): + if is_gae: + return SPAN(T('Not supported'),_style='color:yellow') + elif os.path.exists(filename): os.unlink(filename) return SPAN(T('Disable'),_style='color:green') else: - open(filename,'wb').write(time.ctime()) + safe_open(filename,'wb').write(time.ctime()) return SPAN(T('Enable'),_style='color:red') def peek(): diff --git a/applications/admin/models/access.py b/applications/admin/models/access.py index 1669c526..22d9e03c 100644 --- a/applications/admin/models/access.py +++ b/applications/admin/models/access.py @@ -12,6 +12,9 @@ if request.env.web2py_runtime_gae: session_db = DAL('gae') session.connect(request, response, db=session_db) hosts = (http_host, ) + is_gae = True +else: + is_gae = False if request.env.http_x_forwarded_for or request.is_https: session.secure() @@ -27,7 +30,7 @@ try: raise HTTP(200, T('admin disabled because no admin password')) except IOError: import gluon.fileutils - if request.env.web2py_runtime_gae: + if is_gae: if gluon.fileutils.check_credentials(request): session.authorized = True session.last_time = time.time() diff --git a/gluon/cfs.py b/gluon/cfs.py index b3669f4b..f0c20aaf 100644 --- a/gluon/cfs.py +++ b/gluon/cfs.py @@ -14,6 +14,7 @@ FOR INTERNAL USE ONLY import os import thread +import logging from fileutils import read_file cfs = {} # for speed-up @@ -34,15 +35,16 @@ def getcfs(key, filename, filter=None): This is used on Google App Engine since pyc files cannot be saved. """ try: + logging.info(filename) t = os.stat(filename).st_mtime except OSError: - return filter() + return filter() if callable(filter) else '' cfs_lock.acquire() item = cfs.get(key, None) cfs_lock.release() if item and item[0] == t: return item[1] - if not filter: + if not callable(filter): data = read_file(filename) else: data = filter() diff --git a/gluon/dal.py b/gluon/dal.py index 5f9b5b0e..912fc2ad 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -4329,9 +4329,9 @@ class GoogleDatastoreAdapter(NoSQLAdapter): def select_raw(self,query,fields=None,attributes=None): db = self.db - args_get = attributes.get fields = fields or [] attributes = attributes or {} + args_get = attributes.get new_fields = [] for item in fields: if isinstance(item,SQLALL): diff --git a/gluon/languages.py b/gluon/languages.py index f2d78c52..4b4f6f1a 100644 --- a/gluon/languages.py +++ b/gluon/languages.py @@ -429,7 +429,10 @@ class translator(object): self.request = request self.folder = request.folder self.langpath = ospath.join(self.folder,'languages') - self.filenames = set(os.listdir(self.langpath)) + try: + self.filenames = set(os.listdir(self.langpath)) + except: + self.filenames = set() self.http_accept_language = request.env.http_accept_language # self.cache # filled in self.force() # self.accepted_language = None # filled in self.force()