#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2013 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
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
"""
"""
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
def get_user(self):
userName= self.node.get("userName")
if not userName:
- userName=os.getenv('USER')
+ userName=getUserName()
return userName
def get_host(self):
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
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
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")
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)
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
mach.update()
#dump new CatalogResources.xml
- f=open(catalog_file,'w')
- f.write('<?xml version="1.0" ?>\n')
- doc.write(f)
- f.write('\n')
- f.close()
- print "%s updated" % catalog_file
+ with open(catalog_file,'w') as f:
+ f.write('<?xml version="1.0" ?>\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=[]
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__':