示例#1
0
def test_discover_apps_hidden_file(iscouchapp_, isdir, listdir):
    '''
    Test case for a dir including hidden file
    '''
    assert discover_apps('mock_dir') == ['mock_dir/foo']
    isdir.assert_called_with('mock_dir/foo')
    listdir.assert_called_with('mock_dir')
示例#2
0
def pushapps(conf, source, dest=None, *args, **opts):
    export = opts.get('export', False)
    noatomic = opts.get('no_atomic', False)
    browse = opts.get('browse', False)
    dbs = conf.get_dbs(dest) if not export else None
    apps = []
    source = os.path.normpath(os.path.join(os.getcwd(), source))
    appdirs = util.discover_apps(source)

    logger.debug('Discovered apps: {0}'.format(appdirs))

    for appdir in appdirs:
        doc = document(appdir)
        # if export mode, the ``dbs`` will be None
        hook(conf, appdir, "pre-push", dbs=dbs, pushapps=True)
        if export or not noatomic:
            apps.append(doc)
        else:
            doc.push(dbs, True, browse)
        hook(conf, appdir, "post-push", dbs=dbs, pushapps=True)

    if not apps:
        return 0

    if export:
        docs = [doc.doc() for doc in apps]
        jsonobj = {'docs': docs}
        if opts.get('output'):
            util.write_json(opts.get('output'), jsonobj)
        else:
            print(util.json.dumps(jsonobj))
        return 0

    for db in dbs:
        docs = [doc.doc(db) for doc in apps]
        try:
            db.save_docs(docs)
        except BulkSaveError as e:
            docs1 = []
            for doc in e.errors:
                try:
                    doc['_rev'] = db.last_rev(doc['_id'])
                    docs1.append(doc)
                except ResourceNotFound:
                    pass
            if docs1:
                db.save_docs(docs1)
    return 0
示例#3
0
def pushapps(conf, source, dest=None, *args, **opts):
    export = opts.get('export', False)
    noatomic = opts.get('no_atomic', False)
    browse = opts.get('browse', False)
    dbs = conf.get_dbs(dest) if not export else None
    apps = []
    source = os.path.normpath(os.path.join(os.getcwd(), source))
    appdirs = util.discover_apps(source)

    logger.debug('Discovered apps: {0}'.format(appdirs))

    for appdir in appdirs:
        doc = document(appdir)
        # if export mode, the ``dbs`` will be None
        hook(conf, appdir, "pre-push", dbs=dbs, pushapps=True)
        if export or not noatomic:
            apps.append(doc)
        else:
            doc.push(dbs, True, browse)
        hook(conf, appdir, "post-push", dbs=dbs, pushapps=True)

    if not apps:
        return 0

    if export:
        docs = [doc.doc() for doc in apps]
        jsonobj = {'docs': docs}
        if opts.get('output'):
            util.write_json(opts.get('output'), jsonobj)
        else:
            print(util.json.dumps(jsonobj))
        return 0

    for db in dbs:
        docs = [doc.doc(db) for doc in apps]
        try:
            db.save_docs(docs)
        except BulkSaveError as e:
            docs1 = []
            for doc in e.errors:
                try:
                    doc['_rev'] = db.last_rev(doc['_id'])
                    docs1.append(doc)
                except ResourceNotFound:
                    pass
            if docs1:
                db.save_docs(docs1)
    return 0
示例#4
0
文件: commands.py 项目: h4ki/couchapp
def pushapps(conf, source, dest, *args, **opts):
    export = opts.get("export", False)
    noatomic = opts.get("no_atomic", False)
    browse = opts.get("browse", False)
    dbs = conf.get_dbs(dest)
    apps = []
    source = os.path.normpath(os.path.join(os.getcwd(), source))
    appdirs = util.discover_apps(source)

    logger.debug("Discovered apps: {0}".format(appdirs))

    for appdir in appdirs:
        doc = document(appdir)
        hook(conf, appdir, "pre-push", dbs=dbs, pushapps=True)
        if export or not noatomic:
            apps.append(doc)
        else:
            doc.push(dbs, True, browse)
        hook(conf, appdir, "post-push", dbs=dbs, pushapps=True)

    if not apps:
        return 0

    if export:
        docs = [doc.doc() for doc in apps]
        jsonobj = {"docs": docs}
        if opts.get("output"):
            util.write_json(opts.get("output"), jsonobj)
        else:
            print util.json.dumps(jsonobj)
        return 0

    for db in dbs:
        docs = [doc.doc(db) for doc in apps]
        try:
            db.save_docs(docs)
        except BulkSaveError as e:
            docs1 = []
            for doc in e.errors:
                try:
                    doc["_rev"] = db.last_rev(doc["_id"])
                    docs1.append(doc)
                except ResourceNotFound:
                    pass
            if docs1:
                db.save_docs(docs1)
    return 0
示例#5
0
def test_discover_apps_relative_path(iscouchapp_, isdir, listdir):
    assert discover_apps('mock_dir') == ['mock_dir/foo']
    isdir.assert_called_with('mock_dir/foo')
    listdir.assert_called_with('mock_dir')
示例#6
0
def test_discover_apps(iscouchapp_, isdir, listdir):
    assert discover_apps('/mock_dir') == ['/mock_dir/foo']
    isdir.assert_called_with('/mock_dir/foo')
    listdir.assert_called_with('/mock_dir')