當前位置: 首頁>>代碼示例>>Python>>正文


Python Connector.type方法代碼示例

本文整理匯總了Python中peerdrive.Connector.type方法的典型用法代碼示例。如果您正苦於以下問題:Python Connector.type方法的具體用法?Python Connector.type怎麽用?Python Connector.type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在peerdrive.Connector的用法示例。


在下文中一共展示了Connector.type方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: update

# 需要導入模塊: from peerdrive import Connector [as 別名]
# 或者: from peerdrive.Connector import type [as 別名]
	def update(self, updateItem = True):
		# reset everything
		self.__valid = False
		self.__icon = None
		for i in xrange(len(self.__columnDefs)):
			column = self.__columnDefs[i]
			if column.derived():
				self.__columnValues[i] = column.default()

		# determine revision
		needMerge = False
		isReplicated = False
		if self.__doc:
			l = Connector().lookupDoc(self.__doc)
			isReplicated = len(l.stores()) > 1
			revisions = l.revs()
			if len(revisions) == 0:
				return
			elif len(revisions) > 1:
				needMerge = True
			if updateItem:
				self.__item[''].update()

		self.__rev = self.__item[''].rev()

		# stat
		try:
			s = Connector().stat(self.__rev)
		except IOError:
			return
		self.__uti = s.type()
		if needMerge or isReplicated:
			image = QtGui.QImage(Registry().getIcon(s.type()))
			painter = QtGui.QPainter()
			painter.begin(image)
			if needMerge:
				painter.drawImage(0, 16, QtGui.QImage("icons/emblems/split.png"))
			elif isReplicated:
				painter.drawImage(0, 16, QtGui.QImage("icons/emblems/distributed.png"))
			painter.end()
			self.__icon = QtGui.QIcon(QtGui.QPixmap.fromImage(image))
		else:
			self.__icon = QtGui.QIcon(Registry().getIcon(s.type()))

		self.__isFolder = Registry().conformes(self.__uti, "org.peerdrive.folder")
		self.__replacable = not needMerge and not self.__isFolder
		self.__valid = True
		self.__updateColumns(s)
開發者ID:DavidAlphaFox,項目名稱:chef-server,代碼行數:50,代碼來源:folder.py

示例2: load

# 需要導入模塊: from peerdrive import Connector [as 別名]
# 或者: from peerdrive.Connector import type [as 別名]
 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,代碼行數:29,代碼來源:properties.py

示例3: test_update_keep

# 需要導入模塊: from peerdrive import Connector [as 別名]
# 或者: from peerdrive.Connector import type [as 別名]
	def test_update_keep(self):
		w = self.create(self.store1, "test.format.foo")
		self.assertEqual(w.getType(), "test.format.foo")
		w.commit()
		doc = w.getDoc()
		rev1 = w.getRev()

		with Connector().update(self.store1, doc, rev1) as w:
			self.assertEqual(w.getType(), "test.format.foo")
			w.write('FILE', 'update')
			w.commit()
			rev2 = w.getRev()

		s = Connector().stat(rev1)
		self.assertEqual(s.type(), "test.format.foo")
		s = Connector().stat(rev2)
		self.assertEqual(s.type(), "test.format.foo")
開發者ID:wizzk42,項目名稱:peerdrive,代碼行數:19,代碼來源:tests.py

示例4: test_create

# 需要導入模塊: from peerdrive import Connector [as 別名]
# 或者: from peerdrive.Connector import type [as 別名]
	def test_create(self):
		w = self.create(self.store1, "test.format")
		self.assertEqual(w.getType(), "test.format")
		w.commit()
		doc = w.getDoc()
		rev = w.getRev()

		s = Connector().stat(rev)
		self.assertEqual(s.type(), "test.format")
開發者ID:wizzk42,項目名稱:peerdrive,代碼行數:11,代碼來源:tests.py

示例5: test_fork_keep

# 需要導入模塊: from peerdrive import Connector [as 別名]
# 或者: from peerdrive.Connector import type [as 別名]
    def test_fork_keep(self):
        w = self.create(self.store1, "test.format.foo")
        self.assertEqual(w.getType(), "test.format.foo")
        w.commit()
        doc1 = w.getDoc()
        rev1 = w.getRev()

        w = self.fork(self.store1, rev1)
        self.assertEqual(w.getType(), "test.format.foo")
        w.write("FILE", "update")
        w.commit()
        doc2 = w.getDoc()
        rev2 = w.getRev()

        s = Connector().stat(rev1)
        self.assertEqual(s.type(), "test.format.foo")
        s = Connector().stat(rev2)
        self.assertEqual(s.type(), "test.format.foo")
開發者ID:peerdrive,項目名稱:peerdrive,代碼行數:20,代碼來源:tests.py

示例6: test_update_change

# 需要導入模塊: from peerdrive import Connector [as 別名]
# 或者: from peerdrive.Connector import type [as 別名]
    def test_update_change(self):
        w = self.create(self.store1, "test.format.foo")
        self.assertEqual(w.getType(), "test.format.foo")
        w.commit()
        doc = w.getDoc()
        rev1 = w.getRev()

        with Connector().update(self.store1, doc, rev1) as w:
            self.assertEqual(w.getType(), "test.format.foo")
            w.write("FILE", "update")
            w.setType("test.format.bar")
            self.assertEqual(w.getType(), "test.format.bar")
            w.commit()
            rev2 = w.getRev()

        s = Connector().stat(rev1)
        self.assertEqual(s.type(), "test.format.foo")
        s = Connector().stat(rev2)
        self.assertEqual(s.type(), "test.format.bar")
開發者ID:peerdrive,項目名稱:peerdrive,代碼行數:21,代碼來源:tests.py

示例7: test_fork_change

# 需要導入模塊: from peerdrive import Connector [as 別名]
# 或者: from peerdrive.Connector import type [as 別名]
	def test_fork_change(self):
		w = self.create(self.store1, "test.format.foo")
		self.assertEqual(w.getType(), "test.format.foo")
		w.commit()
		doc1 = w.getDoc()
		rev1 = w.getRev()

		w = self.fork(self.store1, rev1)
		w.write('FILE', 'update')
		self.assertEqual(w.getType(), "test.format.foo")
		w.setType("test.format.bar")
		self.assertEqual(w.getType(), "test.format.bar")
		w.commit()
		doc2 = w.getDoc()
		rev2 = w.getRev()

		s = Connector().stat(rev1)
		self.assertEqual(s.type(), "test.format.foo")
		s = Connector().stat(rev2)
		self.assertEqual(s.type(), "test.format.bar")
開發者ID:wizzk42,項目名稱:peerdrive,代碼行數:22,代碼來源:tests.py

示例8: __doCreate

# 需要導入模塊: from peerdrive import Connector [as 別名]
# 或者: from peerdrive.Connector import type [as 別名]
	def __doCreate(self, srcStore, srcRev):
		info = Connector().stat(srcRev, [srcStore])
		dstStore = self.store()
		with Connector().create(dstStore, info.type(), info.creator()) as w:
			with Connector().peek(srcStore, srcRev) as r:
				for part in info.parts():
					w.write(part, r.readAll(part))
				w.setFlags(r.getFlags())
			w.commit()
			destDoc = w.getDoc()
			# add link
			self.model().insertLink(struct.DocLink(dstStore, destDoc))
			# save immediately
			self.save()
開發者ID:wizzk42,項目名稱:peerdrive,代碼行數:16,代碼來源:folder.py

示例9: __doCreateFromTemplate

# 需要導入模塊: from peerdrive import Connector [as 別名]
# 或者: from peerdrive.Connector import type [as 別名]
	def __doCreateFromTemplate(self, srcStore, srcRev, name):
		info = Connector().stat(srcRev, [srcStore])
		dstStore = self.store()
		with Connector().create(dstStore, info.type(), info.creator()) as w:
			with Connector().peek(srcStore, srcRev) as r:
				w.set_data('', r.get_data(''))
				for att in info.attachments():
					w.write(att, r.readAll(att))
				w.setFlags(r.stat().flags())
			w.commit("Created from template")
			destDoc = w.getDoc()
			# add link
			self.model().insertLink(connector.DocLink(dstStore, destDoc))
			# save immediately
			self.save("Added '"+name+"' from templates")
開發者ID:DavidAlphaFox,項目名稱:chef-server,代碼行數:17,代碼來源:folder.py

示例10: load

# 需要導入模塊: from peerdrive import Connector [as 別名]
# 或者: from peerdrive.Connector import type [as 別名]
	def load(self, store, rev):
		try:
			stat = Connector().stat(rev, [store])
			self.__typeLabel.setText(Registry().getDisplayString(stat.type()))
			self.__mtimeLabel.setText(str(stat.mtime()))
			size = 0
			for part in stat.parts():
				size += stat.size(part)
			for unit in ['Bytes', 'KiB', 'MiB', 'GiB']:
				if size < (1 << 10):
					break
				else:
					size = size >> 10
			sizeText = "%d %s (%d parts)" % (size, unit, len(stat.parts()))
			self.__sizeLabel.setText(sizeText)
		except IOError:
			self.__typeLabel.setText("n/a")
			self.__mtimeLabel.setText("n/a")
			self.__sizeLabel.setText("n/a")
開發者ID:wizzk42,項目名稱:peerdrive,代碼行數:21,代碼來源:properties.py

示例11: docRead

# 需要導入模塊: from peerdrive import Connector [as 別名]
# 或者: from peerdrive.Connector import type [as 別名]
	def docRead(self, readWrite, handle):
		stat = Connector().stat(self.rev())
		uti = stat.type()
		if uti not in FolderModel.UTIs:
			raise TypeError('Unhandled type code: %s' % (uti))
		model = FolderModel(self)

		self.__setModel(model)
		if self.__settings is not None:
			self.__applySettings(self.__settings)

		model.rowsInserted.connect(self._emitSaveNeeded)
		model.rowsRemoved.connect(self._emitSaveNeeded)
		model.dataChanged.connect(self.__dataChanged)
		model.modelReset.connect(self.__dataChanged)
		model.modelReset.connect(lambda: self.selectionChanged.emit())
		self.listView.selectionModel().selectionChanged.connect(
			lambda: self.selectionChanged.emit())

		autoClean = self.metaDataGetField(FolderModel.AUTOCLEAN, False)
		model.doLoad(handle, readWrite, autoClean)
		if model.hasChanged():
			self._emitSaveNeeded()
開發者ID:wizzk42,項目名稱:peerdrive,代碼行數:25,代碼來源:folder.py

示例12: Connector

# 需要導入模塊: from peerdrive import Connector [as 別名]
# 或者: from peerdrive.Connector import type [as 別名]
if not path:
	s = Connector().stat(link.rev())
	hash = s.hash('_')

	name = hash.encode('hex')
	ext = ""
	with Connector().peek(link.store(), link.rev()) as r:
		annotation = r.getData("/org.peerdrive.annotation")

	# read title
	if "title" in annotation:
		(name, ext) = os.path.splitext(annotation["title"])

	# try to get extension from Registry if title has none
	if not ext:
		extensions = Registry().search(s.type(), "extensions")
		if extensions:
			ext = extensions[0]

	# try to get extension from origin if we don't have one already
	if not ext and ("origin" in annotation):
		ext = os.path.splitext(annotation["origin"])[1]

	# copy out file (if necessary)
	path = os.path.join(tempfile.gettempdir(), hash.encode('hex'), name+ext)
	if not os.path.isdir(os.path.dirname(path)):
		os.makedirs(os.path.dirname(path))
	if not os.path.isfile(path):
		with open(path, "wb") as file:
			with Connector().peek(link.store(), link.rev()) as reader:
				file.write(reader.readAll('_'))
開發者ID:DavidAlphaFox,項目名稱:chef-server,代碼行數:33,代碼來源:public.data.py


注:本文中的peerdrive.Connector.type方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。