Skip to content

Commit

Permalink
WIP: Finish command-line tool to replace in file (TriBITSPub#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlettroscoe committed Jun 16, 2021
1 parent 8e869a2 commit cb2f1a5
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions tribits/python_utils/lower_case_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

import sys
import os
import re


Expand Down Expand Up @@ -63,26 +64,40 @@ def makeRegexMatchesLowerCaseInCMakeStr(cmakeCodeStrIn, regex):

usageHelp = r"""
Convert the cmake command calls to lower case and the macro and function names
to lower case in a given file.
Convert the cmake command calls to lower case and macro and function names
in defintions to lower case in a given file.
"""


def getCmndLineOptions():
from argparse import ArgumentParser, RawDescriptionHelpFormatter
clp = ArgumentParser(description=usageHelp,
formatter_class=RawDescriptionHelpFormatter)
clp.add_argument("file", nargs='?', default="",
help="The file to operate on" )
clp.add_argument("file",
help="The file to lower-case the CMake commands within." )
options = clp.parse_args(sys.argv[1:])
return options


def validateCmndLineOptions(inOptions):
if not os.path.exists(inOptions.file):
print("Error, the file '"+inOptions.file+"' does not exist!")
sys.exit(1)


def lowerCaseCMakeCodeInFile(inOptions):
with open(inOptions.file, 'r') as fileHandle:
cmakeStrOrig = fileHandle.read()
cmakeStrLowerCased = makeCmndsLowerCaseInCMakeStr(cmakeStrOrig)
with open(inOptions.file, 'w') as fileHandle:
fileHandle.write(cmakeStrLowerCased)

#
# main()
#


if __name__ == '__main__':
inOptions = getCmndLineOptions()


validateCmndLineOptions(inOptions)
lowerCaseCMakeCodeInFile(inOptions)

0 comments on commit cb2f1a5

Please sign in to comment.