Source code for core.utils.opts

# core/utils.py
#
#

""" utils package. """

__copyright__ = "Copyright 2015, B.H.J Thate"

## IMPORT

from core.defines import homedir
from core import __version__

import optparse
import os

## DEFINES

opts_defs = [
              ('', '--debug', 'store_true', False, 'debug',  "enable debug mode."),
              ('', '--path', 'store_true', False, 'path',  "show syspath"),
              ('-b', '--background', 'store_true', False, 'background',  "switch to background mode."),
              ('-c', '--colors', 'store_false', True, 'colors',  "turn off color mode"),
              ('-o', '--openfire', 'store_true', False, 'openfire', 'use openfire to connect to XMPP.'),
              ('-s', '--shell', 'store_true', False, 'shell',  "shell mode."),
              ('-i', '--init', 'string', "", 'init',  "whether to initialize plugins."),
              ('-d', '--workdir', 'string',  "", 'workdir',  "working directory."),
              ('-p', '--port', 'string', "10102", 'port',  "port to run HTTP server on."),
              ('-l', '--loglevel', 'string', "error", 'loglevel',  "loglevel.")
          ]

opts_defs_sed = [
              ('-d', '--dir', 'string', "", 'dir_sed',  "directory to work with."),
              ('-l', '--loglevel', 'string', "", 'loglevel',  "loglevel"),
          ]  

opts_defs_udp = [
              ('-p', '--port', 'string', "10102", 'port',  "port to run API server on"),
              ('-l', '--loglevel', 'string', "", 'loglevel',  "loglevel"),
          ]


## OPTIONS

[docs]def make_opts(options): parser = optparse.OptionParser(usage='usage: %prog [options]', version=str(__version__)) for option in options: type, default, dest, help = option[2:] if "store" in type: try: parser.add_option(option[0], option[1], action=type, default=default, dest=dest, help=help) except Exception as ex: logging.error("^ fout: %s - optie: %s" % (str(ex), option)) ; continue else: try: parser.add_option(option[0], option[1], type=type, default=default, dest=dest, help=help) except Exception as ex: logging.error("^ fout: %s - optie: %s" % (str(ex), option)) ; continue args = parser.parse_args() return args