Example output to parse:
        141914132 user_name DONE queue_name exec_host b63cee711a job_name Feb 8 14:54
160892
def parse_query_output(cls, out):
        
        query_data = {}

        for line in out.strip().split("\n"):
            parts = line.split()
            if len(parts) < 6:
                continue

            job_id = parts[0]
            status_flag = parts[2]

            # map the status
            status = cls.map_status(status_flag)

            # save the result
            query_data[job_id] = cls.job_status_dict(job_id=job_id, status=status)

        return query_data
1179133
def parseSLURM(string):
    """"""
    # Use scontrol utility to get the hosts list
    import subprocess, os
    hostsstr = subprocess.check_output(["scontrol", "show", "hostnames", string])
    if sys.version_info.major > 2:
        hostsstr = hostsstr.decode()
    # Split using endline
    hosts = hostsstr.split(os.linesep)
    # Take out last empty host
    hosts = filter(None, hosts)
    # Create the desired pair of host and number of hosts
    hosts = [(host, 1) for host in hosts]
    return hosts
1151192
def parse_output(output, keep=("INCLUDE", "LIB", "LIBPATH", "PATH")):
    

    # dkeep is a dict associating key: path_list, where key is one item from
    # keep, and pat_list the associated list of paths
    dkeep = dict([(i, []) for i in keep])

    # rdk will  keep the regex to match the .bat file output line starts
    rdk = {}
    for i in keep:
        rdk[i] = re.compile('%s=(.*)' % i, re.I)

    def add_env(rmatch, key, dkeep=dkeep):
        path_list = rmatch.group(1).split(os.pathsep)
        for path in path_list:
            # Do not add empty paths (when a var ends with ;)
            if path:
                # XXX: For some reason, VC98 .bat file adds "" around the PATH
                # values, and it screws up the environment later, so we strip
                # it.
                path = path.strip('"')
                dkeep[key].append(str(path))

    for line in output.splitlines():
        for k, value in rdk.items():
            match = value.match(line)
            if match:
                add_env(match, k)

    return dkeep
399367
function format(param, data, cb) {
    const time = util.formatTime(new Date());
    const outArray = data.toString().replace(/^\s+|\s+$/g, '').split(/\s+/);
    let outValueArray = [];
    for (let i = 0; i < outArray.length; i++) {
        if ((!isNaN(outArray[i]))) {
            outValueArray.push(outArray[i]);
        }
    }
    const ps = {};
    ps.time = time;
    ps.serverId = param.serverId;
    ps.serverType = ps.serverId.split('-')[0];
    ps.pid = param.pid;
    const pid = ps.pid;
    ps.cpuAvg = outValueArray[1];
    ps.memAvg = outValueArray[2];
    ps.vsz = outValueArray[3];
    ps.rss = outValueArray[4];
    outValueArray = [];
    if (process.platform === 'darwin') {
        ps.usr = 0;
        ps.sys = 0;
        ps.gue = 0;
        cb(null, ps);
        return;
    }
    exec(`pidstat -p ${pid}`, (err, output) => {
        if (err) {
            console.error('the command pidstat failed! ', err.stack);
            return;
        }
        const _outArray = output.toString().replace(/^\s+|\s+$/g, '').split(/\s+/);
        for (let i = 0; i < _outArray.length; i++) {
            if ((!isNaN(_outArray[i]))) {
                outValueArray.push(_outArray[i]);
            }
        }
        ps.usr = outValueArray[1];
        ps.sys = outValueArray[2];
        ps.gue = outValueArray[3];

        cb(null, ps);
    });
}
785003
def at(host, command, seq, params):
    
    params_str = []
    for p in params:
        if type(p) == int:
            params_str.append('{:d}'.format(p))
        elif type(p) == float:
            params_str.append('{:d}'.format(f2i(p)))
        elif type(p) == str:
            params_str.append('"{:s}"'.format(p))
    msg = 'AT*{:s}={:d},{:s}\r'.format(command, seq, ','.join(params_str))
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.sendto(msg.encode(), (host, ardrone.constant.COMMAND_PORT))
980461
def extract_name_from_job_arn(arn):
    
    slash_pos = arn.find('/')
    if slash_pos == -1:
        raise ValueError("Cannot parse invalid ARN: %s" % arn)
    return arn[(slash_pos + 1):]
567341
function parseName(value) {
  var jobParts = [];

  var pathParts = (urlParse(value).pathname || '').split('/').filter(Boolean);
  var state = 0;
  var part;

  // iterate until we find our first job, then collect the continuous job parts
  //   ['foo', 'job', 'a', 'job', 'b', 'bar', 'job', 'c'] => ['a', 'b']
  loop:
  for (var i = 0; i < pathParts.length; i++) {
    part = pathParts[i];

    switch (state) {
      case 0:
        if (part === 'job') state = 2;
        break;
      case 1:
        if (part !== 'job') break loop;
        state = 2;
        break;
      case 2:
        jobParts.push(part);
        state = 1;
        break;
    }
  }

  return jobParts.map(decodeURIComponent);
}
596947
def receiveds_format(receiveds):
    
    log.debug("Receiveds for this email are parsed")

    output = []
    counter = Counter()

    for i in receiveds[::-1]:
        # Clean strings
        j = {k: v.strip() for k, v in i.items() if v}

        # Add hop
        j["hop"] = counter["hop"] + 1

        # Add UTC date
        if i.get("date"):
            # Modify date to manage strange header like:
            # "for <eboktor@romolo.com>; Tue, 7 Mar 2017 14:29:24 -0800",
            i["date"] = i["date"].split(";")[-1]
            try:
                j["date_utc"], _ = convert_mail_date(i["date"])
            except TypeError:
                j["date_utc"] = None

        # Add delay
        size = len(output)
        now = j.get("date_utc")

        if size and now:
            before = output[counter["hop"] - 1].get("date_utc")
            if before:
                j["delay"] = (now - before).total_seconds()
            else:
                j["delay"] = 0
        else:
            j["delay"] = 0

        # append result
        output.append(j)

        # new hop
        counter["hop"] += 1
    else:
        for i in output:
            if i.get("date_utc"):
                i["date_utc"] = i["date_utc"].isoformat()
        else:
            return output
423784
function parseLdOutput(output) {
    const libraryList = output.split('\n').filter(ln => ln.includes('=>'));

    const result = {};
    libraryList.forEach(s => {
        const [name, _, libPath] = s.trim().split(' ');
        result[name] = libPath;
    });

    return result;
}
790995
public static void main(String[] args) {
    final String sysTestData =
            "cpu  43559117 24094 1632164 1033740407 245624 29 200080 0 0 0\n"+
                    "cpu0 1630761 1762 62861 31960072 40486 15 10614 0 0 0\n"+
                    "cpu1 1531923 86 62987 32118372 13190 0 6806 0 0 0\n"+
                    "cpu2 1436788 332 66513 32210723 10867 0 6772 0 0 0\n"+
                    "cpu3 1428700 1001 64574 32223156 8751 0 6811 0 0 0\n"+
                    "cpu4 1424410 152 62649 32232602 6552 0 6836 0 0 0\n"+
                    "cpu5 1427172 1478 58744 32233938 5471 0 6708 0 0 0\n"+
                    "cpu6 1418433 348 60957 32241807 5301 0 6639 0 0 0\n"+
                    "cpu7 1404882 182 60640 32258150 3847 0 6632 0 0 0\n"+
                    "cpu8 1485698 3593 67154 32101739 38387 0 9016 0 0 0\n"+
                    "cpu9 1422404 1601 66489 32193865 15133 0 8800 0 0 0\n"+
                    "cpu10 1383939 3386 69151 32233567 11219 0 8719 0 0 0\n"+
                    "cpu11 1376904 3051 65256 32246197 8307 0 8519 0 0 0\n"+
                    "cpu12 1381437 1496 68003 32237894 6966 0 8676 0 0 0\n"+
                    "cpu13 1376250 1527 66598 32247951 7020 0 8554 0 0 0\n"+
                    "cpu14 1364352 1573 65520 32262764 5093 0 8531 0 0 0\n"+
                    "cpu15 1359076 1176 64380 32269336 5219 0 8593 0 0 0\n"+
                    "cpu16 1363844 6 29612 32344252 4830 2 4366 0 0 0\n"+
                    "cpu17 1477797 1019 70211 32190189 6278 0 3731 0 0 0\n"+
                    "cpu18 1285849 30 29219 32428612 3549 0 3557 0 0 0\n"+
                    "cpu19 1272308 0 27306 32445340 2089 0 3541 0 0 0\n"+
                    "cpu20 1326369 5 29152 32386824 2458 0 4416 0 0 0\n"+
                    "cpu21 1320883 28 31886 32384709 2327 1 4869 0 0 0\n"+
                    "cpu22 1259498 1 26954 32458931 2247 0 3511 0 0 0\n"+
                    "cpu23 1279464 0 26694 32439550 1914 0 3571 0 0 0\n"+
                    "cpu24 1229977 19 32308 32471217 4191 0 4732 0 0 0\n"+
                    "cpu25 1329079 92 79253 32324092 5267 0 4821 0 0 0\n"+
                    "cpu26 1225922 30 34837 32475220 4000 0 4711 0 0 0\n"+
                    "cpu27 1261848 56 43928 32397341 3552 0 5625 0 0 0\n"+
                    "cpu28 1226707 20 36281 32463498 3935 4 5943 0 0 0\n"+
                    "cpu29 1379751 19 35593 32317723 2872 4 5913 0 0 0\n"+
                    "cpu30 1247661 0 32636 32455845 2033 0 4775 0 0 0\n"+
                    "cpu31 1219016 10 33804 32484916 2254 0 4756 0 0 0\n"+
                    "intr 840450413 1194 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 55 0 0 0 0 0 0 45 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"+
                    "ctxt 1506565570\n"+
                    "btime 1385196580\n"+
                    "processes 1226464\n"+
                    "procs_running 21\n"+
                    "procs_blocked 0\n"+
                    "softirq 793917930 0 156954983 77578 492842649 1992553 0 7758971 51856558 228040 82206598\n";

    final String procTestData = "16790 (java) S 1 16789 16789 0 -1 4202496 6714145 0 0 0 4773058 5391 0 0 20 0 110 0 33573283 64362651648 6467228 18446744073709551615 1073741824 1073778376 140734614041280 140734614032416 140242897981768 0 0 3 16800972 18446744073709551615 0 0 17 27 0 0 0 0 0\n";

    LinuxProcFileReader lpfr = new LinuxProcFileReader();
    lpfr.parseSystemProcFile(sysTestData);
    lpfr.parseProcessProcFile(procTestData);
    System.out.println("System idle ticks: " + lpfr.getSystemIdleTicks());
    System.out.println("System total ticks: " + lpfr.getSystemTotalTicks());
    System.out.println("Process total ticks: " + lpfr.getProcessTotalTicks());
    System.out.println("Process RSS: " + lpfr.getProcessRss());
    System.out.println("Number of cpus: " + lpfr.getCpuTicks().length);
  }
343820
def to_s
      string =  "Execution ID:      #{@id}\n"
      string << "Name:              #{@name}\n"
      string << "Workflow ID:       #{@workflow_id}\n"
      string << "State:             #{@state}\n"
      string << "Start Date:        #{Time.at(@start_date / 1000)}\n"
      string << "End Date:          #{end_date.nil? ? '' : Time.at(@end_date / 1000)}\n"
      string << "Started By:        #{@started_by}\n"
      string << "Content Exception: #{@content_exception}\n" unless @content_exception.nil?
      string << "\nInput Parameters:\n"
      @input_parameters.each_value { |wf_param| string << " #{wf_param}" if wf_param.set? } if @input_parameters.size > 0
      string << "\nOutput Parameters:" << "\n"
      @output_parameters.each_value { |wf_param| string << " #{wf_param}" } if @output_parameters.size > 0
      string
    end
294788
def _output_to_dict(cmdoutput, values_mapper=None):
    '''
    
    '''
    if isinstance(cmdoutput, dict):
        if cmdoutput['retcode'] != 0 or cmdoutput['stderr']:
            raise CommandExecutionError(
                'RabbitMQ command failed: {0}'.format(cmdoutput['stderr'])
            )
        cmdoutput = cmdoutput['stdout']

    ret = {}
    if values_mapper is None:
        values_mapper = lambda string: string.split('\t')

    # remove first and last line: Listing ... - ...done
    data_rows = _strip_listing_to_done(cmdoutput.splitlines())

    for row in data_rows:
        try:
            key, values = row.split('\t', 1)
        except ValueError:
            # If we have reached this far, we've hit an edge case where the row
            # only has one item: the key. The key doesn't have any values, so we
            # set it to an empty string to preserve rabbitmq reporting behavior.
            # e.g. A user's permission string for '/' is set to ['', '', ''],
            # Rabbitmq reports this only as '/' from the rabbitmqctl command.
            log.debug('Could not find any values for key \'%s\'. '
                      'Setting to \'%s\' to an empty string.', row, row)
            ret[row] = ''
            continue
        ret[key] = values_mapper(values)
    return ret
110773
@Override
    public List<Job> parse(String text) throws ParseException {
        final List<Job> jobs;
        if (StringUtils.isNotBlank(text)) {
            text = StringUtils.replace(text, "\n\t", "");
            jobs = new LinkedList<Job>();
            String separator = "\n";
            if (text.indexOf("\r\n") > 0) {
                separator = "\r\n";
            }
            final String[] lines = text.split(separator);
            Job job = null;
            for (final String line : lines) {
                Matcher matcher = PATTERN_JOB.matcher(line);
                if (matcher.matches()) {
                    if (job != null) {
                        jobs.add(job);
                    }
                    job = new Job();
                    final String id = matcher.group(1).trim();
                    job.setId(id);
                } else if (StringUtils.isNotBlank(line)) {
                    String[] temp = Utils.splitFirst(line, CHAR_EQUALS);
                    if (temp.length == 2) {
                        final String key = temp[0].trim().toLowerCase();
                        final String value = temp[1].trim();
                        if ("job_name".equalsIgnoreCase(key)) {
                            job.setName(value);
                        } else if ("job_owner".equalsIgnoreCase(key)) {
                            job.setOwner(value);
                        } else if (key.startsWith("resources_used.")) {
                            job.getResourcesUsed().put(key, value);
                        } else if ("job_state".equalsIgnoreCase(key)) {
                            job.setState(value);
                        } else if ("queue".equalsIgnoreCase(key)) {
                            job.setQueue(value);
                        } else if ("server".equalsIgnoreCase(key)) {
                            job.setServer(value);
                        } else if ("checkpoint".equalsIgnoreCase(key)) {
                            job.setCheckpoint(value);
                        } else if ("ctime".equalsIgnoreCase(key)) {
                            job.setCtime(value);
                        } else if ("error_path".equalsIgnoreCase(key)) {
                            job.setErrorPath(value);
                        } else if ("exec_host".equalsIgnoreCase(key)) {
                            job.setExecHost(value);
                        } else if ("exec_port".equalsIgnoreCase(key)) {
                            job.setExecPort(value);
                        } else if ("hold_types".equalsIgnoreCase(key)) {
                            job.setHoldTypes(value);
                        } else if ("join_path".equalsIgnoreCase(key)) {
                            job.setJoinPath(value);
                        } else if ("keep_files".equalsIgnoreCase(key)) {
                            job.setKeepFiles(value);
                        } else if ("mail_points".equalsIgnoreCase(key)) {
                            job.setMailPoints(value);
                        } else if ("mail_users".equalsIgnoreCase(key)) {
                            job.setMailUsers(value);
                        } else if ("mtime".equalsIgnoreCase(key)) {
                            job.setMtime(value);
                        } else if ("output_path".equalsIgnoreCase(key)) {
                            job.setOutputPath(value);
                        } else if ("priority".equalsIgnoreCase(key)) {
                            try {
                                job.setPriority(Integer.parseInt(value));
                            } catch (NumberFormatException nfe) {
                                LOGGER.log(Level.WARNING, "Failed parsing job priority: " + nfe.getMessage(), nfe);
                                job.setPriority(-1);
                            }
                        } else if ("qtime".equalsIgnoreCase(key)) {
                            job.setQtime(value);
                        } else if ("rerunable".equalsIgnoreCase(key)) {
                            job.setRerunable(Boolean.parseBoolean(value));
                        } else if (key.startsWith("resource_list.")) {
                            job.getResourceList().put(key, value);
                        } else if ("session_id".equalsIgnoreCase(key)) {
                            try {
                                job.setSessionId(Integer.parseInt(value));
                            } catch (NumberFormatException nfe) {
                                LOGGER.log(Level.WARNING, "Failed parsing job session id: " + nfe.getMessage(), nfe);
                                job.setSessionId(-1);
                            }
                        } else if ("substate".equalsIgnoreCase(key)) {
                            try {
                                job.setSubstate(Integer.parseInt(value));
                            } catch (NumberFormatException nfe) {
                                LOGGER.log(Level.WARNING, "Failed parsing job substate: " + nfe.getMessage(), nfe);
                                job.setSubstate(-1);
                            }
                        } else if (key.startsWith("variable_list")) {
                            job.getVariableList().put(key, value);
                        } else if ("etime".equalsIgnoreCase(key)) {
                            job.setEtime(value);
                        } else if ("euser".equalsIgnoreCase(key)) {
                            job.setEuser(value);
                        } else if ("egroup".equalsIgnoreCase(key)) {
                            job.setEgroup(value);
                        } else if ("hashname".equalsIgnoreCase(key)) {
                            job.setHashName(value);
                        } else if ("queue_rank".equalsIgnoreCase(key)) {
                            try {
                                job.setQueueRank(Integer.parseInt(value));
                            } catch (NumberFormatException nfe) {
                                LOGGER.log(Level.WARNING, "Failed parsing job queue rank: " + nfe.getMessage(), nfe);
                                job.setQueueRank(-1);
                            }
                        } else if ("queue_type".equalsIgnoreCase(key)) {
                            job.setQueueType(value);
                        } else if ("comment".equalsIgnoreCase(key)) {
                            job.setComment(value);
                        } else if ("submit_args".equalsIgnoreCase(key)) {
                            job.setSubmitArgs(value);
                        } else if ("submit_host".equalsIgnoreCase(key)) {
                            job.setSubmitHost(value);
                        } else if ("start_time".equalsIgnoreCase(key)) {
                            job.setStartTime(value);
                        } else if ("start_count".equalsIgnoreCase(key)) {
                            try {
                                job.setStartCount(Integer.parseInt(value));
                            } catch (NumberFormatException nfe) {
                                LOGGER.log(Level.WARNING, "Failed parsing job start count: " + nfe.getMessage(), nfe);
                                job.setStartCount(-1);
                            }
                        } else if ("fault_tolerant".equalsIgnoreCase(key)) {
                            job.setFaultTolerant(Boolean.parseBoolean(value));
                        } else if ("job_array_id".equalsIgnoreCase(key)) {
                            job.setJobArrayId(Integer.parseInt(value));
                        } else if ("job_radix".equalsIgnoreCase(key)) {
                            try {
                                job.setRadix(Integer.parseInt(value));
                            } catch (NumberFormatException nfe) {
                                LOGGER.log(Level.WARNING, "Failed parsing job radix: " + nfe.getMessage(), nfe);
                                job.setRadix(-1);
                            }
                        } else if ("walltime.remaining".equalsIgnoreCase(key)) {
                            try {
                                job.setWalltimeRemaining(Long.parseLong(value));
                            } catch (NumberFormatException nfe) {
                                LOGGER.log(Level.WARNING, "Failed parsing job walltime remaining: " + nfe.getMessage(),
                                        nfe);
                                job.setWalltimeRemaining(-1L);
                            }
                        }
                    }
                }
            }
            if (job != null) {
                jobs.add(job);
            }
            return jobs;
        } else {
            return Collections.emptyList();
        }
    }
577015
def _parse_output_keys(val):
    
    out = {}
    for k in val.split(","):
        # record output
        if ":" in k:
            name, attrs = k.split(":")
            out[name] = attrs.split(";")
        else:
            out[k] = None
    return out
128185
def _parse_fmdump(output):
    '''
    
    '''
    result = []
    output = output.split("\n")

    # extract header
    header = [field for field in output[0].lower().split(" ") if field]
    del output[0]

    # parse entries
    for entry in output:
        entry = [item for item in entry.split(" ") if item]
        entry = ['{0} {1} {2}'.format(entry[0], entry[1], entry[2])] + entry[3:]

        # prepare faults
        fault = OrderedDict()
        for field in header:
            fault[field] = entry[header.index(field)]

        result.append(fault)

    return result
1088710
def parse():
    
    parser = argparse.ArgumentParser(
        description='Dynamic DynamoDB - Auto provisioning AWS DynamoDB')
    parser.add_argument(
        '-c', '--config',
        help='Read configuration from a configuration file')
    parser.add_argument(
        '--dry-run',
        action='store_true',
        help='Run without making any changes to your DynamoDB table')
    parser.add_argument(
        '--run-once',
        action='store_true',
        help='Run once and then exit Dynamic DynamoDB, instead of looping')
    parser.add_argument(
        '--show-config',
        action='store_true',
        help='Parse config files, print parsed data and then exit Dynamic DynamoDB')
    parser.add_argument(
        '--check-interval',
        type=int,
        help="""How many seconds should we wait between
                the checks (default: 300)""")
    parser.add_argument(
        '--log-file',
        help='Send output to the given log file')
    parser.add_argument(
        '--log-level',
        choices=['debug', 'info', 'warning', 'error'],
        help='Log level to use (default: info)')
    parser.add_argument(
        '--log-config-file',
        help=(
            'Use a custom Python logging configuration file. Overrides both '
            '--log-level and --log-file.'
        ))
    parser.add_argument(
        '--version',
        action='store_true',
        help='Print current version number')
    parser.add_argument(
        '--aws-access-key-id',
        help="Override Boto configuration with the following AWS access key")
    parser.add_argument(
        '--aws-secret-access-key',
        help="Override Boto configuration with the following AWS secret key")
    daemon_ag = parser.add_argument_group('Daemon options')
    daemon_ag.add_argument(
        '--daemon',
        help=(
            'Run Dynamic DynamoDB in daemon mode. Valid modes are '
            '[start|stop|restart|foreground]'))
    daemon_ag.add_argument(
        '--instance',
        default='default',
        help=(
            'Name of the Dynamic DynamoDB instance. '
            'Used to run multiple instances of Dynamic DynamoDB. '
            'Give each instance a unique name and control them separately '
            'with the --daemon flag. (default: default)'))
    daemon_ag.add_argument(
        '--pid-file-dir',
        default='/tmp',
        help='Directory where pid file is located in. Defaults to /tmp')
    dynamodb_ag = parser.add_argument_group('DynamoDB options')
    dynamodb_ag.add_argument(
        '-r', '--region',
        help='AWS region to operate in (default: us-east-1')
    dynamodb_ag.add_argument(
        '-t', '--table-name',
        help=(
            'Table(s) to target. '
            'The name is treated as a regular expression. '
            'E.g. "^my_table.*$" or "my_table"'))
    r_scaling_ag = parser.add_argument_group('Read units scaling properties')
    r_scaling_ag.add_argument(
        '--reads-upper-threshold',
        type=int,
        help="""Scale up the reads with --increase-reads-with if
                the currently consumed read units reaches this many
                percent (default: 90)""")
    r_scaling_ag.add_argument(
        '--throttled-reads-upper-threshold',
        type=int,
        help="""Scale up the reads with --increase-reads-with if
                the count of throttled read events exceeds this
                count (default: 0)""")
    r_scaling_ag.add_argument(
        '--reads-lower-threshold',
        type=int,
        help="""Scale down the reads with --decrease-reads-with if the
                currently consumed read units is as low as this
                percentage (default: 30)""")
    r_scaling_ag.add_argument(
        '--increase-reads-with',
        type=int,
        help="""How much should we increase the read units with?
                (default: 50, max: 100 if --increase-reads-unit = percent)""")
    r_scaling_ag.add_argument(
        '--decrease-reads-with',
        type=int,
        help="""How much should we decrease the read units with?
                (default: 50)""")
    r_scaling_ag.add_argument(
        '--increase-reads-unit',
        type=str,
        help='Do you want to scale in percent or units? (default: percent)')
    r_scaling_ag.add_argument(
        '--decrease-reads-unit',
        type=str,
        help='Do you want to scale in percent or units? (default: percent)')
    r_scaling_ag.add_argument(
        '--min-provisioned-reads',
        type=int,
        help="""Minimum number of provisioned reads""")
    r_scaling_ag.add_argument(
        '--max-provisioned-reads',
        type=int,
        help="""Maximum number of provisioned reads""")
    r_scaling_ag.add_argument(
        '--num-read-checks-before-scale-down',
        type=int,
        help="""Number of consecutive checks that must meet criteria
            before a scale down event occurs""")
    r_scaling_ag.add_argument(
        '--num-read-checks-reset-percent',
        type=int,
        help="""Percentage Value that will cause the num_read_checks_before
            scale_down var to reset back to 0""")
    w_scaling_ag = parser.add_argument_group('Write units scaling properties')
    w_scaling_ag.add_argument(
        '--writes-upper-threshold',
        type=int,
        help="""Scale up the writes with --increase-writes-with
                if the currently consumed write units reaches this
                many percent (default: 90)""")
    w_scaling_ag.add_argument(
        '--throttled-writes-upper-threshold',
        type=int,
        help="""Scale up the reads with --increase-writes-with if
                the count of throttled write events exceeds this
                count (default: 0)""")
    w_scaling_ag.add_argument(
        '--writes-lower-threshold',
        type=int,
        help="""Scale down the writes with --decrease-writes-with
                if the currently consumed write units is as low as this
                percentage (default: 30)""")
    w_scaling_ag.add_argument(
        '--increase-writes-with',
        type=int,
        help="""How much should we increase the write units with?
                (default: 50,
                max: 100 if --increase-writes-unit = 'percent')""")
    w_scaling_ag.add_argument(
        '--decrease-writes-with',
        type=int,
        help="""How much should we decrease the write units with?
                (default: 50)""")
    w_scaling_ag.add_argument(
        '--increase-writes-unit',
        type=str,
        help='Do you want to scale in percent or units? (default: percent)')
    w_scaling_ag.add_argument(
        '--decrease-writes-unit',
        type=str,
        help='Do you want to scale in percent or units? (default: percent)')
    w_scaling_ag.add_argument(
        '--min-provisioned-writes',
        type=int,
        help="""Minimum number of provisioned writes""")
    w_scaling_ag.add_argument(
        '--max-provisioned-writes',
        type=int,
        help="""Maximum number of provisioned writes""")
    w_scaling_ag.add_argument(
        '--num-write-checks-before-scale-down',
        type=int,
        help="""Number of consecutive checks that must meet criteria
            before a scale down event occurs""")
    w_scaling_ag.add_argument(
        '--num-write-checks-reset-percent',
        type=int,
        help="""Percentage Value that will cause the num_write_checks_before
            scale_down var to reset back to 0""")
    args = parser.parse_args()

    # Print the version and quit
    if args.version:
        # Read the dynamic-dynamodb.conf configuration file
        internal_config_file = ConfigParser.RawConfigParser()
        internal_config_file.optionxform = lambda option: option
        internal_config_file.read(
            os.path.abspath(
                os.path.join(
                    os.path.dirname(__file__), '../dynamic-dynamodb.conf')))

        print 'Dynamic DynamoDB version: {0}'.format(
            internal_config_file.get('general', 'version'))
        sys.exit(0)

    # Replace any new values in the configuration
    configuration = {}
    for arg in args.__dict__:
        if args.__dict__.get(arg) is not None:
            configuration[arg] = args.__dict__.get(arg)

    return configuration
981294
def parse_output(host, output):
    
    current_file = None
    for line in output.readlines():
        file_name_search = FILE_PATH_REGEX.search(line)
        if file_name_search:
            current_file = file_name_search.group(1)
            continue
        if INVALID_MESSAGE_REGEX.match(line) or INVALID_BYTES_REGEX.match(line):
            print_line(host, current_file, line, "ERROR")
        elif VALID_MESSAGE_REGEX.match(line) or \
                line.startswith('Starting offset:'):
            continue
        else:
            print_line(host, current_file, line, "UNEXPECTED OUTPUT")