Python sys.args() Examples
The following are 19
code examples of sys.args().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sys
, or try the search function
.
Example #1
Source File: mole.py From pyscf with Apache License 2.0 | 6 votes |
def pack(mol): '''Pack the input args of :class:`Mole` to a dict. Note this function only pack the input arguments (not the entire Mole class). Modifications to mol._atm, mol._bas, mol._env are not tracked. Use :func:`dumps` to serialize the entire Mole object. ''' mdic = {'atom' : mol.atom, 'unit' : mol.unit, 'basis' : mol.basis, 'charge' : mol.charge, 'spin' : mol.spin, 'symmetry': mol.symmetry, 'nucmod' : mol.nucmod, 'nucprop' : mol.nucprop, 'ecp' : mol.ecp, '_nelectron': mol._nelectron, 'verbose' : mol.verbose} return mdic
Example #2
Source File: mole.py From pyscf with Apache License 2.0 | 6 votes |
def _update_from_cmdargs_(mol): # Ipython shell conflicts with optparse # pass sys.args when using ipython try: __IPYTHON__ #sys.stderr.write('Warn: Ipython shell catchs sys.args\n') return except Exception: pass if not mol._built: # parse cmdline args only once opts = cmd_args.cmd_args() if opts.verbose: mol.verbose = opts.verbose if opts.max_memory: mol.max_memory = opts.max_memory if opts.output: mol.output = opts.output
Example #3
Source File: mole.py From pyscf with Apache License 2.0 | 5 votes |
def apply(self, fn, *args, **kwargs): if callable(fn): return lib.StreamObject.apply(self, fn, *args, **kwargs) elif isinstance(fn, (str, unicode)): method = getattr(self, fn.upper()) return method(*args, **kwargs) else: raise TypeError('First argument of .apply method must be a ' 'function/class or a name (string) of a method.')
Example #4
Source File: mole.py From pyscf with Apache License 2.0 | 5 votes |
def __init__(self, method, args, args_bak): self.method = method self.args = args self.args_bak = args_bak
Example #5
Source File: mole.py From pyscf with Apache License 2.0 | 5 votes |
def __enter__(self): self.method(*self.args)
Example #6
Source File: test_zopkio.py From Zopkio with Apache License 2.0 | 5 votes |
def _run_zopkio(self, args): import sys, os.path pwd = os.path.abspath('.') try: os.chdir(os.path.join(os.path.dirname(__file__),"..")) sys.args = args print("Running 'zopkio %s %s'"%(args.testfile, args.nopassword)) from zopkio import __main__ as main succeeded, failed = main.call_main(args) except: os.chdir( pwd ) raise else: return succeeded, failed
Example #7
Source File: test_zopkio.py From Zopkio with Apache License 2.0 | 5 votes |
def test_zopkio_launch(self): """ Run server client test suites and compare to expected outcome on test failures/successes """ runtime.reset_all() args = Args() args.testfile = "./examples/server_client/server_client.py" succeeded, failed = self._run_zopkio(args) self.assertTrue( succeeded >= 4) self.assertTrue( failed >= 12)
Example #8
Source File: init.py From cloudbase-init with Apache License 2.0 | 5 votes |
def _reset_service_password_and_respawn(osutils): """Avoid pass the hash attacks from cloned instances.""" credentials = osutils.reset_service_password() if not credentials: return service_domain, service_user, service_password = credentials _, current_user = osutils.get_current_user() # Notes(alexcoman): No need to check domain as password reset applies # to local users only. if current_user != service_user: LOG.debug("No need to respawn process. Current user: " "%(current_user)s. Service user: " "%(service_user)s", {"current_user": current_user, "service_user": service_user}) return # Note(alexcoman): In order to avoid conflicts caused by the logging # handlers being shared between the current process and the new one, # any logging handlers for the current logger object will be closed. # By doing so, the next time the logger is called, it will be created # under the newly updated process, thus avoiding any issues or # conflicts where the logging can't be done. logging.release_logging_handlers("cloudbaseinit") # Note(alexcoman): In some edge cases the sys.args doesn't contain # the python executable. In order to avoid this kind of issue the # sys.executable will be injected into the arguments if it's necessary. arguments = sys.argv + ["--noreset_service_password"] if os.path.basename(arguments[0]).endswith(".py"): arguments.insert(0, sys.executable) LOG.info("Respawning current process with updated credentials.") token = osutils.create_user_logon_session( service_user, service_password, service_domain, logon_type=osutils.LOGON32_LOGON_BATCH) exit_code = osutils.execute_process_as_user(token, arguments) LOG.info("Process execution ended with exit code: %s", exit_code) sys.exit(exit_code)
Example #9
Source File: fit_common.py From RackHD with Apache License 2.0 | 5 votes |
def fitargs(): """ returns the ['cmd-args-list'] dictionary :return: dictionary or None """ return fitcfg().get('cmd-args-list', None)
Example #10
Source File: walarchive.py From barman with GNU General Public License v3.0 | 5 votes |
def main(args=None): """ The main script entry point :param list[str] args: the raw arguments list. When not provided it defaults to sys.args[1:] """ config = parse_arguments(args) # Do connectivity test if requested if config.test: connectivity_test(config) return # never reached # Check WAL destination is not a directory if os.path.isdir(config.wal_path): exit_with_error("WAL_PATH cannot be a directory: %s" % config.wal_path) try: # Execute barman put-wal through the ssh connection ssh_process = RemotePutWal(config, config.wal_path) except EnvironmentError as exc: exit_with_error('Error executing ssh: %s' % exc) return # never reached # Wait for termination of every subprocess. If CTRL+C is pressed, # terminate all of them RemotePutWal.wait_for_all() # If the command succeeded exit here if ssh_process.returncode == 0: return # Report the exit code, remapping ssh failure code (255) to 3 if ssh_process.returncode == 255: exit_with_error("Connection problem with ssh", 3) else: exit_with_error("Remote 'barman put-wal' command has failed!", ssh_process.returncode)
Example #11
Source File: __init__.py From moderngl-window with MIT License | 5 votes |
def parse_args(args=None, parser=None): """Parse arguments from sys.argv Passing in your own argparser can be user to extend the parser. Keyword Args: args: override for sys.argv parser: Supply your own argparser instance """ parser = parser or create_parser() return parser.parse_args(args or sys.argv[1:]) # --- Validators ---
Example #12
Source File: walarchive.py From barman with GNU General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): super(ChecksumTarInfo, self).__init__(*args, **kwargs) self.data_checksum = None
Example #13
Source File: fit_common.py From RackHD with Apache License 2.0 | 4 votes |
def run_nose(nosepath=None): if not nosepath: nosepath = fitcfg()['cmd-args-list']['test'] # this routine runs nosetests from wrapper using path spec 'nosepath' def _noserunner(pathspecs, noseopts): xmlfile = str(time.time()) + ".xml" # XML report file name env = { 'FIT_CONFIG': mkcfg().get_path(), 'HOME': os.environ['HOME'], 'PATH': os.environ['PATH'], 'PYTHONPATH': ':'.join(sys.path) } argv = ['nosetests'] argv.extend(noseopts) argv.append('--xunit-file') argv.append(xmlfile) argv.extend(pathspecs) argv.extend(fitcfg()['cmd-args-list']['unhandled_arguments']) return subprocess.call(argv, env=env) exitcode = 0 # set nose options noseopts = ['--exe', '--with-nosedep', '--with-stream-monitor', '--sm-amqp-url', 'generate:{}'.format(fitports()['amqp_ssl']), '--sm-dut-ssh-user', fitcreds()['rackhd_host'][0]['username'], '--sm-dut-ssh-password', fitcreds()['rackhd_host'][0]['password'], '--sm-dut-ssh-port', str(fitports()['ssh']), '--sm-dut-ssh-host', fitargs()['rackhd_host']] if fitargs()['group'] != 'all' and fitargs()['group'] != '': noseopts.append('-a') noseopts.append(str(fitargs()['group'])) if fitargs()['list'] is True or fitargs()['list'] == "True": noseopts.append('--collect-only') fitargs()['v'] = 0 print "\nTest Listing for:", fitargs()['test'] print "----------------------------------------------------------------------" if fitargs()['xunit'] is True or fitargs()['xunit'] == "True": noseopts.append('--with-xunit') else: noseopts.append('-s') noseopts.append('-v') # if nosepath is a directory, recurse through subdirs else run single test file if os.path.isdir(nosepath): # Skip the CIT test directories that match these expressions regex = '(tests/*$)|(tests/api$)|(tests/api/.*)' pathspecs = [] for root, _, _ in os.walk(nosepath): if not re.search(regex, root): pathspecs.append(root) exitcode += _noserunner(pathspecs, noseopts) else: exitcode += _noserunner([nosepath], noseopts) return exitcode
Example #14
Source File: argumenthandler_ga.py From CAMISIM with Apache License 2.0 | 4 votes |
def _get_parser_options(args=None, version="Prototype"): """ Parsing of passed arguments. @param args: Passed arguemnts @return: any """ description = """ ####################################### # GenomeAnnotationPipeline # # Version {}# ####################################### Pipeline for the extraction of marker genes, clustering and taxonomic classification""".format(version.ljust(25)) parser = argparse.ArgumentParser( usage="python %(prog)s configuration_file_path", version="MetagenomeSimulationPipeline TC {}".format(version), description=description, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument( "-verbose", "--verbose", action='store_true', default=False, help="display more information!") parser.add_argument( "-debug", "--debug_mode", action='store_true', default=False, help="tmp folders will not be deleted!") parser.add_argument( "-log", "--logfile", type=str, default=None, help="pipeline output will written to this log file") group_input = parser.add_argument_group('optional config arguments') group_input.add_argument( "-p", "--max_processors", default=None, type=int, help="number of available processors") group_input.add_argument("-s", "--phase", default=None, type=int, choices=[0, 1, 2, 3], help=''' 0 -> Full run (Default) 1 -> Marker gene extraction 2 -> Gene alignment and clustering 3 -> Annotation of Genomes ''') group_input = parser.add_argument_group('required') group_input.add_argument("config_file", type=str, default=None, help="path to the configuration file of the pipeline") if args is None: return parser.parse_args() else: return parser.parse_args(args)
Example #15
Source File: __init__.py From moderngl-window with MIT License | 4 votes |
def run_window_config(config_cls: WindowConfig, timer=None, args=None) -> None: """ Run an WindowConfig entering a blocking main loop Args: config_cls: The WindowConfig class to render args: Override sys.args """ setup_basic_logging(config_cls.log_level) parser = create_parser() config_cls.add_arguments(parser) values = parse_args(args=args, parser=parser) config_cls.argv = values window_cls = get_local_window_cls(values.window) # Calculate window size size = values.size or config_cls.window_size size = int(size[0] * values.size_mult), int(size[1] * values.size_mult) # Resolve cursor show_cursor = values.cursor if show_cursor is None: show_cursor = config_cls.cursor window = window_cls( title=config_cls.title, size=size, fullscreen=config_cls.fullscreen or values.fullscreen, resizable=values.resizable if values.resizable is not None else config_cls.resizable, gl_version=config_cls.gl_version, aspect_ratio=config_cls.aspect_ratio, vsync=values.vsync if values.vsync is not None else config_cls.vsync, samples=values.samples if values.samples is not None else config_cls.samples, cursor=show_cursor if show_cursor is not None else True, ) window.print_context_info() activate_context(window=window) timer = Timer() window.config = config_cls(ctx=window.ctx, wnd=window, timer=timer) timer.start() while not window.is_closing: current_time, delta = timer.next_frame() if window.config.clear_color is not None: window.clear(*window.config.clear_color) else: window.use() window.render(current_time, delta) if not window.is_closing: window.swap_buffers() _, duration = timer.stop() window.destroy() if duration > 0: logger.info("Duration: {0:.2f}s @ {1:.2f} FPS".format(duration, window.frames / duration))
Example #16
Source File: walrestore.py From barman with GNU General Public License v3.0 | 4 votes |
def main(args=None): """ The main script entry point """ config = parse_arguments(args) # Do connectivity test if requested if config.test: connectivity_test(config) return # never reached # Check WAL destination is not a directory if os.path.isdir(config.wal_dest): exit_with_error("WAL_DEST cannot be a directory: %s" % config.wal_dest) # Open the destination file try: dest_file = open(config.wal_dest, 'wb') except EnvironmentError as e: exit_with_error("Cannot open '%s' (WAL_DEST) for writing: %s" % (config.wal_dest, e)) return # never reached # If the file is present in SPOOL_DIR use it and terminate try_deliver_from_spool(config, dest_file) # If required load the list of files to download in parallel additional_files = peek_additional_files(config) try: # Execute barman get-wal through the ssh connection ssh_process = RemoteGetWal(config, config.wal_name, dest_file) except EnvironmentError as e: exit_with_error('Error executing "ssh": %s' % e, sleep=config.sleep) return # never reached # Spawn a process for every additional file parallel_ssh_processes = spawn_additional_process( config, additional_files) # Wait for termination of every subprocess. If CTRL+C is pressed, # terminate all of them try: RemoteGetWal.wait_for_all() finally: # Cleanup failed spool files in case of errors for process in parallel_ssh_processes: if process.returncode != 0: os.unlink(process.dest_file) # If the command succeeded exit here if ssh_process.returncode == 0: sys.exit(0) # Report the exit code, remapping ssh failure code (255) to 3 if ssh_process.returncode == 255: exit_with_error("Connection problem with ssh", 3, sleep=config.sleep) else: exit_with_error("Remote 'barman get-wal' command has failed!", ssh_process.returncode, sleep=config.sleep)
Example #17
Source File: walarchive.py From barman with GNU General Public License v3.0 | 4 votes |
def parse_arguments(args=None): """ Parse the command line arguments :param list[str] args: the raw arguments list. When not provided it defaults to sys.args[1:] :rtype: argparse.Namespace """ parser = argparse.ArgumentParser( description="This script will be used as an 'archive_command' " "based on the put-wal feature of Barman. " "A ssh connection will be opened to the Barman host.", ) parser.add_argument( '-V', '--version', action='version', version='%%(prog)s %s' % barman.__version__) parser.add_argument( "-U", "--user", default=DEFAULT_USER, help="The user used for the ssh connection to the Barman server. " "Defaults to '%(default)s'.", ) parser.add_argument( '-c', '--config', metavar="CONFIG", help='configuration file on the Barman server', ) parser.add_argument( '-t', '--test', action='store_true', help="test both the connection and the configuration of the " "requested PostgreSQL server in Barman for WAL retrieval. " "With this option, the 'wal_name' mandatory argument is " "ignored.", ) parser.add_argument( "barman_host", metavar="BARMAN_HOST", help="The host of the Barman server.", ) parser.add_argument( "server_name", metavar="SERVER_NAME", help="The server name configured in Barman " "from which WALs are taken.", ) parser.add_argument( "wal_path", metavar="WAL_PATH", help="The value of the '%%p' keyword " "(according to 'archive_command').", ) return parser.parse_args(args=args)
Example #18
Source File: status.py From paasta with Apache License 2.0 | 4 votes |
def paasta_status(args) -> int: """Print the status of a Yelp service running on PaaSTA. :param args: argparse.Namespace obj created from sys.args by cli""" soa_dir = args.soa_dir system_paasta_config = load_system_paasta_config() return_codes = [0] tasks = [] clusters_services_instances = apply_args_filters(args) for cluster, service_instances in clusters_services_instances.items(): for service, instances in service_instances.items(): all_flink = all(i == FlinkDeploymentConfig for i in instances.values()) actual_deployments: Mapping[str, str] if all_flink: actual_deployments = {} else: actual_deployments = get_actual_deployments(service, soa_dir) if all_flink or actual_deployments: deploy_pipeline = list(get_planned_deployments(service, soa_dir)) tasks.append( ( report_status_for_cluster, dict( service=service, cluster=cluster, deploy_pipeline=deploy_pipeline, actual_deployments=actual_deployments, instance_whitelist=instances, system_paasta_config=system_paasta_config, verbose=args.verbose, ), ) ) else: print(missing_deployments_message(service)) return_codes.append(1) with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor: tasks = [executor.submit(t[0], **t[1]) for t in tasks] # type: ignore for future in concurrent.futures.as_completed(tasks): # type: ignore return_code, output = future.result() print("\n".join(output)) return_codes.append(return_code) return max(return_codes)
Example #19
Source File: status.py From paasta with Apache License 2.0 | 4 votes |
def get_filters(args,) -> Sequence[Callable[[InstanceConfig], bool]]: """Figures out which filters to apply from an args object, and returns them :param args: args object :returns: list of functions that take an instance config and returns if the instance conf matches the filter """ filters = [] if args.service: filters.append(lambda conf: conf.get_service() in args.service.split(",")) if args.clusters: filters.append(lambda conf: conf.get_cluster() in args.clusters.split(",")) if args.instances: filters.append(lambda conf: conf.get_instance() in args.instances.split(",")) if args.deploy_group: filters.append( lambda conf: conf.get_deploy_group() in args.deploy_group.split(",") ) if args.registration: normalized_regs = normalize_registrations( service=args.service, registrations=args.registration.split(",") ) filters.append( lambda conf: any( reg in normalized_regs for reg in ( conf.get_registrations() if hasattr(conf, "get_registrations") else [] ) ) ) if args.owner: owners = args.owner.split(",") filters.append( # If the instance owner is None, check the service owner, else check the instance owner lambda conf: get_team( overrides={}, service=conf.get_service(), soa_dir=args.soa_dir ) in owners if conf.get_team() is None else conf.get_team() in owners ) return filters