Ejemplo n.º 1
0
def findT(application_path, language='en-us'):
    """ 
    must be run by the admin app 
    """

    path = application_path
    try:
        sentences = read_dict(os.path.join(path, 'languages', '%s.py' 
                              % language))
    except:
        sentences = {}
    mp = os.path.join(path, 'models')
    cp = os.path.join(path, 'controllers')
    vp = os.path.join(path, 'views')
    for file in listdir(mp, '.+\.py', 0) + listdir(cp, '.+\.py', 0)\
         + listdir(vp, '.+\.html', 0):
        data = open(file, 'r').read()
        items = regex_translate.findall(data)
        for item in items:
            try:
                msg = eval(item)
                if msg and not sentences.has_key(msg):
                    sentences[msg] = '*** %s' % msg
            except:
                pass
    keys = sorted(sentences)
    file = open(os.path.join(path, 'languages', '%s.py' % language), 'w')
    file.write('{\n')
    for key in keys:
        file.write('%s:%s,\n' % (repr(key), repr(str(sentences[key]))))
    file.write('}\n')
    file.close()
Ejemplo n.º 2
0
def findT(path, language="en-us"):
    """
    must be run by the admin app
    """
    filename = os.path.join(path, "languages", "%s.py" % language)
    sentences = read_dict(filename)
    mp = os.path.join(path, "models")
    cp = os.path.join(path, "controllers")
    vp = os.path.join(path, "views")
    for file in listdir(mp, ".+\.py", 0) + listdir(cp, ".+\.py", 0) + listdir(vp, ".+\.html", 0):
        fp = open(file, "r")
        portalocker.lock(fp, portalocker.LOCK_SH)
        data = fp.read()
        portalocker.unlock(fp)
        fp.close()
        items = regex_translate.findall(data)
        for item in items:
            try:
                message = eval(item)
                if not message.startswith("#") and not "\n" in message:
                    tokens = message.rsplit("##", 1)
                else:
                    # this allows markmin syntax in translations
                    tokens = [message]
                if len(tokens) == 2:
                    message = tokens[0].strip() + "##" + tokens[1].strip()
                if message and not message in sentences:
                    sentences[message] = message
            except:
                pass
    write_dict(filename, sentences)
Ejemplo n.º 3
0
def findT(path, language='en-us'):
    """
    must be run by the admin app
    """
    filename = os.path.join(path, 'languages', '%s.py' % language)
    sentences = read_dict(filename)
    mp = os.path.join(path, 'models')
    cp = os.path.join(path, 'controllers')
    vp = os.path.join(path, 'views')
    for file in listdir(mp, '.+\.py', 0) + listdir(cp, '.+\.py', 0)\
         + listdir(vp, '.+\.html', 0):
        fp = open(file, 'r')
        portalocker.lock(fp, portalocker.LOCK_SH)
        data = fp.read()
        portalocker.unlock(fp)
        fp.close()
        items = regex_translate.findall(data)
        for item in items:
            try:
                msg = eval(item)
                if msg and not msg in sentences:
                    sentences[msg] = msg
            except:
                pass
    write_dict(filename, sentences)
Ejemplo n.º 4
0
def run_models_in(environment):
    """
    Runs all models (in the app specified by the current folder)
    It tries pre-compiled models first before compiling them.
    """

    folder = environment['request'].folder
    c = environment['request'].controller
    f = environment['request'].function
    cpath = os.path.join(folder, 'compiled')
    if os.path.exists(cpath):
        for model in listdir(cpath, '^models_\w+\.pyc$', 0):
            restricted(read_pyc(model), environment, layer=model)
        path = os.path.join(cpath, 'models')
        models = listdir(path, '^\w+\.pyc$',0,sort=False)
        compiled=True
    else:
        path = os.path.join(folder, 'models')
        models = listdir(path, '^\w+\.py$',0,sort=False)
        compiled=False
    paths = (path, os.path.join(path,c), os.path.join(path,c,f))
    for model in models:
        if not os.path.split(model)[0] in paths and c!='appadmin':
            continue
        elif compiled:
            code = read_pyc(model)
        elif is_gae:
            code = getcfs(model, model,
                          lambda: compile2(read_file(model), model))
        else:
            code = getcfs(model, model, None)
        restricted(code, environment, layer=model)
Ejemplo n.º 5
0
def findT(path, language='en-us'):
    """
    must be run by the admin app
    """
    filename = os.path.join(path, 'languages', '%s.py' % language)
    sentences = read_dict(filename)
    mp = os.path.join(path, 'models')
    cp = os.path.join(path, 'controllers')
    vp = os.path.join(path, 'views')
    for file in listdir(mp, '.+\.py', 0) + listdir(cp, '.+\.py', 0)\
         + listdir(vp, '.+\.html', 0):
        fp = open(file, 'r')
        portalocker.lock(fp, portalocker.LOCK_SH)
        data = fp.read()
        portalocker.unlock(fp)
        fp.close()
        items = regex_translate.findall(data)
        for item in items:
            try:
                message = eval(item)
                if not message.startswith('#') and not '\n' in message:
                    tokens = message.rsplit('##', 1)
                else:
                    # this allows markmin syntax in translations
                    tokens = [message]
                if len(tokens) == 2:
                    message = tokens[0].strip() + '##' + tokens[1].strip()
                if message and not message in sentences:
                    sentences[message] = message
            except:
                pass
    write_dict(filename, sentences)
Ejemplo n.º 6
0
def run_models_in(environment):
    """
    Runs all models (in the app specified by the current folder)
    It tries pre-compiled models first before compiling them.
    """

    folder = environment["request"].folder
    c = environment["request"].controller
    f = environment["request"].function
    cpath = pjoin(folder, "compiled")
    if os.path.exists(cpath):
        for model in listdir(cpath, "^models_\w+\.pyc$", 0):
            restricted(read_pyc(model), environment, layer=model)
        path = pjoin(cpath, "models")
        models = listdir(path, "^\w+\.pyc$", 0, sort=False)
        compiled = True
    else:
        path = pjoin(folder, "models")
        models = listdir(path, "^\w+\.py$", 0, sort=False)
        compiled = False
    n = len(path) + 1
    for model in models:
        regex = environment["response"].models_to_run
        if isinstance(regex, list):
            regex = re_compile("|".join(regex))
        file = model[n:].replace(os.path.sep, "/").replace(".pyc", ".py")
        if not regex.search(file) and c != "appadmin":
            continue
        elif compiled:
            code = read_pyc(model)
        elif is_gae:
            code = getcfs(model, model, lambda: compile2(read_file(model), model))
        else:
            code = getcfs(model, model, None)
        restricted(code, environment, layer=model)
Ejemplo n.º 7
0
def read_possible_plurals():
    """ create list of all possible plural rules files
        result is cached to increase speed
    """
    global pcache
    pdir = abspath('gluon','contrib','rules')
    plurals = {}
    # scan rules directory for plural_rules-*.py files:
    for pname in [f for f in listdir(pdir, regex_plural_rules)
                  if osep not in f]:

        lang=pname[13:-3]
        fname=ospath.join(pdir, pname)
        mtime=ostat(fname).st_mtime
        if lang in pcache and pcache[lang][2] == mtime:
            # if plural_file's mtime wasn't changed - use previous value:
            plurals[lang]=pcache[lang]
        else:
            # otherwise, reread plural_rules-file:
            if 'plural_rules-'+lang in cfs:
               n,f1,f2,status=read_plural_rules(lang)
            else:
               n,f1,f2,status=read_plural_rules_aux(fname)
            plurals[lang]=(n, pname, mtime, status)
    pcache=plurals
    return pcache
Ejemplo n.º 8
0
def compile_controllers(folder):
    """
    compiles all the controllers in the applicaiton specified by the
    current folder
    """

    path = os.path.join(folder, "controllers/")
    for file in listdir(path, ".+\.py$"):
        save_pyc(os.path.join(path, file))
        data = open(path + file, "r").read()
        exposed = regex_expose.findall(data)
        for function in exposed:
            command = (
                data
                + """

response._vars=response._caller(%s)"""
                % function
            )
            filename = os.path.join(
                folder, "compiled/", ("controllers/" + file[:-3]).replace("/", "_") + "_" + function + ".py"
            )
            open(filename, "w").write(command)
            save_pyc(filename)
            os.unlink(filename)
Ejemplo n.º 9
0
def read_possible_languages_aux(langdir):
    langs = {}
    # scan languages directory for langfiles:
    for langfile in [f for f in
                      listdir(langdir, regex_langfile) +
                      listdir(langdir, '^default\.py$')
                      if osep not in f]:
        lang=langfile[:-3]
        langs[lang]=get_lang_info(lang, langdir)
    if 'default' not in langs:
        # if default.py is not found, add default value:
        langs['default'] = ('en', 'English', 0)
    deflang=langs['default']
    if deflang[0] not in langs:
        # create language from default.py:
        langs[deflang[0]] = (deflang[0], deflang[1], 0)
    return langs
Ejemplo n.º 10
0
def remove_compiled_application(folder):
    """
    Deletes the folder `compiled` containing the compiled application.
    """
    try:
        shutil.rmtree(pjoin(folder, 'compiled'))
        path = pjoin(folder, 'controllers')
        for file in listdir(path, '.*\.pyc$', drop=False):
            os.unlink(file)
    except OSError:
        pass
Ejemplo n.º 11
0
def remove_compiled_application(folder):
    try:
        path = os.path.join(folder, "compiled/")
        for file in listdir(path):
            os.unlink(os.path.join(path, file))
        os.rmdir(path)
        path = os.path.join(folder, "controllers/")
        for file in os.listdir(path):
            if file.endswith(".pyc"):
                os.unlink(os.path.join(path, file))
    except OSError:
        pass
Ejemplo n.º 12
0
def compile_models(folder):
    """
    compiles all the models in the applicaiton specified by the
    current folder
    """

    path = os.path.join(folder, "models/")
    for file in listdir(path, ".+\.py$"):
        data = open(os.path.join(path, file), "r").read()
        filename = os.path.join(folder, "compiled/", ("models/" + file).replace("/", "_"))
        open(filename, "w").write(data)
        save_pyc(filename)
        os.unlink(filename)
Ejemplo n.º 13
0
def run_models_in(environment):
    """
    runs all models (in the app specified by the current folder) 
    in the environment. it tries precompiled models first.
    """

    folder = environment["request"].folder
    path = os.path.join(folder, "compiled/")
    if os.path.exists(path):
        for model in listdir(path, "^models_.+\.pyc$", 0):
            restricted(read_pyc(model), environment, layer=model)
    else:
        models = listdir(os.path.join(folder, "models/"), "^\w+\.py$", 0)
        for model in models:
            layer = model
            if is_gae:
                code = getcfs(
                    model, model, lambda: compile(open(model, "r").read().replace("\r\n", "\n"), layer, "exec")
                )
            else:
                code = getcfs(model, model, None)
            restricted(code, environment, layer)
Ejemplo n.º 14
0
def findT(path, language=DEFAULT_LANGUAGE):
    """
    must be run by the admin app
    """
    lang_file = pjoin(path, "languages", language + ".py")
    sentences = read_dict(lang_file)
    mp = pjoin(path, "models")
    cp = pjoin(path, "controllers")
    vp = pjoin(path, "views")
    mop = pjoin(path, "modules")
    for filename in (
        listdir(mp, "^.+\.py$", 0)
        + listdir(cp, "^.+\.py$", 0)
        + listdir(vp, "^.+\.html$", 0)
        + listdir(mop, "^.+\.py$", 0)
    ):
        data = portalocker.read_locked(filename)
        items = regex_translate.findall(data)
        for item in items:
            try:
                message = safe_eval(item)
            except:
                continue  # silently ignore inproperly formatted strings
            if not message.startswith("#") and not "\n" in message:
                tokens = message.rsplit("##", 1)
            else:
                # this allows markmin syntax in translations
                tokens = [message]
            if len(tokens) == 2:
                message = tokens[0].strip() + "##" + tokens[1].strip()
            if message and not message in sentences:
                sentences[message] = message
    if not "!langcode!" in sentences:
        sentences["!langcode!"] = DEFAULT_LANGUAGE if language in ("default", DEFAULT_LANGUAGE) else language
    if not "!langname!" in sentences:
        sentences["!langname!"] = (
            DEFAULT_LANGUAGE_NAME if language in ("default", DEFAULT_LANGUAGE) else sentences["!langcode!"]
        )
    write_dict(lang_file, sentences)
Ejemplo n.º 15
0
def run_models_in(environment):
    """
    Runs all models (in the app specified by the current folder)
    It tries pre-compiled models first before compiling them.
    """

    folder = environment['request'].folder
    path = os.path.join(folder, 'compiled')
    if os.path.exists(path):
        for model in listdir(path, '^models_.+\.pyc$', 0):
            restricted(read_pyc(model), environment, layer=model)
    else:
        models = listdir(os.path.join(folder, 'models'), '^\w+\.py$',
                         0)
        for model in models:
            layer = model
            if is_gae:
                code = getcfs(model, model,
                              lambda: compile2(open(model, 'r').read(),layer))
            else:
                code = getcfs(model, model, None)
            restricted(code, environment, layer)
Ejemplo n.º 16
0
def compile_views(folder):
    """
    Compiles all the views in the application specified by `folder`
    """

    path = pjoin(folder, "views")
    for file in listdir(path, "^[\w/\-]+(\.\w+)+$"):
        data = parse_template(file, path)
        filename = ("views/%s.py" % file).replace("/", "_").replace("\\", "_")
        filename = pjoin(folder, "compiled", filename)
        write_file(filename, data)
        save_pyc(filename)
        os.unlink(filename)
Ejemplo n.º 17
0
def compile_views(folder):
    """
    Compiles all the views in the application specified by `folder`
    """

    path = pjoin(folder, 'views')
    for file in listdir(path, '^[\w/\-]+(\.\w+)+$'):
        data = parse_template(file, path)
        filename = ('views/%s.py' % file).replace('/', '_').replace('\\', '_')
        filename = pjoin(folder, 'compiled', filename)
        write_file(filename, data)
        save_pyc(filename)
        os.unlink(filename)
Ejemplo n.º 18
0
def compile_models(folder):
    """
    Compiles all the models in the application specified by `folder`
    """

    path = pjoin(folder, 'models')
    for file in listdir(path, '.+\.py$'):
        data = read_file(pjoin(path, file))
        filename = pjoin(folder, 'compiled', 'models', file)
        mktree(filename)
        write_file(filename, data)
        save_pyc(filename)
        os.unlink(filename)
Ejemplo n.º 19
0
def app_cleanup(app, request):
    """
    Removes session, cache and error files

    Parameters
    ----------
    app:
        application name
    request:
        the global request object
    """
    r = True

    # Remove error files
    files = listdir(apath('%s/errors/' % app, request), '^\d.*$', 0)
    for f in files:
        try:
            os.unlink(f)
        except:
            r = False

    # Remove session files
    files = listdir(apath('%s/sessions/' % app, request), '^\d.*$', 0)
    for f in files:
        try:
            os.unlink(f)
        except:
            r = False

    # Remove cache files
    files = listdir(apath('%s/cache/' % app, request), '^cache.*$', 0)
    for file in files:
        try:
            os.unlink(file)
        except:
            r = False

    return r
def findT(path, language='en'):
    """
    must be run by the admin app
    """
    lang_file = ospath.join(path, 'languages', language + '.py')
    sentences = read_dict(lang_file)
    mp = ospath.join(path, 'models')
    cp = ospath.join(path, 'controllers')
    vp = ospath.join(path, 'views')
    mop = ospath.join(path, 'modules')
    for filename in \
            listdir(mp, '^.+\.py$', 0)+listdir(cp, '^.+\.py$', 0)\
            +listdir(vp, '^.+\.html$', 0)+listdir(mop, '^.+\.py$', 0):
        data = portalocker.read_locked(filename)
        items = regex_translate.findall(data)
        for item in items:
            try:
                message = safe_eval(item)
            except:
                continue # silently ignore inproperly formatted strings
            if not message.startswith('#') and not '\n' in message:
                tokens = message.rsplit('##', 1)
            else:
                # this allows markmin syntax in translations
                tokens = [message]
            if len(tokens) == 2:
                message = tokens[0].strip()+'##'+tokens[1].strip()
            if message and not message in sentences:
                sentences[message] = message
    if not '!langcode!' in sentences:
        sentences['!langcode!'] = (
            'en' if language in ('default', 'en') else language)
    if not '!langname!' in sentences:
        sentences['!langname!'] = (
            'English' if language in ('default', 'en')
            else sentences['!langcode!'])
    write_dict(lang_file, sentences)
Ejemplo n.º 21
0
def findT(path, language=DEFAULT_LANGUAGE):
    """
    must be run by the admin app
    """
    lang_file = pjoin(path, 'languages', language + '.py')
    sentences = read_dict(lang_file)
    mp = pjoin(path, 'models')
    cp = pjoin(path, 'controllers')
    vp = pjoin(path, 'views')
    mop = pjoin(path, 'modules')
    for filename in \
            listdir(mp, '^.+\.py$', 0)+listdir(cp, '^.+\.py$', 0)\
            +listdir(vp, '^.+\.html$', 0)+listdir(mop, '^.+\.py$', 0):
        data = portalocker.read_locked(filename)
        items = regex_translate.findall(data)
        for item in items:
            try:
                message = safe_eval(item)
            except:
                continue  # silently ignore inproperly formatted strings
            if not message.startswith('#') and not '\n' in message:
                tokens = message.rsplit('##', 1)
            else:
                # this allows markmin syntax in translations
                tokens = [message]
            if len(tokens) == 2:
                message = tokens[0].strip() + '##' + tokens[1].strip()
            if message and not message in sentences:
                sentences[message] = message
    if not '!langcode!' in sentences:
        sentences['!langcode!'] = (DEFAULT_LANGUAGE if language
                                   in ('default',
                                       DEFAULT_LANGUAGE) else language)
    if not '!langname!' in sentences:
        sentences['!langname!'] = (DEFAULT_LANGUAGE_NAME if language in (
            'default', DEFAULT_LANGUAGE) else sentences['!langcode!'])
    write_dict(lang_file, sentences)
Ejemplo n.º 22
0
def findT(path, language='en'):
    """
    must be run by the admin app
    """
    filename = ospath.join(path, 'languages', language + '.py')
    sentences = read_dict(filename)
    mp = ospath.join(path, 'models')
    cp = ospath.join(path, 'controllers')
    vp = ospath.join(path, 'views')
    mop = ospath.join(path, 'modules')
    for file in listdir(mp, '^.+\.py$', 0) + listdir(cp, '^.+\.py$', 0)\
         + listdir(vp, '^.+\.html$', 0) + listdir(mop, '^.+\.py$', 0):
        fp = portalocker.LockedFile(file, 'r')
        data = fp.read()
        fp.close()
        items = regex_translate.findall(data)
        for item in items:
            try:
                message = eval(item)
                if not message.startswith('#') and not '\n' in message:
                    tokens = message.rsplit('##', 1)
                else:
                    # this allows markmin syntax in translations
                    tokens = [message]
                if len(tokens) == 2:
                    message = tokens[0].strip() + '##' + tokens[1].strip()
                if message and not message in sentences:
                    sentences[message] = message
            except:
                pass
    if not '!langcode!' in sentences:
        sentences['!langcode!'] = ('en' if language in ('default',
                                                        'en') else language)
    if not '!langname!' in sentences:
        sentences['!langname!'] = ('English' if language in ('default', 'en')
                                   else sentences['!langcode!'])
    write_dict(filename, sentences)
Ejemplo n.º 23
0
def findT(path, language='en'):
    """
    must be run by the admin app
    """
    filename = ospath.join(path, 'languages', language + '.py')
    sentences = read_dict(filename)
    mp = ospath.join(path, 'models')
    cp = ospath.join(path, 'controllers')
    vp = ospath.join(path, 'views')
    mop = ospath.join(path, 'modules')
    for file in listdir(mp, '^.+\.py$', 0) + listdir(cp, '^.+\.py$', 0)\
         + listdir(vp, '^.+\.html$', 0) + listdir(mop, '^.+\.py$', 0):
        fp = portalocker.LockedFile(file, 'r')
        data = fp.read()
        fp.close()
        items = regex_translate.findall(data)
        for item in items:
            try:
                message = eval(item)
                if not message.startswith('#') and not '\n' in message:
                    tokens = message.rsplit('##', 1)
                else:
                    # this allows markmin syntax in translations
                    tokens = [message]
                if len(tokens) == 2:
                    message = tokens[0].strip() + '##' + tokens[1].strip()
                if message and not message in sentences:
                    sentences[message] = message
            except:
                pass
    if not '!langcode!' in sentences:
        sentences['!langcode!'] = (
            'en' if language in ('default', 'en') else language)
    if not '!langname!' in sentences:
        sentences['!langname!'] = (
            'English' if language in ('default', 'en') else sentences['!langcode!'])
    write_dict(filename, sentences)
Ejemplo n.º 24
0
def remove_compiled_application(folder):
    """
    Deletes the folder `compiled` containing the compiled application.
    """
    try:
        path = os.path.join(folder, 'compiled/')
        for file in listdir(path):
            os.unlink(os.path.join(path, file))
        os.rmdir(path)
        path = os.path.join(folder, 'controllers/')
        for file in os.listdir(path):
            if file.endswith('.pyc'):
                os.unlink(os.path.join(path, file))
    except OSError:
        pass
Ejemplo n.º 25
0
def compile_views(folder):
    """
    Compiles all the views in the application specified by `folder`
    """

    path = os.path.join(folder, 'views')
    for file in listdir(path, '^[\w/]+\.\w+$'):
        data = parse_template(file, path)
        filename = ('views/%s.py' % file).replace('/', '_').replace('\\', '_')
        filename = os.path.join(folder, 'compiled', filename)
        fp = open(filename, 'w')
        fp.write(data)
        fp.close()
        save_pyc(filename)
        os.unlink(filename)
Ejemplo n.º 26
0
def compile_views(folder):
    """
    Compiles all the views in the application specified by `folder`
    """

    path = os.path.join(folder, 'views/')
    for file in listdir(path, '^[\w/]+\.\w+$'):
        data = parse_template(file, path)
        filename = ('views/%s.py' % file).replace('/', '_').replace('\\', '_')
        filename = os.path.join(folder, 'compiled', filename)
        fp = open(filename, 'w')
        fp.write(data)
        fp.close()
        save_pyc(filename)
        os.unlink(filename)
Ejemplo n.º 27
0
def compile_views(folder):
    """
    compiles all the views in the applicaiton specified by the
    current folder
    """

    path = os.path.join(folder, "views/")
    for file in listdir(path, ".+\.html$"):
        data = parse_template(file, path)
        filename = os.path.join(
            folder, "compiled/", ("views/" + file[:-5] + ".py").replace("/", "_").replace("\\", "_")
        )
        open(filename, "w").write(data)
        save_pyc(filename)
        os.unlink(filename)
Ejemplo n.º 28
0
def compile_views(folder):
    """
    compiles all the views in the applicaiton specified by the
    current folder
    """

    path = os.path.join(folder, 'views/')
    for file in listdir(path, '.+\.html$'):
        data = parse_template(file, path)
        filename = os.path.join(folder, 'compiled/',
                                ('views/' + file[:-5] + '.py').replace(
                                    '/', '_').replace('\\', '_'))
        open(filename, 'w').write(data)
        save_pyc(filename)
        os.unlink(filename)
Ejemplo n.º 29
0
def remove_compiled_application(folder):
    """
    Deletes the folder `compiled` containing the compiled application.
    """
    try:
        path = os.path.join(folder, 'compiled')
        for file in listdir(path):
            os.unlink(os.path.join(path, file))
        os.rmdir(path)
        path = os.path.join(folder, 'controllers')
        for file in os.listdir(path):
            if file.endswith('.pyc'):
                os.unlink(os.path.join(path, file))
    except OSError:
        pass
Ejemplo n.º 30
0
def run_models_in(environment):
    """
    Runs all models (in the app specified by the current folder)
    It tries pre-compiled models first before compiling them.
    """

    folder = environment['request'].folder
    path = os.path.join(folder, 'compiled/')
    if os.path.exists(path):
        for model in listdir(path, '^models_.+\.pyc$', 0):
            restricted(read_pyc(model), environment, layer=model)
    else:
        models = listdir(os.path.join(folder, 'models/'), '^\w+\.py$',
                         0)
        for model in models:
            layer = model
            if is_gae:
                code = getcfs(model, model, lambda: \
                              compile(open(model, 'r')\
                              .read().replace('\r\n', '\n'), layer,
                              'exec'))
            else:
                code = getcfs(model, model, None)
            restricted(code, environment, layer)
Ejemplo n.º 31
0
def run_models_in(environment):
    """
    Runs all models (in the app specified by the current folder)
    It tries pre-compiled models first before compiling them.
    """

    folder = environment['request'].folder
    c = environment['request'].controller
    f = environment['request'].function
    cpath = pjoin(folder, 'compiled')
    if os.path.exists(cpath):
        for model in listdir(cpath, '^models_\w+\.pyc$', 0):
            restricted(read_pyc(model), environment, layer=model)
        path = pjoin(cpath, 'models')
        models = listdir(path, '^\w+\.pyc$', 0)
        compiled = True
    else:
        path = pjoin(folder, 'models')
        models = listdir(path, '^\w+\.py$', 0)
        compiled = False
    n = len(path) + 1
    for model in models:
        regex = environment['response'].models_to_run
        if isinstance(regex, list):
            regex = re_compile('|'.join(regex))
        file = model[n:].replace(os.path.sep, '/').replace('.pyc', '.py')
        if not regex.search(file) and c != 'appadmin':
            continue
        elif compiled:
            code = read_pyc(model)
        elif is_gae:
            code = getcfs(model, model,
                          lambda: compile2(read_file(model), model))
        else:
            code = getcfs(model, model, None)
        restricted(code, environment, layer=model)
Ejemplo n.º 32
0
def run_models_in(environment):
    """
    Runs all models (in the app specified by the current folder)
    It tries pre-compiled models first before compiling them.
    """

    folder = environment['request'].folder
    c = environment['request'].controller
    f = environment['request'].function
    cpath = pjoin(folder, 'compiled')
    if os.path.exists(cpath):
        for model in listdir(cpath, '^models_\w+\.pyc$', 0):
            restricted(read_pyc(model), environment, layer=model)
        path = pjoin(cpath, 'models')
        models = listdir(path, '^\w+\.pyc$',0,sort=False)
        compiled=True
    else:
        path = pjoin(folder, 'models')
        models = listdir(path, '^\w+\.py$',0,sort=False)
        compiled=False
    n = len(path) + 1
    for model in models:
        regex = environment['response'].models_to_run
        if isinstance(regex, list):
            regex = re_compile('|'.join(regex))
        file = model[n:].replace(os.path.sep, '/').replace('.pyc', '.py')
        if not regex.search(file) and c!= 'appadmin':
            continue
        elif compiled:
            code = read_pyc(model)
        elif is_gae:
            code = getcfs(model, model,
                          lambda: compile2(read_file(model), model))
        else:
            code = getcfs(model, model, None)
        restricted(code, environment, layer=model)
Ejemplo n.º 33
0
def findT(path, language="en-us"):
    """
    must be run by the admin app
    """
    filename = os.path.join(path, "languages", "%s.py" % language)
    sentences = read_dict(filename)
    mp = os.path.join(path, "models")
    cp = os.path.join(path, "controllers")
    vp = os.path.join(path, "views")
    for file in listdir(mp, ".+\.py", 0) + listdir(cp, ".+\.py", 0) + listdir(vp, ".+\.html", 0):
        fp = open(file, "r")
        portalocker.lock(fp, portalocker.LOCK_SH)
        data = fp.read()
        portalocker.unlock(fp)
        fp.close()
        items = regex_translate.findall(data)
        for item in items:
            try:
                msg = eval(item)
                if msg and not msg in sentences:
                    sentences[msg] = msg
            except:
                pass
    write_dict(filename, sentences)
Ejemplo n.º 34
0
def compile_views(folder):
    """
    Compiles all the views in the application specified by `folder`
    """

    path = pjoin(folder, 'views')
    for file in listdir(path, '^[\w/\-]+(\.\w+)*$'):
        try:
            data = parse_template(file, path)
        except Exception, e:
            raise Exception("%s in %s" % (e, file))
        filename = ('views/%s.py' % file).replace('/', '_').replace('\\', '_')
        filename = pjoin(folder, 'compiled', filename)
        write_file(filename, data)
        save_pyc(filename)
        os.unlink(filename)
Ejemplo n.º 35
0
def compile_models(folder):
    """
    Compiles all the models in the application specified by `folder`
    """

    path = os.path.join(folder, 'models')
    for file in listdir(path, '.+\.py$'):
        fp = open(os.path.join(path, file), 'r')
        data = fp.read()
        fp.close()
        filename = os.path.join(folder, 'compiled',
                                ('models/' + file).replace('/', '_'))
        fp = open(filename, 'w')
        fp.write(data)
        fp.close()
        save_pyc(filename)
        os.unlink(filename)
Ejemplo n.º 36
0
def compile_models(folder):
    """
    Compiles all the models in the application specified by `folder`
    """

    path = os.path.join(folder, 'models/')
    for file in listdir(path, '.+\.py$'):
        fp = open(os.path.join(path, file), 'r')
        data = fp.read()
        fp.close()
        filename = os.path.join(folder, 'compiled/', ('models/'
                                 + file).replace('/', '_'))
        fp = open(filename, 'w')
        fp.write(data)
        fp.close()
        save_pyc(filename)
        os.unlink(filename)
Ejemplo n.º 37
0
def compile_controllers(folder):
    """
    Compiles all the controllers in the application specified by `folder`
    """

    path = pjoin(folder, "controllers")
    for file in listdir(path, ".+\.py$"):
        ### why is this here? save_pyc(pjoin(path, file))
        data = read_file(pjoin(path, file))
        exposed = regex_expose.findall(data)
        for function in exposed:
            command = data + "\nresponse._vars=response._caller(%s)\n" % function
            filename = pjoin(
                folder, "compiled", ("controllers/" + file[:-3]).replace("/", "_") + "_" + function + ".py"
            )
            write_file(filename, command)
            save_pyc(filename)
            os.unlink(filename)
Ejemplo n.º 38
0
def compile_controllers(folder):
    """
    Compiles all the controllers in the application specified by `folder`
    """

    path = pjoin(folder, 'controllers')
    for file in listdir(path, '.+\.py$'):
        ### why is this here? save_pyc(pjoin(path, file))
        data = read_file(pjoin(path, file))
        exposed = regex_expose.findall(data)
        for function in exposed:
            command = data + "\nresponse._vars=response._caller(%s)\n" % \
                function
            filename = pjoin(folder, 'compiled', ('controllers/'
                                     + file[:-3]).replace('/', '_')
                             + '_' + function + '.py')
            write_file(filename, command)
            save_pyc(filename)
            os.unlink(filename)
Ejemplo n.º 39
0
def compile_controllers(folder):
    """
    Compiles all the controllers in the application specified by `folder`
    """

    path = pjoin(folder, 'controllers')
    for file in listdir(path, '.+\.py$'):
        ### why is this here? save_pyc(pjoin(path, file))
        data = read_file(pjoin(path,file))
        exposed = regex_expose.findall(data)
        for function in exposed:
            command = data + "\nresponse._vars=response._caller(%s)\n" % \
                function
            filename = pjoin(folder, 'compiled', ('controllers/'
                                     + file[:-3]).replace('/', '_')
                                     + '_' + function + '.py')
            write_file(filename, command)
            save_pyc(filename)
            os.unlink(filename)
Ejemplo n.º 40
0
def compile_controllers(folder):
    """
    Compiles all the controllers in the application specified by `folder`
    """

    path = os.path.join(folder, 'controllers/')
    for file in listdir(path, '.+\.py$'):
        save_pyc(os.path.join(path, file))
        fp = open(path + file, 'r')
        data = fp.read()
        fp.close()
        exposed = regex_expose.findall(data)
        for function in exposed:
            command = data + "\nresponse._vars=response._caller(%s)\n" % \
                function
            filename = os.path.join(folder, 'compiled/', ('controllers/'
                                     + file[:-3]).replace('/', '_')
                                     + '_' + function + '.py')
            fp = open(filename, 'w')
            fp.write(command)
            fp.close()
            save_pyc(filename)
            os.unlink(filename)
Ejemplo n.º 41
0
def compile_controllers(folder):
    """
    compiles all the controllers in the applicaiton specified by the
    current folder
    """

    path = os.path.join(folder, 'controllers/')
    for file in listdir(path, '.+\.py$'):
        save_pyc(os.path.join(path, file))
        data = open(path + file, 'r').read()
        exposed = regex_expose.findall(data)
        for function in exposed:
            command = data + '''

response._vars=response._caller(%s)'''\
                 % function
            filename = os.path.join(
                folder, 'compiled/',
                ('controllers/' + file[:-3]).replace('/', '_') + '_' +
                function + '.py')
            open(filename, 'w').write(command)
            save_pyc(filename)
            os.unlink(filename)
Ejemplo n.º 42
0
def compile_controllers(folder):
    """
    Compiles all the controllers in the application specified by `folder`
    """

    path = os.path.join(folder, 'controllers/')
    for file in listdir(path, '.+\.py$'):
        save_pyc(os.path.join(path, file))
        fp = open(path + file, 'r')
        data = fp.read()
        fp.close()
        exposed = regex_expose.findall(data)
        for function in exposed:
            command = data + "\nresponse._vars=response._caller(%s)\n" % \
                function
            filename = os.path.join(folder, 'compiled/', ('controllers/'
                                     + file[:-3]).replace('/', '_')
                                     + '_' + function + '.py')
            fp = open(filename, 'w')
            fp.write(command)
            fp.close()
            save_pyc(filename)
            os.unlink(filename)
Ejemplo n.º 43
0
def update_all_languages(application_path):
    path = ospath.join(application_path, 'languages/')
    for language in listdir(path, regex_langfile):
        findT(application_path, language[:-3])
Ejemplo n.º 44
0
def update_all_languages(application_path):
    path = os.path.join(application_path, 'languages/')
    for language in listdir(path, '^\w+(\-\w+)?\.py$'):
        findT(application_path, language[:-3])