diff apps/bundle/tasks.py @ 184:b711f0087709

Use DESCRIPTION file for bundles (SCHEMA CHANGE) * Added two new fields to the Bundle model: * octave_format, which allows users to specify if their bundle has been formatted according to octave packaging standards or not * description_file, which points to a file named DESCRIPTION in the root directory (or the next top-level directory), if the octave_format checkbox is ticked and if one exists * Fixed the uploader field for form by making it a hidden input and preventing hidden inputs from showing up entirely
author dellsystem <ilostwaldo@gmail.com>
date Sat, 27 Oct 2012 15:58:08 -0400
parents 76abe6d681ea
children 4033ebe1867f
line wrap: on
line diff
--- a/apps/bundle/tasks.py	Sat Oct 27 15:41:58 2012 -0400
+++ b/apps/bundle/tasks.py	Sat Oct 27 15:58:08 2012 -0400
@@ -26,8 +26,6 @@
     dir_contents = [os.path.join(dir_name, f) for f in os.listdir(dir_name)]
     dirs = filter(os.path.isdir, dir_contents)
     files = filter(os.path.isfile, dir_contents)
-    print "Directories: %s" % ", ".join(dirs)
-    print "Files: %s" % ", ".join(files)
 
     for file_path in sorted(dirs) + sorted(files):
         filename = os.path.basename(file_path)
@@ -37,6 +35,7 @@
             version=bundle.latest_version)
 
         if file_path in files:
+            is_desc = False
             bundle_file.is_dir = False
             bundle_file.file_size = os.path.getsize(file_path)
 
@@ -47,6 +46,16 @@
                     # Store the contents of the file in the code field
                     bundle_file.save_file_contents(file)
 
+                    # DESCRIPTION file should be at most 1 level deep
+                    single_parent = (parent_dir is not None or
+                        '/' not in parent_dir)
+                    is_desc = single_parent and filename == 'DESCRIPTION'
+
+            # Check if this is the description file (if no description exists)
+            if bundle.octave_format and bundle.description == '' and is_desc:
+                bundle.description_file = bundle_file
+                bundle.save()
+
             bundle_file.save()
         else:
             # It's a directory - call this function on it recursively