[qmtest] [PATCH] fix reading attachments data

Mark Mitchell mark at codesourcery.com
Tue Jul 15 18:50:16 UTC 2003


On Mon, 2003-07-14 at 05:25, Vladimir Prus wrote:
> Hello,
> I think reading of attachment data is broken in HEAD.

I checked in this variant of your patch.  Thanks!

-- 
Mark Mitchell <mark at codesourcery.com>
CodeSourcery, LLC
-------------- next part --------------
2003-07-15  Vladimir Prus <ghost at cs.msu.su>
	    Mark Mitchell <mark at codesourcery.com>

	* qm/attachment.py (AttachmentStore.__init__): Remove.
	(FileAttachmentStore.__init__): New method.
	(FileAttachmentStore.GetDataFile): Support relative paths.
	(TemporaryAttachmentStore.__init__): Adjust accordingly.
	(TemporaryAttachmentStore.GetDataFile): Remove.
	* qm/test/classes/xml_database.py (XMLDatabase.__init__): Use the
	database root when creating the attachment store.

Index: qm/attachment.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/attachment.py,v
retrieving revision 1.18
diff -c -5 -p -r1.18 attachment.py
*** qm/attachment.py	3 Jul 2003 16:52:40 -0000	1.18
--- qm/attachment.py	15 Jul 2003 18:45:55 -0000
*************** class AttachmentStore(object):
*** 184,199 ****
  
      Please note that the 'AttachmentStore' interface provides methods
      for retrieving attachment data only; not for storing it.  The
      interface for storing may be defined in any way by implementations."""
  
-     def __init__(self):
-         """Create a new 'AttachmentStore'."""
- 
-         pass
- 
-     
      def GetData(self, location):
          """Return the data for an attachment.
  
          returns -- A string containing the attachment data."""
  
--- 184,193 ----
*************** class AttachmentStore(object):
*** 256,265 ****
--- 250,270 ----
  class FileAttachmentStore(AttachmentStore):
      """An attachment store based on the file system.
  
      The locations are the names of files in the file system."""
  
+     def __init__(self, root = None):
+         """Construct a new 'FileAttachmentStore'
+ 
+         'root' -- If not 'None', the root directory for the store.  All
+         locations are relative to this directory.  If 'None', all
+         locations are relative to the current directory."""
+         
+         super(AttachmentStore, self).__init__()
+         self.__root = root
+         
+         
      def GetData(self, location):
  
          # Open the file.
          f = open(self.GetDataFile(location))
          # Read the contents.
*************** class FileAttachmentStore(AttachmentStor
*** 270,280 ****
          return s
  
  
      def GetDataFile(self, location):
  
!         return location
  
  
      def GetSize(self, location):
          
          return os.stat(self.GetDataFile(location))[6]
--- 275,288 ----
          return s
  
  
      def GetDataFile(self, location):
  
!         if root is not None:
!             return os.path.join(root, location)
!         else:
!             return location
  
  
      def GetSize(self, location):
          
          return os.stat(self.GetDataFile(location))[6]
*************** class TemporaryAttachmentStore(FileAttac
*** 318,338 ****
      def __init__(self):
          """Construct a temporary attachment store.
  
          The store is initially empty."""
  
-         # Initialize the base class.
-         super(TemporaryAttachmentStore, self).__init__()
          # Construct a temporary directory in which to store attachment
          # data.
          self.__tmpdir = temporary_directory.TemporaryDirectory()
!         self.__path = self.__tmpdir.GetPath()
! 
! 
!     def GetDataFile(self, location):
! 
!         return os.path.join(self.__path, location)
  
  
      def HandleUploadRequest(self, request):
          """Handle a web request to upload attachment data.
  
--- 326,341 ----
      def __init__(self):
          """Construct a temporary attachment store.
  
          The store is initially empty."""
  
          # Construct a temporary directory in which to store attachment
          # data.
          self.__tmpdir = temporary_directory.TemporaryDirectory()
!         # Initialize the base class.
!         path = self.__tmpdir.GetPath()
!         super(TemporaryAttachmentStore, self).__init__(path)
  
  
      def HandleUploadRequest(self, request):
          """Handle a web request to upload attachment data.
  
Index: qm/test/classes/xml_database.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/test/classes/xml_database.py,v
retrieving revision 1.13
diff -c -5 -p -r1.13 xml_database.py
*** qm/test/classes/xml_database.py	3 Jul 2003 16:52:40 -0000	1.13
--- qm/test/classes/xml_database.py	15 Jul 2003 18:45:55 -0000
*************** class XMLDatabase(ExtensionDatabase):
*** 51,61 ****
      def __init__(self, path, arguments):
  
          # Initialize base classes.
          ExtensionDatabase.__init__(self, path, arguments)
          # Create an AttachmentStore for this database.
!         self.__store = qm.attachment.FileAttachmentStore()
  
  
      def _GetTestFromPath(self, test_id, test_path):
          try:
              return self.__LoadItem(test_id, test_path,
--- 51,61 ----
      def __init__(self, path, arguments):
  
          # Initialize base classes.
          ExtensionDatabase.__init__(self, path, arguments)
          # Create an AttachmentStore for this database.
!         self.__store = qm.attachment.FileAttachmentStore(path)
  
  
      def _GetTestFromPath(self, test_id, test_path):
          try:
              return self.__LoadItem(test_id, test_path,


More information about the qmtest mailing list