comparison 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
comparison
equal deleted inserted replaced
183:cdcbfaa65cfe 184:b711f0087709
24 directory. 24 directory.
25 """ 25 """
26 dir_contents = [os.path.join(dir_name, f) for f in os.listdir(dir_name)] 26 dir_contents = [os.path.join(dir_name, f) for f in os.listdir(dir_name)]
27 dirs = filter(os.path.isdir, dir_contents) 27 dirs = filter(os.path.isdir, dir_contents)
28 files = filter(os.path.isfile, dir_contents) 28 files = filter(os.path.isfile, dir_contents)
29 print "Directories: %s" % ", ".join(dirs)
30 print "Files: %s" % ", ".join(files)
31 29
32 for file_path in sorted(dirs) + sorted(files): 30 for file_path in sorted(dirs) + sorted(files):
33 filename = os.path.basename(file_path) 31 filename = os.path.basename(file_path)
34 full_path = file_path[len(bundle.get_temp_path()) + 1:] 32 full_path = file_path[len(bundle.get_temp_path()) + 1:]
35 bundle_file = BundleFile(bundle=bundle, name=filename, 33 bundle_file = BundleFile(bundle=bundle, name=filename,
36 parent=parent_dir, full_path=full_path, 34 parent=parent_dir, full_path=full_path,
37 version=bundle.latest_version) 35 version=bundle.latest_version)
38 36
39 if file_path in files: 37 if file_path in files:
38 is_desc = False
40 bundle_file.is_dir = False 39 bundle_file.is_dir = False
41 bundle_file.file_size = os.path.getsize(file_path) 40 bundle_file.file_size = os.path.getsize(file_path)
42 41
43 # Only highlight the file contents if it's plain text 42 # Only highlight the file contents if it's plain text
44 mime_type = magic.from_file(file_path, mime=True) 43 mime_type = magic.from_file(file_path, mime=True)
45 if mime_type.startswith('text/') or mime_type in text_mimetypes: 44 if mime_type.startswith('text/') or mime_type in text_mimetypes:
46 with open(file_path, 'rt') as file: 45 with open(file_path, 'rt') as file:
47 # Store the contents of the file in the code field 46 # Store the contents of the file in the code field
48 bundle_file.save_file_contents(file) 47 bundle_file.save_file_contents(file)
48
49 # DESCRIPTION file should be at most 1 level deep
50 single_parent = (parent_dir is not None or
51 '/' not in parent_dir)
52 is_desc = single_parent and filename == 'DESCRIPTION'
53
54 # Check if this is the description file (if no description exists)
55 if bundle.octave_format and bundle.description == '' and is_desc:
56 bundle.description_file = bundle_file
57 bundle.save()
49 58
50 bundle_file.save() 59 bundle_file.save()
51 else: 60 else:
52 # It's a directory - call this function on it recursively 61 # It's a directory - call this function on it recursively
53 bundle_file.is_dir = True 62 bundle_file.is_dir = True