Esempio n. 1
0
def generate_api(folder_root_path, name, path, version=1, prefix=None):
    """
    1. add route
    2. add api file
    3. add service file
    4. add api functional test file
    """
    route_name = ''
    if name[0:4] != 'api_':
        route_name = 'api_%s' % name
    if path[0] != '/':
        path = '/' + path
    if prefix==None and version==None:
        version = 1
    if prefix != None and prefix[0] != '/':
        prefix = '/' + prefix
    filename = name + '.py'
    test_filename = 'test_api_' + filename

    #prepare route_path
    if prefix != None:
        if prefix == '/':
            prefix = ''
        route_path = "'%s'" % (prefix + path)
    else:
        to_add_prefix = "api_prefix + '%s' + " % version
        route_path = to_add_prefix + "'%s'" % path

    success = True
    if success:
        success = add_new_route(folder_root_path, route_name=route_name,
                route_path=route_path, rtype='api')
    if success:
        success = add_new_api(folder_root_path, name=name, route_name=route_name,
                              filename=filename)
    if success:
        success = add_new_service(folder_root_path, name=name, filename=filename)
    if success:
        success = add_new_api_test(folder_root_path, name=name,
                                   route_path=route_path,
                                   route_name=route_name,
                                   filename=test_filename,
                                   api_version=version,
                                   )
    return success
Esempio n. 2
0
def generate_page(folder_root_path, path, name):
    """
    1. add route
    2. add page file
    2. add page template file
    4. add page functional test file
    """
    route_name = ''
    if name[0:4] != 'page_':
        route_name = 'scarab.page_%s' % name
    if path[0] != '/':
        path = '/' + path
    route_path = "'%s'" % path
    filename = name + '.py'
    service_name = name + '_p'
    service_filename = name + '_p.py'
    test_filename = 'test_page_' + filename
    template_filename = name + '.jinja2'

    success = True
    if success:
        success = add_new_route(folder_root_path, route_name=route_name,
                route_path=route_path, rtype='page')
    if success:
        success = add_new_page(folder_root_path, name=name, route_name=route_name,
                               filename=filename, template_filename=template_filename,
                               )
    if success:
        success = add_new_service(folder_root_path, name=name, filename=service_filename)
    if success:
        success = add_new_template(folder_root_path, name=name,
                                   page_filename=filename,
                                   template_filename=template_filename)
    if success:
        success = add_new_page_test(folder_root_path,
                                    name=name,
                                    route_path=route_path,
                                    route_name=route_name,
                                    filename=test_filename,
                                    )
    return success