changeset 437:765255e9cc92

Continue without "remember" feature if the necessary imports fail
author Chris Cannam
date Tue, 28 Jun 2011 13:44:00 +0100
parents b7a740eef696
children a5696a1f2dc5
files easyhg2.py
diffstat 1 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/easyhg2.py	Tue Jun 28 13:27:05 2011 +0100
+++ b/easyhg2.py	Tue Jun 28 13:44:00 2011 +0100
@@ -50,14 +50,15 @@
     from PyQt4 import Qt, QtGui
 except ImportError:
     easyhg_pyqt_ok = False
-
 easyhg_qtapp = None
 
-#!!! same as above for this? or just continue without remember feature?
-from Crypto.Cipher import AES
-import base64
-
-import ConfigParser # Mercurial version won't write files
+easyhg_authfile_imports_ok = True
+try:
+    from Crypto.Cipher import AES
+    import ConfigParser # Mercurial version won't write files
+    import base64
+except ImportError:
+    easyhg_authfile_imports_ok = False
 
 #!!! should be in a class here
 
@@ -166,11 +167,14 @@
 
     uri = canonical_url(authuri)
 
-    pkey = base64.b64encode('%s@@%s' % (uri, user)).replace('=', '_')
+    pkey = None
     pekey = self.ui.config('easyhg', 'authkey')
     pfile = self.ui.config('easyhg', 'authfile')
-    use_authfile = (pekey and pfile)
-    if pfile: pfile = os.path.expanduser(pfile)
+    use_authfile = (easyhg_authfile_imports_ok and pekey and pfile)
+    if use_authfile:
+        pkey = base64.b64encode('%s@@%s' % (uri, user)).replace('=', '_')
+    if pfile:
+        pfile = os.path.expanduser(pfile)
     pdata = None
 
     self.ui.write("pekey is %s\n" % pekey)