sys.argv.pop

Here are the examples of the python api sys.argv.pop taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

19 Examples 7

Example 1

Project: oi
Source File: d.py
View license
def main():
    addr = sys.argv.pop(1)
    program = oi.Program('my program', addr)

    program.add_command(
        'ping', lambda: 'pong')

    program.add_command(
        'state', lambda: program.state, 'show program state')

    program.add_command(
        'store', lambda key, val: setattr(program.state, key, val) or True,
        'store an item')

    program.add_command(
        'get', lambda key: getattr(program.state, key, None),
        'get an item')

    program.run()

Example 2

Project: py12306
Source File: pyi_rth_django.py
View license
def _restart_with_reloader(*args):
    import sys
    a0 = sys.argv.pop(0)
    try:
        return old_restart_with_reloader(*args)
    finally:
        sys.argv.insert(0, a0)

Example 3

View license
def main(prog, args):
    if args[:1] == ["--create-test-repo"]:
        repo_path = args[1]
        create_standard_repo(repo_path, prefix="sub/dir/")
    else:
        if args[:1] == ["--meld"]:
            TestCase.run_meld = True
            sys.argv.pop(1)
        unittest.main()

Example 4

View license
def main(prog, args):
    if args[:1] == ["--create-test-repo"]:
        repo_path = args[1]
        create_standard_repo(repo_path, prefix="sub/dir/")
    else:
        if args[:1] == ["--meld"]:
            TestCase.run_meld = True
            sys.argv.pop(1)
        unittest.main()

Example 5

Project: tasa
Source File: cli.py
View license
def runm():
    """ This is super minimal and pretty hacky, but it counts as a first pass.
    """
    signal.signal(signal.SIGINT, signal_handler)
    count = int(sys.argv.pop(1))
    processes = [Process(target=run, args=()) for x in range(count)]
    try:
        for p in processes:
            p.start()
    except KeyError:
        # Not sure why we see a keyerror here. Weird.
        pass
    finally:
        for p in processes:
            p.join()

Example 6

View license
def test():
    import sys, os

    def nextArg():
        try: return sys.argv.pop(1)
        except: return None

    checkProxySetting()

    url = nextArg() or "http://betty.userland.com"
    api = nextArg() or "examples.getStateName(32)" # "examples.getStateList([1,2])"
    try:
        server = xmlrpclib.Server(url, transport=ProxyTransport())
        print "Url: %s" % url

        try: print "Proxy: %s" % os.environ['http_proxy']
        except KeyError: print "Proxy: (Apparently none)"

        print "API: %s" % api
        r = eval("server.%s" % api)
        print "Result: ", r

    except xmlrpclib.ProtocolError, e:
        print "Connection error: %s" % e
    except xmlrpclib.Fault, e:
        print "Error: %s" % e

Example 7

Project: tuskar
Source File: cmd.py
View license
def main():
    # Split arguments, require at least a command
    execname = sys.argv.pop(0)
    if len(sys.argv) < 2:
        _exit_error(execname, "No command specified", RC_NOCOMMAND, log=False)

    configfile = sys.argv.pop(0)
    userargs = sys.argv[:]

    # Add ../ to sys.path to allow running from branch
    possible_topdir = os.path.normpath(os.path.join(os.path.abspath(execname),
                                                    os.pardir, os.pardir))
    if os.path.exists(os.path.join(possible_topdir, "tuskar", "__init__.py")):
        sys.path.insert(0, possible_topdir)

    from tuskar.openstack.common.rootwrap import wrapper

    # Load configuration
    try:
        rawconfig = ConfigParser.RawConfigParser()
        rawconfig.read(configfile)
        config = wrapper.RootwrapConfig(rawconfig)
    except ValueError as exc:
        msg = "Incorrect value in %s: %s" % (configfile, exc.message)
        _exit_error(execname, msg, RC_BADCONFIG, log=False)
    except ConfigParser.Error:
        _exit_error(execname, "Incorrect configuration file: %s" % configfile,
                    RC_BADCONFIG, log=False)

    if config.use_syslog:
        wrapper.setup_syslog(execname,
                             config.syslog_log_facility,
                             config.syslog_log_level)

    # Execute command if it matches any of the loaded filters
    filters = wrapper.load_filters(config.filters_path)
    try:
        filtermatch = wrapper.match_filter(filters, userargs,
                                           exec_dirs=config.exec_dirs)
        if filtermatch:
            command = filtermatch.get_command(userargs,
                                              exec_dirs=config.exec_dirs)
            if config.use_syslog:
                logging.info("(%s > %s) Executing %s (filter match = %s)" % (
                    os.getlogin(), pwd.getpwuid(os.getuid())[0],
                    command, filtermatch.name))

            obj = subprocess.Popen(command,
                                   stdin=sys.stdin,
                                   stdout=sys.stdout,
                                   stderr=sys.stderr,
                                   preexec_fn=_subprocess_setup,
                                   env=filtermatch.get_environment(userargs))
            obj.wait()
            sys.exit(obj.returncode)

    except wrapper.FilterMatchNotExecutable as exc:
        msg = ("Executable not found: %s (filter match = %s)"
               % (exc.match.exec_path, exc.match.name))
        _exit_error(execname, msg, RC_NOEXECFOUND, log=config.use_syslog)

    except wrapper.NoFilterMatched:
        msg = ("Unauthorized command: %s (no filter matched)"
               % ' '.join(userargs))
        _exit_error(execname, msg, RC_UNAUTHORIZED, log=config.use_syslog)

Example 8

Project: oi
Source File: c.py
View license
def main():
    addr = sys.argv.pop(1)
    print('addr is: `{}`'.format(addr))
    ctl = oi.CtlProgram('ctl program', addr)
    ctl.run()

Example 9

Project: MCEdit-Unified
Source File: mce.py
View license
    def run(self):
        logging.basicConfig(format=u'%(levelname)s:%(message)s')
        logging.getLogger().level = logging.INFO

        sys.argv.pop(0)

        if len(sys.argv):
            world = sys.argv.pop(0)

            if world.lower() in ("-h", "--help"):
                self.printUsageAndQuit()

            if len(sys.argv) and sys.argv[0].lower() == "create":
                # accept the syntax, "mce world3 create"
                self._create([world])
                print "Created world {0}".format(world)

                sys.exit(0)
            else:
                self.loadWorld(world)
        else:
            self.batchMode = True
            self.printUsage()

            while True:
                try:
                    world = raw_input("Please enter world name or path to world folder: ")
                    self.loadWorld(world)
                except EOFError:
                    print "End of input."
                    raise SystemExit
                except Exception, e:
                    print "Cannot open {0}: {1}".format(world, e)
                else:
                    break

        if len(sys.argv):
            # process one command from command line
            try:
                self.processCommand(" ".join(sys.argv))
            except UsageError:
                self.printUsageAndQuit()
            self._save([])

        else:
            # process many commands on standard input, maybe interactively
            self.batchMode = True
            while True:
                try:
                    command = raw_input(u"{0}> ".format(self.level.displayName))
                    print
                    self.processCommand(command)

                except EOFError:
                    print "End of file. Saving automatically."
                    self._save([])
                    raise SystemExit
                except Exception, e:
                    if self.debug:
                        traceback.print_exc()
                    print 'Exception during command: {0!r}'.format(e)
                    print "Use 'debug' to enable tracebacks."

Example 10

Project: MCEdit-Unified
Source File: mce.py
View license
    def run(self):
        logging.basicConfig(format=u'%(levelname)s:%(message)s')
        logging.getLogger().level = logging.INFO

        sys.argv.pop(0)

        if len(sys.argv):
            world = sys.argv.pop(0)

            if world.lower() in ("-h", "--help"):
                self.printUsageAndQuit()

            if len(sys.argv) and sys.argv[0].lower() == "create":
                # accept the syntax, "mce world3 create"
                self._create([world])
                print "Created world {0}".format(world)

                sys.exit(0)
            else:
                self.loadWorld(world)
        else:
            self.batchMode = True
            self.printUsage()

            while True:
                try:
                    world = raw_input("Please enter world name or path to world folder: ")
                    self.loadWorld(world)
                except EOFError:
                    print "End of input."
                    raise SystemExit
                except Exception, e:
                    print "Cannot open {0}: {1}".format(world, e)
                else:
                    break

        if len(sys.argv):
            # process one command from command line
            try:
                self.processCommand(" ".join(sys.argv))
            except UsageError:
                self.printUsageAndQuit()
            self._save([])

        else:
            # process many commands on standard input, maybe interactively
            self.batchMode = True
            while True:
                try:
                    command = raw_input(u"{0}> ".format(self.level.displayName))
                    print
                    self.processCommand(command)

                except EOFError:
                    print "End of file. Saving automatically."
                    self._save([])
                    raise SystemExit
                except Exception, e:
                    if self.debug:
                        traceback.print_exc()
                    print 'Exception during command: {0!r}'.format(e)
                    print "Use 'debug' to enable tracebacks."

Example 11

Project: AIQ
Source File: ComputeFromLog.py
View license
def main():

    global logging, log_file

    detailed = False

    print
    print "Compute AIQ from log file results, version 1.0"
    print

    sys.argv.pop(0)

    if len(sys.argv) == 0:
        usage()
        sys.exit()

    if sys.argv[0] == "--full":
        detailed = True
        sys.argv.pop(0)

    if len(sys.argv) == 0:
        usage()
        sys.exit()

    for file_name in sys.argv:
        file = open( file_name, 'r')
        estimate( file, detailed )
        print ":" + basename(file_name)
        if detailed: print
        file.close()

Example 12

Project: AIQ
Source File: ComputeFromLog.py
View license
def main():

    global logging, log_file

    detailed = False

    print
    print "Compute AIQ from log file results, version 1.0"
    print

    sys.argv.pop(0)

    if len(sys.argv) == 0:
        usage()
        sys.exit()

    if sys.argv[0] == "--full":
        detailed = True
        sys.argv.pop(0)

    if len(sys.argv) == 0:
        usage()
        sys.exit()

    for file_name in sys.argv:
        file = open( file_name, 'r')
        estimate( file, detailed )
        print ":" + basename(file_name)
        if detailed: print
        file.close()

Example 13

Project: pymclevel
Source File: mce.py
View license
    def run(self):
        logging.basicConfig(format=u'%(levelname)s:%(message)s')
        logging.getLogger().level = logging.INFO

        sys.argv.pop(0)

        if len(sys.argv):
            world = sys.argv.pop(0)

            if world.lower() in ("-h", "--help"):
                self.printUsageAndQuit()

            if len(sys.argv) and sys.argv[0].lower() == "create":
                # accept the syntax, "mce world3 create"
                self._create([world])
                print "Created world {0}".format(world)

                sys.exit(0)
            else:
                self.loadWorld(world)
        else:
            self.batchMode = True
            self.printUsage()

            while True:
                try:
                    world = raw_input("Please enter world name or path to world folder: ")
                    self.loadWorld(world)
                except EOFError, e:
                    print "End of input."
                    raise SystemExit
                except Exception, e:
                    print "Cannot open {0}: {1}".format(world, e)
                else:
                    break

        if len(sys.argv):
            # process one command from command line
            try:
                self.processCommand(" ".join(sys.argv))
            except UsageError:
                self.printUsageAndQuit()
            self._save([])

        else:
            # process many commands on standard input, maybe interactively
            command = [""]
            self.batchMode = True
            while True:
                try:
                    command = raw_input(u"{0}> ".format(self.level.displayName))
                    print
                    self.processCommand(command)

                except EOFError, e:
                    print "End of file. Saving automatically."
                    self._save([])
                    raise SystemExit
                except Exception, e:
                    if self.debug:
                        traceback.print_exc()
                    print 'Exception during command: {0!r}'.format(e)
                    print "Use 'debug' to enable tracebacks."

Example 14

Project: pymclevel
Source File: mce.py
View license
    def run(self):
        logging.basicConfig(format=u'%(levelname)s:%(message)s')
        logging.getLogger().level = logging.INFO

        sys.argv.pop(0)

        if len(sys.argv):
            world = sys.argv.pop(0)

            if world.lower() in ("-h", "--help"):
                self.printUsageAndQuit()

            if len(sys.argv) and sys.argv[0].lower() == "create":
                # accept the syntax, "mce world3 create"
                self._create([world])
                print "Created world {0}".format(world)

                sys.exit(0)
            else:
                self.loadWorld(world)
        else:
            self.batchMode = True
            self.printUsage()

            while True:
                try:
                    world = raw_input("Please enter world name or path to world folder: ")
                    self.loadWorld(world)
                except EOFError, e:
                    print "End of input."
                    raise SystemExit
                except Exception, e:
                    print "Cannot open {0}: {1}".format(world, e)
                else:
                    break

        if len(sys.argv):
            # process one command from command line
            try:
                self.processCommand(" ".join(sys.argv))
            except UsageError:
                self.printUsageAndQuit()
            self._save([])

        else:
            # process many commands on standard input, maybe interactively
            command = [""]
            self.batchMode = True
            while True:
                try:
                    command = raw_input(u"{0}> ".format(self.level.displayName))
                    print
                    self.processCommand(command)

                except EOFError, e:
                    print "End of file. Saving automatically."
                    self._save([])
                    raise SystemExit
                except Exception, e:
                    if self.debug:
                        traceback.print_exc()
                    print 'Exception during command: {0!r}'.format(e)
                    print "Use 'debug' to enable tracebacks."

Example 15

Project: py360
Source File: py360.py
View license
def main():
    usage="""
Python FUSE file system for Xbox 360 hard drives (XFAT)

%prog [imagefile] [mountpoint] [options]
""" 
    server = Py360(filename = sys.argv.pop(1), version="%prog " + fuse.__version__,
                     usage=usage,
                     dash_s_do='setsingle')

    # While Partition is (now) thread safe, testing showed that single threaded
    # mode was 6 times faster. This is because only one cluster could be read
    # at a time regardless of number of threads. With a file object pool or a
    # file cache this might swing the other way.
    # If implementing this remember Fuse loves to read in 128kb chunks.
    # 
    # Partition is only optionally threadsafe
    server.multithreaded = False 
    server.parse(errex=1)
    server.main()

Example 16

Project: py360
Source File: py360.py
View license
def main():
    usage="""
Python FUSE file system for Xbox 360 hard drives (XFAT)

%prog [imagefile] [mountpoint] [options]
""" 
    server = Py360(filename = sys.argv.pop(1), version="%prog " + fuse.__version__,
                     usage=usage,
                     dash_s_do='setsingle')

    # While Partition is (now) thread safe, testing showed that single threaded
    # mode was 6 times faster. This is because only one cluster could be read
    # at a time regardless of number of threads. With a file object pool or a
    # file cache this might swing the other way.
    # If implementing this remember Fuse loves to read in 128kb chunks.
    # 
    # Partition is only optionally threadsafe
    server.multithreaded = False 
    server.parse(errex=1)
    server.main()

Example 17

Project: nanny
Source File: nanny.py
View license
def main():
    commands = {"deps": deps, "remote-version": remote_version, "push": push, "clean": clean,
                "versions": versions, "list": list_available, "stage": stage, "info": child_information, "history": child_history, "help": print_help}
    sys.argv.pop(0) #remove filename

    command = None
    if len(sys.argv) > 0:
        command = sys.argv.pop(0)
    if command is None or command not in commands:
        command = "help"

    try:
        if command=="help":
            client = None
        else:
            client = SSHClient()
            client.load_system_host_keys()
            client.connect(REPOSITORY_HOST, username=REPOSITORY_USER, key_filename=REPOSITORY_KEY)

        try:
            commands[command](client, sys.argv)
            if command != "help":
                print ""
                print command + " [SUCCESSFUL]"

        except Exception, e:
            print e
            print command + " [FAILED]"

    finally:
        if client is not None:
            client.close()

Example 18

Project: nanny
Source File: nanny.py
View license
def main():
    commands = {"deps": deps, "remote-version": remote_version, "push": push, "clean": clean,
                "versions": versions, "list": list_available, "stage": stage, "info": child_information, "history": child_history, "help": print_help}
    sys.argv.pop(0) #remove filename

    command = None
    if len(sys.argv) > 0:
        command = sys.argv.pop(0)
    if command is None or command not in commands:
        command = "help"

    try:
        if command=="help":
            client = None
        else:
            client = SSHClient()
            client.load_system_host_keys()
            client.connect(REPOSITORY_HOST, username=REPOSITORY_USER, key_filename=REPOSITORY_KEY)

        try:
            commands[command](client, sys.argv)
            if command != "help":
                print ""
                print command + " [SUCCESSFUL]"

        except Exception, e:
            print e
            print command + " [FAILED]"

    finally:
        if client is not None:
            client.close()

Example 19

Project: oslo.rootwrap
Source File: cmd.py
View license
def main(run_daemon=False):
    # Split arguments, require at least a command
    execname = sys.argv.pop(0)
    if run_daemon:
        if len(sys.argv) != 1:
            _exit_error(execname, "Extra arguments to daemon", RC_NOCOMMAND,
                        log=False)
    else:
        if len(sys.argv) < 2:
            _exit_error(execname, "No command specified", RC_NOCOMMAND,
                        log=False)

    configfile = sys.argv.pop(0)

    # Load configuration
    try:
        rawconfig = moves.configparser.RawConfigParser()
        rawconfig.read(configfile)
        config = wrapper.RootwrapConfig(rawconfig)
    except ValueError as exc:
        msg = "Incorrect value in %s: %s" % (configfile, exc.args[0])
        _exit_error(execname, msg, RC_BADCONFIG, log=False)
    except moves.configparser.Error:
        _exit_error(execname, "Incorrect configuration file: %s" % configfile,
                    RC_BADCONFIG, log=False)

    if config.use_syslog:
        wrapper.setup_syslog(execname,
                             config.syslog_log_facility,
                             config.syslog_log_level)

    filters = wrapper.load_filters(config.filters_path)

    if run_daemon:
        # NOTE(dims): When not running as daemon, this import
        # slows us down just a bit. So moving it here so we have
        # it only when we need it.
        from oslo_rootwrap import daemon as daemon_mod
        daemon_mod.daemon_start(config, filters)
    else:
        run_one_command(execname, config, filters, sys.argv)