Browse code

Print a proper error for missing dateutil module

Catch the failure to import dateutil where it happens,
not later in s3cmd's ImportError handler. As this is a new
dependency, many people don't have it installed already.

Without this, the s3cmd ImportError handler (invoked because the
import in S3/Utils.py of dateutil fails), throws another uncaught
exception when invoking
s = u' '.join([unicodise(a) for a in sys.argv])
because unicodeise() came from S3/Utils.py which, as just noted,
failed to import.

Matt Domsch authored on 2014/03/28 11:29:30
Showing 1 changed files
... ...
@@ -16,11 +16,24 @@ import hmac
16 16
 import base64
17 17
 import errno
18 18
 import urllib
19
-import dateutil.parser
20 19
 from calendar import timegm
21
-
22 20
 from logging import debug, info, warning, error
23
-
21
+try:
22
+    import dateutil.parser
23
+except ImportError:
24
+    sys.stderr.write(u"""
25
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
26
+ImportError trying to import dateutil.parser.
27
+Please install the python dateutil module:
28
+$ sudo apt-get install python-dateutil
29
+  or
30
+$ sudo yum install python-dateutil
31
+  or
32
+$ pip install python-dateutil
33
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34
+""")
35
+    sys.stderr.flush()
36
+    sys.exit(1)
24 37
 
25 38
 import Config
26 39
 import Exceptions