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


Python peerdrive.Connector类代码示例

本文整理汇总了Python中peerdrive.Connector的典型用法代码示例。如果您正苦于以下问题:Python Connector类的具体用法?Python Connector怎么用?Python Connector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: performSync

    def performSync(self, doc, strategy):
        watch = self.watchDoc(doc, connector.Watch.EVENT_MODIFIED)

        self.startSync(strategy, self.store1, self.store2)

        # first wait until the doc gets changed
        while True:
            watch.reset()
            self.assertTrue(watch.waitForWatch())
            l = Connector().lookupDoc(doc)
            if len(l.revs()) == 1:
                break

        self.assertEqual(len(l.stores()), 2)
        self.assertTrue(self.store1 in l.stores())
        self.assertTrue(self.store2 in l.stores())

        # wait until sync_worker moved on
        result = self.erlCall(
            """peerdrive_sync_locks:lock(<<16#"""
            + doc.encode("hex")
            + """:128>>),
			peerdrive_sync_locks:unlock(<<16#"""
            + doc.encode("hex")
            + """:128>>)."""
        )
        self.assertEqual(result, "{ok, ok}")

        return l
开发者ID:peerdrive,项目名称:peerdrive,代码行数:29,代码来源:tests.py

示例2: test_sync_merge

    def test_sync_merge(self):
        (doc, rev1, rev2) = self.createMerge(
            "org.peerdrive.folder",
            {"META": struct.dumps({"a": 1}), "PDSD": struct.dumps([{"": 1}, {"": 2}])},
            {"META": struct.dumps({"a": 4, "b": 2}), "PDSD": struct.dumps([{"": 1}, {"": 2}, {"": 3}])},
            {"META": struct.dumps({"a": 1, "c": 3}), "PDSD": struct.dumps([{"": 2}])},
        )
        l = self.performSync(doc, "merge")

        rev = l.revs()[0]
        s = Connector().stat(rev)
        self.assertEqual(len(s.parents()), 2)
        self.assertTrue(rev1 in s.parents())
        self.assertTrue(rev2 in s.parents())

        # all revs on all stores?
        l = Connector().lookupRev(rev1)
        self.assertTrue(self.store1 in l)
        self.assertTrue(self.store2 in l)
        l = Connector().lookupRev(rev2)
        self.assertTrue(self.store1 in l)
        self.assertTrue(self.store2 in l)

        # see if merge was ok
        with Connector().peek(self.store1, rev) as r:
            meta = struct.loads(self.store1, r.readAll("META"))
            if "org.peerdrive.annotation" in meta:
                del meta["org.peerdrive.annotation"]
            self.assertEqual(meta, {"a": 4, "b": 2, "c": 3})
            pdsd = sorted(struct.loads(self.store1, r.readAll("PDSD")))
            self.assertEqual(pdsd, [{"": 2}, {"": 3}])
开发者ID:peerdrive,项目名称:peerdrive,代码行数:31,代码来源:tests.py

示例3: __addReplicateActions

	def __addReplicateActions(self, menu, link):
		c = Connector()
		try:
			allVolumes = set(c.lookupRev(self.rev()))
			if isinstance(link, connector.DocLink):
				lookup = c.lookupDoc(link.doc())
				curVolumes = set(lookup.stores())
				try:
					for rev in lookup.revs():
						curVolumes = curVolumes & set(c.lookupRev(rev, curVolumes))
				except IOError:
					curVolumes = set()
			else:
				curVolumes = set(c.lookupRev(link.rev()))
		except IOError:
			return

		if not curVolumes:
			return

		srcVol = list(curVolumes)[0]
		repVolumes = allVolumes - curVolumes
		for store in repVolumes:
			name = struct.readTitle(connector.DocLink(store, store), "Unknown store")
			action = menu.addAction("Replicate item to '%s'" % name)
			action.triggered.connect(
				lambda x,l=link,s=store: self.__doReplicate(srcVol, l, s))
开发者ID:DavidAlphaFox,项目名称:chef-server,代码行数:27,代码来源:folder.py

示例4: test_suspend

	def test_suspend(self):
		(doc, rev1, rev2) = self.createSuspendDoc()

		l = Connector().lookupDoc(doc)
		self.assertEqual(l.revs(), [rev1])
		self.assertEqual(l.preRevs(), [rev2])
		self.assertRevContent(self.store1, rev1, {'FILE' : 'ok'})
		self.assertRevContent(self.store1, rev2, {'FILE' : 'update'})
开发者ID:wizzk42,项目名称:peerdrive,代码行数:8,代码来源:tests.py

示例5: test_create

	def test_create(self):
		w = self.create(self.store1)
		w.commit()
		self.assertEqual(w.getFlags(), set())
		rev = w.getRev()

		s = Connector().stat(rev)
		self.assertEqual(s.flags(), set())
开发者ID:wizzk42,项目名称:peerdrive,代码行数:8,代码来源:tests.py

示例6: test_mtime

	def test_mtime(self):
		w = self.create(self.store1)
		w.writeAll('FILE', "fubar")
		w.commit()
		rev = w.getRev()
		s = Connector().stat(rev)
		now = datetime.datetime.now()
		self.assertTrue(s.mtime() <= now)
		self.assertTrue(s.mtime() > now - datetime.timedelta(seconds=3))
开发者ID:wizzk42,项目名称:peerdrive,代码行数:9,代码来源:tests.py

示例7: test_resume_wrong

	def test_resume_wrong(self):
		(doc, rev1, rev2) = self.createSuspendDoc()
		self.assertRaises(IOError, Connector().resume, self.store1, doc, rev1)

		l = Connector().lookupDoc(doc)
		self.assertEqual(l.revs(), [rev1])
		self.assertEqual(l.preRevs(), [rev2])
		self.assertRevContent(self.store1, rev1, {'FILE' : 'ok'})
		self.assertRevContent(self.store1, rev2, {'FILE' : 'update'})
开发者ID:wizzk42,项目名称:peerdrive,代码行数:9,代码来源:tests.py

示例8: assertRevContent

	def assertRevContent(self, store, rev, content):
		with Connector().peek(store, rev) as r:
			for (part, data) in content.items():
				revData = r.readAll(part)
				self.assertEqual(revData, data)

		s = Connector().stat(rev, [store])
		for part in s.parts():
			self.assertTrue(part in content)
开发者ID:wizzk42,项目名称:peerdrive,代码行数:9,代码来源:tests.py

示例9: test_sync_merge_fallback

    def test_sync_merge_fallback(self):
        (doc, rev1, rev2) = self.createMerge("public.data", {}, {"FILE": "left3"}, {"FILE": "right3"})
        l = self.performSync(doc, "merge")

        rev = l.revs()[0]
        s = Connector().stat(rev)
        self.assertEqual(len(s.parents()), 2)
        self.assertTrue(rev1 in s.parents())
        self.assertTrue(rev2 in s.parents())
        self.assertRevContent(self.store1, rev, {"FILE": "left3"})
开发者ID:peerdrive,项目名称:peerdrive,代码行数:10,代码来源:tests.py

示例10: load

 def load(self, store, rev):
     try:
         stat = Connector().stat(rev, [store])
         self.__typeLabel.setText(Registry().getDisplayString(stat.type()))
         self.__crtimeLabel.setText(str(stat.crtime()))
         self.__mtimeLabel.setText(str(stat.mtime()))
         size = stat.dataSize()
         for a in stat.attachments():
             size += stat.size(a)
         for unit in ["Bytes", "KiB", "MiB", "GiB"]:
             if size < (1 << 10):
                 break
             else:
                 size = size >> 10
         sizeText = "%d %s (%d attachments)" % (size, unit, len(stat.attachments()))
         self.__sizeLabel.setText(sizeText)
         if stat.flags():
             flagsText = reduce(
                 lambda x, y: x + ", " + y, [flagToText.get(f, "<" + str(f) + ">") for f in stat.flags()]
             )
         else:
             flagsText = "-"
         self.__flagsLabel.setText(flagsText)
     except IOError:
         self.__typeLabel.setText("n/a")
         self.__mtimeLabel.setText("n/a")
         self.__sizeLabel.setText("n/a")
开发者ID:peerdrive,项目名称:peerdrive,代码行数:27,代码来源:properties.py

示例11: test_sync_latest

	def test_sync_latest(self):
		(doc, rev1, rev2) = self.createMerge("public.data", {}, {'FILE' : "left2"},
			{'FILE' : "right2"})
		l = self.performSync(doc, 'latest')

		rev = l.revs()[0]
		s = Connector().stat(rev)
		self.assertEqual(len(s.parents()), 2)
		self.assertTrue(rev1 in s.parents())
		self.assertTrue(rev2 in s.parents())
		self.assertRevContent(self.store1, rev, {'FILE' : 'left2'})
开发者ID:wizzk42,项目名称:peerdrive,代码行数:11,代码来源:tests.py

示例12: __loadComment

 def __loadComment(self, rev):
     try:
         stat = Connector().stat(rev, [self.__store])
         mtime = str(stat.mtime())
         comment = stat.comment()
         if comment:
             return mtime + " - " + comment
         else:
             return mtime
     except IOError:
         return "???"
开发者ID:peerdrive,项目名称:peerdrive,代码行数:11,代码来源:properties.py

示例13: test_update_change

	def test_update_change(self):
		w = self.create(self.store1)
		w.commit()
		doc = w.getDoc()
		rev = w.getRev()

		with Connector().update(self.store1, doc, rev) as w:
			w.setFlags([0, 3, 8])
			w.commit()
			rev = w.getRev()

		s = Connector().stat(rev)
		self.assertEqual(s.flags(), set([0, 3, 8]))
开发者ID:wizzk42,项目名称:peerdrive,代码行数:13,代码来源:tests.py

示例14: __init__

    def __init__(self, link, parent=None):
        super(PropertiesDialog, self).__init__(parent)

        mainLayout = QtGui.QVBoxLayout()
        # mainLayout.setSizeConstraint(QtGui.QLayout.SetFixedSize)

        self.__doc = link.doc()
        self.__rev = link.rev()
        if self.__doc:
            isDoc = True
            banner = "document"
            l = Connector().lookupDoc(self.__doc)
            stores = [s for s in l.stores() if Connector().lookupRev(l.rev(s), [s]) == [s]]
        else:
            isDoc = False
            banner = "revision"
            stores = Connector().lookupRev(self.__rev)

        if len(stores) == 0:
            QtGui.QMessageBox.warning(self, "Missing document", "The requested document was not found on any store.")
            sys.exit(1)

        self.__docTab = DocumentTab(link.store(), stores, banner)
        self.__docTab.switchStore.connect(self.__switchStore)
        self.__revTab = RevisionTab()
        self.__annoTab = AnnotationTab(isDoc)
        self.__annoTab.changed.connect(self.__changed)
        self.__hisTab = HistoryTab()

        tabWidget = QtGui.QTabWidget()
        tabWidget.addTab(self.__annoTab, "Annotation")
        tabWidget.addTab(self.__hisTab, "History")

        if isDoc:
            self.__buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Save | QtGui.QDialogButtonBox.Close)
            self.__buttonBox.button(QtGui.QDialogButtonBox.Save).setEnabled(False)
            self.__buttonBox.accepted.connect(self.__save)
            self.__buttonBox.rejected.connect(self.reject)
        else:
            self.__buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok)
            self.__buttonBox.accepted.connect(self.accept)

        mainLayout.addWidget(self.__docTab)
        mainLayout.addWidget(self.__revTab)
        mainLayout.addWidget(tabWidget)
        mainLayout.addWidget(self.__buttonBox)
        self.setLayout(mainLayout)

        self.__switchStore(self.__docTab.activeStore())

        self.setWindowTitle("Properties of %s" % (self.__annoTab.getTitle()))
开发者ID:peerdrive,项目名称:peerdrive,代码行数:51,代码来源:properties.py

示例15: test_create_keep_handle

	def test_create_keep_handle(self):
		with Connector().create(self.store1, "public.data", "test.ignore") as w:
			w.commit()
			doc = w.getDoc()
			rev = w.getRev()

			# perform a GC cycle
			self.gc(self.store1)

			l = Connector().lookupDoc(doc)
			self.assertEqual(l.revs(), [rev])
			self.assertEqual(l.preRevs(), [])

			Connector().stat(rev)
开发者ID:wizzk42,项目名称:peerdrive,代码行数:14,代码来源:tests.py


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