def main(): parser = PromptParser() parser.add_argument('-p', '--path', metavar='', help='{path} - path of the directory to organize ') parser1 = PromptParser() parser1.add_argument( '-o', '--order', default='type', help='{extension,size,date,type} - the way you need to organize', metavar='', choices=['extension', 'size', 'date', 'type'], ) path = parser.parse_args().path organizeBy = parser1.parse_args().order if organizeBy == 'extension': organize_by_extension(path) elif organizeBy == 'size': organize_by_size(path) elif organizeBy == 'date': organize_by_date(path) elif organizeBy == 'type': organize_by_type(path) else: print('Wrong Choice for Organizing')
def test_mismatched_default(input_mock): """Test a parser which has a default which isn't the same type as the type""" input_mock.return_value = "" parser = PromptParser() parser.add_argument("--argument", type=str, default=None) args = parser.parse_args([]) assert args.argument is None input_mock.assert_called()
def test_auto_parser(): """Test a basic parser when the enviroment variable is set to disable prompts""" parser = PromptParser() parser.add_argument( "--argument", "-a", help="An argument you could provide", default="foo" ) args = parser.parse_args([]) assert args.argument == "foo"
def test_default_parser(input_mock): """Test a basic parser with a default value""" input_mock.side_effect = mock_input("") parser = PromptParser() parser.add_argument( "--argument", "-a", help="An argument you could provide", default="foo" ) args = parser.parse_args([]) assert args.argument == "foo"
def test_invalid_type(input_mock): """Test a parser with a type argument. Check that it fails when the type is wrong""" input_mock.side_effect = mock_input("abc") with pytest.raises(SystemExit): parser = PromptParser() parser.add_argument( "--argument", "-a", help="An argument you could provide", type=int ) args = parser.parse_args([]) input_mock.assert_called()
def test_valid_type(input_mock): """Test a parser with a type argument. Check that it succeeds when the type is correct""" input_mock.side_effect = mock_input("123") parser = PromptParser() parser.add_argument( "--argument", "-a", help="An argument you could provide", type=int ) args = parser.parse_args([]) assert args.argument == 123 input_mock.assert_called()
def test_no_default(input_mock, capsys, monkeypatch): """If a flag has no default, the prompt should still say ``None``""" # Mock the input function input_mock.side_effect = mock_input("abc") # Create the parser parser = PromptParser() parser.add_argument("--argument", "-a", help="An argument you could provide") args = parser.parse_args([]) captured = capsys.readouterr() assert "None" in captured.out
def main(): parser = PromptParser() parser.add_argument('--pcap', '-p', help='PCAP file to analyze', default='foo') pcap_file = parser.parse_args().pcap run_bro(pcap_file) for file in get_files('extract_files'): scan_file(file) ha_sandbox(file)
def test_secure_parser(getpass_mock): """Test a secure parser, which shouldn't echo the user's input to stdout""" getpass_mock.return_value = "abc" parser = PromptParser() parser.add_argument( "--argument", "-a", help="An argument you could provide", secure=True, default="foo", ) args = parser.parse_args([]) assert args.argument == "abc" getpass_mock.assert_called()
def test_basic_parser(input_mock, capsys): """Test a basic parser with no type argument""" # Mock the input function input_mock.side_effect = mock_input("abc") parser = PromptParser() parser.add_argument( "--argument", "-a", help="An argument you could provide", default="foo" ) args = parser.parse_args([]) # If the user inputs "abc", that should be the value of the argument assert args.argument == "abc" # The default value "foo" should be shown to the user captured = capsys.readouterr() assert "foo" in captured.out
def main(): parser = PromptParser() add_arguments(parser) args = parser.parse_args() if ".txt" in args.path: files = args.path else: files = glob.glob(f"{args.path}/*.txt") assert len(files) > 1, "Warning not '.txt' files found in directory." procobj = nd.ProcessingObject(files, args.bead_radius, opt_kwargs={'baseline_percentage': 0.2}) models = [x.strip() for x in args.models.split(',')] procobj.fit_models(*models, save_plot=args.save_plot) procobj.to_csv(f"results.csv")
def main(): parser = PromptParser() add_arguments(parser) args = parser.parse_args() PATH = "data" # OR IT TAKES A .TXT FILE BEAD_RADIUS = 18.5e-6 MODELS = "hertz_model, line" SAVE = False if ".txt" in args.path: files = args.path else: files = glob.glob(f"{args.path}/*.txt") obj = nd.ProcessingObject(files, args.bead_radius) models = [x.strip() for x in args.models.split(",")] obj.fit_models(*models, save_plot=args.save_plot) obj.to_csv("results_demo2.csv", index=None)
def main(): print("Artifactory Token Generator %s" % version) parser = PromptParser( description='A command line tool to help with generating API Key to Artifactory with SAML access.') subparsers = parser.add_subparsers(help="", dest="action") subparsers.required = True login_args(subparsers) configure_args(subparsers) args = parser.parse_args() if args.action == "login": config = SAML2ArtConfig() config.load(DEFAULT_CONFIG_FILE_PATH) login_saml2art(config, args) elif args.action == "configure": configure_saml2art(args, DEFAULT_CONFIG_FILE_PATH) else: parser.print_help()
def create_parser(): parser = PromptParser() parser.add_argument('--server-url', '-s', dest='server_url', default=os.environ.get('BBMIGRATE_SERVER_URL'), help='URL of the Bitbucket Server') parser.add_argument('--server-user', '-su', dest='server_user', default=os.environ.get('BBMIGRATE_SERVER_USER'), help='Bitbucket Server username') parser.add_argument('--server-pass', '-sp', dest='server_pass', default=os.environ.get('BBMIGRATE_SERVER_PASS'), help='Bitbucket Server password', secure=True) parser.add_argument('--workspace', '-w', dest='workspace', default=os.environ.get('BBMIGRATE_WORKSPACE'), help='Bitbucket Cloud workspace name') parser.add_argument('--cloud-user', '-cu', dest='cloud_user', default=os.environ.get('BBMIGRATE_CLOUD_USER'), help='Bitbucket Cloud username (not e-mail)') parser.add_argument('--threads', '-t', dest='threads', default=env_or('BBMIGRATE_THREADS', "5"), help='Number of threads to use (default: 5)') parser.add_argument('--cloud-pass', '-cp', dest='cloud_pass', default=os.environ.get('BBMIGRATE_CLOUD_PASS'), help='Bitbucket Cloud password', secure=True) parser.add_argument( '--no-remove-repos', '-norm', dest='no_remove_repos', default=env_or('BBMIGRATE_NO_REMOVE_REPOS', "False"), help='Do not remove locally-cloned repos (default: false)') parser.add_argument( '--repo-path', '-rp', dest='repo_path', default=env_or('BBMIGRATE_REPO_PATH', "/tmp/bbmigrate"), help='base path to output the projects/repos (default: /tmp/bbmigrate') return parser
def parse_args(): parser = PromptParser(description='Create gn3 databags') parser.add_argument('-i', '--instance', dest='geonetwork_instance', help='geonetwork 2 instance ' 'e.g. https://catalogue-imos.aodn.org.au') parser.add_argument('-u', '--username', dest='username', help='username for basic auth') parser.add_argument('-p', '--password', dest='password', help='password for basic auth. ' 'If a username is given but not a password, the ' 'password will be prompted for.', secure=True) parser.add_argument('-o', '--output-directory', default='.', dest='output_directory', help='directory at which to backup the repositories') return parser.parse_args()
from argparse_prompt import PromptParser parser = PromptParser() parser.add_argument('--argument', '-a', help='An argument you could provide', type=int) print(parser.parse_args().argument)
#!/usr/bin/env python3 from argparse_prompt import PromptParser parser = PromptParser() parser.add_argument('--argument', '-a', help='An argument you could provide', default='foo') print(parser.parse_args().argument)
out_file_path = Path(out_file_path) asset_folder = Path(asset_folder) out_file_path.parent.mkdir(parents=True, exist_ok=True) with open(out_file_path, "w+") as f: f.write("---\n") for key, value in self.metadata.items(): f.write(f"{key}: {value}\n") f.write("---\n") f.write(HEADER) for cell in self.cells: cell.render(f, asset_folder) if __name__ == "__main__": parser = PromptParser( description= "A utility for converting Jupyter Notebooks into UBI Center posts.") parser.add_argument("notebook", help="The notebook file to convert.") parser.add_argument("--layout", default="post", help="The layout style") parser.add_argument("--current", default="post") parser.add_argument("--cover", default="", help="The cover image path") parser.add_argument("--navigation", default=True) parser.add_argument("--title", default="Title goes here", help="The title") parser.add_argument("--date", default="2012-09-01", help="The publishing date") parser.add_argument("--tags", default="[]", help="The tags") parser.add_argument("--class_", default="post-template") parser.add_argument("--subclass", default="'post'") parser.add_argument("--author", default="max", help="The author name") parser.add_argument("--excerpt",
def main(): parser = PromptParser() parser.add_argument('--sequence_number', help='Enter Sequence Number', type=int, default=None) parser.add_argument('--start_num', help='Enter first number in sequence', type=int, default=1) parser.add_argument('--end_num', help='Enter last number in sequence', type=int, default=None) parser.add_argument( '--block_interval', help='After how many samples would you like a control block', type=int, default=None) parser.add_argument( '--beginning_blanks', help='How many blanks would you like at the top of the run', type=int, default=1) parser.add_argument( '--standard_format', help='Is this a pHILIC, lipid, or ZIC run (input 1, 2, or 3)', type=int, default=None) parser.add_argument('--directory', help='Enter directory to save files', default='C:\\Users\\ASHL01\\Desktop') parser.add_argument('--filename1', help='Enter filename1 (LC)', default='SQtestLC.csv') parser.add_argument('--filename2', help='Enter filename2 (MS)', default='SQtestMS.csv') #print(parser.parse_args().argument) args = parser.parse_args() trays = Trays(args.start_num, args.end_num) trays.print_placement() standard_string = 'ISTD' if args.standard_format == 1 else 'LQC' if args.standard_format == 2 else 'QC' if args.standard_format == 3 else None if standard_string is None: raise ValueError('enter 1 for pHILIC, 2 for lipid, or 3 for ZIC') seqgen = SequenceGenerator(trays, args.sequence_number, args.block_interval, standard_string, args.beginning_blanks) seqgen.directory(args.directory) if os.path.exists('.\\' + args.filename1): raise ValueError('This file already exists') if os.path.exists('.\\' + args.filename2): raise ValueError('This file already exists') seqgen.export_format_1(args.filename2) seqgen.export_format_2(args.filename1)
## merge all datasets/images associated with tags with labels 'arch%' and 'amoeb%' into one existing tag with ID 233 $ python -m tag_manager.tag_manager_cli -u root -s 172.17.0.3 -i 233 -e arch% amoeb% ## merge all datasets/images associated with tags with labels 'arch%' and 'amoeb%' and tags with IDs 245 and 253 ## into one existing tag with ID 233 $ python -m tag_manager.tag_manager_cli -u root -s 172.17.0.3 -i 233 -e arch% amoeb% -r 245 253 ## merge all datasets/images associated with tags with label '"Screaming" Hairy l'éléphan%' ## into one existing tag with ID 233 $ python -m tag_manager.tag_manager_cli -u root -s 172.17.0.3 -i 233 \ -e "\"Screaming\" Hairy l'éléphan%" ''' # Instantiate the parser # see https://pypi.org/project/argparse-prompt/ parser = PromptParser(description='Tag Manager CLI Application') # set of connection params parser.add_argument( '-u', '--username', dest='username', required=True, metavar='username', help="specifies the username for connection to the remote OMERO server", type=str, prompt=False) parser.add_argument( '-s', '--server',
from argparse_prompt import PromptParser parser = PromptParser() parser.add_argument('--argument', '-a', help='Choose either Ansible or Terraform', default='Ansible or Terraform?') parser.add_argument('--filepath', '-fp', help='Specify file path', default='Whats the file path?') argument = parser.parse_args().argument filepath = parser.parse_args().filepath if (argument == 'Terraform' or argument == 'Ansible'): print("You chose: " + argument) else: print( "Incorrect input. Must choose either Ansible or Terraform. Please try again." ) print("Selected file path is: " + filepath)