Salome HOME
updated copyright message
[modules/kernel.git] / salome_adm / prepare_generating_doc.py
index dbe0153e75ef44f2336b684e9224c4b91d699d12..8a6073a377cd188dc180b914d6ecf94472afaa9b 100755 (executable)
@@ -1,5 +1,5 @@
-#!/usr/bin/env python
-# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+#!/usr/bin/env python3
+# Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # Current the script does:
 # 1. remove Python documentation in triple double quotes (like """some_comments""")
 #
-# Usage: prepare_generating_doc.py [-o <output_file>] <input_file> 
+# Usage: prepare_generating_doc.py [-o <output_file>] <input_file>
 #
 # If <output_file> is not specified, it is generated in the current directory.
 #
-#################################################################################
+###############################################################################
 
-import os, sys, re
+import os, sys
 
 def main(input_file, output_file = None):
-    
+
     # open input file
     try:
         infile = open(input_file, 'rb')
-    except:
+    except Exception:
         sys.exit("File %s is not found" % input_file)
         pass
 
     if not output_file: output_file = os.path.basename(input_file)
-    
+
     # open output file
     try:
         outfile = open(output_file, 'wb')
-    except:
+    except Exception:
         sys.exit("File %s cannot be opened for write" % output_file)
         pass
 
@@ -65,8 +65,8 @@ def main(input_file, output_file = None):
 
     for line in infile.readlines():
         # 1. remove comments like """some_comments"""
-        n = line.find('"""')
-        n1 = line[(n+2):].find('"""')
+        n = line.find(b'"""')
+        n1 = line[(n+2):].find(b'"""')
         if (n > -1) and (n1 > -1):
             continue
         if isCom:
@@ -92,14 +92,13 @@ def main(input_file, output_file = None):
     pass
 
 if __name__ == "__main__":
-    import optparse
-    parser = optparse.OptionParser(usage="%prog [options] input_file")
+    import argparse
+    parser = argparse.ArgumentParser()
     h  = "Output file (if not specified, generated in the current directory)"
-    parser.add_option("-o", "--output", dest="output",
-                      action="store", default=None, metavar="file",
-                      help=h)
-    (options, args) = parser.parse_args()
-
-    if len( args ) < 1: sys.exit("Input file is not specified")
-    main( args[0], options.output )
+    parser.add_argument("-o", "--output", dest="output",
+                        action="store", default=None, metavar="file",
+                        help=h)
+    parser.add_argument('input_file')
+    args = parser.parse_args()
+    main( args.input_file, args.output )
     pass