Example #1
0
def init(conf, *args, **opts):
    if not args:
        dest = os.getcwd()
    else:
        dest = os.path.normpath(os.path.join(os.getcwd(), args[0]))

    if dest is None:
        raise AppError('Unknown dest')

    if opts['empty'] and opts['template']:
        raise AppError('option "empty" cannot use with "template"')

    if util.iscouchapp(dest):
        raise AppError("can't create an app at '{0}'. "
                       "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)))

    # ``couchapp init -e dest``
    if opts['empty']:
        document(dest, create=True)

    # ``couchapp init -t template_name dest``
    elif opts['template']:
        generator.init_template(dest, template=opts['template'])

    # ``couchapp init dest``
    else:
        generator.init_basic(dest)

    logger.info('{0} created.'.format(dest))

    return 0
Example #2
0
def browse(conf, path, *args, **opts):
    if len(args) == 0:
        dest = path
        doc_path = '.'
    else:
        doc_path = path
        dest = args[0]

    doc_path = os.path.normpath(os.path.join(os.getcwd(), doc_path))
    if not util.iscouchapp(doc_path):
        raise AppError("Dir '{0}' is not a couchapp.".format(doc_path))

    conf.update(doc_path)

    doc = document(doc_path, create=False, docid=opts.get('docid'))

    dbs = conf.get_dbs(dest)
    doc.browse(dbs)
Example #3
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
Example #4
0
def test_iscouchapp(isfile):
    assert iscouchapp('/mock_dir') == True
    isfile.assert_called_with('/mock_dir/.couchapprc')