Merge branch 'master' into senslab2
[sfa.git] / sfa / client / sfi.py
index af701b9..e837270 100644 (file)
@@ -13,6 +13,7 @@ import datetime
 import codecs
 import pickle
 import json
+import shutil
 from lxml import etree
 from StringIO import StringIO
 from optparse import OptionParser
@@ -528,39 +529,35 @@ class Sfi:
 
         return
     
-    def upgrade_config(self, config_file):
-        """
-        upgrade from shell to ini format
-        """
-        fp, fn = mkstemp(suffix='sfi_config', text=True)
-        try:
-            tmp_config = Config(fn)
-            tmp_config.add_section('sfi')
-            tmp_config.load(config_file)
-            tmp_config.save(config_file)
-        except:
-            raise
-        finally:
-            os.unlink(fn)
-        
-        
     ####################
     def read_config(self):
         config_file = os.path.join(self.options.sfi_dir,"sfi_config")
+        shell_config_file  = os.path.join(self.options.sfi_dir,"sfi_config.sh")
         try:
-           config = Config (config_file)
+            if Config.is_ini(config_file):
+                config = Config (config_file)
+            else:
+                # try upgrading from shell config format
+                fp, fn = mkstemp(suffix='sfi_config', text=True)  
+                config = Config(fn)
+                # we need to preload the sections we want parsed 
+                # from the shell config
+                config.add_section('sfi')
+                config.add_section('sface')
+                config.load(config_file)
+                # back up old config
+                shutil.move(config_file, shell_config_file)
+                # write new config
+                config.save(config_file)
+                 
         except:
-            try:
-                # try upgrading from old config format
-                self.upgrade_config(config_file) 
-            except:
-               self.logger.critical("Failed to read configuration file %s"%config_file)
-               self.logger.info("Make sure to remove the export clauses and to add quotes")
-               if self.options.verbose==0:
-                   self.logger.info("Re-run with -v for more details")
-               else:
-                   self.logger.log_exc("Could not read config file %s"%config_file)
-               sys.exit(1)
+            self.logger.critical("Failed to read configuration file %s"%config_file)
+            self.logger.info("Make sure to remove the export clauses and to add quotes")
+            if self.options.verbose==0:
+                self.logger.info("Re-run with -v for more details")
+            else:
+                self.logger.log_exc("Could not read config file %s"%config_file)
+            sys.exit(1)
      
         errors = 0
         # Set SliceMgr URL
@@ -640,7 +637,7 @@ class Sfi:
             if not os.path.isfile(client_bootstrap.private_key_filename()):
                 self.logger.info ("private key not found, trying legacy name")
                 try:
-                    legacy_private_key = os.path.join (self.options.sfi_dir, "%s.pkey"%get_leaf(self.user))
+                    legacy_private_key = os.path.join (self.options.sfi_dir, "%s.pkey"%Xrn.unescape(get_leaf(self.user)))
                     self.logger.debug("legacy_private_key=%s"%legacy_private_key)
                     client_bootstrap.init_private_key_if_missing (legacy_private_key)
                     self.logger.info("Copied private key from legacy location %s"%legacy_private_key)
@@ -1113,6 +1110,7 @@ or with an slice hrn, shows currently provisioned resources
                 rspec.filter({'component_manager_id': server_version['urn']})
                 rspec = RSpecConverter.to_pg_rspec(rspec.toxml(), content_type='request')
             else:
+                print >>sys.stderr, "\r\n \r\n \r\n WOOOOOO"
                 users = sfa_users_arg(user_records, slice_record)
 
         # do not append users, keys, or slice tags. Anything