sys.sysexit

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

7 Examples 7

Example 1

Project: series-renamer Source File: series_renamer.py
Function: throw_error
def throwError(msg):
	"""
	Throws error and exists
	"""
	drawline('#', msg)
	print("ERROR :", msg)
	sysexit()

Example 2

Project: pybingwallpaper Source File: main.py
Function: generate_config_file
def generate_config_file(configdb, config_content):
    filename = config_content.config_file
    _logger.info('save following config to file %s:\n\t%s',
            filename,
            config.pretty(config_content, '\n\t'))
    save_config(configdb, config_content, filename)
    sysexit(0)

Example 3

Project: RSPET Source File: rspet_client.py
Function: main
def main():
    """Main function. Handle object instances."""
    try:
        rhost = argv[1]
    except IndexError:
        print ("Must provide hotst")
        sysexit()
    try:
        myself = Client(rhost, argv[2])
    except IndexError:
        myself = Client(rhost)
    try:
        myself.connect()
    except sock_error:
        myself.reconnect()
    myself.loop()

Example 4

Project: RSPET Source File: rspet_server.py
Function: main
def main():
    """Main function."""
    try:
        cli = Console(int(argv[1]))
    except IndexError:
        cli = Console()
    try:
        cli.loop()
    except KeyError:
        print("Got KeyError")
        cli.trash()
        del cli
        sysexit()
    except KeyboardInterrupt:
        cli.trash()
        del cli
        sysexit()
    cli.trash()
    del cli

Example 5

Project: pybingwallpaper Source File: main.py
Function: load_config
def load_config(configdb, args = None):
    args = argv[1:] if args is None else args
    set_debug_details(args.count('--debug')+args.count('-d'))

    default_config = config.DefaultValueLoader().load(configdb)
    _logger.debug('default config:\n\t%s', config.pretty(default_config, '\n\t'))

    # parse cli options at first because we need the config file path in it
    cli_config = config.CommandLineArgumentsLoader().load(configdb, argv[1:])
    _logger.debug('cli arg parsed:\n\t%s', config.pretty(cli_config, '\n\t'))
    run_config = config.merge_config(default_config, cli_config)

    if run_config.generate_config:
        generate_config_file(configdb, run_config)

    config_file = run_config.config_file
    if not isfile(config_file):
        _logger.warning("can't find config file %s, use default settings and cli settings",
                config_file)
    else:
        try:
            conf_config = config.from_file(configdb, run_config.config_file)
        except config.ConfigFileLoader.ConfigValueError as err:
            _logger.error(err)
            sysexit(1)

        _logger.debug('config file parsed:\n\t%s', config.pretty(conf_config, '\n\t'))
        run_config = config.merge_config(run_config, conf_config)

    # override saved settings again with cli options again, because we want
    # command line options to take higher priority
    run_config = config.merge_config(run_config, cli_config)
    if run_config.setter_args:
        run_config.setter_args = ','.join(run_config.setter_args).split(',')
    else:
        run_config.setter_args = list()

    # backward compatibility modifications
    if run_config.size_mode == 'collect':
        _logger.warning(
            'size_mode=collect is obsolete, considering use collect=accompany instead'
        )
        run_config.size_mode = 'highest'
        if 'accompany' not in run_config.collect:
            run_config.collect.append('accompany')

    _logger.info('running config is:\n\t%s', config.pretty(run_config, '\n\t'))
    return run_config

Example 6

Project: RSPET Source File: rspet_server.py
Function: loop
    def loop(self):
        """Main CLI loop"""
        self._logo()
        try:
            start_new_thread(self.server.loop, ())
        except sock_error:
            print("Address is already in use")
            sysexit()

        while not Console.quit_signal:
            try:
                cmd = raw_input(Console.prompt)
            except KeyboardInterrupt:
                raise KeyboardInterrupt

            cmdargs = cmd.split(" ")
            #"Sanitize" user input by stripping spaces.
            cmdargs = [x for x in cmdargs if x != ""]
            if cmdargs == []: #Check if command was empty.
                continue
            cmd = cmdargs[0]
            del cmdargs[0]
            #Execute command.
            try:
                if Console.state in Plugin.__cmd_states__[cmd]:
                    results = self.server.execute(cmd, cmdargs)
                else:
                    results = [None, 5, "Command used out of scope."]
            except KeyError:
                results = [None, 6, "Command not found. Try help for a list of all commands!"]
            tmp_state = results[0]
            #return_code = results[1] # Future use ? Also API.
            return_string = results[2]
            if return_string != "":
                print(return_string)
            try:
                Console.states[tmp_state](self) #State transition.
            except KeyError: #If none is returned make no state change.
                continue
        self.server.trash()

Example 7

Project: RSPET Source File: rspet_server.py
Function: init
    def __init__(self, max_conns=5, ip="0.0.0.0", port="9000"):
        """Start listening on socket."""
        self.ip = ip
        self.port = port
        self.max_conns = max_conns
        self.sock = socket(AF_INET, SOCK_STREAM)
        self.serial = 0
        self.hosts = {} # List of hosts
        self.selected = [] # List of selected hosts
        self.plugins = [] # List of active plugins
        self.log_opt = [] # List of Letters. Indicates logging level

        with open("config.json") as json_config:
            self.config = json.load(json_config)
        self.log_opt = self.config["log"]
        self._log("L", "Session Start.")
        for plugin in self.config["plugins"]:
            try:
                __import__("Plugins.%s" % plugin)
                self._log("L", "%s plugin loaded." % plugin)
            except ImportError:
                self._log("E", "%s plugin failed to load." % plugin)
        try:
            self.sock.bind((ip, int(port)))
            self.sock.listen(max_conns)
            self._log("L", "Socket bound @ %s:%s." %(self.ip, self.port))
        except sock_error:
            print("Something went wrong during binding & listening")
            self._log("E", "Error binding socket @ %s:%s." %(self.ip, self.port))
            sysexit()