def main(): parser = ArgParser(usage) parser.add_argument( "module_name", type=str, default="", help="name of module to checkout") args = parser.parse_args() # if len(args) != 1: >>> argparse can't run if args not given <<< # parser.error("Incorrect number of arguments.") module = args.module # import svn client from dls_environment.svn import svnClient svn = svnClient() if args.area == "ioc": assert len(module.split('/')) > 1, 'Missing Technical Area under Beamline' vendor = gitf.vendorModule(module, args.area) vendor_current = os.path.join(vendor, "current") svn.setLogMessage('Searching vendor module branch for last import to "current"') for node in svn.ls(vendor): tt = os.path.join(vendor, os.path.basename(node['name'])) if os.path.basename(node['name']) != "current": diffs = svn.diff('/tmp', vendor_current, svn.Revision(svn.opt_revision_kind.head), tt, svn.Revision(svn.opt_revision_kind.head), True, True, True) if not diffs: print os.path.basename(node['name']) break
class ArgParserParseArgsTest(unittest.TestCase): def setUp(self): self.parser = ArgParser("") def test_given_dash_i_in_args_then_area_is_ioc(self): args = self.parser.parse_args("-i".split()) self.assertEqual(args.area, "ioc") def test_given_double_dash_ioc_in_args_then_area_is_ioc(self): args = self.parser.parse_args("--ioc".split()) self.assertEqual(args.area, "ioc") def test_given_dash_p_in_args_then_area_is_python(self): args = self.parser.parse_args("-p".split()) self.assertEqual(args.area, "python") def test_given_double_dash_python_in_args_then_area_is_python(self): args = self.parser.parse_args("--python".split()) self.assertEqual(args.area, "python") def test_given_double_dash_python3_in_args_then_area_is_python3(self): args = self.parser.parse_args("--python3".split()) self.assertEqual(args.area, "python3")
class AddEpicsVersionTest(unittest.TestCase): def setUp(self): self.parser = ArgParser("") self.parser.add_epics_version_flag() def test_epics_argument_has_correct_attributes(self): option = self.parser._option_string_actions['-e'] self.assertIsInstance(option, _StoreAction) self.assertEqual(option.dest, "epics_version") self.assertIn("--epics_version", option.option_strings)
class AddGitTest(unittest.TestCase): def setUp(self): self.parser = ArgParser("") self.parser.add_git_flag() def test_git_option_has_correct_attributes(self): option = self.parser._option_string_actions['-g'] self.assertIsInstance(option, _StoreTrueAction) self.assertEqual(option.dest, "git") self.assertIn("--git", option.option_strings)
class AddReleaseTest(unittest.TestCase): def setUp(self): self.parser = ArgParser("") self.parser.add_release_arg() def test_release_has_correct_attributes(self): arguments = self.parser._positionals._actions[4] self.assertEqual(arguments.type, str) self.assertEqual(arguments.dest, 'release')
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * module_name * release Flags: * -u: `untar` * -e: `epics_version` Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ parser = ArgParser(usage) parser.add_module_name_arg() parser.add_release_arg() parser.add_epics_version_flag() parser.add_argument( "-u", "--untar", action="store_true", dest="untar", help="Untar archive created with dls-archive-module.py") return parser
class AddBranchTest(unittest.TestCase): def setUp(self): self.parser = ArgParser("") self.parser.add_branch_flag() def test_branch_argument_has_correct_attributes(self): option = self.parser._option_string_actions['-b'] self.assertIsInstance(option, _StoreAction) self.assertEqual(option.type, str) self.assertEqual(option.dest, "branch") self.assertIn("--branch", option.option_strings)
def make_parser(): """ Takes default parser arguments and adds module_name Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ parser = ArgParser(usage) parser.add_module_name_arg() return parser
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * module_name Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ parser = ArgParser(usage) parser.add_module_name_arg() return parser
def make_parser(): """ Takes ArgParse instance with default arguments and adds Flags: * -d (domain) :class:`argparse.ArgumentParser` Returns: :class:`argparse.ArgumentParser`: Parser instance """ parser = ArgParser(usage) parser.add_argument("domain_name", nargs="?", type=str, help="domain of ioc to list") return parser
class AddReleaseTest(unittest.TestCase): def setUp(self): self.parser = ArgParser("") def test_arg_parser_quits_if_release_not_added_and_release_provided(self): try: self.parser.parse_args("-p 0-1".split()) self.fail("Parser should have quit.") except SystemExit: pass def test_arg_parser_parses_release_correctly(self): self.parser.add_release_arg() args = self.parser.parse_args("-p 0-1".split()) self.assertEqual(args.release, "0-1")
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * module_name Flags: * -n (no-import) * -f (fullname) Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ supported_areas = ["support", "ioc", "python", "tools"] parser = ArgParser(usage, supported_areas) parser.add_module_name_arg() parser.add_argument( "-n", "--no-import", action="store_true", dest="no_import", help="Creates the module but doesn't store it on the server", ) parser.add_argument( "-f", "--fullname", action="store_true", dest="fullname", help="create new-style ioc, with full ioc name in path", ) return parser
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * module_name Flags: * -b (branch) Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ parser = ArgParser(usage) parser.add_branch_flag( help_msg="Checkout a specific named branch rather than the default (master)") parser.add_argument("module_name", nargs="?", type=str, default="", help="Name of module") return parser
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * module_name Flags: * -b (branch) Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ parser = ArgParser(usage) parser.add_branch_flag( help_msg="Checkout a specific named branch rather than the default" " (master)") parser.add_argument("module_name", nargs="?", type=str, default="", help="Name of module") return parser
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * module_name Flags: * -n (no-import) * -f (fullname) Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ supported_areas = ["support", "ioc", "python", "python3", "tools"] parser = ArgParser(usage, supported_areas) parser.add_module_name_arg() parser.formatter_class = argparse.RawDescriptionHelpFormatter # The following arguments cannot be used together group = parser.add_mutually_exclusive_group() group.add_argument( "-n", "--no-import", action="store_true", dest="no_import", help="Creates the module but doesn't store it on the server") group.add_argument( "-e", "--empty", action="store_true", dest="empty", help="Initialize an empty remote repository on the server. Does not " "create a local repo nor commit any files.") parser.add_argument( "-q", "--ignore_existing", action="store_true", dest="ignore_existing", help="When used together with -e/--empty, this script will exit " "silently with success if a repository with the given name " "already exists on the server.") return parser
class ArgParserParseArgsTest(unittest.TestCase): def setUp(self): self.parser = ArgParser("") def test_given_dash_i_in_args_then_area_is_ioc(self): args = self.parser.parse_args("-i".split()) self.assertEqual(args.area, "ioc") def test_given_double_dash_ioc_in_args_then_area_is_ioc(self): args = self.parser.parse_args("--ioc".split()) self.assertEqual(args.area, "ioc") def test_given_dash_p_in_args_then_area_is_python(self): args = self.parser.parse_args("-p".split()) self.assertEqual(args.area, "python") def test_given_double_dash_python_in_args_then_area_is_python(self): args = self.parser.parse_args("--python".split()) self.assertEqual(args.area, "python")
def make_parser(): parser = ArgParser(usage) parser.add_argument( "source", type=str, default=None, help="name of module to release") parser.add_argument( "module_name", type=str, default=None, help="name of module to release") parser.add_argument( "release", type=str, default=None, help="release number of module to release") return parser
def make_parser(): parser = ArgParser(usage) parser.add_argument( "module_name", type=str, default=None, help="name of module to branch") # >>> Doesn't nee release number? parser.add_argument( "release", type=str, default=None, help="release number of module to branch") parser.add_argument( "branch_name", type=str, default=None, help="name of new module branch") return parser
def setUp(self): self.parser = ArgParser("") self.parser.add_epics_version_flag()
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * module_name * release Flags: * -b (branch) * -f (force) * -t (no-test-build) * -l (local-build-only) * -e (epics_version) * -T (test_build_only * -m (message) * -n (next_version) * -r (rhel_version) or --w (windows arguments) * -g (redundant_argument) * -c (commit) Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ parser = ArgParser(usage) parser.add_module_name_arg() parser.add_release_arg(optional=True) parser.add_branch_flag(help_msg="Release from a branch") parser.add_epics_version_flag( help_msg="Change the EPICS version. This will determine which build " "server your job is built on for EPICS modules. Default is " "from your environment") parser.add_argument( "-f", "--force", action="store_true", dest="force", default=None, help="Force a release. If the release exists in prod it is removed " "(otherwise in this case the default behaviour is to rebuild " "the existing release). Overrides some sanity checks and is " "therefore to be used with caution.") parser.add_argument("-t", "--no-test-build", action="store_true", dest="skip_test", help="If set, this will skip the local test build " "and just do a release") parser.add_argument( "-l", "--local-build-only", action="store_true", dest="local_build", help="If set, this will only do the local test build and no more.") parser.add_argument( "-T", "--test_build-only", action="store_true", dest="test_only", help="If set, this will only do a test build on the build server.") parser.add_argument( "-m", "--message", action="store", type=str, dest="message", default="", help="Add user message to the end of the default commit message. " "The message will be <module_name>: Released version <release>." "<message>") parser.add_argument( "-n", "--next_version", action="store_true", dest="next_version", help="Use the next version number as the release version") parser.add_argument( "-g", "--redundant_argument", action="store_true", dest="redundant_argument", help="Redundant argument to preserve backward compatibility") parser.add_argument( "-c", "--commit", action="store", type=str, dest="commit", help="If <release> is given, " "this option causes the tag to be created " "on the server, at the given COMMIT. The <release> is " "checked against the DLS naming convention. " "This option can also be used to execute only test builds " "at the given commit by omitting <release> and using " "either -T or -l. This avoids having to tag to do a test build.") title = "Build operating system arguments" desc = "Note: The following arguments are mutually exclusive - only use " \ "one" # Can only add description to group, so have to nest inside ordinary group desc_group = parser.add_argument_group(title=title, description=desc) group = desc_group.add_mutually_exclusive_group() group.add_argument( "-r", "--rhel_version", action="store", type=str, dest="rhel_version", help="change the rhel version of the build. This will determine which " "build server your job is build on for non-epics modules. Default " "is from /etc/redhat-release. Can be 6 or 7") group.add_argument( "-w", "--windows", action="store", dest="windows", type=str, help="Release the module or IOC only for the Windows version. " "If the module has already been released with the same version " "the build server will rebuild that release for Windows. " "Existing unix builds of the same module version will not be " "affected. If the EPICS version is different to the default " "it must be specified explicitly. Possible options are: " "32 (win32-x86, R3.14.12.3, Server 2008)," "64 (windows-x64, R3.14.12.3, Server 2008), " "64_2012 (windows-x64, R3.14.12.7, Server 2012)") return parser
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * module_name Flags: * -b (branch) * -l (latest) * -g (git) * -e (epics_version) * -r (rhel_version) Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ parser = ArgParser(usage) parser.add_module_name_arg() parser.add_epics_version_flag() parser.add_git_flag( help_msg="Print releases available in git") parser.add_argument( "-l", "--latest", action="store_true", dest="latest", help="Only print the latest release") parser.add_argument( "-r", "--rhel_version", action="store", type=int, dest="rhel_version", default=get_rhel_version(), help="Change the rhel version of the environment, default is " + get_rhel_version() + " (from your system)") return parser
def setUp(self): self.parser = ArgParser("") self.parser.add_branch_flag()
def setUp(self): self.parser = ArgParser("") self.parser.add_module_name_arg()
def setUp(self): self.parser = ArgParser("")
def make_parser(): e = environment() parser = ArgParser(usage) parser.add_argument( "module_name", type=str, help="name of module to publish") parser.add_argument( "release", type=str, help="release of module to publish") parser.add_argument( "-f", "--force", action="store_true", dest="force", help="force the publish, disable warnings") parser.add_argument( "-e", "--epics_version", action="store", type=str, dest="epics_version", help="Change the epics version. This will determine where " "the built documentation is copied from. Default is %s " "(from your environment)" % e.epicsVer()) parser.add_argument( "-r", "--rhel_version", action="store", type=int, dest="rhel_version", default=get_rhel_version(), help="change the rhel version of the " + "environment, default is " + get_rhel_version() + " (from your system)") return parser
def setUp(self): self.parser = ArgParser("") self.parser.add_release_arg()
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * modules Flags: * -c (contact) * -d (cc) * -s (csv) * -m (import) Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ parser = ArgParser(usage) parser.formatter_class = argparse.RawDescriptionHelpFormatter # nargs='*' makes <modules> an optional positional argument; a list of N # entries parser.add_argument( "modules", nargs='*', type=str, default=None, help="Name(s) of module(s) to list/set contacts for") parser.add_argument( "-c", "--contact", action="store", type=str, metavar="FED_ID", dest="contact", help="Set the contact property to FED_ID") parser.add_argument( "-d", "--cc", action="store", type=str, metavar="FED_ID", dest="cc", help="Set the cc property to FED_ID") parser.add_argument( "-s", "--csv", action="store_true", dest="csv", help="Print output as csv file") parser.add_argument( "-m", "--import", action="store", type=str, metavar="CSV_FILE", dest="imp", help="Import a CSV_FILE with header and rows of format:" + "\nModule, Contact, Contact Name, CC, CC Name") return parser
def setUp(self): self.parser = ArgParser("") self.parser.add_git_flag()
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * module_name * release Flags: * -u: `untar` * -e: `epics_version` Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ parser = ArgParser(USAGE, SUPPORTED_AREAS) parser.add_module_name_arg() parser.add_release_arg() parser.add_epics_version_flag() parser.add_rhel_version_flag() parser.add_argument("-u", "--untar", action="store_true", dest="untar", help="Untar archive created with dls-tar-module.py") return parser
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * module_name * releases Flags: * -e (earlier_release) * -l (later_release) * -v (verbose) * -r (raw) Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ parser = ArgParser(usage) parser.add_module_name_arg() parser.add_argument( "releases", nargs='*', type=str, default=None, help="Releases range to print logs for") parser.add_argument( "-e", "--earlier_release", action="store", dest="earlier_release", type=str, help="Start point of log messages") parser.add_argument( "-l", "--later_release", action="store", dest="later_release", type=str, help="End point of log messages") parser.add_argument( "-v", "--verbose", action="store_true", dest="verbose", help="Adds date, time, message body and file diff information to logs") parser.add_argument( "-r", "--raw", action="store_true", dest="raw", help="Print raw text (not in colour)") return parser
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * module_name Flags: * -b (branch) * -l (latest) * -g (git) * -e (epics_version) * -r (rhel_version) Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ parser = ArgParser(usage) parser.add_module_name_arg() parser.add_epics_version_flag() parser.add_git_flag(help_msg="Print releases available in git") parser.add_argument("-l", "--latest", action="store_true", dest="latest", help="Only print the latest release") parser.add_argument( "-r", "--rhel_version", action="store", type=int, dest="rhel_version", default=get_rhel_version(), help="Change the rhel version of the environment, default is " + get_rhel_version() + " (from your system)") return parser
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * module_name * releases Flags: * -e (earlier_release) * -l (later_release) * -v (verbose) * -r (raw) Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ parser = ArgParser(usage) parser.add_module_name_arg() parser.add_argument("releases", nargs='*', type=str, default=None, help="Releases range to print logs for") parser.add_argument("-e", "--earlier_release", action="store", dest="earlier_release", type=str, help="Start point of log messages") parser.add_argument("-l", "--later_release", action="store", dest="later_release", type=str, help="End point of log messages") parser.add_argument( "-v", "--verbose", action="store_true", dest="verbose", help="Adds date, time, message body and file diff information to logs") parser.add_argument("-r", "--raw", action="store_true", dest="raw", help="Print raw text (not in colour)") return parser
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * module_name * release Flags: * -b (branch) * -f (force) * -t (no-test-build) * -l (local-build-only) * -e (epics_version) * -T (test_build_only * -m (message) * -n (next_version) * -r (rhel_version) or --w (windows arguments) Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ parser = ArgParser(usage) parser.add_module_name_arg() parser.add_release_arg() parser.add_branch_flag(help_msg="Release from a branch") parser.add_epics_version_flag( help_msg="Change the epics version. This will determine which build " "server your job is built on for epics modules. Default is " "from your environment" ) parser.add_argument( "-f", "--force", action="store_true", dest="force", default=None, help="force a release. If the release exists in prod it is removed. " "If the release exists in git it is exported to prod, otherwise " "the release is created in git and exported to prod", ) parser.add_argument( "-t", "--no-test-build", action="store_true", dest="skip_test", help="If set, this will skip the local test build " "and just do a release", ) parser.add_argument( "-l", "--local-build-only", action="store_true", dest="local_build", help="If set, this will only do the local test build and no more.", ) parser.add_argument( "-T", "--test_build-only", action="store_true", dest="test_only", help="If set, this will only do a test build on the build server", ) parser.add_argument( "-m", "--message", action="store", type=str, dest="message", default="", help="Add user message to the end of the default commit message. " "The message will be <module_name>: Released version <release>. <message>", ) parser.add_argument( "-n", "--next_version", action="store_true", dest="next_version", help="Use the next version number as the release version", ) title = "Build operating system arguments" desc = "Note: The following arguments are mutually exclusive - only use one" desc_group = parser.add_argument_group(title=title, description=desc) # Can only add description to group, so have group = desc_group.add_mutually_exclusive_group() # to nest inside ordinary group group.add_argument( "-r", "--rhel_version", action="store", type=str, dest="rhel_version", help="change the rhel version of the build. This will determine which " "build server your job is build on for non-epics modules. Default " "is from /etc/redhat-release. Can be 6", ) group.add_argument( "-w", "--windows", action="store", dest="windows", type=str, help="Release the module or IOC only for the Windows version. " "Note that the windows build server can not create a test build. " "A configure/RELEASE.win32-x86 or configure/RELEASE.windows64 file" " must exist in the module in order for the build to start. " "If the module has already been released with the same version " "the build server will rebuild that release for windows. " "Existing unix builds of the same module version will not be " "affected. Must specify 32 or 64 after the flag to choose 32/64-bit. " "Both 32 and 64 bit builds are built on the same 64-bit build server", ) return parser
def make_parser(): """ Takes ArgParse instance with default arguments and adds Positional Arguments: * modules Flags: * -c (contact) * -d (cc) * -s (csv) * -m (import) Returns: :class:`argparse.ArgumentParser`: ArgParse instance """ parser = ArgParser(usage) # nargs='*' makes <modules> an optional positional argument; a list of N entries parser.add_argument( "modules", nargs='*', type=str, default=None, help="Name(s) of module(s) to list/set contacts for") parser.add_argument( "-c", "--contact", action="store", type=str, metavar="FED_ID", dest="contact", help="Set the contact property to FED_ID") parser.add_argument( "-d", "--cc", action="store", type=str, metavar="FED_ID", dest="cc", help="Set the cc property to FED_ID") parser.add_argument( "-s", "--csv", action="store_true", dest="csv", help="Print output as csv file") parser.add_argument( "-m", "--import", action="store", type=str, metavar="CSV_FILE", dest="imp", help="Import a CSV_FILE with header and rows of format:" + "\nModule, Contact, Contact Name, CC, CC Name") return parser
def make_parser(): parser = ArgParser(usage) parser.add_argument( "source", type=str, default=None, help="source to update from") parser.add_argument( "module_name", type=str, default=None, help="name of module to update") parser.add_argument( "old_tag", type=str, default=None, help="tag of old module") parser.add_argument( "new_tag", type=str, default=None, help="tag of new module") parser.add_argument( "-f", "--force", action="store_true", dest="force", help="force the update, disable warnings") return parser