Created
January 9, 2012 12:17
-
-
Save jun66j5/1582705 to your computer and use it in GitHub Desktop.
Patch: uses resource_exists instead of AttachmentModule.resource_exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: attachmentvalidate/console.py | |
=================================================================== | |
--- attachmentvalidate/console.py (revision 14) | |
+++ attachmentvalidate/console.py (working copy) | |
@@ -1,16 +1,18 @@ | |
- #!/usr/bin/env python | |
+#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from trac.admin.api import IAdminCommandProvider | |
-from trac.attachment import AttachmentModule, Attachment | |
+from trac.attachment import Attachment | |
from trac.core import Component, implements | |
+from trac.resource import resource_exists | |
from trac.util.text import print_table | |
+ | |
class ValidateCommand(Component): | |
""" Provides 'attachment validate' command for trac-admin script. """ | |
implements(IAdminCommandProvider) | |
- QUERY = "SELECT type,id,filename FROM attachment" | |
+ QUERY = "SELECT type,id,filename FROM attachment ORDER BY type,id,filename" | |
# IAdminCommandProvider methods | |
def get_admin_commands(self): | |
@@ -24,8 +26,12 @@ | |
db = self.env.get_read_db() | |
cursor = db.cursor() | |
cursor.execute(ValidateCommand.QUERY) | |
- attachment_module = AttachmentModule(self.env) | |
- print_table([(attachment_module.resource_exists( | |
- Attachment(self.env, type, id, filename).resource) and ' ' or '!', | |
- type + ':' + id, filename) | |
- for type, id, filename in cursor]) | |
\ No newline at end of file | |
+ attachment_exists = self._attachment_exists | |
+ print_table([(attachment_exists(type, id, filename) and ' ' or '!', | |
+ type + ':' + id, | |
+ filename) | |
+ for type, id, filename in cursor]) | |
+ | |
+ def _attachment_exists(self, type, id, filename): | |
+ att = Attachment(self.env, type, id, filename) | |
+ return resource_exists(self.env, att.resource) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment