本文整理汇总了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)
示例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")
示例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")
示例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")
示例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")
示例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")
示例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")
示例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()
示例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")
示例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")
示例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()
示例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('_'))