Beispiel #1
0
def _data_file(fn, config, curdir=None):
    datapath = utils.data_dir(config.get('WORK_DIR', curdir))
    return os.path.join(datapath, fn)
Beispiel #2
0
def main(argv):
    parser = OptionParser()
    parser.add_option('-v', '--verbose', action='store_true', dest='verbose', \
                        help='increase verbosity')
    parser.add_option('--pid', type='int', help='process id')
    parser.add_option('--pname', help='process name')
    parser.add_option('--log-file', dest='logfile',  default='pyumdh.log',  \
            help='log file (default is %default)')
    opts, args = parser.parse_args(argv)

    binpath = utils.module_path()
    # load configuration and map its contents to a dict so that we could later
    # merge stock options with any dynamic content
    configpath = os.path.join(binpath, 'config.py')
    if os.path.exists(configpath):
        extconfig = imp.load_source('config', configpath)
        configopts = utils.Attributify(extconfig)
    else:
        configopts = utils.Attributify(config)

    log = logging.getLogger('umdh')
    log.addHandler(logging.StreamHandler())
    if opts.logfile:
        log.addHandler(logging.FileHandler(opts.logfile))
    if opts.verbose:
        log.setLevel(logging.DEBUG)

    datadir = utils.data_dir(configopts.get('WORK_DIR', binpath))
    log.debug('data files are here=%s' % datadir)

    configerrors = []

    if not configopts['DBG_BIN_PATHS']:
        log.warning('You might want to provide path to your application ' \
                    'binaries for symbol lookup to work best\n(configure ' \
                    'DBG_BIN_PATHS)')
    if not configopts['DBG_SYMBOL_PATHS']:
        log.warning('You might want to configure symbol paths for UMDH ' \
                'in DBG_SYMBOL_PATHS')
    if not configopts['DBG_TOOLS_PATH']:
        configerrors.append('You have to provide path to debugging tools for ' \
                'windows in DBG_TOOLS_PATH')

    if configerrors:
        error = '\n'.join(configerrors)
        log.critical(error)
        print 'If it is your first time running, please take time ' \
                'to go over config.py'
        return 1

    # check if any .cache files are available
    # cache files are a handy way to continue working on a particular active
    # umdh session
    cachefiles = [fn for fn in os.listdir(datadir) if fnmatch(fn, '.cache.py')]

    if not cachefiles and not opts.pid and not opts.pname:
        print 'Specify either process name or process id'
        parser.print_help()
        return 2

    if opts.pid or opts.pname:
        # if only process name has been specified, look up its pid
        pid = opts.pid or _find_pid(opts.pname, configopts)
    elif cachefiles:
        # currently, it makes sense to only handle a single cache file
        # i.e. file for the current session
        fn = cachefiles.pop()
        cachedconfig = imp.load_source('config', os.path.join(datadir, fn))
        cachedopts = utils.Attributify(cachedconfig)
        configopts.update(cachedopts)
        pid = int(configopts['active_pid'])
    umdh(pid, configopts)
    return 0
Beispiel #3
0
def _data_file(fn, config, curdir=None):
    datapath = utils.data_dir(config.get('WORK_DIR', curdir))
    return os.path.join(datapath, fn)
Beispiel #4
0
def main(argv):
    parser = OptionParser()
    parser.add_option('-v', '--verbose', action='store_true', dest='verbose', \
                        help='increase verbosity')
    parser.add_option('--pid', type='int', help='process id')
    parser.add_option('--pname', help='process name')
    parser.add_option('--log-file', dest='logfile',  default='pyumdh.log',  \
            help='log file (default is %default)')
    opts, args = parser.parse_args(argv)

    binpath = utils.module_path()
    # load configuration and map its contents to a dict so that we could later
    # merge stock options with any dynamic content
    configpath = os.path.join(binpath, 'config.py')
    if os.path.exists(configpath):
        extconfig = imp.load_source('config', configpath)
        configopts = utils.Attributify(extconfig)
    else:
        configopts = utils.Attributify(config)

    log = logging.getLogger('umdh')
    log.addHandler(logging.StreamHandler())
    if opts.logfile:
        log.addHandler(logging.FileHandler(opts.logfile))
    if opts.verbose:
        log.setLevel(logging.DEBUG)

    datadir = utils.data_dir(configopts.get('WORK_DIR', binpath))
    log.debug('data files are here=%s' % datadir)

    configerrors = []

    if not configopts['DBG_BIN_PATHS']:
        log.warning('You might want to provide path to your application ' \
                    'binaries for symbol lookup to work best\n(configure ' \
                    'DBG_BIN_PATHS)')
    if not configopts['DBG_SYMBOL_PATHS']:
        log.warning('You might want to configure symbol paths for UMDH ' \
                'in DBG_SYMBOL_PATHS')
    if not configopts['DBG_TOOLS_PATH']:
        configerrors.append('You have to provide path to debugging tools for ' \
                'windows in DBG_TOOLS_PATH')

    if configerrors:
        error = '\n'.join(configerrors)
        log.critical(error)
        print 'If it is your first time running, please take time ' \
                'to go over config.py'
        return 1

    # check if any .cache files are available
    # cache files are a handy way to continue working on a particular active
    # umdh session
    cachefiles = [fn for fn in os.listdir(datadir) if fnmatch(fn, '.cache.py')]

    if not cachefiles and not opts.pid and not opts.pname:
        print 'Specify either process name or process id'
        parser.print_help()
        return 2

    if opts.pid or opts.pname:
        # if only process name has been specified, look up its pid
        pid = opts.pid or _find_pid(opts.pname, configopts)
    elif cachefiles:
        # currently, it makes sense to only handle a single cache file
        # i.e. file for the current session
        fn = cachefiles.pop()
        cachedconfig = imp.load_source('config', os.path.join(datadir, fn))
        cachedopts = utils.Attributify(cachedconfig)
        configopts.update(cachedopts)
        pid = int(configopts['active_pid'])
    umdh(pid, configopts)
    return 0
Beispiel #5
0
        sys.exit(1)

    (opts, args) = parser.parse_args()
    sys.argv[:] = args

    log = logging.getLogger('umdh')
    log.addHandler(logging.StreamHandler())
    if opts.verbose:
        log.setLevel(logging.DEBUG)

    if args:
        log.debug('unqualified files=%s' % args)
    if os.path.exists(configpath):
        log.debug('using local config.py')

    datadir = utils.data_dir(config.get('WORK_DIR', binpath))
    cachefiles = [fn for fn in os.listdir(datadir) if fnmatch(fn, '.cache.py')]
    if cachefiles:
        cachefile = cachefiles.pop()
        log.debug('using cached config: %s' % cachefile)
        cachedconfig = imp.load_source('config', \
                                os.path.join(datadir, cachefile))
        cachedopts = utils.Attributify(cachedconfig)
        config.update(cachedopts)
    # in case we receive ids for log files on the command line
    # guess them by probing files in the configured working directory
    # given options from the cached config
    files = opts.logs or args
    try:
        _ids = map(int, files)
    except ValueError: