Browse code

Added option --no-mime-magic to disable mime magic, bug #198

radomir authored on 2013/09/02 18:22:24
Showing 4 changed files
... ...
@@ -75,6 +75,7 @@ class Config(object):
75 75
     bucket_location = "US"
76 76
     default_mime_type = "binary/octet-stream"
77 77
     guess_mime_type = True
78
+    use_mime_magic = True
78 79
     mime_type = ""
79 80
     enable_multipart = True
80 81
     multipart_chunk_size_mb = 15    # MB
... ...
@@ -408,7 +408,7 @@ class S3(object):
408 408
         content_type = self.config.mime_type
409 409
         content_encoding = None
410 410
         if filename != "-" and not content_type and self.config.guess_mime_type:
411
-            (content_type, content_encoding) = mime_magic(filename)
411
+            (content_type, content_encoding) = mime_magic(filename) if self.config.use_mime_magic else mimetypes.guess_type(filename)
412 412
         if not content_type:
413 413
             content_type = self.config.default_mime_type
414 414
 
... ...
@@ -1863,6 +1863,7 @@ def main():
1863 1863
     optparser.add_option(      "--default-mime-type", dest="default_mime_type", action="store_true", help="Default MIME-type for stored objects. Application default is binary/octet-stream.")
1864 1864
     optparser.add_option("-M", "--guess-mime-type", dest="guess_mime_type", action="store_true", help="Guess MIME-type of files by their extension or mime magic. Fall back to default MIME-Type as specified by --default-mime-type option")
1865 1865
     optparser.add_option(      "--no-guess-mime-type", dest="guess_mime_type", action="store_false", help="Don't guess MIME-type and use the default type instead.")
1866
+    optparser.add_option(      "--no-mime-magic", dest="use_mime_magic", action="store_false", help="Don't use mime magic when guessing MIME-type.")
1866 1867
     optparser.add_option("-m", "--mime-type", dest="mime_type", type="mimetype", metavar="MIME/TYPE", help="Force MIME-type. Override both --default-mime-type and --guess-mime-type.")
1867 1868
 
1868 1869
     optparser.add_option(      "--add-header", dest="add_header", action="append", metavar="NAME:VALUE", help="Add a given HTTP header to the upload request. Can be used multiple times. For instance set 'Expires' or 'Cache-Control' headers (or both) using this options if you like.")
... ...
@@ -253,6 +253,9 @@ Guess MIME-type of files by their extension or mime magic. Fall back to default
253 253
 \fB\-\-no\-guess\-mime\-type\fR
254 254
 Don't guess MIME-type and use the default type instead.
255 255
 .TP
256
+\fB\-\-no\-mime\-magic\fR
257
+Don't use mime magic when guessing MIME-type.
258
+.TP
256 259
 \fB\-m\fR MIME/TYPE, \fB\-\-mime\-type\fR=MIME/TYPE
257 260
 Force MIME-type. Override both \fB--default-mime-type\fR and \fB--guess-mime-type\fR.
258 261
 .TP