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


Python Attachment.filename方法代码示例

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


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

示例1: test_get_path_encoded

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import filename [as 别名]
 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,代码行数:9,代码来源:attachment.py

示例2: test_path_extension

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import filename [as 别名]
 def test_path_extension(self):
     attachment = Attachment(self.env, 'ticket', 42)
     attachment.filename = 'Foo.Mp3'
     self.assertEqual(os.path.join(self.attachments_dir, 'ticket',
                                   hashes['42'][0:3], hashes['42'],
                                   hashes['Foo.Mp3'] + '.Mp3'),
                      attachment.path)
     attachment = Attachment(self.env, 'wiki', 'SomePage')
     attachment.filename = 'bar.7z'
     self.assertEqual(os.path.join(self.attachments_dir, 'wiki',
                                   hashes['SomePage'][0:3],
                                   hashes['SomePage'],
                                   hashes['bar.7z'] + '.7z'),
                      attachment.path)
     attachment = Attachment(self.env, 'ticket', 42)
     attachment.filename = 'foo.$$$'
     self.assertEqual(os.path.join(self.attachments_dir, 'ticket',
                                   hashes['42'][0:3], hashes['42'],
                                   hashes['foo.$$$']),
                      attachment.path)
     attachment = Attachment(self.env, 'wiki', 'SomePage')
     attachment.filename = u'bar.aäc'
     self.assertEqual(os.path.join(self.attachments_dir, 'wiki',
                                   hashes['SomePage'][0:3],
                                   hashes['SomePage'],
                                   hashes[u'bar.aäc']),
                      attachment.path)
开发者ID:dafrito,项目名称:trac-mirror,代码行数:29,代码来源:attachment.py

示例3: test_get_path

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import filename [as 别名]
 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,代码行数:9,代码来源:attachment.py

示例4: test_get_path_encoded

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import filename [as 别名]
 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:moreati,项目名称:trac-gitsvn,代码行数:13,代码来源:attachment.py

示例5: test_get_path

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import filename [as 别名]
 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:moreati,项目名称:trac-gitsvn,代码行数:13,代码来源:attachment.py

示例6: test_get_path_encoded

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import filename [as 别名]
 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',
                                   hashes['42'][0:3], hashes['42'],
                                   hashes['Teh foo.txt'] + '.txt'),
                      attachment.path)
     attachment = Attachment(self.env, 'wiki', u'ÜberSicht')
     attachment.filename = 'Teh bar.jpg'
     self.assertEqual(os.path.join(self.attachments_dir, 'wiki',
                                   hashes[u'ÜberSicht'][0:3],
                                   hashes[u'ÜberSicht'],
                                   hashes['Teh bar.jpg'] + '.jpg'),
                      attachment.path)
开发者ID:dafrito,项目名称:trac-mirror,代码行数:16,代码来源:attachment.py

示例7: test_add_attachment_html_notification

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import filename [as 别名]
    def test_add_attachment_html_notification(self):
        ticket = Ticket(self.env)
        ticket['description'] = 'Some ticket description'
        ticket['summary'] = 'Some ticket summary'
        ticket['type'] = 'defect'
        ticket['status'] = 'new'
        ticket.insert()

        attachment = Attachment(self.env, ticket)
        attachment.description = "`Some` '''!WikiFormatted''' ''text''"
        attachment.filename = 'somefile.txt'
        event = TicketChangeEvent('ticket', 'changed', ticket,
                                  author='user1', attachment=attachment)
        actual = self.tf.format([], 'ticket', 'text/html', event)

        filename = resource_filename(__name__, 'attachment_notification.html')
        file = open(filename, 'r')
        expected = file.read()
        file.close()
        self.assertEqual(expected, actual)
开发者ID:lkraav,项目名称:trachacks,代码行数:22,代码来源:formatters.py

示例8: process_request

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import filename [as 别名]
    def process_request(self, req):
        if req.path_info.startswith("/svg"):
            # ["", "svg", "attachments", "wiki" or "ticket", filename.ext...]
            parts = req.path_info.split("/")
            attachment = Attachment(self.env, parts[3], "/".join(parts[4:-1]))
            attachment.filename = parts[-1]
            try:
                message = open(attachment.path).read()
            except:
                raise HTTPException(404)

            req.send_response(200)
            req.send_header('Cache-control', 'no-cache')
            req.send_header('Expires', 'Fri, 01 Jan 1999 00:00:00 GMT')
            req.send_header('Content-Type', 'image/svg+xml')
            req.send_header('Content-Length', len(isinstance(message, unicode) and message.encode("utf-8") or message))
            req.end_headers()

            if req.method != 'HEAD':
                req.write(message)
            raise RequestDone
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:23,代码来源:web_ui.py

示例9: render_macro

# 需要导入模块: from trac.attachment import Attachment [as 别名]
# 或者: from trac.attachment.Attachment import filename [as 别名]

#.........这里部分代码省略.........
                module, file = parts
                rev = None
                if '@' in file:
                    file, rev = file.split('@')
                url = req.href.browser(file, rev=rev)
                raw_url = req.href.browser(file, rev=rev, format='raw')
                desc = filespec
            else: # #ticket:attachment or WikiPage:attachment
                # FIXME: do something generic about shorthand forms...
                id, file = parts
                if id and id[0] == '#':
                    module = 'ticket'
                    id = id[1:]
                elif id == 'htdocs':
                    raw_url = url = req.href.chrome('site', file)
                    desc = os.path.basename(file)
                elif id in ('http', 'https', 'ftp'): # external URLs
                    raw_url = url = desc = id+':'+file
                else:
                    module = 'wiki'
        elif len(parts) == 1:               # attachment
            # determine current object
            # FIXME: should be retrieved from the formatter...
            # ...and the formatter should be provided to the macro
            file = filespec
            module, id = 'wiki', 'WikiStart'
            path_info = req.path_info.split('/',2)
            if len(path_info) > 1:
                module = path_info[1]
            if len(path_info) > 2:
                id = path_info[2]
            if module not in ['wiki', 'ticket']:
                raise Exception('Cannot reference local attachment from here')
        else:
            raise Exception('No filespec given')
        if not url: # this is an attachment
            from trac.attachment import Attachment
            attachment = Attachment(self.env, module, id, file)
            url = attachment.href(req)

            dia_url = attachment.href(req, format='raw')
	    dia_path = attachment.path
	    dia_filename = attachment.filename
            img_url = dia_url.replace(".dia",".png")
	    img_path = dia_path.replace('.dia','.png')
	    img_filename = dia_filename.replace('.dia','.png')

            self.env.log.info('Getting file modification times.')
            #get file modification times
            try:
              dia_mtime = os.path.getmtime(dia_path)
            except Exception:
              raise Exception('File does not exist: %s', dia_path)

            try:
              img_mtime = os.path.getmtime(img_path)
            except Exception:
              img_mtime = 0
                
            self.env.log.info('Comparing dia and png file modification times : %s, %s',dia_mtime,img_mtime)

            # if diagram is newer than image, then regenerate image
            if (dia_mtime > img_mtime):
              try:
		# TODO: read this comment and adjust the command line to taste
		# You should probably use the correct path
		# The options are correct for the 0.96.1, but you may bee to adjust them
                diacmd = 'dia -l --filter=png --export='+img_path+' '+dia_path
                self.env.log.info('Running Dia : %s',diacmd)
	        f = popen2.Popen4(diacmd)
                lines = []
                while (f.poll() == -1):
                  lines += f.fromchild.readlines()
                  f.wait()	
	        #ecode = os.spawnl(os.P_WAIT,'/usr/bin/dia','/usr/bin/dia','-l','--export-to-format=png', '--export='+img_path, dia_path)
                self.env.log.info('Exiting Dia')
              except Exception, e:
                self.env.log.info('Dia failed with exception= %s',e)
                raise Exception('Dia execution failed.')
            try:
	      attachment._fetch(img_filename)
	    except Exception:
              db = self.env.get_db_cnx()
              handle_ta = True
              attachment.size = 0
              attachment.time = 0
              cursor = db.cursor()
              cursor.execute("INSERT INTO attachment "
                             "VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",
                             (attachment.parent_type, attachment.parent_id, img_filename,
                              attachment.size, attachment.time, 'PNG render of a DIA file', attachment.author,
                              attachment.ipnr))
              attachment.filename = img_filename

              self.env.log.info('New attachment: %s', img_filename)

              if handle_ta:
                  db.commit()

            desc = 'JPG render of a DIA file.'
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:104,代码来源:DiaView.py


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