Пример #1
0
def main():
    """Process command line args."""
    clrm.init()

    args = sys.argv[1:]
    if args:
        args_set = set(args)

        max_args = 2  # -q and one other
        doc_arg_set = set(['-d', '--doc'])
        help_arg_set = set(['-h', '--help'])
        license_arg_set = set(['-l', '--license'])
        quiet_arg_set = set(['-q', '--quiet'])
        reference_arg_set = set(['-r', '--reference'])
        version_arg_set = set(['-V', '--version'])
        legal_args_set = (doc_arg_set | help_arg_set | license_arg_set |
                          quiet_arg_set | reference_arg_set | version_arg_set)

        # if any wrong arg, too many args or (max args and -q not among them)
        if (args_set - legal_args_set or len(args) > max_args or
           (len(args) == max_args and not (quiet_arg_set & args_set))):
            print(common.banner())
            print(clrm.Fore.RED + lcl.WRONG_ARG + '\n')
            print(clrm.Fore.RESET + common.usage())
        else:
            if not (quiet_arg_set & args_set):
                print(common.banner())

            if doc_arg_set & args_set:
                get_app_info()
                update_doc()
            elif license_arg_set & args_set:
                print(common.license_())
            elif help_arg_set & args_set:
                print(common.usage())
            elif reference_arg_set & args_set:
                get_app_info()
                update_ref()
            elif version_arg_set & args_set:
                print(lcl.VERSION, common.version())
            else:  # only -q
                create_setup()
    else:
        print(common.banner())
        create_setup()
Пример #2
0
def man_upd(argv, childs, last_upd):
    """Manual update based on args.

    First it checks all args and only if all are correct are they processed.
    """
    arg_nok = ''
    args_ok = False

    # check args
    for arg in argv:
        if '-' in arg:
            child, days = str.lower(arg).split('-')
        elif '+' in arg:
            child, days = str.lower(arg).split('+')
        else:
            arg_nok = arg
            args_ok = False
            break

        try:
            days = int(days)
        except ValueError:  # as error:
            arg_nok = arg
            args_ok = False
            break

        if ((child in childs) and
           (-shrd.MAX_DAYS <= days <= shrd.MAX_DAYS)):
            args_ok = True
        else:
            arg_nok = arg
            args_ok = False
            break

    if args_ok:  # process args
        print_state(childs, last_upd)
        for arg in argv:
            if '-' in arg:
                child, days = str.lower(arg).split('-')
                days = -int(days)
            elif '+' in arg:
                child, days = str.lower(arg).split('+')
                days = int(days)

            childs[child] += days
            if childs[child] > 0:
                childs[child] = min(shrd.MAX_DAYS, childs[child])
            else:
                childs[child] = max(0, childs[child])
        last_upd = dt.date.today()
        shrd.update_file(childs, last_upd)
        print_state(childs, last_upd)
    else:
        print(clrm.Fore.RED + lcl.WRONG_ARG + arg_nok + '\n')
        print(clrm.Fore.RESET + common.usage())
Пример #3
0
def start(argv):
    """Print banner and process args."""
    ansi.init()

    print(common.banner())

    if not argv:
        print_ips()
    else:
        arg0 = argv[0]
        if arg0 in ['-h', '--help']:
            print(common.usage())
        elif arg0 in ['-l', '--license']:
            print(common.license_())
        elif arg0 in ['-p', '--pause']:
            print_ips()
            input(lcl.PRESS_ANY_KEY)
        elif arg0 in ['-V', '--version']:
            print(lcl.VERSION, common.version())
        else:
            print(ansi.Fore.RED + lcl.WRONG_ARG + arg0 + '\n')
            print(ansi.Fore.RESET + common.usage())

    sys.exit(0)  # ToDo: other return codes
Пример #4
0
def start(argv):
    """Print banner and process args."""
    ansi.init()

    print(common.banner())

    if not argv:
        print_ips()
    else:
        arg0 = argv[0]
        if arg0 in ['-h', '--help']:
            print(common.usage())
        elif arg0 in ['-l', '--license']:
            print(common.license_())
        elif arg0 in ['-p', '--pause']:
            print_ips()
            input(lcl.PRESS_ANY_KEY)
        elif arg0 in ['-V', '--version']:
            print(lcl.VERSION, common.version())
        else:
            print(ansi.Fore.RED + lcl.WRONG_ARG + arg0 + '\n')
            print(ansi.Fore.RESET + common.usage())

    sys.exit(0)  # ToDo: other return codes
Пример #5
0
def start(argv):
    """Print banner, read/create data & log file and process args."""
    clrm.init()

    print(common.banner())
    childs, last_upd = shrd.open_create_datafile()

    arg0 = argv[0]
    if arg0 in ['-a', '--auto']:
        auto_upd(childs, last_upd)
    elif arg0 in ['-h', '--help']:
        print(common.usage())
    elif arg0 in ['-l', '--license']:
        print(common.license_())
    elif arg0 in ['-V', '--version']:
        print(lcl.VERSION, common.version())
    else:
        man_upd(argv, childs, last_upd)

    sys.exit(0)  # ToDo: other return codes
Пример #6
0
def main(argv):

    mealie_version = "3.1.0"
    mealie_banner = "MEA Lightweight Integration Engine for Maximo 6.2.7"
    build_dt = "$Date: 2012/02/07 09:50:02 $"

    param_file = None
    entity_type = None
    entity_key = None
    entity_level = None

    # Will source data just be validated without attempting to load into MEA?
    test_mode = False     # Default unless -t specified
    full_mode = False     # MA00047 Every entity processed must be new
    normal_mode = False   # MA00047

    show_version = False     

    try:
        opts, _args = getopt.getopt(argv, "e:k:p:l:tufV")
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    # Parse all args passed
    for opt, arg in opts:
        if opt == '-e':
            entity_type = arg
        elif opt == '-k':
            entity_key = arg
        elif opt == '-l':
            entity_level = arg
        elif opt == '-p':
            param_file = arg
        elif opt == '-t':
            test_mode = True
        elif opt == '-f':
            full_mode = True
        elif opt == '-u':
            normal_mode = True
        elif opt == '-V':
            show_version = True

    # Now let's validate the combination of args

    # Firstly, the version can be displayed. In this case it should be the only arg

    if (show_version):
        if (entity_type or entity_key or param_file or test_mode):
            usage()
            sys.exit(2)
        else:
            print "%s, version %s. Build %s" % (mealie_banner, mealie_version, build_dt)
            sys.exit(0)

    # MA00047 We must choose to run in one of: either test mode or full mode or normal mode
    if (test_mode):
        if (full_mode or normal_mode):
            print("ERROR: Only one of the arguments -u -t -f may be specified")
            usage()
            sys.exit(2)
    elif (full_mode):
        if (test_mode or normal_mode):
            print("ERROR: Only one of the arguments -u -t -f may be specified")
            usage()
            sys.exit(2)
    elif (normal_mode):
        if (test_mode or full_mode):
            print("ERROR: Only one of the arguments -u -t -f may be specified")
            usage()
            sys.exit(2)
    else:
        print("ERROR: At least one of the arguments -u -t -f must be specified")
        usage()
        sys.exit(2)


    # Otherwise the parameter file and entity must be explicitly specified
    # with the test mode argument being optional

    if not (entity_type and param_file):
        usage()
        sys.exit(2)

    if (entity_type != 'ASS' and entity_type != 'ASP' and entity_type != 'LOC'):
        print "ERROR: Unknown entity type %s" % (entity_type)
        usage()
        sys.exit(2)

    if (full_mode) and (entity_type == 'ASP'):
        print "ERROR: -f argument is not allowed for entity %s" % (entity_type)
        usage()
        sys.exit(2)

    # Get the parameters from the parameter file

    config = ConfigParser.ConfigParser() # RawConfigParser() does not do interpolation
    config.read(param_file)

    # Configure logging

    try:
        mea_wait_interval = int(config.get('log', 'mea_wait_interval'))
    except ConfigParser.NoSectionError:
        print "ERROR: No [log] section defined in %s or %s does not exist" % (param_file, param_file)
        sys.exit(2)
    except ConfigParser.NoOptionError:
        mea_wait_interval = 180   # Default wait interval
    except ValueError:
        print("ERROR: Invalid value \"%s\" for mea_wait_interval in %s" % (config.get('log', 'mea_wait_interval'), param_file))
        sys.exit(2)

    try:
        log_file = config.get('log', 'logfile')
    except ConfigParser.NoOptionError:
        log_file = '/usr/local/log/mealie.log' # Default log filename

    try:
        log_severity = config.getint('log', 'severity')
    except ConfigParser.NoOptionError:
        log_severity = 20 # Default to INFO

    mealie_logger = logging.getLogger('MealieLogger')
    mealie_logger.setLevel(log_severity)

    fh = logging.FileHandler(log_file)
    fh.setLevel(log_severity)

    LOG_FORMAT = "%(asctime)-15s %(module)-10s %(levelname)-5s %(message)s"
    formatter = logging.Formatter(LOG_FORMAT)
    fh.setFormatter(formatter)
    
    mealie_logger.addHandler(fh)

    # Validate source and target parameters

    try:
        source_type = config.get('source', 'type')
    except ConfigParser.NoSectionError:
        print "ERROR: No [source] section defined in %s or %s does not exist" % (param_file, param_file)
        sys.exit(2)
    except ConfigParser.NoOptionError:
        print "ERROR: No source type defined in %s" % param_file
        sys.exit(2)

    # MA00047 The command line argument -f may only be specified for a spreadsheet source

    if (source_type != 'XLS' and full_mode):
        print "ERROR: -f argument is not valid for source_type %s. Type mealie -h for help" % source_type
        sys.exit(2)

    # The command line argument -k should only be, and must be, specified for a database source

    if (source_type == 'XLS' and entity_key):
        print "ERROR: -k argument should not be supplied if source_type is %s" % source_type
        sys.exit(2)

    if (source_type == 'ORA' and not entity_key):
        print "ERROR: -k argument must be supplied if source_type is %s" % source_type
        sys.exit(2)

    try:
        source_db = config.get('source', 'db')
    except ConfigParser.NoOptionError:
        if (source_type != 'ORA'):
            source_db = None
        else:
            print "ERROR: No source database defined in %s" % param_file
            sys.exit(2)

    try:
        source_user = config.get('source', 'user')
    except ConfigParser.NoOptionError:
        if (source_type != 'ORA'):
            source_user = None
        else:
            print "ERROR: No source user defined in %s" % param_file
            sys.exit(2)

    try:
        source_pwd = config.get('source', 'pwd')
    except ConfigParser.NoOptionError:
        source_pwd = None

    try:
        source_xlsfile = config.get('source', 'xlsfile')
    except ConfigParser.NoOptionError:
        if (source_type != 'XLS'):
            source_xlsfile = None
        else:
            print "ERROR: No source xlsfile defined in %s" % param_file
            sys.exit(2)


    try:
        target_db = config.get('target', 'db')
    except ConfigParser.NoSectionError:
        print "ERROR: No [target] section defined in %s" % param_file
        sys.exit(2)
    except ConfigParser.NoOptionError:
        print "ERROR: No target database defined in %s" % param_file
        sys.exit(2)

    try:
        target_user = config.get('target', 'user')
    except ConfigParser.NoOptionError:
        print "ERROR: No target user defined in %s" % param_file
        sys.exit(2)

    try:
        target_pwd = config.get('target', 'pwd')
    except ConfigParser.NoOptionError:
        target_pwd = None


    if (source_type == 'ORA'):
        if (test_mode):
            mealie_logger.info("Test Mode: Data sourced from %s will NOT be loaded" % (source_db))
            print "Test Mode: Data sourced from %s will NOT be loaded" % (source_db)
        else:
            mealie_logger.info("Data sourced from %s will be loaded into %s" % (source_db, target_db))
            print "Data sourced from %s will be loaded into %s" % (source_db, target_db)
    elif (source_type == 'XLS'):
        if (test_mode):
            mealie_logger.info("Test Mode: Data sourced from %s will NOT be loaded" % (source_xlsfile))
            print "Test Mode: Data sourced from %s will NOT be loaded" % (source_xlsfile)
        else:
            mealie_logger.info("Data sourced from %s will be loaded into %s" % (source_xlsfile, target_db))
            print "Data sourced from %s will be loaded into %s" % (source_xlsfile, target_db)
    else:
        print "ERROR: Unsupported source type %s defined in %s" % (source_type, param_file)
        sys.exit(2)

    # 7592 Treat -f as if it were -u for Production because of real time updates
    if (full_mode and string.upper(target_db) == 'MAXPROD'):
        full_mode = False
        normal_mode = True

    if (full_mode):
        mealie_logger.info("Full Load: All entities processed must be loaded by MEA after %d seconds" % mea_wait_interval)

    mealie_logger.info("Logging level set to %s" % log_severity)

    mealie_logger.info("Processing entity %s LIKE %s" % (entity_type, entity_key))

    if (entity_level):
        mealie_logger.info("Processing entity LEVEL %s" % entity_level)
    else:
        mealie_logger.info("Processing all entity LEVELs")

    er = EntityRun(log_file, log_severity, mealie_logger,
                        source_db, source_user, source_pwd,
                        source_xlsfile,
                        source_type,
                        target_db, target_user, target_pwd,
                        entity_type, entity_key, entity_level,
                        mea_wait_interval,
                        normal_mode, test_mode, full_mode)

    return er
Пример #7
0
def usage(file_name):
    """ This is usage for how to use this tool """
    common.usage(file_name)
Пример #8
0
 def show_help(*args):
     """Show help message."""
     tk_msg_box.showinfo(lcl.HELP, common.usage())
Пример #9
0
 def show_help(*args):
     """Show help message."""
     tk_msg_box.showinfo(lcl.HELP, common.usage())