Esempio n. 1
0
def generate(conf, path, *args, **opts):
    dest = path
    if len(args) < 1:
        raise AppError("Can't generate function, name or path is missing")
        
    if len(args) == 1:
        kind="app"
        name = args[0]
    elif len(args) == 2:
        kind = args[0]
        name = args[1]
    elif len(args) >= 3:
        kind = args[0]
        dest = args[1]
        name = args[2]
        
    if dest is None:
        if kind == "app":
            dest = os.path.normpath(os.path.join(os.getcwd(), ".", name))
            opts['create'] = True
        else:
            raise AppError("You aren't in a couchapp.")
    
    hook(conf, dest, "pre-generate")    
    generator.generate(dest, kind, name, **opts)
    hook(conf, dest, "post-generate")
    return 0
Esempio n. 2
0
def generate(conf, path, *args, **opts):
    dest = path
    if len(args) < 1:
        raise AppError("Can't generate function, name or path is missing")

    if len(args) == 1:
        kind = "app"
        name = args[0]
    elif len(args) == 2:
        kind = args[0]
        name = args[1]
    elif len(args) >= 3:
        kind = args[0]
        dest = args[1]
        name = args[2]

    if dest is None:
        if kind == "app":
            dest = os.path.normpath(os.path.join(os.getcwd(), ".", name))
            opts['create'] = True
        else:
            raise AppError("You aren't in a couchapp.")

    hook(conf, dest, "pre-generate")
    generator.generate(dest, kind, name, **opts)
    hook(conf, dest, "post-generate")
    return 0
Esempio n. 3
0
def generate(conf, path, *args, **opts):
    '''
    :param path: result of util.findcouchapp
    '''
    dest = path
    if len(args) < 1:
        raise AppError("Can't generate function, name or path is missing")

    if len(args) == 1:
        kind = "app"
        name = args[0]
    elif len(args) == 2:
        kind = args[0]
        name = args[1]
    elif len(args) >= 3:
        kind = args[0]
        dest = args[1]
        name = args[2]

    if dest is None:
        if kind == "app":
            dest = os.path.normpath(os.path.join(os.getcwd(), name))
            opts['create'] = True
        else:
            raise AppError("You aren't in a couchapp.")
    elif dest and kind == 'app':
        raise AppError("can't create an app inside another app '{0}'.".format(
                       dest))

    hook(conf, dest, "pre-generate")
    generator.generate(dest, kind, name, **opts)
    hook(conf, dest, "post-generate")
    return 0
Esempio n. 4
0
def startapp(conf, *args, **opts):
    if len(args) < 1:
        raise AppError("Can't start an app, name or path is missing")

    if len(args) == 1:
        name = args[0]
        dest = os.path.normpath(os.path.join(os.getcwd(), ".", name))
    elif len(args) == 2:

        name = args[1]
        dest = os.path.normpath(os.path.join(args[0], args[1]))

    if os.path.isfile(os.path.join(dest, ".couchapprc")):
        raise AppError("can't create an app at '%s'. One already exists"
                       "here" % dest)

    generator.generate(dest, "startapp", name, **opts)
    return 0
Esempio n. 5
0
def startapp(conf, *args, **opts):
    if len(args) < 1:
        raise AppError("Can't start an app, name or path is missing")

    if len(args) == 1:
        name = args[0]
        dest = os.path.normpath(os.path.join(os.getcwd(), ".", name))
    elif len(args) == 2:
        
        name = args[1]
        dest = os.path.normpath(os.path.join(args[0], args[1]))

    if os.path.isfile(os.path.join(dest, ".couchapprc")):
        raise AppError("can't create an app at '%s'. One already exists"
                "here" % dest)

    generator.generate(dest, "startapp", name, **opts)
    return 0
Esempio n. 6
0
def startapp(conf, *args, **opts):
    if len(args) < 1:
        raise AppError("Can't start an app, name or path is missing")

    if len(args) == 1:
        name = args[0]
        dest = os.path.normpath(os.path.join(os.getcwd(), ".", name))
    elif len(args) == 2:
        name = args[1]
        dest = os.path.normpath(os.path.join(args[0], name))

    if util.iscouchapp(dest):
        raise AppError("can't create an app at '%s'. " "One already exists here.".format(dest))
    if util.findcouchapp(dest):
        raise AppError("can't create an app inside another app '{0}'.".format(util.findcouchapp(dest)))

    generator.generate(dest, "startapp", name, **opts)
    return 0
Esempio n. 7
0
def generate(conf, path, *args, **opts):
    '''
    :param path: result of util.findcouchapp
    '''
    dest = path
    if len(args) < 1:
        raise AppError("Can't generate function, name or path is missing")

    if len(args) == 1:
        kind = "app"
        name = args[0]
    elif len(args) == 2:
        kind = args[0]
        name = args[1]
    elif len(args) >= 3:
        kind = args[0]
        dest = args[1]
        name = args[2]

    if kind == 'app':  # deprecated warning
        logger.warning('"genrate app" will be deprecated in future release. '
                       'Please use "init -t TEMPLATE" instead.')
        args = (dest,) if dest is not None else tuple()
        kwargs = {
            'template': opts['template'] if opts['template'] else 'default',
            'empty': False
        }
        return init(conf, *args, **kwargs)

    if dest is None:
        raise AppError("You aren't in a couchapp.")

    hook(conf, dest, "pre-generate")
    generator.generate(dest, kind, name, **opts)
    hook(conf, dest, "post-generate")
    return 0
Esempio n. 8
0
def generate(conf, path, *args, **opts):
    '''
    :param path: result of util.findcouchapp
    '''
    dest = path
    if len(args) < 1:
        raise AppError("Can't generate function, name or path is missing")

    if len(args) == 1:
        kind = "app"
        name = args[0]
    elif len(args) == 2:
        kind = args[0]
        name = args[1]
    elif len(args) >= 3:
        kind = args[0]
        dest = args[1]
        name = args[2]

    if kind == 'app':  # deprecated warning
        logger.warning('"genrate app" will be deprecated in future release. '
                       'Please use "init -t TEMPLATE" instead.')
        args = (dest, ) if dest is not None else tuple()
        kwargs = {
            'template': opts['template'] if opts['template'] else 'default',
            'empty': False
        }
        return init(conf, *args, **kwargs)

    if dest is None:
        raise AppError("You aren't in a couchapp.")

    hook(conf, dest, "pre-generate")
    generator.generate(dest, kind, name, **opts)
    hook(conf, dest, "post-generate")
    return 0
Esempio n. 9
0
def test_generate_dispatch_to_vendor(gen_vendor, gen_func):
    generate('/mock/app', 'vendor', 'myvendor', template='default')

    assert not gen_func.called
    assert gen_vendor.called
Esempio n. 10
0
def test_generate_invalid_functions(gen_vendor, gen_func):
    generate('/mock/app', 'strange', 'mock_func', template='default')

    assert not gen_func.called
    assert not gen_vendor.called
Esempio n. 11
0
def test_generate_dispatch_function(gen_vendor, gen_func):
    generate('/mock/app', 'view', 'mock_view', template='default')

    assert gen_func.called
    assert not gen_vendor.called
Esempio n. 12
0
def test_generate_dispatch_to_vendor(gen_vendor, gen_func):
    generate('/mock/app', 'vendor', 'myvendor', template='default')

    assert not gen_func.called
    assert gen_vendor.called
Esempio n. 13
0
def test_generate_invalid_functions(gen_vendor, gen_func):
    generate('/mock/app', 'strange', 'mock_func', template='default')

    assert not gen_func.called
    assert not gen_vendor.called
Esempio n. 14
0
def test_generate_dispatch_function(gen_vendor, gen_func):
    generate('/mock/app', 'view', 'mock_view', template='default')

    assert gen_func.called
    assert not gen_vendor.called