Beispiel #1
0
def main():

    # handle pipes better
    import signal
    signal.signal(signal.SIGPIPE, signal.SIG_DFL)

    global prog
    prog = os.path.basename(sys.argv[0])

    global logfile
    logfile = None

    if len(sys.argv) < 2:
        print >> sys.stderr, 'usage: %s <command>' % prog
        print >> sys.stderr, \
              '  Try "%s --help" for a list of supported commands' % prog
        sys.exit(1)
    
    # configure logging
    import logging
    console = logging.StreamHandler(sys.stdout)
    console.setLevel(logging.INFO)
    formatter = logging.Formatter(prog + ': %(message)s')
    console.setFormatter(formatter)
    logging.getLogger('').addHandler(console)
    global log
    log = logging.getLogger('')
    log.setLevel(logging.DEBUG)

    try:
        debug_level = int(os.environ['CSET_DEBUG_LEVEL'])
    except KeyError:
        debug_level = 0
    except ValueError:
        log.error('Invalid CSET_DEBUG_LEVEL environment variable')
        sys.exit(1)

    while True:
        if len(sys.argv) == 1:
            log.error('no arguments, nothing to do!')
            sys.exit(2)
        cmd = sys.argv[1]
        if cmd in ['-l', '--log']:
            if len(sys.argv) < 3:
                log.critical('not enough arguments')
                sys.exit(1)
            # FIXME: very fragile
            logfile = sys.argv[2]
            #trace = logging.FileHandler('/var/log/cset.log', 'w')
            trace = logging.FileHandler(logfile, 'a')
            trace.setLevel(logging.DEBUG)
            formatter = logging.Formatter('%(asctime)s %(name)-6s %(levelname)-8s %(message)s',
                                          '%y%m%d-%H:%M:%S')
            trace.setFormatter(formatter)
            logging.getLogger('').addHandler(trace)
            log.debug("---------- STARTING ----------")
            from cpuset.version import version
            log.debug('Cpuset (cset) %s' % version)
            del(sys.argv[2])
            del(sys.argv[1])
            continue
        if cmd in ['-h', '--help']:
           if len(sys.argv) >= 3:
               cmd = commands.canonical_cmd(sys.argv[2])
               sys.argv[2] = '--help'
           else:
               print_help()
               sys.exit(0)
        if cmd == 'help':
            if len(sys.argv) == 3 and not sys.argv[2] in ['-h', '--help']:
                cmd = commands.canonical_cmd(sys.argv[2])
                if not cmd in commands:
                    log.error('help: "%s" command unknown' % cmd)
                    sys.exit(1)

                sys.argv[0] += ' %s' % cmd
                command = commands[cmd]
                parser = OptionParser(usage = command.usage,
                                      option_list = command.options)
                from pydoc import pager
                pager(parser.format_help())
            else:
                print_help()
            sys.exit(0)
        if cmd in ['-v', '--version', 'version']:
            from cpuset.version import version
            log.info('Cpuset (cset) %s' % version)
            sys.exit(0)
        if cmd in ['-c', 'copyright', 'copying']:
            log.info(__copyright__)
            sys.exit(0)
        if cmd in ['-m', '--machine']:
            config.mread = True
            del(sys.argv[1])
            continue
        if cmd in ['-x', '--tohex']:
            if len(sys.argv) < 3:
                log.critical('not enough arguments')
                sys.exit(1)
            cpuspec = sys.argv[2]
            import cset
            try:
                print cset.cpuspec_to_hex(cpuspec)
            except (ValueError, OSError, IOError, CpusetException, CmdException), err:
                log.critical('**> ' + str(err))
                if debug_level:
                    raise
                else:
                    sys.exit(2)
            sys.exit(0)

        break
Beispiel #2
0
            cpuspec = sys.argv[2]
            import cset
            try:
                print cset.cpuspec_to_hex(cpuspec)
            except (ValueError, OSError, IOError, CpusetException, CmdException), err:
                log.critical('**> ' + str(err))
                if debug_level:
                    raise
                else:
                    sys.exit(2)
            sys.exit(0)

        break

    # re-build the command line arguments
    cmd = commands.canonical_cmd(cmd)
    sys.argv[0] += ' %s' % cmd
    del(sys.argv[1])
    log.debug('cmdline: ' + ' '.join(sys.argv))

    try:
        # importing the cset class creates the model
        log.debug("creating cpuset model")
        import cpuset.cset
        command = commands[cmd]
        usage = command.usage.split('\n')[0].strip()
        parser = OptionParser(usage = usage, option_list = command.options)
        options, args = parser.parse_args()
        command.func(parser, options, args)
    except (ValueError, OSError, IOError, CpusetException, CmdException), err:
        log.critical('**> ' + str(err))
Beispiel #3
0
def main():

    # handle pipes better
    import signal
    signal.signal(signal.SIGPIPE, signal.SIG_DFL)

    global prog
    prog = os.path.basename(sys.argv[0])

    global logfile
    logfile = None

    if len(sys.argv) < 2:
        print('usage: %s <command>' % prog, file=sys.stderr)
        print('  Try "%s --help" for a list of supported commands' % prog,
              file=sys.stderr)
        sys.exit(1)

    # configure logging
    import logging
    console = logging.StreamHandler(sys.stdout)
    console.setLevel(logging.INFO)
    formatter = logging.Formatter(prog + ': %(message)s')
    console.setFormatter(formatter)
    logging.getLogger('').addHandler(console)
    global log
    log = logging.getLogger('')
    log.setLevel(logging.DEBUG)

    try:
        debug_level = int(os.environ['CSET_DEBUG_LEVEL'])
    except KeyError:
        debug_level = 0
    except ValueError:
        log.error('Invalid CSET_DEBUG_LEVEL environment variable')
        sys.exit(1)

    while True:
        if len(sys.argv) == 1:
            log.error('no arguments, nothing to do!')
            sys.exit(2)
        cmd = sys.argv[1]
        if cmd in ['-l', '--log']:
            if len(sys.argv) < 3:
                log.critical('not enough arguments')
                sys.exit(1)
            # FIXME: very fragile
            logfile = sys.argv[2]
            #trace = logging.FileHandler('/var/log/cset.log', 'w')
            trace = logging.FileHandler(logfile, 'a')
            trace.setLevel(logging.DEBUG)
            formatter = logging.Formatter(
                '%(asctime)s %(name)-6s %(levelname)-8s %(message)s',
                '%y%m%d-%H:%M:%S')
            trace.setFormatter(formatter)
            logging.getLogger('').addHandler(trace)
            log.debug("---------- STARTING ----------")
            from cpuset.version import version
            log.debug('Cpuset (cset) %s' % version)
            del (sys.argv[2])
            del (sys.argv[1])
            continue
        if cmd in ['-h', '--help']:
            if len(sys.argv) >= 3:
                cmd = commands.canonical_cmd(sys.argv[2])
                sys.argv[2] = '--help'
            else:
                print_help()
                sys.exit(0)
        if cmd == 'help':
            if len(sys.argv) == 3 and not sys.argv[2] in ['-h', '--help']:
                cmd = commands.canonical_cmd(sys.argv[2])
                if not cmd in commands:
                    log.error('help: "%s" command unknown' % cmd)
                    sys.exit(1)

                sys.argv[0] += ' %s' % cmd
                command = commands[cmd]
                parser = OptionParser(usage=command.usage,
                                      option_list=command.options)
                from pydoc import pager
                pager(parser.format_help())
            else:
                print_help()
            sys.exit(0)
        if cmd in ['-v', '--version', 'version']:
            from cpuset.version import version
            log.info('Cpuset (cset) %s' % version)
            sys.exit(0)
        if cmd in ['-c', 'copyright', 'copying']:
            log.info(__copyright__)
            sys.exit(0)
        if cmd in ['-m', '--machine']:
            config.mread = True
            del (sys.argv[1])
            continue
        if cmd in ['-x', '--tohex']:
            if len(sys.argv) < 3:
                log.critical('not enough arguments')
                sys.exit(1)
            cpuspec = sys.argv[2]
            from . import cset
            try:
                print(cset.cpuspec_to_hex(cpuspec))
            except (ValueError, OSError, IOError, CpusetException,
                    CmdException) as err:
                log.critical('**> ' + str(err))
                if debug_level:
                    raise
                else:
                    sys.exit(2)
            sys.exit(0)

        break

    # re-build the command line arguments
    cmd = commands.canonical_cmd(cmd)
    sys.argv[0] += ' %s' % cmd
    del (sys.argv[1])
    log.debug('cmdline: ' + ' '.join(sys.argv))

    try:
        # importing the cset class creates the model
        log.debug("creating cpuset model")
        import cpuset.cset
        command = commands[cmd]
        usage = command.usage.split('\n')[0].strip()
        parser = OptionParser(usage=usage, option_list=command.options)
        options, args = parser.parse_args()
        command.func(parser, options, args)
    except (ValueError, OSError, IOError, CpusetException,
            CmdException) as err:
        log.critical('**> ' + str(err))
        if str(err).find('Permission denied') != -1:
            log.critical(
                'insufficient permissions, you probably need to be root')
        if str(err).find('invalid literal') != -1:
            log.critical('option not understood')
        if debug_level:
            raise
        else:
            sys.exit(2)
    except KeyboardInterrupt:
        sys.exit(1)

    sys.exit(0)
Beispiel #4
0
def main():

    # handle pipes better
    import signal
    signal.signal(signal.SIGPIPE, signal.SIG_DFL)

    global prog
    prog = os.path.basename(sys.argv[0])

    global logfile
    logfile = None

    if len(sys.argv) < 2:
        print('usage: %s <command>' % prog, file=sys.stderr)
        print('  Try "%s --help" for a list of supported commands' % prog, file=sys.stderr)
        sys.exit(1)
    
    # configure logging
    import logging
    console = logging.StreamHandler(sys.stdout)
    console.setLevel(logging.INFO)
    formatter = logging.Formatter(prog + ': %(message)s')
    console.setFormatter(formatter)
    logging.getLogger('').addHandler(console)
    global log
    log = logging.getLogger('')
    log.setLevel(logging.DEBUG)

    try:
        debug_level = int(os.environ['CSET_DEBUG_LEVEL'])
    except KeyError:
        debug_level = 0
    except ValueError:
        log.error('Invalid CSET_DEBUG_LEVEL environment variable')
        sys.exit(1)

    while True:
        if len(sys.argv) == 1:
            log.error('no arguments, nothing to do!')
            sys.exit(2)
        cmd = sys.argv[1]
        if cmd in ['-l', '--log']:
            if len(sys.argv) < 3:
                log.critical('not enough arguments')
                sys.exit(1)
            # FIXME: very fragile
            logfile = sys.argv[2]
            #trace = logging.FileHandler('/var/log/cset.log', 'w')
            trace = logging.FileHandler(logfile, 'a')
            trace.setLevel(logging.DEBUG)
            formatter = logging.Formatter('%(asctime)s %(name)-6s %(levelname)-8s %(message)s',
                                          '%y%m%d-%H:%M:%S')
            trace.setFormatter(formatter)
            logging.getLogger('').addHandler(trace)
            log.debug("---------- STARTING ----------")
            from cpuset.version import version
            log.debug('Cpuset (cset) %s' % version)
            del(sys.argv[2])
            del(sys.argv[1])
            continue
        if cmd in ['-h', '--help']:
           if len(sys.argv) >= 3:
               cmd = commands.canonical_cmd(sys.argv[2])
               sys.argv[2] = '--help'
           else:
               print_help()
               sys.exit(0)
        if cmd == 'help':
            if len(sys.argv) == 3 and not sys.argv[2] in ['-h', '--help']:
                cmd = commands.canonical_cmd(sys.argv[2])
                if not cmd in commands:
                    log.error('help: "%s" command unknown' % cmd)
                    sys.exit(1)

                sys.argv[0] += ' %s' % cmd
                command = commands[cmd]
                parser = OptionParser(usage = command.usage,
                                      option_list = command.options)
                from pydoc import pager
                pager(parser.format_help())
            else:
                print_help()
            sys.exit(0)
        if cmd in ['-v', '--version', 'version']:
            from cpuset.version import version
            log.info('Cpuset (cset) %s' % version)
            sys.exit(0)
        if cmd in ['-c', 'copyright', 'copying']:
            log.info(__copyright__)
            sys.exit(0)
        if cmd in ['-m', '--machine']:
            config.mread = True
            del(sys.argv[1])
            continue
        if cmd in ['-x', '--tohex']:
            if len(sys.argv) < 3:
                log.critical('not enough arguments')
                sys.exit(1)
            cpuspec = sys.argv[2]
            from . import cset
            try:
                print(cset.cpuspec_to_hex(cpuspec))
            except (ValueError, OSError, IOError, CpusetException, CmdException) as err:
                log.critical('**> ' + str(err))
                if debug_level:
                    raise
                else:
                    sys.exit(2)
            sys.exit(0)

        break

    # re-build the command line arguments
    cmd = commands.canonical_cmd(cmd)
    sys.argv[0] += ' %s' % cmd
    del(sys.argv[1])
    log.debug('cmdline: ' + ' '.join(sys.argv))

    try:
        # importing the cset class creates the model
        log.debug("creating cpuset model")
        import cpuset.cset
        command = commands[cmd]
        usage = command.usage.split('\n')[0].strip()
        parser = OptionParser(usage = usage, option_list = command.options)
        options, args = parser.parse_args()
        command.func(parser, options, args)
    except (ValueError, OSError, IOError, CpusetException, CmdException) as err:
        log.critical('**> ' + str(err))
        if str(err).find('Permission denied') != -1:
            log.critical('insufficient permissions, you probably need to be root')
        if str(err).find('invalid literal') != -1:
            log.critical('option not understood')
        if debug_level:
            raise
        else:
            sys.exit(2)
    except KeyboardInterrupt:
        sys.exit(1)

    sys.exit(0)
Beispiel #5
0
def main():

    # handle pipes better
    import signal
    signal.signal(signal.SIGPIPE, signal.SIG_DFL)

    global prog
    prog = os.path.basename(sys.argv[0])

    global logfile
    logfile = None

    if len(sys.argv) < 2:
        print >> sys.stderr, 'usage: %s <command>' % prog
        print >> sys.stderr, \
              '  Try "%s --help" for a list of supported commands' % prog
        sys.exit(1)

    # configure logging
    import logging
    console = logging.StreamHandler(sys.stdout)
    console.setLevel(logging.INFO)
    formatter = logging.Formatter(prog + ': %(message)s')
    console.setFormatter(formatter)
    logging.getLogger('').addHandler(console)
    global log
    log = logging.getLogger('')
    log.setLevel(logging.DEBUG)

    try:
        debug_level = int(os.environ['CSET_DEBUG_LEVEL'])
    except KeyError:
        debug_level = 0
    except ValueError:
        log.error('Invalid CSET_DEBUG_LEVEL environment variable')
        sys.exit(1)

    while True:
        if len(sys.argv) == 1:
            log.error('no arguments, nothing to do!')
            sys.exit(2)
        cmd = sys.argv[1]
        if cmd in ['-l', '--log']:
            if len(sys.argv) < 3:
                log.critical('not enough arguments')
                sys.exit(1)
            # FIXME: very fragile
            logfile = sys.argv[2]
            #trace = logging.FileHandler('/var/log/cset.log', 'w')
            trace = logging.FileHandler(logfile, 'a')
            trace.setLevel(logging.DEBUG)
            formatter = logging.Formatter(
                '%(asctime)s %(name)-6s %(levelname)-8s %(message)s',
                '%y%m%d-%H:%M:%S')
            trace.setFormatter(formatter)
            logging.getLogger('').addHandler(trace)
            log.debug("---------- STARTING ----------")
            from cpuset.version import version
            log.debug('Cpuset (cset) %s' % version)
            del (sys.argv[2])
            del (sys.argv[1])
            continue
        if cmd in ['-h', '--help']:
            if len(sys.argv) >= 3:
                cmd = commands.canonical_cmd(sys.argv[2])
                sys.argv[2] = '--help'
            else:
                print_help()
                sys.exit(0)
        if cmd == 'help':
            if len(sys.argv) == 3 and not sys.argv[2] in ['-h', '--help']:
                cmd = commands.canonical_cmd(sys.argv[2])
                if not cmd in commands:
                    log.error('help: "%s" command unknown' % cmd)
                    sys.exit(1)

                sys.argv[0] += ' %s' % cmd
                command = commands[cmd]
                parser = OptionParser(usage=command.usage,
                                      option_list=command.options)
                from pydoc import pager
                pager(parser.format_help())
            else:
                print_help()
            sys.exit(0)
        if cmd in ['-v', '--version', 'version']:
            from cpuset.version import version
            log.info('Cpuset (cset) %s' % version)
            sys.exit(0)
        if cmd in ['-c', 'copyright', 'copying']:
            log.info(__copyright__)
            sys.exit(0)
        if cmd in ['-m', '--machine']:
            config.mread = True
            del (sys.argv[1])
            continue
        if cmd in ['-x', '--tohex']:
            if len(sys.argv) < 3:
                log.critical('not enough arguments')
                sys.exit(1)
            cpuspec = sys.argv[2]
            import cset
            try:
                print cset.cpuspec_to_hex(cpuspec)
            except (ValueError, OSError, IOError, CpusetException,
                    CmdException), err:
                log.critical('**> ' + str(err))
                if debug_level:
                    raise
                else:
                    sys.exit(2)
            sys.exit(0)

        break
Beispiel #6
0
            import cset
            try:
                print cset.cpuspec_to_hex(cpuspec)
            except (ValueError, OSError, IOError, CpusetException,
                    CmdException), err:
                log.critical('**> ' + str(err))
                if debug_level:
                    raise
                else:
                    sys.exit(2)
            sys.exit(0)

        break

    # re-build the command line arguments
    cmd = commands.canonical_cmd(cmd)
    sys.argv[0] += ' %s' % cmd
    del (sys.argv[1])
    log.debug('cmdline: ' + ' '.join(sys.argv))

    try:
        # importing the cset class creates the model
        log.debug("creating cpuset model")
        import cpuset.cset
        command = commands[cmd]
        usage = command.usage.split('\n')[0].strip()
        parser = OptionParser(usage=usage, option_list=command.options)
        options, args = parser.parse_args()
        command.func(parser, options, args)
    except (ValueError, OSError, IOError, CpusetException, CmdException), err:
        log.critical('**> ' + str(err))