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


Python Attachment.insert方法代码示例

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


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

示例1: test_rename_page

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [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])
开发者ID:zjj,项目名称:trac_hack,代码行数:33,代码来源:model.py

示例2: import_wiki_attachments

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [as 别名]
    def import_wiki_attachments(self, template_path):
        """Imports wiki attachments from template using the Attachment API."""

        # check that there are attachments to import
        template_attachment_path = os.path.join(template_path, 'attachments', 'wiki')
        if os.path.isdir(template_attachment_path):

            # clear the wiki attachment table
            @self.env.with_transaction()
            def clear_attachments(db):
                """Clears any wiki attachments from the current attachment table."""

                cursor = db.cursor()
                cursor.execute("DELETE FROM attachment WHERE type='wiki'")

            # move attachment file into the env and insert database row
            filepath = os.path.join(template_path, 'attachment.xml')
            tree = ET.ElementTree(file=filepath)
            for att in tree.getroot():
                attachment = Attachment(self.env, 'wiki', att.attrib['parent_id'])
                attachment.description = att.text
                try:
                    fileobj = open(os.path.join(template_attachment_path, 
                               att.attrib['parent_id'], unicode_quote(att.attrib['name'])))
                    attachment.insert(att.attrib['name'], fileobj, att.attrib['size'])
                except IOError:
                    self.log.info("Unable to import attachment %s", att.attrib['name'])
开发者ID:CGI-define-and-primeportal,项目名称:trac-plugin-createtemplate,代码行数:29,代码来源:importer.py

示例3: test_reparent

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [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)
开发者ID:zjj,项目名称:trac_hack,代码行数:27,代码来源:attachment.py

示例4: addTicket

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [as 别名]
	def addTicket(self, ticket, source):
		'''Add a ticket from a dict'''
		db = self._env.get_db_cnx()
		cursor = db.cursor()
		idCountRes = cursor.execute('select count(*) as count from ticket where id = %s', (ticket['id'],))
		idCount = idCountRes.fetchone()[0]
		assert idCount == 0, 'Ticket %s found in %s' % (ticket['id'], self.name)

		insertMainTicketQuery = 'insert into ticket (id, type, time, changetime, component, severity, priority, owner, \
			reporter, cc, version, milestone, status, resolution, summary, description, keywords) \
			values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'
		insertMainTicketValues = (ticket['id'], ticket['type'], ticket['time'], ticket['changetime'], ticket['component'], \
			ticket['severity'], ticket['priority'], ticket['owner'], ticket['reporter'], ticket['cc'], ticket['version'], \
			ticket['milestone'], ticket['status'], ticket['resolution'], ticket['summary'], ticket['description'], ticket['keywords'])
		insertMainTicketRes = cursor.execute(insertMainTicketQuery, insertMainTicketValues)

		#so we know where the ticket came from
		insertTicketSourceQuery = 'insert into ticket_custom (ticket, name, value) values (%s, %s, %s)'
		insertTicketSourceValues = (ticket['id'], 'project', source)
		insertTicketSourceRes = cursor.execute(insertTicketSourceQuery, insertTicketSourceValues)

		insertTicketChangeQuery = 'insert into ticket_change (ticket, time, author, field, oldvalue, newvalue) values (%s, %s, %s, %s, %s, %s)'
		for ticket_change in ticket['ticket_change']:
			insertTicketChangeValues = (ticket['id'], ticket_change['time'], ticket_change['author'], ticket_change['field'], ticket_change['oldvalue'], ticket_change['newvalue'])
			insertTicketChangeRes = cursor.execute(insertTicketChangeQuery, insertTicketChangeValues)

		for a in ticket['attachment']:
			ticketAttach = Attachment(self._env, 'ticket', ticket['id'])
			ticketAttach.description = a['description']
			ticketAttach.author = a['author']
			ticketAttach.ipnr = a['ipnr']
			ticketAttach.insert(a['filename'], a['fileobj'], a['size'], t=a['time'])
		db.commit()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:35,代码来源:ptrac.py

示例5: test_insert_unique

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [as 别名]
 def test_insert_unique(self):
     attachment = Attachment(self.env, 'ticket', 42)
     attachment.insert('foo.txt', StringIO(''), 0)
     self.assertEqual('foo.txt', attachment.filename)
     attachment = Attachment(self.env, 'ticket', 42)
     attachment.insert('foo.txt', StringIO(''), 0)
     self.assertEqual('foo.2.txt', attachment.filename)
开发者ID:moreati,项目名称:trac-gitsvn,代码行数:9,代码来源:attachment.py

示例6: _create_attachment

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [as 别名]
    def _create_attachment(self, req, tid, upload, description):
        attachment = Attachment(self.env, "ticket", tid)

        if hasattr(upload.file, "fileno"):
            size = os.fstat(upload.file.fileno())[6]
        else:
            upload.file.seek(0, 2)
            size = upload.file.tell()
            upload.file.seek(0)
        if size == 0:
            raise TracError(_("Can't upload empty file"))

        max_size = self.env.config.get("attachment", "max_size")
        if 0 <= max_size < size:
            raise TracError(_("Maximum attachment size: %(num)s bytes", num=max_size), _("Upload failed"))

        filename = _normalized_filename(upload.filename)
        if not filename:
            raise TracError(_("No file uploaded"))

        attachment.description = description
        attachment.author = get_reporter_id(req, "author")
        attachment.ipnr = req.remote_addr

        attachment.insert(filename, upload.file, size)
开发者ID:kzhamaji,项目名称:AwesomeAttachmentPlugin,代码行数:27,代码来源:awesomeattachments.py

示例7: _do_uploadPicture

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [as 别名]
    def _do_uploadPicture(self, req, userProfile, teamRosterData, req_arg_picture = 'tr_userProfile_picture' ):
        
        upload = req.args.get(req_arg_picture, None)
        if upload == None or not hasattr(upload, 'filename') or not upload.filename:
            return userProfile.picture_href
        
        if hasattr(upload.file, 'fileno'):
            size = os.fstat(upload.file.fileno())[6]
        else:
            upload.file.seek(0, 2) # seek to end of file
            size = upload.file.tell()
            upload.file.seek(0)
        if size == 0:
            raise TracError(_("Can't upload empty file"))

        filename = upload.filename
        filename = filename.replace('\\', '/').replace(':', '/')        
        filename = os.path.basename(filename)
        
        if not filename:
            raise TracError(_('No file uploaded'))
        
        page = WikiPage(self.env,  self.teamRoster_wikiPage)
        if not page.exists:
            page.text="= Team Roster Pictures ="
            page.save( 'trac', 'Page created by tracteamroster component',  req.remote_addr)
       
              
        attachment = Attachment(self.env, 'wiki', self.teamRoster_wikiPage)
        attachment.author = get_reporter_id(req, 'author')
        attachment.ipnr = req.remote_addr
        attachment.insert('_'.join([userProfile.id, filename]), upload.file, size)
        
        return req.href('/'.join(['raw-attachment', 'wiki',self.teamRoster_wikiPage,attachment.filename]))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:36,代码来源:admin.py

示例8: test_insert_unique

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [as 别名]
 def test_insert_unique(self):
     attachment = Attachment(self.env, 'ticket', 42)
     attachment.insert('foo.txt', tempfile.TemporaryFile(), 0)
     self.assertEqual('foo.txt', attachment.filename)
     attachment = Attachment(self.env, 'ticket', 42)
     attachment.insert('foo.txt', tempfile.TemporaryFile(), 0)
     self.assertEqual('foo.2.txt', attachment.filename)
开发者ID:cyphactor,项目名称:lifecyclemanager,代码行数:9,代码来源:attachment.py

示例9: _process_attachment

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [as 别名]
    def _process_attachment(self, req, config, build):
        resource_id = req.args['member'] == 'config' \
                    and build.config or build.resource.id
        upload = req.args['file']
        if not upload.file:
            send_error(req, message="Attachment not received.")
        self.log.debug('Received attachment %s for attaching to build:%s',
                      upload.filename, resource_id)

        # Determine size of file
        upload.file.seek(0, 2) # to the end
        size = upload.file.tell()
        upload.file.seek(0)    # beginning again

        # Delete attachment if it already exists
        try:
            old_attach = Attachment(self.env, 'build',
                            parent_id=resource_id, filename=upload.filename)
            old_attach.delete()
        except ResourceNotFound:
            pass

        # Save new attachment
        attachment = Attachment(self.env, 'build', parent_id=resource_id)
        attachment.description = req.args.get('description', '')
        attachment.author = req.authname
        attachment.insert(upload.filename, upload.file, size)

        self._send_response(req, 201, 'Attachment created', headers={
                            'Content-Type': 'text/plain',
                            'Content-Length': str(len('Attachment created'))})
开发者ID:kroman0,项目名称:bitten,代码行数:33,代码来源:master.py

示例10: test_rename_page

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [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])
开发者ID:exocad,项目名称:exotrac,代码行数:35,代码来源:model.py

示例11: test_reparent

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [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)
开发者ID:dafrito,项目名称:trac-mirror,代码行数:27,代码来源:attachment.py

示例12: convert

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [as 别名]
def convert(moindir, tracdir = None, mapfile = None):
    pagemap = None
    if mapfile:
        pagemap = {}
        for line in open(mapfile):
            if line[0] == '#': continue
            (page, wikidir) = line.split()
            pagemap[page] = wikidir

    pages = os.listdir(moindir)
    for page in pages:
        wikidir = tracdir
        if pagemap:
            if not pagemap.has_key(page): continue
            wikidir = pagemap[page]

        admin  = TracAdmin()
        admin.env_set (wikidir)
        revdir = moindir + '/' + page + '/revisions'
        if os.access(revdir, os.F_OK):
            revisions = os.listdir(revdir)
            for rev in revisions:
                cmd='wiki import %s %s' % ( recodeName(page),  revdir +'/'+rev)
                print cmd, "->", wikidir
                admin.onecmd(cmd)
        # Process attachments
        attdir = moindir + '/' + page + '/attachments'
        if os.access(attdir, os.F_OK):
            attachments = os.listdir(attdir)
            for att in attachments:
                attachment = Attachment(admin.env_open(), 'wiki', page)
                size = os.stat(attdir + '/'+ att)[6]
                print "attaching " + att + ' = ' + str(size)
                attfile = open (attdir + '/'+ att)
                attachment.insert (att, attfile, size)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:37,代码来源:moin2trac.py

示例13: image_setup

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [as 别名]
def image_setup(tc):
    add_pages(tc, ['page:fr'])
    from trac.attachment import Attachment
    tc.env.path = tempfile.mkdtemp(prefix='trac-tempenv-')
    attachment = Attachment(tc.env, 'wiki', 'page:fr')
    attachment.description = "image in page:fr"
    attachment.insert('img.png', StringIO(''), 0, 2)
开发者ID:dafrito,项目名称:trac-mirror,代码行数:9,代码来源:macros.py

示例14: _create_attachment

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [as 别名]
 def _create_attachment(self, req, ticket, upload, description):
     if hasattr(upload, 'filename'):
         attachment = Attachment(self.env, 'ticket', ticket.id)
   
     if hasattr(upload.file, 'fileno'):
         size = os.fstat(upload.file.fileno())[6]
     else:
         upload.file.seek(0, 2)
         size = upload.file.tell()
         upload.file.seek(0)
     if size == 0:
         raise TracError(_("Can't upload empty file"))
     
     max_size = self.env.config.get('attachment', 'max_size')
     if max_size >= 0 and size > max_size:
         raise TracError(_('Maximum attachment size: %(num)s bytes', num=max_size), _('Upload failed'))
     
     filename = unicodedata.normalize('NFC', unicode(upload.filename, 'utf-8'))
     filename = filename.replace('\\', '/').replace(':', '/')
     filename = os.path.basename(filename)
     if not filename:
         raise TracError(_('No file uploaded'))
   
     attachment.description = description
     if 'author' in req.args:
         attachment.author = get_reporter_id(req, 'author')
         attachment.ipnr = req.remote_addr
   
     attachment.insert(filename, upload.file, size)
开发者ID:lkraav,项目名称:trachacks,代码行数:31,代码来源:awesomeattachments.py

示例15: test_insert_unique

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import insert [as 别名]
 def test_insert_unique(self):
     attachment = Attachment(self.env, "ticket", 42)
     attachment.insert("foo.txt", StringIO(""), 0)
     self.assertEqual("foo.txt", attachment.filename)
     attachment = Attachment(self.env, "ticket", 42)
     attachment.insert("foo.txt", StringIO(""), 0)
     self.assertEqual("foo.2.txt", attachment.filename)
开发者ID:zjj,项目名称:trac_hack,代码行数:9,代码来源:attachment.py


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