本文整理汇总了Python中trac.attachment.Attachment.select方法的典型用法代码示例。如果您正苦于以下问题:Python Attachment.select方法的具体用法?Python Attachment.select怎么用?Python Attachment.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.attachment.Attachment
的用法示例。
在下文中一共展示了Attachment.select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reparent
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def test_reparent(self):
attachment1 = Attachment(self.env, "wiki", "SomePage")
attachment1.insert("foo.txt", StringIO(""), 0)
path1 = attachment1.path
attachment2 = Attachment(self.env, "wiki", "SomePage")
attachment2.insert("bar.jpg", StringIO(""), 0)
attachments = Attachment.select(self.env, "wiki", "SomePage")
self.assertEqual(2, len(list(attachments)))
attachments = Attachment.select(self.env, "ticket", 123)
self.assertEqual(0, len(list(attachments)))
assert os.path.exists(path1) and os.path.exists(attachment2.path)
attachment1.reparent("ticket", 123)
self.assertEqual("ticket", attachment1.parent_realm)
self.assertEqual("ticket", attachment1.resource.parent.realm)
self.assertEqual("123", attachment1.parent_id)
self.assertEqual("123", attachment1.resource.parent.id)
attachments = Attachment.select(self.env, "wiki", "SomePage")
self.assertEqual(1, len(list(attachments)))
attachments = Attachment.select(self.env, "ticket", 123)
self.assertEqual(1, len(list(attachments)))
assert not os.path.exists(path1) and os.path.exists(attachment1.path)
assert os.path.exists(attachment2.path)
示例2: test_reparent
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def test_reparent(self):
attachment1 = Attachment(self.env, 'wiki', 'SomePage')
attachment1.insert('foo.txt', StringIO(''), 0)
path1 = attachment1.path
attachment2 = Attachment(self.env, 'wiki', 'SomePage')
attachment2.insert('bar.jpg', StringIO(''), 0)
attachments = Attachment.select(self.env, 'wiki', 'SomePage')
self.assertEqual(2, len(list(attachments)))
attachments = Attachment.select(self.env, 'ticket', 123)
self.assertEqual(0, len(list(attachments)))
assert os.path.exists(path1) and os.path.exists(attachment2.path)
attachment1.reparent('ticket', 123)
self.assertEqual('ticket', attachment1.parent_realm)
self.assertEqual('ticket', attachment1.resource.parent.realm)
self.assertEqual('123', attachment1.parent_id)
self.assertEqual('123', attachment1.resource.parent.id)
attachments = Attachment.select(self.env, 'wiki', 'SomePage')
self.assertEqual(1, len(list(attachments)))
attachments = Attachment.select(self.env, 'ticket', 123)
self.assertEqual(1, len(list(attachments)))
assert not os.path.exists(path1) and os.path.exists(attachment1.path)
assert os.path.exists(attachment2.path)
示例3: images
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def images(self, ticket, href=None):
"""returns images for a ticket"""
# construct a ticket from an id
if isinstance(ticket, int):
ticket = Ticket(self.env, ticket)
if not ticket.exists:
return {}
attachments = list(Attachment.select(self.env, 'ticket', ticket.id))
images = {}
for attachment in attachments:
try:
filename, category = self.image_category(attachment)
except TypeError:
continue
images.setdefault(filename, {})[category] = attachment.filename
if href is not None:
# turn the keys into links
for values in images.values():
for key, value in values.items():
values[key] = href('attachment', 'ticket', ticket.id, value, format='raw')
return images
示例4: test_rename_page
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def test_rename_page(self):
data = (1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)
self.env.db_transaction(
"INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
('TestPage',) + data)
attachment = Attachment(self.env, 'wiki', 'TestPage')
attachment.insert('foo.txt', StringIO(), 0, 1)
page = WikiPage(self.env, 'TestPage')
page.rename('PageRenamed')
self.assertEqual('PageRenamed', page.name)
self.assertEqual('PageRenamed', page.resource.id)
self.assertEqual([data], self.env.db_query("""
SELECT version, time, author, ipnr, text, comment, readonly
FROM wiki WHERE name=%s
""", ('PageRenamed',)))
attachments = Attachment.select(self.env, 'wiki', 'PageRenamed')
self.assertEqual('foo.txt', attachments.next().filename)
self.assertRaises(StopIteration, attachments.next)
Attachment.delete_all(self.env, 'wiki', 'PageRenamed')
old_page = WikiPage(self.env, 'TestPage')
self.assertFalse(old_page.exists)
self.assertEqual([], self.env.db_query("""
SELECT version, time, author, ipnr, text, comment, readonly
FROM wiki WHERE name=%s
""", ('TestPage',)))
listener = TestWikiChangeListener(self.env)
self.assertEqual((page, 'TestPage'), listener.renamed[0])
示例5: test_rename_page
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def test_rename_page(self):
cursor = self.db.cursor()
data = (1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)
cursor.execute("INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
('TestPage',) + data)
attachment = Attachment(self.env, 'wiki', 'TestPage')
attachment.insert('foo.txt', StringIO(), 0, 1)
page = WikiPage(self.env, 'TestPage')
page.rename('PageRenamed')
self.assertEqual('PageRenamed', page.name)
cursor.execute("SELECT version,time,author,ipnr,text,comment,"
"readonly FROM wiki WHERE name=%s", ('PageRenamed',))
self.assertEqual(data, cursor.fetchone())
self.assertEqual(None, cursor.fetchone())
attachments = Attachment.select(self.env, 'wiki', 'PageRenamed')
self.assertEqual('foo.txt', attachments.next().filename)
self.assertRaises(StopIteration, attachments.next)
Attachment.delete_all(self.env, 'wiki', 'PageRenamed', self.db)
old_page = WikiPage(self.env, 'TestPage')
self.assertEqual(False, old_page.exists)
cursor.execute("SELECT version,time,author,ipnr,text,comment,"
"readonly FROM wiki WHERE name=%s", ('TestPage',))
self.assertEqual(None, cursor.fetchone())
listener = TestWikiChangeListener(self.env)
self.assertEqual((page, 'TestPage'), listener.renamed[0])
示例6: _render_confirm_delete
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def _render_confirm_delete(self, req, page):
req.perm(page.resource).require('WIKI_DELETE')
version = None
if 'delete_version' in req.args:
version = int(req.args.get('version', 0))
old_version = int(req.args.get('old_version') or 0) or version
what = 'multiple' if version and old_version \
and version - old_version > 1 \
else 'single' if version else 'page'
num_versions = 0
new_date = None
old_date = None
for v, t, author, comment, ipnr in page.get_history():
if (v <= version or what == 'page') and new_date is None:
new_date = t
if (v <= old_version and what == 'multiple' or
num_versions > 1 and what == 'single'):
break
num_versions += 1
old_date = t
data = self._page_data(req, page, 'delete')
attachments = Attachment.select(self.env, self.realm, page.name)
data.update({
'what': what, 'new_version': None, 'old_version': None,
'num_versions': num_versions, 'new_date': new_date,
'old_date': old_date, 'attachments': list(attachments),
})
if version is not None:
data.update({'new_version': version, 'old_version': old_version})
self._wiki_ctxtnav(req, page)
return 'wiki_delete.html', data, None
示例7: listAttachments
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def listAttachments(self, req, ticket):
""" Lists attachments for a given ticket. Returns (filename,
description, size, time, author) for each attachment."""
attachments = []
for a in Attachment.select(self.env, 'ticket', ticket):
if 'ATTACHMENT_VIEW' in req.perm(a.resource):
yield (a.filename, a.description, a.size, a.date, a.author)
示例8: _do_seed
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def _do_seed(self):
# Create a subscription for all existing attachments
cursor = self.env.get_read_db().cursor()
cursor.execute("SELECT DISTINCT type, id FROM attachment")
rows = cursor.fetchall()
for row in rows:
for attachment in Attachment.select(self.env, row[0], row[1]):
Subscription.from_attachment(self.env, attachment)
# Create a subscription for all existing revisions
rm = RepositoryManager(self.env)
repos = rm.get_real_repositories()
for repo in repos:
_rev = repo.get_oldest_rev()
while _rev:
try:
_cs = repo.get_changeset(_rev)
Subscription.from_changeset(self.env, _cs)
except NoSuchChangeset:
pass
_rev = repo.next_rev(_rev)
# Create a subscription for all existing comments
comments = Comments(None, self.env).all()
for comment in comments:
Subscription.from_comment(self.env, comment)
示例9: reparent_blog_attachments
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def reparent_blog_attachments(env, orig_name, new_name):
""" Re-associate blog post attachments to FullBlog posts """
cnx = env.get_db_cnx()
cur = cnx.cursor()
new_dir = Attachment(env, 'blog', new_name).path
attachment_paths = list()
for attachment in Attachment.select(env, 'wiki', orig_name):
if os.path.exists(os.path.join(new_dir, attachment.filename)):
print "Attachment", attachment.filename, "already where it should be"
continue
if not os.path.exists(attachment.path):
raise Exception("Cannot find attachment %s for post %s" % (
attachment.filename, orig_name
))
attachment_paths.append(attachment.path)
try:
cur.execute(
"UPDATE attachment "
"SET type = 'blog', id = %s "
"WHERE type = 'wiki' AND id = %s",
(new_name, orig_name)
)
except Exception, e:
print("Unable to import blog attachment %s into the FullBlog: %s" % (orig_name, e))
raise
示例10: test_delete
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def test_delete(self):
attachment1 = Attachment(self.env, "wiki", "SomePage")
attachment1.insert("foo.txt", StringIO(""), 0)
attachment2 = Attachment(self.env, "wiki", "SomePage")
attachment2.insert("bar.jpg", StringIO(""), 0)
attachments = Attachment.select(self.env, "wiki", "SomePage")
self.assertEqual(2, len(list(attachments)))
attachment1.delete()
attachment2.delete()
assert not os.path.exists(attachment1.path)
assert not os.path.exists(attachment2.path)
attachments = Attachment.select(self.env, "wiki", "SomePage")
self.assertEqual(0, len(list(attachments)))
示例11: test_delete
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def test_delete(self):
attachment1 = Attachment(self.env, 'wiki', 'SomePage')
attachment1.insert('foo.txt', StringIO(''), 0)
attachment2 = Attachment(self.env, 'wiki', 'SomePage')
attachment2.insert('bar.jpg', StringIO(''), 0)
attachments = Attachment.select(self.env, 'wiki', 'SomePage')
self.assertEqual(2, len(list(attachments)))
attachment1.delete()
attachment2.delete()
assert not os.path.exists(attachment1.path)
assert not os.path.exists(attachment2.path)
attachments = Attachment.select(self.env, 'wiki', 'SomePage')
self.assertEqual(0, len(list(attachments)))
示例12: _render_attachment
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def _render_attachment(self, req, cr_id, perm = False):
for idx, attachment in enumerate(Attachment.select(self.env, 'CodeReview',
cr_id)):
hdf = attachment_to_hdf(self.env, db=self.env.get_db_cnx(), req=req, attachment=attachment)
req.hdf['codereview.attachments.%s' % idx] = hdf
if req.perm.has_permission('CODE_REVIEW_EDIT') and perm:
req.hdf['codereview.attach_href'] = self.env.href.attachment('CodeReview',
cr_id)
示例13: test_upgrading_database_moves_attachment_to_correct_product
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def test_upgrading_database_moves_attachment_to_correct_product(self):
ticket = self.insert_ticket('ticket')
wiki = self.insert_wiki('MyWiki')
attachment = self._create_file_with_content('Hello World!')
self.add_attachment(ticket.resource, attachment)
self.add_attachment(wiki.resource, attachment)
self._enable_multiproduct()
self.env.upgrade()
with self.product('@'):
attachments = list(
Attachment.select(self.env, 'ticket', ticket.id))
attachments.extend(
Attachment.select(self.env, 'wiki', wiki.name))
self.assertEqual(len(attachments), 2)
for attachment in attachments:
self.assertEqual(attachment.open().read(), 'Hello World!')
示例14: test_insert
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def test_insert(self):
attachment = Attachment(self.env, 'ticket', 42)
attachment.insert('foo.txt', StringIO(''), 0, 1)
attachment = Attachment(self.env, 'ticket', 42)
attachment.insert('bar.jpg', StringIO(''), 0, 2)
attachments = Attachment.select(self.env, 'ticket', 42)
self.assertEqual('foo.txt', attachments.next().filename)
self.assertEqual('bar.jpg', attachments.next().filename)
self.assertRaises(StopIteration, attachments.next)
示例15: test_insert
# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import select [as 别名]
def test_insert(self):
attachment = Attachment(self.env, "ticket", 42)
attachment.insert("foo.txt", StringIO(""), 0, 1)
attachment = Attachment(self.env, "ticket", 42)
attachment.insert("bar.jpg", StringIO(""), 0, 2)
attachments = Attachment.select(self.env, "ticket", 42)
self.assertEqual("foo.txt", attachments.next().filename)
self.assertEqual("bar.jpg", attachments.next().filename)
self.assertRaises(StopIteration, attachments.next)