Salome HOME
Compilation under Windows: add missing header
[modules/kernel.git] / bin / appliskel / update_catalogs.py
old mode 100644 (file)
new mode 100755 (executable)
index 8555e0c..d2be159
@@ -1,6 +1,6 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #  -*- coding: utf-8 -*-
-# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2021  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
 """
 """
 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')))
+APPLI=getAppliPath.relpath(appli_local,os.path.realpath(os.path.expanduser("~")))
 
-usage="""usage: %prog [options]
+usage="""%(prog)s [options]
 Typical use is:
   python update_catalogs.py
 
@@ -148,7 +148,7 @@ class Resource:
       #local machine, use cp
       if appliPath[0]!='/':
         #relative path
-        appliPath=os.path.join(os.getenv("HOME"),appliPath)
+        appliPath=os.path.join(os.path.expanduser("~"),appliPath)
 
       if appliPath == appli_local:
         return
@@ -191,7 +191,7 @@ class Resource:
     if hostname == "localhost" or hostname == get_hostname() and userName == getUserName():
       #user local resource
       if appliPath[0]!='/':
-        appliPath=os.path.join(os.getenv("HOME"),appliPath)
+        appliPath=os.path.join(os.path.expanduser("~"),appliPath)
       if appliPath == appli_local:
         #main local resource: get catalogs in share/salome/resources
         catalogs_list=glob.glob(os.path.join(appliPath,"share","salome","resources","*","*Catalog.xml"))
@@ -207,9 +207,8 @@ 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)
@@ -251,11 +250,10 @@ def main():
     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()
+  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)
@@ -264,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__':