当前位置: 首页>>代码示例>>Python>>正文


Python Server.replicate方法代码示例

本文整理汇总了Python中couchdb.Server.replicate方法的典型用法代码示例。如果您正苦于以下问题:Python Server.replicate方法的具体用法?Python Server.replicate怎么用?Python Server.replicate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在couchdb.Server的用法示例。


在下文中一共展示了Server.replicate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Server

# 需要导入模块: from couchdb import Server [as 别名]
# 或者: from couchdb.Server import replicate [as 别名]
src = Server(args.source)
dest = Server(args.dest)

count = 0
for dbname in src :
    db = src[dbname]
    if (len(dbname) >= 4 and dbname[:4] == "mica" ) or dbname == "_users" :
        try :
            newdb = dest[dbname]
        except couchdb.http.ResourceNotFound, e :
            dest.create(dbname)
            newdb = dest[dbname]

        security = db.security
        print "Copying " + str(dbname) + " security parameters: " + str(security)
        newdb.security = security
        if db.info()["doc_count"] != newdb.info()["doc_count"] :
            print "Replicating: " + str(dbname)
            src.replicate(args.source + "/" + dbname, args.dest + "/" + dbname, continuous = True) 
        else :
            print "Already replicated: " + str(dbname)
            continue

        while db.info()["doc_count"] > newdb.info()["doc_count"] :
            print "Source count: " + str(db.info()["doc_count"]) + " dest count: " +  str(newdb.info()["doc_count"])
            sleep(5)

        count += 1

print "DBs: " + str(count)
开发者ID:hinesmr,项目名称:mica,代码行数:32,代码来源:migrate.py

示例2: replicate

# 需要导入模块: from couchdb import Server [as 别名]
# 或者: from couchdb.Server import replicate [as 别名]
def replicate(database, url, device, device_password, device_id,
              db_login, db_password,
              to_local=False, continuous=True, deleted=True, seq=None,
              ids=None):
    '''
    Run a replication from a CouchDB database to a remote Cozy instance.

    Args:

    * *database*: Name of the local datbase.
    * *url*: Url of the remote Cozy.
    * *device*: name of the current device (that should be regitered to the
      remote Cozy).
    * *device_password*: password of the current device to connect to the
      Remote Cozy.
    * *device_id*: ID of the device.
    * *db_login*:
    * *db_password*:

    Optionl args:

    * *to_local*: if True, data go from remote Cozy to local Couch.
    * *continuous*: if False, it's a single shot replication.
    * *deleted*: if false deleted documents are not replicated.
    * *seq*: sequence number from where to start the replication.
    * *ids*: Document ids to replicate.
    '''
    url = url.split('/')
    local = 'http://%s:%[email protected]:5984/%s' % \
            (db_login, db_password, database)
    remote = "https://%s:%[email protected]%s/cozy" % (device, device_password, url[2])
    server = Server('http://localhost:5984/')

    if to_local:
        target = local
        source = remote
    else:
        target = remote
        source = local

    if deleted:
        filter_name = "%s/filter" % device_id
    else:
        filter_name = "%s/filterDocType" % device_id

    if seq is None and ids is None:
        server.replicate(source, target, continuous=continuous,
                         filter=filter_name)
    elif seq is None:
        server.replicate(source, target, continuous=continuous, ids=ids)
    else:
        server.replicate(source, target, continuous=continuous,
                         filter=filter_name, since_seq=seq)

    if continuous and to_local:
        logger.info(
            '[Replication] Continous replication to local database started.')
    elif continuous and not to_local:
        logger.info(
            '[Replication] Continous replication to remote Cozy started.')
    elif not continuous and to_local:
        logger.info(
            '[Replication] One shot replication to local database started.')
    elif not continuous and not to_local:
        logger.info(
            '[Replication] One shot replication to remote Cozy started.')
开发者ID:Kloadut,项目名称:cozy-fuse-linux,代码行数:68,代码来源:replication.py

示例3: CouchFSDocument

# 需要导入模块: from couchdb import Server [as 别名]
# 或者: from couchdb.Server import replicate [as 别名]

#.........这里部分代码省略.........
            for res in self.db.view("file/byFullPath", key=path):
                self.currentFile = self.currentFile + buf
                return len(buf)

        except (KeyError, ResourceNotFound):
            pass

        print 'Something went wrong while writing %s' % path
        return -errno.ENOENT

    def release(self, path, fuse_file_info):
        """
        Save file to database and launch replication to remote Cozy.
            path {string}: file path
            fuse_file_info {struct}: information about open file

            Release is called when there are no more references
            to an open file: all file descriptors are closed and
            all memory mappings are unmapped.
        """
        if self.currentFile != "":

            for res in self.db.view("file/byFullPath", key=path):
                res = res.value
                binary_id = res["binary"]["file"]["id"]

                self.db.put_attachment(self.db[binary_id],
                                       self.currentFile,
                                       filename="file")

                binary = self.db[binary_id]
                res['binary']['file']['rev'] = binary['_rev']
                self.db.save(res)
                self._replicate_from_local([binary_id])

            self.currentFile = ""

    def mknod(self, path, mode, dev):
        """
        Create special/ordinary file. Since it's a new file, the file and
        and the binary metadata are created in the database. Then file is saved
        as an attachment to the database.
            path {string}: file path
            mode {string}: file permissions
            dev: if the file type is S_IFCHR or S_IFBLK, dev specifies the major
                 and minor numbers of the newly created device special file
        """
        (file_path, name) = _path_split(path)

        new_binary = { "docType": "Binary" }
        binary_id = self.db.create(new_binary)
        self.db.put_attachment(self.db[binary_id], '', filename="file")

        rev = self.db[binary_id]["_rev"]
        newFile = {
            "name": name,
            "path": file_path,
            "binary": {
                "file": {
                    "id": binary_id,
                    "rev": rev
                }
            },
            "docType": "File"
        }
        self.db.create(newFile)
开发者ID:frankrousseau,项目名称:couchdb-fuse,代码行数:70,代码来源:cozy_fuse.py


注:本文中的couchdb.Server.replicate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。