X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=bin%2Fappliskel%2Fupdate_catalogs.py;h=e9981d662fcae5d72f454139802af87a0ae8aa68;hb=3e8cb819ece8ab264fe0c8d6d970387d2bfeb755;hp=ce54f8c4aa9bce6426a545c38a5658f797003fa3;hpb=703cf8ca778de35a6b463d4b4fca7c36697d717f;p=modules%2Fkernel.git diff --git a/bin/appliskel/update_catalogs.py b/bin/appliskel/update_catalogs.py index ce54f8c4a..e9981d662 100644 --- a/bin/appliskel/update_catalogs.py +++ b/bin/appliskel/update_catalogs.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE # # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -25,13 +25,14 @@ """ """ import sys,os,shutil,glob,socket -import optparse +import argparse +from salome_utils import getUserName import getAppliPath appli_local=os.path.realpath(os.path.dirname(__file__)) APPLI=getAppliPath.relpath(appli_local,os.path.realpath(os.getenv('HOME'))) -usage="""usage: %prog [options] +usage="""%(prog)s [options] Typical use is: python update_catalogs.py @@ -116,7 +117,7 @@ class Resource: def get_user(self): userName= self.node.get("userName") if not userName: - userName=os.getenv('USER') + userName=getUserName() return userName def get_host(self): @@ -143,7 +144,7 @@ class Resource: resource_dir=os.path.join(cata_dir,self.get_name()) - if hostname == "localhost" or hostname == get_hostname() and userName == os.getenv("USER"): + if hostname == "localhost" or hostname == get_hostname() and userName == getUserName(): #local machine, use cp if appliPath[0]!='/': #relative path @@ -154,11 +155,11 @@ class Resource: os.mkdir(resource_dir) cata_path=os.path.join(appliPath,"share","salome","resources","*Catalog.xml") cmd="cp %s %s" % (cata_path,resource_dir) - print cmd + print(cmd) os.system(cmd) cata_path=os.path.join(appliPath,"share","salome","resources","*","*Catalog.xml") cmd="cp %s %s" % (cata_path,resource_dir) - print cmd + print(cmd) os.system(cmd) else: #remote machine, use rcopy @@ -166,12 +167,12 @@ class Resource: cata_path=os.path.join(appliPath,"share","salome","resources","*Catalog.xml") cmd="%s %s@%s:%s %s" cmd= cmd%(rcopy,userName,hostname,cata_path,resource_dir) - print cmd + print(cmd) os.system(cmd) cata_path=os.path.join(appliPath,"share","salome","resources","*","*Catalog.xml") cmd="%s %s@%s:%s %s" cmd= cmd%(rcopy,userName,hostname,cata_path,resource_dir) - print cmd + print(cmd) os.system(cmd) schema_cata=os.path.join(resource_dir,"*SchemaCatalog.xml") @@ -187,7 +188,7 @@ class Resource: resource_dir=os.path.join(cata_dir,self.get_name()) catalogs_list=glob.glob(os.path.join(resource_dir,"*Catalog.xml")) - if hostname == "localhost" or hostname == get_hostname() and userName == os.getenv("USER"): + if hostname == "localhost" or hostname == get_hostname() and userName == getUserName(): #user local resource if appliPath[0]!='/': appliPath=os.path.join(os.getenv("HOME"),appliPath) @@ -206,12 +207,11 @@ class Resource: def main(): - parser = optparse.OptionParser(usage=usage) - - options, args = parser.parse_args() + parser = argparse.ArgumentParser(usage=usage) + args = parser.parse_args() if not os.path.exists(catalog_file_base): - print "ERROR: the base catalog file %s is mandatory" % catalog_file_base + print("ERROR: the base catalog file %s is mandatory" % catalog_file_base) sys.exit(1) #Parse CatalogResource.xml @@ -250,12 +250,11 @@ def main(): mach.update() #dump new CatalogResources.xml - f=open(catalog_file,'w') - f.write('\n') - doc.write(f) - f.write('\n') - f.close() - print "%s updated" % catalog_file + with open(catalog_file,'w') as f: + f.write('\n') + doc.write(f) + f.write('\n') + print("%s updated" % catalog_file) #update configRemote.sh in env.d directory (environment variable SALOME_CATALOGS_PATH) path=[] @@ -263,9 +262,8 @@ def main(): if mach.resource_dir: path.append(mach.resource_dir) - f=open(os.path.join(appli_local,"env.d","configRemote.sh"),'w') - f.write("export SALOME_CATALOGS_PATH=%s\n" % SEP.join(path)) - f.close() + with open(os.path.join(appli_local,"env.d","configRemote.sh"),'w') as f: + f.write("export SALOME_CATALOGS_PATH=%s\n" % SEP.join(path)) if __name__ == '__main__':