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


Python attachment.Attachment类代码示例

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


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

示例1: import_wiki_attachments

    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,代码行数:27,代码来源:importer.py

示例2: _do_uploadPicture

    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,代码行数:34,代码来源:admin.py

示例3: remove

 def remove(self, req, realm, objid, filename):
     """ Delete an attachment. """
     resource = Resource(realm, objid).child('attachment', filename)
     attachment = Attachment(self.env, resource)
     req.perm(attachment.resource).require('ATTACHMENT_DELETE')
     attachment.delete()
     return True
开发者ID:esogs,项目名称:IttecoTracPlugin,代码行数:7,代码来源:rpc.py

示例4: deleteAttachment

 def deleteAttachment(self, req, ticket, filename):
     """ Delete an attachment. """
     if not model.Ticket(self.env, ticket).exists:
         raise TracError('Ticket "%s" does not exists' % ticket)
     attachment = Attachment(self.env, 'ticket', ticket, filename)
     attachment.delete()
     return True
开发者ID:Puppet-Finland,项目名称:trac,代码行数:7,代码来源:ticket.py

示例5: _migrate_attachments

 def _migrate_attachments(self, attachments, to_product=None, copy=False):
     for type, id, filename in attachments:
         old_path = Attachment._get_path(self.env.path, type, id, filename)
         new_path = self.env.path
         if to_product:
             new_path = os.path.join(new_path, 'products', to_product)
         new_path = Attachment._get_path(new_path, type, id, filename)
         dirname = os.path.dirname(new_path)
         if not os.path.exists(old_path):
             self.log.warning(
                 "Missing attachment files for %s:%s/%s",
                 type, id, filename)
             continue
         if os.path.exists(new_path):
             # TODO: Do we want to overwrite?
             continue
         try:
             if not os.path.exists(dirname):
                 os.makedirs(dirname)
             if copy:
                 if hasattr(os, 'link'):
                     # TODO: It this safe?
                     os.link(old_path, new_path)
                 else:
                     shutil.copy(old_path, new_path)
             else:
                 os.rename(old_path, new_path)
         except OSError as err:
             self.log.warning(
                 "Could not move attachment %s from %s %s to"
                 "product @ (%s)",
                 filename, type, id, str(err)
             )
开发者ID:thimalk,项目名称:bloodhound-789,代码行数:33,代码来源:api.py

示例6: process_request

    def process_request(self, req):
        """Process the request. For ClearSilver, return a (template_name,
        content_type) tuple, where `template` is the ClearSilver template to use
        (either a `neo_cs.CS` object, or the file name of the template), and
        `content_type` is the MIME type of the content. For Genshi, return a
        (template_name, data, content_type) tuple, where `data` is a dictionary
        of substitutions for the template.

        For both templating systems, "text/html" is assumed if `content_type` is
        `None`.

        Note that if template processing should not occur, this method can
        simply send the response itself and not return anything.
        """

        # handle image setting
        if req.method == 'POST':
            self.set_default_image(req)
            req.redirect(req.get_header('referer') or req.href(req.path_info))

        # GET default image
        ticket_id, size = self.ticket_id_and_size(req.path_info)
        image = DefaultTicketImage(self.env).default_image(ticket_id, size)
        assert image is not None # TODO better
        images = ImageTrac(self.env).images(ticket_id)
        attachment = Attachment(self.env, 'ticket', ticket_id, images[image][size])
        mimeview = Mimeview(self.env)
        mimetype = mimeview.get_mimetype(attachment.filename)
        req.send(attachment.open().read(), mimetype)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:29,代码来源:web_ui.py

示例7: test_get_path_encoded

 def test_get_path_encoded(self):
     attachment = Attachment(self.env, "ticket", 42)
     attachment.filename = "Teh foo.txt"
     self.assertEqual(os.path.join(self.attachments_dir, "ticket", "42", "Teh%20foo.txt"), attachment.path)
     attachment = Attachment(self.env, "wiki", u"ÜberSicht")
     attachment.filename = "Teh bar.jpg"
     self.assertEqual(os.path.join(self.attachments_dir, "wiki", "%C3%9CberSicht", "Teh%20bar.jpg"), attachment.path)
开发者ID:zjj,项目名称:trac_hack,代码行数:7,代码来源:attachment.py

示例8: delete

    def delete(self, db=None):
        """Remove a build configuration and all dependent objects from the
        database."""
        assert self.exists, "Cannot delete non-existing configuration"
        if not db:
            db = self.env.get_db_cnx()
            handle_ta = True
        else:
            handle_ta = False

        for platform in list(TargetPlatform.select(self.env, self.name, db=db)):
            platform.delete(db=db)

        for build in list(Build.select(self.env, config=self.name, db=db)):
            build.delete(db=db)

        # Delete attachments
        Attachment.delete_all(self.env, "build", self.resource.id, db)

        cursor = db.cursor()
        cursor.execute("DELETE FROM bitten_config WHERE name=%s", (self.name,))

        if handle_ta:
            db.commit()
        self._old_name = None
开发者ID:kroman0,项目名称:bitten,代码行数:25,代码来源:model.py

示例9: convert

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,代码行数:35,代码来源:moin2trac.py

示例10: delete

 def delete(self, version=0):
     """ Deletes a specific version, or if none is provided
     then all versions will be deleted. If all (or just one version exists) it
     will also delete all comments and any attachments attached to the post. """
     if version:
         sql = "DELETE FROM fullblog_posts WHERE name=%s AND version=%s"
         args = (self.name, version)
     else:
         sql = "DELETE FROM fullblog_posts WHERE name=%s"
         args = (self.name,)
     if hasattr(self.env, 'db_transaction'):
         self.env.db_transaction(sql, args)
         db = None
     else:
         db = self.env.get_db_cnx()
         cursor = db.cursor()
         cursor.execute(sql, args)
         db.commit()
     if not len(self.get_versions()):
         # Delete comments
         for comment in self.get_comments():
             comment.delete()
         # Delete attachments
         if db is not None:
             Attachment.delete_all(self.env, 'blog', self.name, db)
         else:
             Attachment.delete_all(self.env, 'blog', self.name)
     return True
开发者ID:kzhamaji,项目名称:TracFullBlogPlugin,代码行数:28,代码来源:model.py

示例11: do_delete

 def do_delete(db):
     cursor = db.cursor()
     Attachment.delete_all(self.env, self.resource.realm, self.resource.id, db)
     cursor.execute("""
     DELETE FROM mailinglistraw WHERE id IN
     (SELECT raw FROM mailinglistmessages WHERE id = %s)""", (self.id,))
     cursor.execute('DELETE FROM mailinglistmessages WHERE id = %s', (self.id,))
开发者ID:CGI-define-and-primeportal,项目名称:trac-plugin-mailinglist,代码行数:7,代码来源:model.py

示例12: image_setup

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,代码行数:7,代码来源:macros.py

示例13: source

    def source(self, req, args):
        arg = re.compile(":").split(args)
        if (len(arg) != 2):
            raise TracError('Usage: BibAdd(attachment:[path/to/]file)')

        realm = 'wiki'
        page = None
        file = arg[1]

        path_info = arg[1].split('/', 1)  # greedy! split wikipath and filename

        if len(path_info) > 2:
            raise TracError('Usage: BibAdd(attachment:[path/to/]file)')
        elif len(path_info) == 1:
            file = path_info[0]
            page = req.args.get('page')
            if page is None:  # TODO: clean solution
                page = 'WikiStart'
            bib = Attachment(self.env, realm, page, file)
        elif len(path_info) == 2:
            page = path_info[0]
            file = path_info[1]

            bib = Attachment(self.env, realm, page, file)
        file = bib.open()
        text = file.read()
        file.close()

        return _extract(text)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:29,代码来源:source.py

示例14: update

    def update(self, author=None):
        """Update the milestone.
        """
        self.name = simplify_whitespace(self.name)
        if not self.name:
            raise TracError(_("Invalid milestone name."))

        old = self._old.copy()
        with self.env.db_transaction as db:
            if self.name != old['name']:
                # Update milestone field in tickets
                self.move_tickets(self.name, author, "Milestone renamed")
                # Reparent attachments
                Attachment.reparent_all(self.env, self.realm, old['name'],
                                        self.realm, self.name)

            self.env.log.info("Updating milestone '%s'", old['name'])
            db("""UPDATE milestone
                  SET name=%s, due=%s, completed=%s, description=%s
                  WHERE name=%s
                  """, (self.name, to_utimestamp(self.due),
                        to_utimestamp(self.completed),
                        self.description, old['name']))
            self.checkin()
        # Fields need reset if renamed or completed/due changed
        TicketSystem(self.env).reset_ticket_fields()

        old_values = dict((k, v) for k, v in old.iteritems()
                          if getattr(self, k) != v)
        for listener in TicketSystem(self.env).milestone_change_listeners:
            listener.milestone_changed(self, old_values)
开发者ID:pkdevbox,项目名称:trac,代码行数:31,代码来源:model.py

示例15: test_get_path

 def test_get_path(self):
     attachment = Attachment(self.env, "ticket", 42)
     attachment.filename = "foo.txt"
     self.assertEqual(os.path.join(self.attachments_dir, "ticket", "42", "foo.txt"), attachment.path)
     attachment = Attachment(self.env, "wiki", "SomePage")
     attachment.filename = "bar.jpg"
     self.assertEqual(os.path.join(self.attachments_dir, "wiki", "SomePage", "bar.jpg"), attachment.path)
开发者ID:zjj,项目名称:trac_hack,代码行数:7,代码来源:attachment.py


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