# We do all our imports at the top of our program. import argparse import datetime import os import sys import subprocess import ConsoleUtils # Give the program a name. program_name = 'ScoreWalkerBuild' # Describe what the program does beiefly. program_description = 'A Script for Building ScoreWalker.' # The argument parser for the program. parser = argparse.ArgumentParser(prog=program_name, description=program_description, add_help=False) build_date = datetime.datetime.now().strftime('%Y.%m.%d-%H.%M.%S') program_version = '1.0.0' program_author = 'Sequence Logic LLC' printer = ConsoleUtils.SLPrinter(program_name) sys.stdout = printer dependencies = ['dtcore', 'dtcs', 'dtdb'] mvn_clean = '' mvn_install = '' out_path = '' workspace = '' def set_up_env(): global workspace, mvn_clean, mvn_install # Create some maven commands workspace = os.environ['WORKSPACE'] mvn_repo = os.path.join(workspace, '.m2') mvn_clean = 'mvn -Dmaven.repo.local=%s clean' % mvn_repo # Set the output directory branch_name = os.environ['BRANCH_NAME'] build_time_stamp = os.environ['BUILD_TIMESTAMP'] out_path = os.path.join(branch_name, build_time_stamp) def build_dependencies(): for dep in dependencies: os.chdir(os.path.join(workspace)) subprocess.Popen() # This is the main function of the program. def main(arg): print('Required argument = %s' % arg) def check_args(arg1, arg2): fatal_errors = False # We only exit if a required argument was bad, we can handle optional arguments. if fatal_errors: parser.print_help() print('Exiting...') exit(0) # Prints the argument values passed in. def show_args(arg1, arg2): # print the arguments with a brief summation of what they mean. print('Value of Argument 1: %s' % arg1) print('Value of Argument 2: %s' % arg2) # Set up arguments here; more groups can be made if required. def make_args(): # A group for required arguments required_args = parser.add_argument_group('Required') # A group for optional arguments optional_args = parser.add_argument_group('Optional') # All arguments in required_args have required=True required_args.add_argument('-r', '--argument1', required=True, help='A required argument.') # All arguments in optional_args have required=False optional_args.add_argument('-o', '--argument2', required=False, help='An optional argument.') # The help method is added here so it appears in the same group as the other arguments. optional_args.add_argument('-h', '--help', action="help", help='Prints the help message.') # This is where we call the main method from. if __name__ == '__main__': printer.write_no_prefix(ConsoleUtils.get_header(program_name, program_version, build_date, )) make_args() # Get the arguments, we don't need to do a check for required arguments, since the ArgumentParser class does that # for us already in the 'parse_args' method. We can do custom argument checks in our 'check_args' method. args = parser.parse_args() # Get the argument. some_arg_string = args.argument1 some_opt_string = args.argument2 # Do an argument check. check_args(some_arg_string, some_opt_string) # Now we can run... main(some_arg_string)