From 1b34f47ec97ce81262907d0cacbe6a769fea5f2f Mon Sep 17 00:00:00 2001 From: mdipierro Date: Sat, 14 Jul 2012 22:45:32 -0500 Subject: [PATCH] many improvements from Vladyslav --- VERSION | 2 +- applications/admin/controllers/appadmin.py | 2 +- applications/admin/controllers/mercurial.py | 4 +-- applications/admin/controllers/openshift.py | 6 ++-- applications/admin/views/appadmin.html | 2 +- .../admin/views/openshift/deploy.html | 10 +++--- applications/examples/controllers/appadmin.py | 2 +- applications/examples/views/appadmin.html | 2 +- applications/welcome/controllers/appadmin.py | 2 +- applications/welcome/views/appadmin.html | 2 +- gluon/fileutils.py | 24 ++++++------- gluon/main.py | 14 +------- gluon/settings.py | 34 +++++++++++++++++-- gluon/sqlhtml.py | 4 ++- 14 files changed, 63 insertions(+), 47 deletions(-) diff --git a/VERSION b/VERSION index 535f9bbf..f7868640 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.00.0 (2012-07-14 20:15:46) dev +Version 2.00.0 (2012-07-14 22:45:25) dev diff --git a/applications/admin/controllers/appadmin.py b/applications/admin/controllers/appadmin.py index a45f5539..482eb727 100644 --- a/applications/admin/controllers/appadmin.py +++ b/applications/admin/controllers/appadmin.py @@ -197,7 +197,7 @@ def select(): _name='update_fields', _value=request.vars.update_fields or '')), TR(T('Delete:'), INPUT(_name='delete_check', _class='delete', _type='checkbox', value=False), ''), - TR('', '', INPUT(_type='submit', _value='submit'))), + TR('', '', INPUT(_type='submit', _value=T('submit')))), _action=URL(r=request,args=request.args)) if request.vars.csvfile != None: try: diff --git a/applications/admin/controllers/mercurial.py b/applications/admin/controllers/mercurial.py index 68921342..6c063097 100644 --- a/applications/admin/controllers/mercurial.py +++ b/applications/admin/controllers/mercurial.py @@ -42,7 +42,7 @@ def commit(): path = apath(app, r=request) repo = hg_repo(path) form = FORM('Comment:',INPUT(_name='comment',requires=IS_NOT_EMPTY()), - INPUT(_type='submit',_value='Commit')) + INPUT(_type='submit',_value=T('Commit'))) if form.accepts(request.vars,session): oldid = repo[repo.lookup('.')] addremove(repo) @@ -69,7 +69,7 @@ def revision(): repo = hg_repo(path) revision = request.args(1) ctx=repo.changectx(revision) - form=FORM(INPUT(_type='submit',_value='revert')) + form=FORM(INPUT(_type='submit',_value=T('Revert'))) if form.accepts(request.vars): hg.update(repo, revision) session.flash = "reverted to revision %s" % ctx.rev() diff --git a/applications/admin/controllers/openshift.py b/applications/admin/controllers/openshift.py index 6f3620d2..52889b5e 100644 --- a/applications/admin/controllers/openshift.py +++ b/applications/admin/controllers/openshift.py @@ -3,15 +3,15 @@ from distutils import dir_util try: from git import * except ImportError: - session.flash = 'requires python-git, but not installed' + session.flash = T('requires python-git, but not installed') redirect(URL('default','site')) def deploy(): apps = sorted(file for file in os.listdir(apath(r=request))) form = SQLFORM.factory( - Field('osrepo',default='/tmp',label='Path to local openshift repo root.', + Field('osrepo',default='/tmp',label=T('Path to local openshift repo root.'), requires=EXISTS(error_message=T('directory not found'))), - Field('osname',default='web2py',label='WSGI reference name'), + Field('osname',default='web2py',label=T('WSGI reference name')), Field('applications','list:string', requires=IS_IN_SET(apps,multiple=True), label=T('web2py apps to deploy'))) diff --git a/applications/admin/views/appadmin.html b/applications/admin/views/appadmin.html index efbb3b0c..73c4ae47 100644 --- a/applications/admin/views/appadmin.html +++ b/applications/admin/views/appadmin.html @@ -63,7 +63,7 @@

{{=T("Import/Export")}}


[ {{=T("export as csv file")}} ] {{if table:}} - {{=FORM(str(T('or import from csv file'))+" ",INPUT(_type='file',_name='csvfile'),INPUT(_type='hidden',_value=table,_name='table'),INPUT(_type='submit',_value='import'))}} + {{=FORM(str(T('or import from csv file'))+" ",INPUT(_type='file',_name='csvfile'),INPUT(_type='hidden',_value=table,_name='table'),INPUT(_type='submit',_value=T('import')))}} {{pass}} diff --git a/applications/admin/views/openshift/deploy.html b/applications/admin/views/openshift/deploy.html index 44cd21fe..76d8a314 100644 --- a/applications/admin/views/openshift/deploy.html +++ b/applications/admin/views/openshift/deploy.html @@ -12,20 +12,20 @@ $(document).ready(function() { }); -

OpenShift Deployment Interface

+

{{=T("OpenShift Deployment Interface")}}

{{=T("This page can commit your changes to an openshift app repo and push them to your cloud instance. This assumes that you've already created the application instance using the web2py skeleton and have that repo somewhere on a filesystem that this web2py instance can access. This functionality requires GitPython installed and on the python path of the runtime that web2py is operating in.")}}

{{=T("Note: If you receive an error with github status code of 128, ensure the system and account you are deploying from has a cooresponding ssh key configured in the openshift account.")}}

{{if command:}} -

Command

- +

{{=T("Command")}}

+ {{=CODE(command)}} -

OpenShift Output

+

{{=T("OpenShift Output")}}


 {{else:}}
-

Deployment form

+

{{=T("Deployment form")}}

{{=form}}
diff --git a/applications/examples/controllers/appadmin.py b/applications/examples/controllers/appadmin.py index a45f5539..482eb727 100644 --- a/applications/examples/controllers/appadmin.py +++ b/applications/examples/controllers/appadmin.py @@ -197,7 +197,7 @@ def select(): _name='update_fields', _value=request.vars.update_fields or '')), TR(T('Delete:'), INPUT(_name='delete_check', _class='delete', _type='checkbox', value=False), ''), - TR('', '', INPUT(_type='submit', _value='submit'))), + TR('', '', INPUT(_type='submit', _value=T('submit')))), _action=URL(r=request,args=request.args)) if request.vars.csvfile != None: try: diff --git a/applications/examples/views/appadmin.html b/applications/examples/views/appadmin.html index efbb3b0c..73c4ae47 100644 --- a/applications/examples/views/appadmin.html +++ b/applications/examples/views/appadmin.html @@ -63,7 +63,7 @@

{{=T("Import/Export")}}


[ {{=T("export as csv file")}} ] {{if table:}} - {{=FORM(str(T('or import from csv file'))+" ",INPUT(_type='file',_name='csvfile'),INPUT(_type='hidden',_value=table,_name='table'),INPUT(_type='submit',_value='import'))}} + {{=FORM(str(T('or import from csv file'))+" ",INPUT(_type='file',_name='csvfile'),INPUT(_type='hidden',_value=table,_name='table'),INPUT(_type='submit',_value=T('import')))}} {{pass}} diff --git a/applications/welcome/controllers/appadmin.py b/applications/welcome/controllers/appadmin.py index a45f5539..482eb727 100644 --- a/applications/welcome/controllers/appadmin.py +++ b/applications/welcome/controllers/appadmin.py @@ -197,7 +197,7 @@ def select(): _name='update_fields', _value=request.vars.update_fields or '')), TR(T('Delete:'), INPUT(_name='delete_check', _class='delete', _type='checkbox', value=False), ''), - TR('', '', INPUT(_type='submit', _value='submit'))), + TR('', '', INPUT(_type='submit', _value=T('submit')))), _action=URL(r=request,args=request.args)) if request.vars.csvfile != None: try: diff --git a/applications/welcome/views/appadmin.html b/applications/welcome/views/appadmin.html index efbb3b0c..73c4ae47 100644 --- a/applications/welcome/views/appadmin.html +++ b/applications/welcome/views/appadmin.html @@ -63,7 +63,7 @@

{{=T("Import/Export")}}


[ {{=T("export as csv file")}} ] {{if table:}} - {{=FORM(str(T('or import from csv file'))+" ",INPUT(_type='file',_name='csvfile'),INPUT(_type='hidden',_value=table,_name='table'),INPUT(_type='submit',_value='import'))}} + {{=FORM(str(T('or import from csv file'))+" ",INPUT(_type='file',_name='csvfile'),INPUT(_type='hidden',_value=table,_name='table'),INPUT(_type='submit',_value=T('import')))}} {{pass}} diff --git a/gluon/fileutils.py b/gluon/fileutils.py index 907e8cc0..ba7fd932 100644 --- a/gluon/fileutils.py +++ b/gluon/fileutils.py @@ -16,7 +16,6 @@ import time import datetime from http import HTTP from gzip import open as gzopen -from settings import global_settings __all__ = [ @@ -71,16 +70,6 @@ def readlines_file(filename, mode='r'): "applies .split('\n') to the output of read_file()" return read_file(filename, mode).split('\n') -def abspath(*relpath, **base): - "convert relative path to absolute path based (by default) on applications_parent" - path = os.path.join(*relpath) - gluon = base.get('gluon', False) - if os.path.isabs(path): - return path - if gluon: - return os.path.join(global_settings.gluon_parent, path) - return os.path.join(global_settings.applications_parent, path) - def mktree(path): head,tail =os.path.split(path) @@ -396,6 +385,15 @@ def make_fake_file_like_object(): return LogFile() - - +from settings import global_settings # we need to import settings here because + # settings imports fileutils too +def abspath(*relpath, **base): + "convert relative path to absolute path based (by default) on applications_parent" + path = os.path.join(*relpath) + gluon = base.get('gluon', False) + if os.path.isabs(path): + return path + if gluon: + return os.path.join(global_settings.gluon_parent, path) + return os.path.join(global_settings.applications_parent, path) diff --git a/gluon/main.py b/gluon/main.py index 21b5bfeb..1dfd9fae 100644 --- a/gluon/main.py +++ b/gluon/main.py @@ -52,15 +52,7 @@ from custom_import import custom_import_install # The two are identical unless web2py_path is changed via the web2py.py -f folder option # main.web2py_path is the same as applications_parent (for backward compatibility) -if not hasattr(os, 'mkdir'): - global_settings.db_sessions = True -if global_settings.db_sessions is not True: - global_settings.db_sessions = set() -global_settings.gluon_parent = os.environ.get('web2py_path', os.getcwd()) -global_settings.applications_parent = global_settings.gluon_parent web2py_path = global_settings.applications_parent # backward compatibility -global_settings.app_folders = set() -global_settings.debugging = False custom_import_install(web2py_path) @@ -107,11 +99,7 @@ requests = 0 # gc timer # pattern used to validate client address regex_client = re.compile('[\w\-:]+(\.[\w\-]+)*\.?') # ## to account for IPV6 - -version_info = open(abspath('VERSION', gluon=True), 'r') -web2py_version = parse_version(version_info.read().strip()) -version_info.close() -global_settings.web2py_version = web2py_version +web2py_version = global_settings.web2py_version try: import rocket diff --git a/gluon/settings.py b/gluon/settings.py index 4762cbd4..b5f75f4a 100644 --- a/gluon/settings.py +++ b/gluon/settings.py @@ -4,13 +4,41 @@ Copyrighted by Massimo Di Pierro License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html) """ +import os +import sys +import platform from storage import Storage global_settings = Storage() settings = global_settings # legacy compatibility - - - +if not hasattr(os, 'mkdir'): + global_settings.db_sessions = True + +if global_settings.db_sessions is not True: + global_settings.db_sessions = set() + +global_settings.gluon_parent = os.environ.get('web2py_path', os.getcwd()) + +global_settings.applications_parent = global_settings.gluon_parent + +global_settings.app_folders = set() + +global_settings.debugging = False + +global_settings.is_pypy = hasattr(platform,'python_implementation') and \ + platform.python_implementation() == 'PyPy' + +global_settings.is_jython = 'java' in sys.platform.lower() or \ + hasattr(sys, 'JYTHON_JAR') or \ + str(sys.copyright).find('Jython') > 0 + +version_info = open(os.path.join(global_settings.gluon_parent, 'VERSION'), 'r') +raw_version_string = version_info.read().strip() +version_info.close() + +from fileutils import parse_version # we need fileutils import here, because + # fileutils also imports settings +global_settings.web2py_version = parse_version(raw_version_string) diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index 92474abc..c6b4d1a8 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -758,6 +758,8 @@ class SQLFORM(FORM): labels={'name': 'Your name'}, linkto=URL(f='table/db/') """ + from gluon import current + T = current.T self.ignore_rw = ignore_rw self.formstyle = formstyle @@ -980,7 +982,7 @@ class SQLFORM(FORM): if not readonly: if 'submit' in buttons: widget = self.custom.submit = INPUT(_type='submit', - _value=submit_button) + _value=T(submit_button)) elif buttons: widget = self.custom.submit = DIV(*buttons) if self.custom.submit: