Beispiel #1
0
 def __init__(self):
     '''
     Constructor
     '''
     DB.__init__(self)
     self.cfg = Configuration.Instance()  # @UndefinedVariable
     self.sid = get_uuid()
     logging.debug('session uuid:%s' % self.sid)
Beispiel #2
0
    def __init__(self):
        '''
        Constructor
        '''
        cmd.Cmd.__init__(self)
        self.cfg = Configuration.Instance()  # @UndefinedVariable
        # current command
        self.cmd = None
        self.arg = None
        self.line = None

        # no 'Cmd' output in non-interactive mode
        interactive = os.isatty(0)
        if not interactive:
            f = open(os.devnull, 'w')
            sys.stdout = f
Beispiel #3
0
def l(cmd, retcode, msg, log_level):
    '''
    logging message facility which logs and returns log message
    
    cmd        command-line with params
    retcode    command return-code
    msg        informative message
    log_level  log level of the message
    '''
    logging.debug("[IN] %s" % cmd)
    logging.debug("[OUT] %s, log_level:%d" % (msg, log_level))
    interactive = Configuration.Instance().interactive  # @UndefinedVariable
    if interactive:
        c = ANSIColours.Instance()  # @UndefinedVariable
    if log_level == DEBUG:
        if not interactive:
            msg = "0|%s" % msg
        else:
            msg = "%s%s%s" % (c.get('white'), msg, c.endc)
        logging.debug(msg)
    if log_level == INFO:
        if not interactive:
            msg = "0|%s" % msg
        else:
            msg = "%s%s%s" % (c.get('blue'), msg, c.endc)
        logging.info(msg)
    if log_level == WARN:
        if not interactive:
            msg = "0|%s" % msg
        else:
            msg = "%s%s%s" % (c.get('magenta'), msg, c.endc)
        logging.warn(msg)
    if log_level == ERROR:
        if not interactive:
            msg = "1|%s" % msg
        else:
            msg = "%s%s%s" % (c.get('red'), msg, c.endc)
        logging.error(msg)
    if log_level == CRITICAL:  # @UndefinedVariable
        if not interactive:
            msg = "1|%s" % msg
        else:
            msg = "%s%s%s" % (c.get('red', True), msg, c.endc)
        logging.critical(msg)
    return msg
Beispiel #4
0
def main():
    # check '~/.pyraxshell' and config files exist, create them if missing
    if not check_dir_home():
        print("This is the first time 'pyraxshell' runs, please, configure "
              "'%s' according to your needs" % CONFIG_FILE)
        #create db
        DB()
        Sessions.Instance().create_table_sessions()  # @UndefinedVariable
        Sessions.Instance().create_table_commands()  # @UndefinedVariable
        # create default configuration file
        Configuration.Instance()  # @UndefinedVariable
        sys.exit(0)

    # ########################################
    # VERSION CHECK
    if not version.check_version_file():
        sys.exit(1)

    # ########################################
    # LOGGING
    start_logging()
    logging.debug('starting')

    #     from baseconfigfile import BaseConfigFile
    #     bcf = BaseConfigFile()

    # ########################################
    # ACCOUNTS
    accounts = Account.Instance()  # @UnusedVariable @UndefinedVariable

    # config file is read by 'BaseConfigFile' constructor
    # ########################################
    # CONFIGURATION
    cfg = Configuration.Instance()  # @UndefinedVariable
    # override settings with CLI params
    cfg.parse_cli(sys.argv)
    logging.debug("configuration: %s" % cfg)

    # set user's log level if specified
    if not Configuration.Instance().log_level == None:  # @UndefinedVariable
        l = logging.getLogger()
        for h in l.handlers:
            h.setLevel(cfg.log_level)

    # ########################################
    # START SESSION
    Sessions.Instance().start_session()  # @UndefinedVariable
    #     Sessions.Instance().insert_table_commands('IN', 'OUT')  # @UndefinedVariable

    # ########################################
    # DO STUFF
    # handle configuration
    if cfg.pyrax_http_debug == True:
        pyrax.set_http_debug(True)
    if cfg.pyrax_no_verify_ssl == True:
        # see: https://github.com/rackspace/pyrax/issues/187
        pyrax.set_setting("verify_ssl", False)
    # start notifier
    Notifier().start()
    # main loop
    Cmd_Pyraxshell().cmdloop()