diff apps/bundle/tasks.py @ 209:4033ebe1867f

Add ability to download files This makes use of a new model (BundleVersion) to keep track of the locations on disk of the original uploads for each version. This will require some manual processing to get it working for existing bundles, since the information needed isn't being stored at the moment.
author dellsystem <ilostwaldo@gmail.com>
date Sun, 17 Feb 2013 14:57:39 -0500
parents b711f0087709
children 95edf106bdef
line wrap: on
line diff
--- a/apps/bundle/tasks.py	Sat Oct 27 16:26:54 2012 -0400
+++ b/apps/bundle/tasks.py	Sun Feb 17 14:57:39 2013 -0500
@@ -7,7 +7,7 @@
 import magic
 from celery import task
 
-from apps.bundle.models import Bundle, BundleFile
+from apps.bundle.models import Bundle, BundleFile, BundleVersion
 
 
 mimetypes.add_type('application/x-gzip', '.tgz')
@@ -72,14 +72,16 @@
     mime_type = magic.from_file(file, mime=True)
     extension = mimetypes.guess_extension(mime_type)
 
-    print "mime type: %s" % mime_type
-    print "extension: %s" % extension
-
     if extension in archive_extensions:
         new_path = file + extension
         # Treat it as an archive. Rename it to that, then extract
         os.rename(file, new_path)
 
+        # Create the new BundleVersion
+        new_file_name = os.path.basename(new_path)
+        BundleVersion.objects.create(bundle=bundle, file_name=new_file_name,
+            version=bundle.latest_version)
+
         try:
             # Extract it to a directory, same path as the filename
             archive.extract(new_path, to_path=file)
@@ -87,7 +89,6 @@
             # Now go through the extracted files, make BundleFiles from them
             process_files_in_dir(bundle, file, None)
         except archive.ArchiveException:
-            print "Archive exception"
             pass
     elif mime_type.startswith('text/'):
         # Should be a plain text file - create a CodeFile for it
@@ -97,6 +98,5 @@
         bundle_file.save_file_contents(open(file, 'rt'),
             original_filename=bundle.file_name)
 
-    print "Done uploading!"
     bundle.done_uploading = True
     bundle.save()