def sync_main(file, apps):
    d = {}
    for app in apps:
        path = 'applications/%s/' % app
        findT(path, file)
        langfile = open(os.path.join(path, 'languages', '%s.py' % file))
        try:
            data = eval(langfile.read())
        finally:
            langfile.close()

        d = sync_language(d, data)

    path = 'applications/%s/' % apps[-1]
    file1 = os.path.join(path, 'languages', '%s.py' % file)

    f = open(file1, 'w')
    try:
        f.write('# coding: utf8\n')
        f.write('{\n')
        keys = d.keys()
        keys.sort()
        for key in keys:
            f.write("'''%s''':'''%s''',\n" %
                    (key.replace("'", "\\'"), str(d[key].replace("'", "\\'"))))
        f.write('}\n')
    finally:
        f.close()

    oapps = reversed(apps[:-1])
    for app in oapps:
        path2 = 'applications/%s/' % app
        file2 = os.path.join(path2, 'languages', '%s.py' % file)
        if file1 != file2:
            shutil.copyfile(file1, file2)
示例#2
0
def sync_main(file, apps):
    d = {}
    for app in apps:
        path = 'applications/%s/' % app
        findT(path, file)
        langfile = open(os.path.join(path, 'languages', '%s.py' % file))
        try:
            data = eval(langfile.read())
        finally:
            langfile.close()

        d = sync_language(d, data)


    path = 'applications/%s/' % apps[-1]
    file1 = os.path.join(path, 'languages', '%s.py' % file)

    f = open(file1, 'w')
    try:
        f.write('# coding: utf8\n')
        f.write('{\n')
        keys = d.keys()
        keys.sort()
        for key in keys:
            f.write("'''%s''':'''%s''',\n" % (key.replace("'", "\\'"), str(d[key].replace("'", "\\'"))))
        f.write('}\n')
    finally:
        f.close()

    oapps = reversed(apps[:-1])
    for app in oapps:
        path2 = 'applications/%s/' % app
        file2 = os.path.join(path2, 'languages', '%s.py' % file)
        if file1 != file2:
            shutil.copyfile(file1, file2)
示例#3
0
def update_languages(cwd, default_lang):
	defaultfp = os.path.join(cwd, "languages", '%s.py' %default_lang)
	findT(cwd, default_lang)
	default = read_dict(defaultfp)

	for lang in os.listdir(os.path.join(cwd, "languages")):
		if lang == default_lang+".py" or lang.startswith("plural-"): continue
		
		i18n = read_dict(os.path.join(cwd, "languages", lang))
		if i18n:
			new_dict = default
			for phrase in i18n:
				if phrase in default:
					new_dict[phrase] = i18n[phrase]
			write_file(open(os.path.join(cwd, "languages", lang), 'w'), new_dict)
			print(lang)
示例#4
0
def update_languages(cwd, default_lang):
    defaultfp = os.path.join(cwd, '%s.py' % default_lang)
    findT(cwd, default_lang)
    default = read_dict(defaultfp)

    for x in os.listdir(cwd):
        if x == default_lang or x.startswith("plural-"): continue

        i18n = read_dict(os.path.join(cwd, x))
        if i18n:
            nd = default
            for k_d1 in i18n:
                if k_d1 in default:
                    nd[k_d1] = i18n[k_d1]
            write_file(open(x, 'w'), nd)
            print x
def update_languages(cwd, default_lang):
	defaultfp = os.path.join(cwd, '%s.py' %default_lang)
	findT(cwd, default_lang)
	default = read_dict(defaultfp)

	for x in os.listdir(cwd):
		if x == default_lang or x.startswith("plural-"): continue
		
		i18n = read_dict(os.path.join(cwd, x))
		if i18n:
			nd = default
			for k_d1 in i18n:
				if k_d1 in default:
					nd[k_d1] = i18n[k_d1]
			write_file(open(x, 'w'), nd)
			print x
示例#6
0
def update_languages(cwd, default_lang):
    defaultfp = os.path.join(cwd, "languages", '%s.py' % default_lang)
    findT(cwd, default_lang)
    default = read_dict(defaultfp)

    for lang in os.listdir(os.path.join(cwd, "languages")):
        if lang == default_lang + ".py" or lang.startswith("plural-"): continue

        i18n = read_dict(os.path.join(cwd, "languages", lang))
        if i18n:
            new_dict = default
            for phrase in i18n:
                if phrase in default:
                    new_dict[phrase] = i18n[phrase]
            write_file(open(os.path.join(cwd, "languages", lang), 'w'),
                       new_dict)
            print(lang)
示例#7
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import shutil
import os
sys.path.insert(0, '.')
from gluon.languages import findT

file = sys.argv[1]
apps = sys.argv[2:]
d = {}
for app in apps:
    path = 'applications/%s/' % app
    findT(path, file)
    d.update(eval(open(os.path.join(path, 'languages', '%s.py'
              % file)).read()))
path = 'applications/%s/' % apps[-1]
file1 = os.path.join(path, 'languages', '%s.py' % file)
f = open(file1, 'w')
f.write('{\n')
keys = d.keys()
keys.sort()
for key in keys:
    f.write('%s:%s,\n' % (repr(key), repr(str(d[key]))))
f.write('}\n')
f.close()

oapps = apps[:-1]
oapps.reverse()
for app in oapps:
    path2 = 'applications/%s/' % app
示例#8
0
import os
import sys
sys.path.insert(0, '../../../')

from gluon.languages import findT

# create /tmp/languages/template.py
if not os.path.exists('../languages/template.py'):
    open('../languages/template.py', "w").close()
    
findT('../', 'template')
示例#9
0
文件: default.py 项目: huiker/web2py
def create_file():
    """ Create files handler """

    try:
        path = apath(request.vars.location)
        filename = re.sub('[^\w./-]+', '_', request.vars.filename)

        if path[-11:] == '/languages/':
            # Handle language files
            if len(filename) == 0:
                raise SyntaxError

            app = path.split('/')[-3]
            findT(apath(app), filename)
            session.flash = T('language file "%(filename)s" created/updated',
                              dict(filename=filename))
            redirect(request.vars.sender)

        elif path[-8:] == '/models/':
            # Handle python models
            if not filename[-3:] == '.py':
                filename += '.py'

            if len(filename) == 3:
                raise SyntaxError

            fn = re.sub('\W', '', filename[:-3].lower())
            text = '# %s\n%s=SQLDB("sqlite://%s.db")'
            text = text % (T('try something like'), fn, fn)

        elif path[-13:] == '/controllers/':
            # Handle python controlers
            if not filename[-3:] == '.py':
                filename += '.py'

            if len(filename) == 3:
                raise SyntaxError

            text = '# %s\ndef index(): return dict(message="hello from %s")'
            text = text % (T('try something like'), filename)

        elif path[-7:] == '/views/':
            # Handle template (html) views
            if not filename[-5:] == '.html':
                filename += '.html'

            if len(filename) == 5:
                raise SyntaxError

            msg = T('This is the %(filename)s template',
                    dict(filename=filename))
            text = dedent("""
                   {{extend 'layout.html'}}
                   <h1>%s</h1>
                   {{=BEAUTIFY(response._vars)}}""" % msg)

        elif path[-9:] == '/modules/':
            # Handle python module files
            if not filename[-3:] == '.py':
                filename += '.py'

            if len(filename) == 3:
                raise SyntaxError

            text = dedent("""
                   from gluon.html import *
                   from gluon.http import *
                   from gluon.validators import *
                   from gluon.sqlhtml import *
                   # request, response, session, cache, T, db(s) 
                   # must be passed and cannot be imported!""")

        elif path[-8:] == '/static/':
            text = ''
        else:
            redirect(request.vars.sender)

        full_filename = os.path.join(path, filename)
        dirpath = os.path.dirname(full_filename)

        if not os.path.exists(dirpath):
            os.makedirs(dirpath)

        if os.path.exists(full_filename):
            raise SyntaxError

        open(full_filename, 'w').write(text)
        session.flash = T('file "%(filename)s" created',
                          dict(filename=full_filename[len(path):]))
        redirect(
            URL(r=request,
                f='edit',
                args=[os.path.join(request.vars.location, filename)]))
    except Exception, e:
        session.flash = T('cannot create file')
示例#10
0
import sys
import shutil
import os

from gluon.languages import findT

sys.path.insert(0, '.')

file = sys.argv[1]
apps = sys.argv[2:]

d = {}
for app in apps:
    path = 'applications/%s/' % app
    findT(path, file)
    data = eval(open(os.path.join(path, 'languages', '%s.py' % file)).read())
    d.update(data)

path = 'applications/%s/' % apps[-1]
file1 = os.path.join(path, 'languages', '%s.py' % file)

f = open(file1, 'w')
f.write('{\n')

keys = d.keys()
keys.sort()
for key in keys:
    f.write('%s:%s,\n' % (repr(key), repr(str(d[key]))))

f.write('}\n')
示例#11
0
def create_file():
    """ Create files handler """

    try:
        path = apath(request.vars.location)
        filename = re.sub('[^\w./-]+', '_', request.vars.filename)

        if path[-11:] == '/languages/':
            # Handle language files
            if len(filename) == 0:
                raise SyntaxError

            app = path.split('/')[-3]
            findT(apath(app), filename)
            session.flash = T('language file "%(filename)s" created/updated',
                              dict(filename=filename))
            redirect(request.vars.sender)

        elif path[-8:] == '/models/':
            # Handle python models
            if not filename[-3:] == '.py':
                filename += '.py'

            if len(filename) == 3:
                raise SyntaxError

            fn = re.sub('\W', '', filename[:-3].lower())
            text = '# %s\n%s=SQLDB("sqlite://%s.db")'
            text = text % (T('try something like'), fn, fn)

        elif path[-13:] == '/controllers/':
            # Handle python controlers
            if not filename[-3:] == '.py':
                filename += '.py'

            if len(filename) == 3:
                raise SyntaxError

            text = '# %s\ndef index(): return dict(message="hello from %s")'
            text = text % (T('try something like'), filename)

        elif path[-7:] == '/views/':
            # Handle template (html) views
            if not filename[-5:] == '.html':
                filename += '.html'
            
            if len(filename) == 5:
                raise SyntaxError

            msg = T('This is the %(filename)s template',
                    dict(filename=filename))
            text = dedent("""
                   {{extend 'layout.html'}}
                   <h1>%s</h1>
                   {{=BEAUTIFY(response._vars)}}""" % msg)

        elif path[-9:] == '/modules/':
            # Handle python module files
            if not filename[-3:] == '.py':
                filename += '.py'

            if len(filename) == 3:
                raise SyntaxError

            text = dedent("""
                   from gluon.html import *
                   from gluon.http import *
                   from gluon.validators import *
                   from gluon.sqlhtml import *
                   # request, response, session, cache, T, db(s) 
                   # must be passed and cannot be imported!""")

        elif path[-8:] == '/static/':
            text = ''
        else:
            redirect(request.vars.sender)

        full_filename = os.path.join(path, filename)
        dirpath = os.path.dirname(full_filename)

        if not os.path.exists(dirpath):
            os.makedirs(dirpath)

        if os.path.exists(full_filename):
            raise SyntaxError

        open(full_filename, 'w').write(text)
        session.flash = T('file "%(filename)s" created',
                          dict(filename=full_filename[len(path):]))
        redirect(URL(r=request, f='edit',
                 args=[os.path.join(request.vars.location, filename)]))
    except Exception, e:
        session.flash = T('cannot create file')