Improved code slashing code

This commit is contained in:
Daniel Dayley 2021-11-02 21:53:01 -06:00
parent 3fa4d28040
commit e64ebbbdc4
2 changed files with 13 additions and 10 deletions

View File

@ -18,7 +18,7 @@ if __name__ == '__main__':
# Gather Argument options # Gather Argument options
EXAMPLE_TEXT='Example:\n\tpython-tool -h' EXAMPLE_TEXT='Example:\n\tpython-tool -h'
parser = argparse.ArgumentParser(epilog=EXAMPLE_TEXT,formatter_class=argparse.RawDescriptionHelpFormatter) parser = argparse.ArgumentParser(epilog=EXAMPLE_TEXT,formatter_class=argparse.RawDescriptionHelpFormatter)
##config_parser.add_argument('-c', '--config', action='store', help='Specify a config file (~/.config/python-tool.yml)',default='~/.config/python-tool.yml') ##CONFIG_parser.add_argument('-c', '--config', action='store', help='Specify a config file (~/.config/python-tool.yml)',default='~/.config/python-tool.yml')
parser.add_argument('-H', '--hosts', action='append', default=None, help='Collects arguments in an array.') parser.add_argument('-H', '--hosts', action='append', default=None, help='Collects arguments in an array.')
parser.add_argument('-d', '--dry-run', action='store_true', help='Store the existence of a variable.') parser.add_argument('-d', '--dry-run', action='store_true', help='Store the existence of a variable.')
parser.add_argument('-l', '--log', action='store', help='Specify a file to log to.') parser.add_argument('-l', '--log', action='store', help='Specify a file to log to.')
@ -32,12 +32,15 @@ if __name__ == '__main__':
if args.log : if args.log :
logging.basicConfig(level=logging.INFO,filename=args.log) logging.basicConfig(level=logging.INFO,filename=args.log)
# Parse config ##CONFIG_# Parse config
config_path = os.path.normpath(args.config) ##CONFIG_try :
file_descriptor = open(os.path.normpath(os.path.expanduser(os.path.expandvars(config_path)))) ##CONFIG_ config_path = os.path.normpath(args.config)
config = yaml.safe_load(file_descriptor) ##CONFIG_ file_descriptor = open(os.path.normpath(os.path.expanduser(os.path.expandvars(config_path))))
if not isinstance(config,dict) : ##CONFIG_ config = yaml.safe_load(file_descriptor)
raise ValueError('expected dictonary as top-level yaml object') ##CONFIG_ if not isinstance(config,dict) :
##CONFIG_ raise ValueError('expected dictonary as top-level yaml object')
##CONFIG_except Exception as e :
##CONFIG_ debug("Unable to parse config: " + str(e),0)
# Main functions # Main functions
print('Hello World!') print('Hello World!')

View File

@ -79,6 +79,7 @@ new_python_tool() {
# Record setup instructions # Record setup instructions
declare -a PYTHON_TOOL_SETUP_INSTRUCTIONS declare -a PYTHON_TOOL_SETUP_INSTRUCTIONS
declare -a PYTHON_TOOL_WARNINGS
# Describe the project # Describe the project
echo "Describe the project: " echo "Describe the project: "
@ -147,10 +148,9 @@ new_python_tool() {
done done
if [ "$INSTALL_CONFIG" == 'y' ]; then if [ "$INSTALL_CONFIG" == 'y' ]; then
sed_i "s#INSTALL=\"\(.*\)\"#INSTALL=\"\1config \"#g" ./"$NAME"/setup.sh sed_i "s#INSTALL=\"\(.*\)\"#INSTALL=\"\1config \"#g" ./"$NAME"/setup.sh
sed_i "s/.*##config_\(parser.*\)/\1/g" ./"$NAME"/bin/"$NAME" sed_i "s/.*##CONFIG_\(.*\)/\1/g" ./"$NAME"/bin/"$NAME"
##config_parser
else else
sed_i "s/.*##config_\(parser.*\)//g" ./"$NAME"/bin/"$NAME" sed_i "s/.*##CONFIG_\(.*\)//g" ./"$NAME"/bin/"$NAME"
rm ./"$NAME"/config.yml rm ./"$NAME"/config.yml
fi fi