Example #1
0
def sitemap():
    # Import Os and Regex
    import os
    from gluon.myregex import regex_expose

    # Finding You Controllers 
    ctldir = os.path.join(request.folder,"controllers")
    ctls=os.listdir(ctldir)
    
    # Excluding The appadmin.py and the Manage.py
    if 'appadmin.py' in ctls: ctls.remove('appadmin.py')
    if 'manage.py' in ctls: ctls.remove('manage.py')

    # Adding  Schemas for the site map

    sitemap=TAG.urlset(_xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")

    # Add The Pages That You Dont want in the XML Sitemap
    ExcludedPages = ['edit', 'saved','delete','new','setpublic','user', 'publishing', 'preview','deletedraft','verified', 'requestreset', 'newform', 'download','handle_error','sitemap','register','google0ac0168ea35fcffb','BingSiteAuth','successful','mailcheck' ]
    ExcludedCtrl = ['administrator', 'plugin_ckeditor', 'verifyprocess', 'payment', 'myaccount', 'account', 'plans','payment','products']

    # Define Your Domain
    # urldomain = '%(scheme)s://www.gextiendas.es' % {'scheme':request.env.wsgi_url_scheme}
    urldomain = '%(scheme)s://%(host)s' % {'scheme':request.env.wsgi_url_scheme,'host':request.env.http_host}

    for ctl in ctls:
            if ctl.endswith(".bak") == False:

                if ctl.replace(".py","") not in ExcludedCtrl:
                    filename = os.path.join(ctldir,ctl)
                    data = open(filename, 'r').read()
                    functions = regex_expose.findall(data)
                    ctl = ctl[:-3].replace("_"," ")

                    # Adding Statics URLs From Your Controllers 
                    for f in functions:
                        # Ignore the Pages from the list above (  ExcludedPages )
                        if f not in ExcludedPages:
                             sitemap.append(TAG.url(TAG.loc('%s/%s/%s' % (urldomain, ctl,f.replace("_"," ")))))


    #  Dynamic URLs From Tables  For ex ... >> www.domain.com/post/1
    from blog import Blog, Images
    try:
        Blog(db,ckeditor)
        Images(db)
    except:
        pass
    posts = db(db.blog.public==True).select(db.blog.ALL, orderby=~db.blog.created_on)
    for item in posts:
        #sitemap.append(TAG.url(TAG.loc('%s/%s/blog/show/%s' % (urldomain, request.application,item.id))))
        sitemap.append(TAG.url(TAG.loc('%s/blog/show/%s' % (urldomain, item.urlfriendly))))
    
    return '<?xml version="1.0" encoding="UTF-8"?>\n%s' % sitemap.xml()
Example #2
0
def compile_controllers(folder):
    """
    Compiles all the controllers in the application specified by `folder`
    """

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

    path = pjoin(folder, 'controllers')
    for fname in listdir(path, '.+\.py$'):
        ### why is this here? save_pyc(pjoin(path, file))
        data = read_file(pjoin(path, fname))
        exposed = regex_expose.findall(data)
        for function in exposed:
            command = data + "\nresponse._vars=response._caller(%s)\n" % \
                function
            filename = pjoin(folder, 'compiled',
                             'controllers.%s.%s.py' % (fname[:-3], function))
            write_file(filename, command)
            save_pyc(filename)
            os.unlink(filename)
Example #4
0
def find_exposed_functions(data):
    data = regex_longcomments.sub('',data)
    return regex_expose.findall(data)
Example #5
0
def find_exposed_functions(data):
    data = regex_longcomments.sub('', data)
    return regex_expose.findall(data)
Example #6
0
def run_controller_in(controller, function, environment):
    """
    Runs the controller.function() (for the app specified by
    the current folder).
    It tries pre-compiled controller_function.pyc first before compiling it.
    """

    # if compiled should run compiled!
    folder = environment['request'].folder
    path = pjoin(folder, 'compiled')
    badc = 'invalid controller (%s/%s)' % (controller, function)
    badf = 'invalid function (%s/%s)' % (controller, function)
    if os.path.exists(path):
        filename = pjoin(path, 'controllers.%s.%s.pyc'
                         % (controller, function))
        if not os.path.exists(filename):
            ### for backward compatibility
            filename = pjoin(path, 'controllers_%s_%s.pyc'
                             % (controller, function))
            ### end for backward compatibility
            if not os.path.exists(filename):                
                raise HTTP(404,
                           rewrite.THREAD_LOCAL.routes.error_message % badf,
                           web2py_error=badf)
        restricted(read_pyc(filename), environment, layer=filename)
    elif function == '_TEST':
        # TESTING: adjust the path to include site packages
        from settings import global_settings
        from admin import abspath, add_path_first
        paths = (global_settings.gluon_parent, abspath(
            'site-packages', gluon=True), abspath('gluon', gluon=True), '')
        [add_path_first(path) for path in paths]
        # TESTING END

        filename = pjoin(folder, 'controllers/%s.py'
                                 % controller)
        if not os.path.exists(filename):
            raise HTTP(404,
                       rewrite.THREAD_LOCAL.routes.error_message % badc,
                       web2py_error=badc)
        environment['__symbols__'] = environment.keys()
        code = read_file(filename)
        code += TEST_CODE
        restricted(code, environment, layer=filename)
    else:
        filename = pjoin(folder, 'controllers/%s.py'
                                 % controller)
        if not os.path.exists(filename):
            raise HTTP(404,
                       rewrite.THREAD_LOCAL.routes.error_message % badc,
                       web2py_error=badc)
        code = read_file(filename)
        exposed = regex_expose.findall(code)
        if not function in exposed:
            raise HTTP(404,
                       rewrite.THREAD_LOCAL.routes.error_message % badf,
                       web2py_error=badf)
        code = "%s\nresponse._vars=response._caller(%s)\n" % (code, function)
        if is_gae:
            layer = filename + ':' + function
            code = getcfs(layer, filename, lambda: compile2(code, layer))
        restricted(code, environment, filename)
    response = environment['response']
    vars = response._vars
    if response.postprocessing:
        vars = reduce(lambda vars, p: p(vars), response.postprocessing, vars)
    if isinstance(vars, unicode):
        vars = vars.encode('utf8')
    elif hasattr(vars, 'xml') and callable(vars.xml):
        vars = vars.xml()
    return vars
Example #7
0
def run_controller_in(controller, function, environment):
    """
    Runs the controller.function() (for the app specified by
    the current folder).
    It tries pre-compiled controller_function.pyc first before compiling it.
    """

    # if compiled should run compiled!
    folder = environment['request'].folder
    path = pjoin(folder, 'compiled')
    badc = 'invalid controller (%s/%s)' % (controller, function)
    badf = 'invalid function (%s/%s)' % (controller, function)
    if os.path.exists(path):
        filename = pjoin(path,
                         'controllers.%s.%s.pyc' % (controller, function))
        if not os.path.exists(filename):
            ### for backward compatibility
            filename = pjoin(path,
                             'controllers_%s_%s.pyc' % (controller, function))
            ### end for backward compatibility
            if not os.path.exists(filename):
                raise HTTP(404,
                           rewrite.THREAD_LOCAL.routes.error_message % badf,
                           web2py_error=badf)
        restricted(read_pyc(filename), environment, layer=filename)
    elif function == '_TEST':
        # TESTING: adjust the path to include site packages
        from settings import global_settings
        from admin import abspath, add_path_first
        paths = (global_settings.gluon_parent,
                 abspath('site-packages',
                         gluon=True), abspath('gluon', gluon=True), '')
        [add_path_first(path) for path in paths]
        # TESTING END

        filename = pjoin(folder, 'controllers/%s.py' % controller)
        if not os.path.exists(filename):
            raise HTTP(404,
                       rewrite.THREAD_LOCAL.routes.error_message % badc,
                       web2py_error=badc)
        environment['__symbols__'] = environment.keys()
        code = read_file(filename)
        code += TEST_CODE
        restricted(code, environment, layer=filename)
    else:
        filename = pjoin(folder, 'controllers/%s.py' % controller)
        if not os.path.exists(filename):
            raise HTTP(404,
                       rewrite.THREAD_LOCAL.routes.error_message % badc,
                       web2py_error=badc)
        code = read_file(filename)
        exposed = regex_expose.findall(code)
        if not function in exposed:
            raise HTTP(404,
                       rewrite.THREAD_LOCAL.routes.error_message % badf,
                       web2py_error=badf)
        code = "%s\nresponse._vars=response._caller(%s)\n" % (code, function)
        if is_gae:
            layer = filename + ':' + function
            code = getcfs(layer, filename, lambda: compile2(code, layer))
        restricted(code, environment, filename)
    response = environment['response']
    vars = response._vars
    if response.postprocessing:
        vars = reduce(lambda vars, p: p(vars), response.postprocessing, vars)
    if isinstance(vars, unicode):
        vars = vars.encode('utf8')
    elif hasattr(vars, 'xml') and callable(vars.xml):
        vars = vars.xml()
    return vars
Example #8
0
def find_exposed_functions(dt):
    dt = regex_longcomments.sub('', dt)
    return regex_expose.findall(dt)