I was trying to get my local LAVA instance to work with our lab's data base dump. So I had the DB, but not all the media files. LAVA almost works when you do this, but I hit two small issues that prevented me from looking at bundle streams and it their test runs.

I realize this is an edge case, but its handy for when you want to test with a real database, but don't want all the media files. I'm not sure this is the exact way we want to fix this, so rather than do a merge proposal I thought I'd get your thoughts on the patch first.

There were two main issues in the code:

bundle_detail wants to get the "document format" for the media file associated with the bundle. Since the file didn't exist we hit an exception. I added a small check to the get_document_format to handle this by returning "n/a".

bundle_detail and test_run_detail wanted to display the size of media files. This calls a new function content_size which will catch an error if the file doesn't exist and simply return 0.

I'm not sure if this patch is doing to good a job of hiding the fact an error does exist. Maybe we should put a conditional in the template file to display an error when the file doesn't exist also?

-andy
=== modified file 'dashboard_app/models.py'
--- dashboard_app/models.py	2012-03-26 04:00:57 +0000
+++ dashboard_app/models.py	2012-04-20 22:59:22 +0000
@@ -428,6 +428,13 @@
 
     content = property(_get_content)
 
+    def content_size(self):
+        try:
+            size = self.content.size()
+        except:
+            size = 0 #file doesn't exist
+        return size
+
     def compress(self):
         c = self._raw_content
         self._gz_content.save(c.name, c)
@@ -540,6 +547,9 @@
             self.content.close()
 
     def get_document_format(self):
+        if not os.path.exists(self.content.path):
+            return 'n/a'
+
         self.content.open('rb')
         try:
             fmt, doc = DocumentIO.load(self.content)

=== modified file 'dashboard_app/templates/dashboard_app/bundle_detail.html'
--- dashboard_app/templates/dashboard_app/bundle_detail.html	2011-11-04 03:06:40 +0000
+++ dashboard_app/templates/dashboard_app/bundle_detail.html	2012-04-20 23:00:02 +0000
@@ -32,7 +32,7 @@
   <dt>Content SHA1:</dt>
   <dd>{{ bundle.content_sha1 }}</dd>
   <dt>Content size:</dt>
-  <dd>{{ bundle.content.size|filesizeformat }}</dd>
+  <dd>{{ bundle.content_size|filesizeformat }}</dd>
 </dl>
 
 <h3>Storage and format</h3>

=== modified file 'dashboard_app/templates/dashboard_app/test_run_detail.html'
--- dashboard_app/templates/dashboard_app/test_run_detail.html	2012-03-12 05:02:49 +0000
+++ dashboard_app/templates/dashboard_app/test_run_detail.html	2012-04-20 22:59:46 +0000
@@ -49,7 +49,7 @@
     <li><a href="{{ attachment.get_absolute_url }}"
       >{{ attachment }}</a>
       {% if attachment.content %}
-      ({{ attachment.content.size|filesizeformat }})
+      ({{ attachment.content_size|filesizeformat }})
       {% endif %}
     </li>
     {% empty %}

_______________________________________________
linaro-validation mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/linaro-validation

Reply via email to