Mercurial > agora-palash
comparison apps/bundle/tasks.py @ 179:76abe6d681ea
Add whitelist for other text-like mimetypes
Just XML for now.
author | dellsystem <ilostwaldo@gmail.com> |
---|---|
date | Sat, 20 Oct 2012 23:43:41 -0400 |
parents | 86129d185ddb |
children | b711f0087709 |
comparison
equal
deleted
inserted
replaced
178:df160069b769 | 179:76abe6d681ea |
---|---|
11 | 11 |
12 | 12 |
13 mimetypes.add_type('application/x-gzip', '.tgz') | 13 mimetypes.add_type('application/x-gzip', '.tgz') |
14 mimetypes.add_type('application/x-bzip2', '.tz2') | 14 mimetypes.add_type('application/x-bzip2', '.tz2') |
15 archive_extensions = ('.zip', '.tgz', '.tar', '.tz2') | 15 archive_extensions = ('.zip', '.tgz', '.tar', '.tz2') |
16 text_mimetypes = ( | |
17 'application/xml', | |
18 ) | |
16 | 19 |
17 | 20 |
18 def process_files_in_dir(bundle, dir_name, parent_dir): | 21 def process_files_in_dir(bundle, dir_name, parent_dir): |
19 """ | 22 """ |
20 Go through all the subdirectories and files (in that order) in this | 23 Go through all the subdirectories and files (in that order) in this |
37 bundle_file.is_dir = False | 40 bundle_file.is_dir = False |
38 bundle_file.file_size = os.path.getsize(file_path) | 41 bundle_file.file_size = os.path.getsize(file_path) |
39 | 42 |
40 # Only highlight the file contents if it's plain text | 43 # Only highlight the file contents if it's plain text |
41 mime_type = magic.from_file(file_path, mime=True) | 44 mime_type = magic.from_file(file_path, mime=True) |
42 if mime_type.startswith('text/'): | 45 if mime_type.startswith('text/') or mime_type in text_mimetypes: |
43 with open(file_path, 'rt') as file: | 46 with open(file_path, 'rt') as file: |
44 # Store the contents of the file in the code field | 47 # Store the contents of the file in the code field |
45 bundle_file.save_file_contents(file) | 48 bundle_file.save_file_contents(file) |
46 | 49 |
47 bundle_file.save() | 50 bundle_file.save() |