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


Python Attachment.author方法代码示例

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


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

示例1: _do_uploadPicture

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [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

示例2: _create_attachment

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [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

示例3: _create_attachment

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [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

示例4: addTicket

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [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: _process_attachment

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [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

示例6: addAttachment

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [as 别名]
 def addAttachment(self, ticket_id, filename, datafile, filesize,
                   author, description, upload_time):
     # copied from bugzilla2trac
     attachment = Attachment(self.env, 'ticket', ticket_id)
     attachment.author = author
     attachment.description = description
     attachment.insert(filename, datafile, filesize, upload_time)
     del attachment
开发者ID:chrishildebrandt,项目名称:tracscripts,代码行数:10,代码来源:sfn2trac.py

示例7: addAttachment

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [as 别名]
 def addAttachment(self, author, a):
     if a["filename"] != "":
         description = a["description"]
         id = a["bug_id"]
         filename = a["filename"]
         filedata = StringIO.StringIO(a["thedata"])
         filesize = len(filedata.getvalue())
         time = a["creation_ts"]
         print "    ->inserting attachment '%s' for ticket %s -- %s" % (filename, id, description)
         attachment = Attachment(self.env, "ticket", id)
         attachment.author = author
         attachment.description = description
         attachment.insert(filename, filedata, filesize, datetime2epoch(time))
         del attachment
开发者ID:exocad,项目名称:exotrac,代码行数:16,代码来源:bugzilla2trac.py

示例8: attach

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [as 别名]
    def attach(self, ticket, image):
        attachment = Attachment(self.env, 'ticket', ticket.id)
        attachment.author = ticket['reporter']
        attachment.description = ticket['summary']
        image.file.seek(0,2) # seek to end of file
        size = image.file.tell()
        filename = image.filename
        image.file.seek(0)
        attachment.insert(filename, image.file, size)

        # XXX shouldn't this only be called for, like, the
        # first image or whenever you really want to set the default?
        from imagetrac.default_image import DefaultTicketImage
        if self.env.is_component_enabled(DefaultTicketImage):
            DefaultTicketImage(self.env).set_default(ticket.id, filename)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:17,代码来源:image.py

示例9: addAttachment

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [as 别名]
 def addAttachment(self, author, a):
     if a['filename'] != '':
         description = a['description']
         id = a['bug_id']
         filename = a['filename']
         filedata = StringIO.StringIO(a['thedata'])
         filesize = len(filedata.getvalue())
         time = a['creation_ts']
         print "    ->inserting attachment '%s' for ticket %s -- %s" % \
                 (filename, id, description)
         attachment = Attachment(self.env, 'ticket', id)
         attachment.author = author
         attachment.description = description
         attachment.insert(filename, filedata, filesize, datetime2epoch(time))
         del attachment
开发者ID:zjj,项目名称:trac_hack,代码行数:17,代码来源:bugzilla2trac.py

示例10: addAttachment

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [as 别名]
    def addAttachment(self, author, a):
        description = a['description'].encode('utf-8')
        id = a['bug_id']
        filename = a['filename'].encode('utf-8')
        filedata = StringIO.StringIO(a['thedata'].tostring())
        filesize = len(filedata.getvalue())
        time = a['creation_ts']
        print "    ->inserting attachment '%s' for ticket %s -- %s" % \
                (filename, id, description)

        attachment = Attachment(self.env, 'ticket', id)
        attachment.author = author
        attachment.description = description
        attachment.insert(filename, filedata, filesize, time.strftime('%s'))
        del attachment
开发者ID:cyphactor,项目名称:lifecyclemanager,代码行数:17,代码来源:bugzilla2trac.py

示例11: putAttachment

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [as 别名]
 def putAttachment(self, req, ticket, filename, description, data, replace=True):
     """ Add an attachment, optionally (and defaulting to) overwriting an
     existing one. Returns filename."""
     if not model.Ticket(self.env, ticket).exists:
         raise TracError, 'Ticket "%s" does not exist' % ticket
     if replace:
         try:
             attachment = Attachment(self.env, 'ticket', ticket, filename)
             attachment.delete()
         except TracError:
             pass
     attachment = Attachment(self.env, 'ticket', ticket)
     attachment.author = req.authname or 'anonymous'
     attachment.description = description
     attachment.insert(filename, StringIO(data.data), len(data.data))
     return attachment.filename
开发者ID:Puppet-Finland,项目名称:trac,代码行数:18,代码来源:ticket.py

示例12: putAttachmentEx

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [as 别名]
 def putAttachmentEx(self, req, pagename, filename, description, data, replace=True):
     """ Attach a file to a Wiki page. Returns the (possibly transformed)
     filename of the attachment.
     
     Use this method if you don't care about WikiRPC compatibility. """
     if not WikiPage(self.env, pagename).exists:
         raise TracError, 'Wiki page "%s" does not exist' % pagename
     if replace:
         try:
             attachment = Attachment(self.env, 'wiki', pagename, filename)
             attachment.delete()
         except TracError:
             pass
     attachment = Attachment(self.env, 'wiki', pagename)
     attachment.author = req.authname or 'anonymous'
     attachment.description = description
     attachment.insert(filename, StringIO(data.data), len(data.data))
     return attachment.filename
开发者ID:Puppet-Finland,项目名称:trac,代码行数:20,代码来源:wiki.py

示例13: putAttachment

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [as 别名]
 def putAttachment(self, req, ticket, filename, description, data, replace=True):
     """ Add an attachment, optionally (and defaulting to) overwriting an
     existing one. Returns filename."""
     if not model.Ticket(self.env, ticket).exists:
         raise ResourceNotFound('Ticket "%s" does not exist' % ticket)
     if replace:
         try:
             attachment = Attachment(self.env, 'ticket', ticket, filename)
             req.perm(attachment.resource).require('ATTACHMENT_DELETE')
             attachment.delete()
         except TracError:
             pass
     attachment = Attachment(self.env, 'ticket', ticket)
     req.perm(attachment.resource).require('ATTACHMENT_CREATE')
     attachment.author = req.authname
     attachment.description = description
     attachment.insert(filename, StringIO(data.data), len(data.data))
     return attachment.filename
开发者ID:42cc,项目名称:XmlRpcPlugin,代码行数:20,代码来源:ticket.py

示例14: addWikiPage

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [as 别名]
	def addWikiPage(self, page, attachments):
		'''Add a wiki page as a list of dictionaries'''
		db = self._env.get_db_cnx()
		cursor = db.cursor()
		pageCountRes = cursor.execute('select count(*) as count from wiki where name = %s', (page[0]['name'],))
		pageCount = pageCountRes.fetchone()[0]
		assert pageCount == 0, 'Page %s found in %s' % (page[0]['name'], self.name)

		insertWikiQuery = 'insert into wiki (name, version, time, author, ipnr, text, comment, readonly) values (%s, %s, %s, %s, %s, %s, %s, %s)'
		for pV in page:
			insertValues = (pV['name'], pV['version'], pV['time'], pV['author'], pV['ipnr'], pV['text'], pV['comment'], pV['readonly'])
			insertRes = cursor.execute(insertWikiQuery, insertValues)
		for a in attachments:
			pageAttach = Attachment(self._env, 'wiki', pV['name'])
			pageAttach.description = a['description']
			pageAttach.author = a['author']
			pageAttach.ipnr = a['ipnr']
			pageAttach.insert(a['filename'], a['fileobj'], a['size'], t=a['time'])
		db.commit()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:21,代码来源:ptrac.py

示例15: get_uploaded_file_href

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import author [as 别名]
    def get_uploaded_file_href(self, req, user, field, req_field):
        """Returns uploaded file's url
        
        @param req: trac.web.req
        @param user: tracusermanager.api.User
        @param field: str
        @param req_field: str 
        @return: str
        """
        
        # validate request field
        upload = req.args.get(req_field, None)
        if upload == None or not hasattr(upload, 'filename') or not upload.filename:
            return user[field]
        
        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.attachments_wikiPage)
        if not page.exists:
            page.text="= UserManager's Attachments ="
            page.save( 'trac', 'Page created by tracusermanager.profile component',  req.remote_addr)
       
        attachment = Attachment(self.env, 'wiki', self.attachments_wikiPage)
        attachment.author = get_reporter_id(req, 'author')
        attachment.ipnr = req.remote_addr
        attachment.description = (_("%s\'s Avatar") % (user.username))
        attachment.insert('_'.join([user.username, filename]), upload.file, size)
        
        return req.href('/'.join(['raw-attachment', 'wiki',self.attachments_wikiPage, attachment.filename]))
开发者ID:ejucovy,项目名称:trac-UserManagerPlugin,代码行数:45,代码来源:api.py


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