Browse code

Warn if requests module is not present

S3/Crypto.py now requires the requests module, which often isn't
present. Throw an error if it's not, with instructions for how to
install it.

Matt Domsch authored on 2014/12/17 01:15:47
Showing 2 changed files
... ...
@@ -13,8 +13,27 @@ from logging import debug
13 13
 
14 14
 import os
15 15
 import datetime
16
-import requests
17 16
 import urllib
17
+from ExitCodes import EX_OSFILE
18
+
19
+try:
20
+    import requests
21
+except ImportError:
22
+    sys.stderr.write(u"""
23
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
24
+ImportError trying to import requests
25
+Please install the python requests module:
26
+$ sudo apt-get install python-requests
27
+  or
28
+$ sudo yum install python-requests
29
+  or
30
+$ sudo pacman -S python2-requests
31
+  or
32
+$ pip install requests
33
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34
+""")
35
+    sys.stderr.flush()
36
+    sys.exit(EX_OSFILE)
18 37
 
19 38
 # hashlib backported to python 2.4 / 2.5 is not compatible with hmac!
20 39
 if sys.version_info[0] == 2 and sys.version_info[1] < 6:
... ...
@@ -75,7 +75,7 @@ Authors:
75 75
 --------
76 76
     Michal Ludvig  <michal@logix.cz>
77 77
 """ % (S3.PkgInfo.long_description),
78
-    requires=["dateutil"]
78
+    requires=["dateutil", "requests"]
79 79
     )
80 80
 
81 81
 # vim:et:ts=4:sts=4:ai