Changeset 3271
- Timestamp:
- 02/24/08 20:18:30 (9 months ago)
- Files:
-
- screenshotsplugin/0.10/tracscreenshots/core.py (modified) (7 diffs)
- screenshotsplugin/0.10/tracscreenshots/tags.py (modified) (1 diff)
- screenshotsplugin/0.10/tracscreenshots/templates/screenshot-add.cs (modified) (1 diff)
- screenshotsplugin/0.11/tracscreenshots/core.py (modified) (8 diffs)
- screenshotsplugin/0.11/tracscreenshots/templates/screenshot-add.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
screenshotsplugin/0.10/tracscreenshots/core.py
r3161 r3271 1 1 # -*- coding: utf8 -*- 2 2 3 import sets, re, os, os.path, time, mimetypes, unicodedata, Image3 import sets, re, os, os.path, shutil, time, mimetypes, unicodedata, Image 4 4 5 5 from trac.core import * … … 40 40 41 41 #Â Configuration options. 42 title = Option('screenshots', 'title', 'Screenshots',42 mainnav_title = Option('screenshots', 'mainnav_title', 'Screenshots', 43 43 'Main navigation bar button title.') 44 metanav_title = Option('screenshots', 'metanav_title', '', 45 'Meta navigation bar link title.') 44 46 path = Option('screenshots', 'path', '/var/lib/trac/screenshots', 45 47 'Path where to store uploaded screenshots.') … … 78 80 def get_navigation_items(self, req): 79 81 if req.perm.has_permission('SCREENSHOTS_VIEW'): 80 yield 'mainnav', 'screenshots', html.a(self.title, 81 href = req.href.screenshots()) 82 if self.mainnav_title: 83 yield 'mainnav', 'screenshots', html.a(self.mainnav_title, 84 href = req.href.screenshots()) 85 if self.metanav_title: 86 yield 'metanav', 'screenshots', html.a(self.metanav_title, 87 href = req.href.screenshots()) 82 88 83 89 # IRequestHandler methods. … … 107 113 req.hdf['screenshots'] = data 108 114 req.hdf['screenshots.href'] = req.href.screenshots() 109 req.hdf['screenshots.title'] = self.title 115 req.hdf['screenshots.title'] = self.mainnav_title or self.metanav_title 116 req.hdf['screenshots.has_tags'] = self.env.is_component_enabled( 117 'tracscreenshots.tags.ScreenshotsTags') 118 #req.hdf['screenshots.has_tags'] = self.config.get('components', 119 # 'tracscreenshots.tags.screenshotstags') == 'enabled' 110 120 return template, content_type 111 121 … … 241 251 api.add_screenshot(cursor, screenshot) 242 252 243 244 253 # Get inserted screenshot to with new id. 245 254 screenshot = api.get_screenshot_by_time(cursor, … … 269 278 270 279 # Prepare file paths 271 filename = os.path.join(self.path, unicode(screenshot['id']), 272 '%s-%ix%i.%s' % (result.group(1), screenshot['width'], 273 screenshot['height'], result.group(2))) 274 filename = unicodedata.normalize('NFC', filename) 275 filename = filename.replace('\\', '/').replace(':', '/') 276 path = os.path.dirname(filename) 277 self.log.debug('filename: %s' % (filename,)) 278 self.log.debug('filename: %s' % (path,)) 280 path = os.path.join(self.path, unicode(screenshot['id'])) 281 filepath = os.path.join(path, '%s-%ix%i.%s' % (result.group(1), 282 screenshot['width'], screenshot['height'], result.group(2))) 283 path = os.path.normpath(path) 284 filepath = os.path.normpath(filepath) 285 self.log.debug('path: %s' % (path,)) 286 self.log.debug('filepath: %s' % (filepath,)) 279 287 280 288 # Store uploaded image. 281 289 try: 282 290 os.mkdir(path) 283 image.save(filename) 284 except: 291 out_file = open(filepath, 'wb+') 292 file.seek(0) 293 shutil.copyfileobj(file, out_file) 294 out_file.close() 295 except Exception, error: 285 296 api.delete_screenshot(cursor, screenshot['id']) 297 try: 298 self.log.debug(error) 299 except: 300 pass 286 301 try: 287 302 os.remove(filename) … … 294 309 raise TracError('Error storing file. Is directory' \ 295 310 ' specified in path config option in [screenshots]' \ 296 ' section of trac.ini existing?') 311 ' section of trac.ini existing? Original message was: %s' \ 312 % (error,)) 297 313 298 314 # Notify change listeners. screenshotsplugin/0.10/tracscreenshots/tags.py
r2659 r3271 5 5 from tracscreenshots.api import * 6 6 from trac.core import * 7 7 8 from tractags.api import ITaggingSystemProvider, DefaultTaggingSystem, \ 8 9 TagEngine screenshotsplugin/0.10/tracscreenshots/templates/screenshot-add.cs
r2644 r3271 40 40 </div> 41 41 <?cs /if ?> 42 <div class="field"> 43 <label for="tags">Additional tags:</label><br/> 44 <?cs if:args.action == 'add' ?> 45 <input type="text" id="tags" name="tags" value=""/><br/> 46 <?cs else ?> 47 <input type="text" id="tags" name="tags" value="<?cs var:screenshots.screenshot.tags ?>"/><br/> 48 <?cs /if ?> 49 </div> 42 <?cs if:screenshots.has_tags ?> 43 <div class="field"> 44 <label for="tags">Additional tags:</label><br/> 45 <?cs if:args.action == 'add' ?> 46 <input type="text" id="tags" name="tags" value=""/><br/> 47 <?cs else ?> 48 <input type="text" id="tags" name="tags" value="<?cs var:screenshots.screenshot.tags ?>"/><br/> 49 <?cs /if ?> 50 </div> 51 <?cs /if ?> 50 52 <div class="field"> 51 53 <label for="components">Components:</label><br/> screenshotsplugin/0.11/tracscreenshots/core.py
r3141 r3271 1 1 # -*- coding: utf8 -*- 2 2 3 import sets, re, os, os.path, mimetypes, unicodedata, Image3 import sets, re, os, os.path, shutil, mimetypes, unicodedata, Image 4 4 from datetime import * 5 5 … … 41 41 42 42 #Â Configuration options. 43 title = Option('screenshots', 'title', 'Screenshots',43 mainnav_title = Option('screenshots', 'mainnav_title', 'Screenshots', 44 44 'Main navigation bar button title.') 45 metanav_title = Option('screenshots', 'metanav_title', '', 46 'Meta navigation bar link title.') 45 47 path = Option('screenshots', 'path', '/var/lib/trac/screenshots', 46 48 'Path where to store uploaded screenshots.') … … 79 81 def get_navigation_items(self, req): 80 82 if req.perm.has_permission('SCREENSHOTS_VIEW'): 81 yield 'mainnav', 'screenshots', html.a(self.title, 82 href = req.href.screenshots()) 83 if self.mainnav_title: 84 yield 'mainnav', 'screenshots', html.a(self.mainnav_title, 85 href = req.href.screenshots()) 86 if self.metanav_title: 87 yield 'metanav', 'screenshots', html.a(self.metanav_title, 88 href = req.href.screenshots()) 83 89 84 90 # IRequestHandler methods. … … 107 113 108 114 # Prepare data structure. 109 self.data['title'] = self.title 115 self.data['title'] = self.mainnav_title or self.metanav_title 116 self.data['has_tags'] = self.env.is_component_enabled( 117 'tracscreenshots.tags.ScreenshotsTags') 110 118 111 119 # Get action from request and perform them. … … 117 125 add_stylesheet(req, 'screenshots/css/screenshots.css') 118 126 add_script(req, 'screenshots/js/screenshots.js') 119 120 # Prepare HDF structure.121 req.hdf['screenshots'] = self.data122 127 123 128 # Return template and its data. … … 263 268 api.add_screenshot(context, screenshot) 264 269 265 266 270 # Get inserted screenshot to with new id. 267 271 screenshot = api.get_screenshot_by_time(context, … … 291 295 292 296 # Prepare file paths 293 filename = os.path.join(self.path, to_unicode(screenshot['id']), 294 '%s-%ix%i.%s' % (result.group(1), screenshot['width'], 295 screenshot['height'], result.group(2))) 296 filename = unicodedata.normalize('NFC', filename) 297 filename = filename.replace('\\', '/').replace(':', '/') 298 path = os.path.dirname(filename) 299 self.log.debug('filename: %s' % (filename,)) 300 self.log.debug('filename: %s' % (path,)) 297 path = os.path.join(self.path, unicode(screenshot['id'])) 298 filepath = os.path.join(path, '%s-%ix%i.%s' % (result.group(1), 299 screenshot['width'], screenshot['height'], result.group(2))) 300 path = os.path.normpath(path) 301 filepath = os.path.normpath(filepath) 302 self.log.debug('path: %s' % (path,)) 303 self.log.debug('filename: %s' % (filepath,)) 301 304 302 305 # Store uploaded image. 303 306 try: 304 307 os.mkdir(path) 305 image.save(filename) 308 out_file = open(filepath, 'wb+') 309 file.seek(0) 310 shutil.copyfileobj(file, out_file) 311 out_file.close() 306 312 except Exception, error: 307 313 api.delete_screenshot(context, screenshot['id']) … … 320 326 raise TracError('Error storing file. Is directory' \ 321 327 ' specified in path config option in [screenshots]' \ 322 ' section of trac.ini existing?') 328 ' section of trac.ini existing? Original message was: %s' \ 329 % (error,)) 323 330 324 331 # Notify change listeners. screenshotsplugin/0.11/tracscreenshots/templates/screenshot-add.html
r3141 r3271 29 29 <input type="file" id="image" name="image" value=""/><br/> 30 30 </div> 31 <div class="field">31 <div py:if="screenshots.has_tags" class="field"> 32 32 <label for="tags">Additional tags:</label><br/> 33 33 <input type="text" id="tags" name="tags" value="${(req.args.action == 'edit') and screenshots.screenshot.tags or ''}"/><br/>
