Load stats from provided arg or github
193984
def load_stats(data, user)
      return data if data
      raise('No data or user provided') unless user
      stats = GithubStats.new(user).data
      raise("Failed to find data for #{user} on GitHub") unless stats
      stats
    end
1340955
def load_stats(self, cache=None, wait=None):
        
        if cache is None:
            cache = not self.debug
        if wait is None:
            wait = self.debug
        if not cache or self._stats is None:
            self._stats = self._load_stats()
            start = time.time()
            while wait and self._stats.get('status') == 'compiling':
                if self.timeout and (time.time() - start > self.timeout):
                    raise RuntimeError("Webpack {0!r} timed out while compiling"
                                       .format(self.stats_file.path))
                time.sleep(0.1)
                self._stats = self._load_stats()
        return self._stats
769195
def stats(self):
        """"""
        if not self.parents:
            text = self.repo.git.diff_tree(self.hexsha, '--', numstat=True, root=True)
            text2 = ""
            for line in text.splitlines()[1:]:
                (insertions, deletions, filename) = line.split("\t")
                text2 += "%s\t%s\t%s\n" % (insertions, deletions, filename)
            text = text2
        else:
            text = self.repo.git.diff(self.parents[0].hexsha, self.hexsha, '--', numstat=True)
        return Stats._list_from_string(self.repo, text)
1360857
def Parse(self, cmd, args, stdout, stderr, return_val, time_taken,
            knowledge_base):
    """"""
    _ = stderr, time_taken, args, knowledge_base  # Unused.
    self.CheckReturn(cmd, return_val)
    output = iter(stdout.decode("utf-8").splitlines())

    repo_regexes = {
        "name": self._re_compile("Repo-name"),
        "revision": self._re_compile("Repo-revision"),
        "last_update": self._re_compile("Repo-updated"),
        "num_packages": self._re_compile("Repo-pkgs"),
        "size": self._re_compile("Repo-size"),
        "baseurl": self._re_compile("Repo-baseurl"),
        "timeout": self._re_compile("Repo-expire")
    }

    repo_id_re = self._re_compile("Repo-id")

    for line in output:
      match = repo_id_re.match(line)
      if match:
        repo_info = rdf_client.PackageRepository()
        setattr(repo_info, "id", match.group(1).strip())
        while line:
          for attr, regex in iteritems(repo_regexes):
            match = regex.match(line)
            if match:
              setattr(repo_info, attr, match.group(1).strip())
              break
          line = next(output)
        yield repo_info
254021
def get_params_parser():
    """"""

    parser = argparse.ArgumentParser()

    ElasticOcean.add_params(parser)

    parser.add_argument('-g', '--debug', dest='debug', action='store_true')
    parser.add_argument('-t', '--token', dest='token', help="GitHub token")
    parser.add_argument('-o', '--org', dest='org', help='GitHub Organization to be analyzed')
    parser.add_argument('-c', '--contact', dest='contact', help='Contact (mail) to notify events.')
    parser.add_argument('--twitter', dest='twitter', help='Twitter account to notify.')
    parser.add_argument('-w', '--web-dir', default='/var/www/cauldron/dashboards', dest='web_dir',
                        help='Redirect HTML project pages for accessing Kibana dashboards.')
    parser.add_argument('-k', '--kibana-url', default='https://dashboard.cauldron.io', dest='kibana_url',
                        help='Kibana URL.')
    parser.add_argument('-u', '--graas-url', default='https://cauldron.io', dest='graas_url',
                        help='GraaS service URL.')
    parser.add_argument('-n', '--nrepos', dest='nrepos', type=int, default=NREPOS,
                        help='Number of GitHub repositories from the Organization to be analyzed (default:10)')

    return parser
794645
def add_stats(self, args):
        """"""
        bg_name, stats = args
        logger.debug("Stats: %s %s", bg_name, stats)
        
        for motif_id in stats.keys():
            if motif_id not in self.stats:
                self.stats[motif_id] = {}
        
            self.stats[motif_id][bg_name] = stats[motif_id]
1374662
def parse_args(args, cfg):
    
    prog = pathlib.Path(sys.argv[0]).parts[-1].replace('.py', '')
    prog_version = "%%(prog)s %s" % versionner.__version__

    # pylint: disable=invalid-name
    p = argparse.ArgumentParser(prog=prog, description='Helps manipulating version of the project')
    p.add_argument('--file', '-f', dest='version_file', type=str,
        default=cfg.version_file,
        help="path to file where version is saved")
    p.add_argument('--version', '-v', action="version", version=prog_version)
    p.add_argument('--date-format', type=str,
        default=cfg.date_format,
        help="Date format used in project files")
    p.add_argument('--verbose', action="store_true",
        help="Be more verbose if it's possible")

    sub = p.add_subparsers(dest='command')

    p_init = sub.add_parser('init', aliases=commands.get_aliases_for('init'),
        help="Create new version file")
    p_init.add_argument('value', nargs='?', type=str,
        default=cfg.default_init_version,
        help="Initial version")
    p_init.add_argument('--vcs-engine', type=str,
        default=cfg.vcs_engine,
        help="Select VCS engine (only git is supported currently)", )
    p_init.add_argument('--vcs-commit-message', '-m', type=str,
        default=cfg.vcs_commit_message,
        help="Commit message used when committing changes")
    p_init.add_argument('--commit', '-c', action='store_true',
        help="Commit changes done by `up` command (only if there is no changes in repo before)")

    p_up = sub.add_parser('up', aliases=commands.get_aliases_for('up'),
        help="Increase version")
    p_up.add_argument('--vcs-engine', type=str,
        default=cfg.vcs_engine,
        help="Select VCS engine (only git is supported currently)", )
    p_up.add_argument('--vcs-commit-message', '-m', type=str,
        default=cfg.vcs_commit_message,
        help="Commit message used when committing changes")
    p_up.add_argument('--commit', '-c', action='store_true',
        help="Commit changes done by `up` command (only if there is no changes in repo before)")
    p_up.add_argument('value', nargs='?', type=int,
        default=cfg.default_increase_value,
        help="Increase version by this value (default: %d)" % cfg.default_increase_value)

    p_up_gr = p_up.add_mutually_exclusive_group()
    p_up_gr.add_argument('--major', '-j', action="store_true",
        help="increase major part of version" + (" (project default)" if cfg.up_part == 'major' else ""))
    p_up_gr.add_argument('--minor', '-n', action="store_true",
        help="increase minor part of version" + (" (project default)" if cfg.up_part == 'minor' else ""))
    p_up_gr.add_argument('--patch', '-p', action="store_true",
        help="increase patch part of version" + (" (project default)" if cfg.up_part == 'patch' else ""))

    p_set = sub.add_parser('set', aliases=commands.get_aliases_for('set'),
        help="Set version to specified one")
    p_set.add_argument('--major', '-j', type=int,
        help="set major part of version to MAJOR")
    p_set.add_argument('--minor', '-n', type=int,
        help="set minor part of version to MINOR")
    p_set.add_argument('--patch', '-p', type=int,
        help="set patch part of version to PATCH")
    p_set.add_argument('--prerelease', '-r', type=str,
        help="set prerelease part of version to PRERELEASE")
    p_set.add_argument('--build', '-b', type=str,
        help="set build part of version to BUILD")
    p_set.add_argument('--vcs-engine', type=str,
        default=cfg.vcs_engine,
        help="Select VCS engine (only git is supported currently)", )
    p_set.add_argument('--vcs-commit-message', '-m', type=str,
        default=cfg.vcs_commit_message,
        help="Commit message used when committing changes")
    p_set.add_argument('--commit', '-c', action='store_true',
        help="Commit changes done by `set` command (only if there is no changes in repo before)")
    p_set.add_argument('value', nargs='?', type=str,
        help="set version to this value")

    p_tag = sub.add_parser('tag', aliases=commands.get_aliases_for('tag'),
        help="Create VCS tag with current version")
    p_tag.add_argument('--vcs-tag-param', dest='vcs_tag_params', type=str, action="append",
        help="Additional params for VCS for \"tag\" command")

    sub.add_parser('read', aliases=commands.get_aliases_for('read'),
        help="Read current version")

    args = p.parse_args(args)

    cfg.command = args.command
    cfg.version_file = pathlib.Path(args.version_file).absolute()
    cfg.date_format = args.date_format
    cfg.verbose = args.verbose

    version_file_requirement = 'doesn\'t matter'
    if cfg.command == 'init':
        version_file_requirement = 'none'

        cfg.commit = args.commit
        cfg.vcs_engine = args.vcs_engine
        cfg.vcs_commit_message = args.vcs_commit_message
        cfg.value = args.value

    elif cfg.command == 'up':
        version_file_requirement = 'required'

        cfg.commit = args.commit
        cfg.vcs_engine = args.vcs_engine
        cfg.vcs_commit_message = args.vcs_commit_message
        cfg.value = args.value
        if args.major:
            cfg.up_part = 'major'
        elif args.minor:
            cfg.up_part = 'minor'
        elif args.patch:
            cfg.up_part = 'patch'

    elif cfg.command == 'set':
        version_file_requirement = 'required'

        cfg.commit = args.commit
        cfg.vcs_engine = args.vcs_engine
        cfg.vcs_commit_message = args.vcs_commit_message

        if args.value:
            cfg.value = args.value
        else:
            cfg.value = (
                args.major, args.minor, args.patch,
                args.prerelease, args.build
            )

            if all(value is None for value in cfg.value):
                p.error("Version is not specified")

    elif cfg.command == 'tag':
        version_file_requirement = 'required'

        cfg.vcs_tag_params = args.vcs_tag_params or []

    elif cfg.command is None:
        cfg.command = 'read'
        version_file_requirement = 'required'

    if version_file_requirement == 'required':
        if not cfg.version_file.exists():
            p.error("Version file \"%s\" doesn't exists" % cfg.version_file)
    elif version_file_requirement == 'none':
        if cfg.version_file.exists():
            p.error("Version file \"%s\" already exists" % cfg.version_file)
710033
def build_argparser():
    """"""
    parser = ArgumentParser('Utility for managing MAR files')
    create_group = parser.add_argument_group("Create a MAR file")
    create_group.add_argument("-c", "--create", metavar="MARFILE", help="create MAR")
    create_group.add_argument("-V", "--productversion", dest="productversion",
                              help="product/version string")
    create_group.add_argument("-H", "--channel", dest="channel",
                              help="channel this MAR file is applicable to")
    create_group.add_argument("files", nargs=REMAINDER,
                              help="files to add to the MAR file")

    extract_group = parser.add_argument_group("Extract a MAR file")
    extract_group.add_argument("-x", "--extract", help="extract MAR", metavar="MARFILE")

    list_group = parser.add_argument_group("Print information on a MAR file")
    list_group.add_argument("-t", "--list", help="print out MAR contents",
                            metavar="MARFILE")
    list_group.add_argument("-T", "--list-detailed", metavar="MARFILE",
                            help="print out MAR contents including signatures")

    verify_group = parser.add_argument_group("Verify a MAR file")
    verify_group.add_argument("-v", "--verify", metavar="MARFILE",
                              help="verify the marfile")

    parser.add_argument("-j", "--bzip2", action="store_const", dest="compression",
                        const="bz2", help="compress/decompress members with BZ2")
    parser.add_argument("-J", "--xz", action="store_const", dest="compression",
                        const="xz", help="compress/decompress archive with XZ")
    parser.add_argument("--auto", action="store_const", dest="compression",
                        const="auto", help="automatically decompress contents")

    parser.add_argument("-k", "--keyfiles", dest="keyfiles", action='append',
                        help="sign/verify with given key(s)")
    parser.add_argument("-C", "--chdir", dest="chdir",
                        help="chdir to this directory before creating or "
                        "extracing; location of marfile isn't affected by "
                        "this option.")
    parser.add_argument("--verbose", dest="loglevel", action="store_const",
                        const=logging.DEBUG, default=logging.WARN,
                        help="increase logging verbosity")
    parser.add_argument('--version', action='version', version='mar version {}'.format(mardor.version_str))

    signing_group = parser.add_argument_group('Sign a MAR file')
    signing_group.add_argument('--hash', help='output hash for signing', choices=('sha1', 'sha384'))
    signing_group.add_argument('--asn1', help='format hash as an ASN1 DigestInfo block',
                               default=False, action='store_true')
    signing_group.add_argument('--add-signature', help='inject signature', nargs=3,
                               metavar=('input', 'output', 'signature'))

    return parser
590583
def load_from_args(args):
    
    if not args.reads:
        return None

    if args.read_source_name:
        read_source_names = util.expand(
            args.read_source_name,
            'read_source_name',
            'read source',
            len(args.reads))
    else:
        read_source_names = util.drop_prefix(args.reads)

    filters = []
    for (name, info) in READ_FILTERS.items():
        value = getattr(args, name)
        if value is not None:
            filters.append(functools.partial(info[-1], value))

    return [
        load_bam(filename, name, filters)
        for (filename, name)
        in zip(args.reads, read_source_names)
    ]
686244
function getParams(args, proto, ObjName) {

    if (null == proto) {
        logger.error('No proto File Configured！');
        return {};
    } else if (typeof proto == "string") {
        if (fs.existsSync(proto)) {
            proto = ProtoBuf.loadProtoFile(proto);
        } else if (fs.existsSync(proto + ".proto")) {
            proto = ProtoBuf.loadProtoFile(proto + ".proto");
        } else {
            return {};
        }
    }

    var Obj = proto.build(ObjName);
    var msg = Obj.decode64(args);
    debug && logger.trace("Load Data From Client [ %s ]", JSON.stringify(msg));
    return msg;
}
557130
function processArgs(args, files = []) {
  return args.reduce((acc, arg) => {
    let stats;
    try {
      stats = fs.statSync(arg);
    } catch (err) {
      // Do nothing
    }

    // If argument is a directory, process the files inside
    if (stats && stats.isDirectory()) {
      return processArgs(
        fs.readdirSync(arg).map(file => path.join(arg, file)),
        files
      );
    }

    // If `statSync` failed, validating will handle the error
    // If the argument is a file, check if its a JSON file before validating
    if (!stats || JsonFileRegex.test(arg)) {
      acc.push(validateFile(arg));
    }

    return acc;
  }, files);
}
738589
def main(argv=None):
    """"""
    if argv is None:
        argv = sys.argv[1:]
    usage = '\n\n\n'.join(__doc__.split('\n\n\n')[1:])
    version = 'Gitpress ' + __version__

    # Parse options
    args = docopt(usage, argv=argv, version=version)

    # Execute command
    try:
        return execute(args)
    except RepositoryNotFoundError as ex:
        error('No Gitpress repository found at', ex.directory)
798432
def get(args):
    """"""
    from . import config
    for key in args.key.split("."):
        config = getattr(config, key)
    print(json.dumps(config))
720262
def get(self):
        """"""
        if self.gist:
            content = self.github.read_gist_file(self.gist)
            self.local.save(content)
348277
def ls(args):
    
    table = []
    queues = list(resources.sqs.queues.filter(QueueNamePrefix="github"))
    max_age = datetime.now(tzutc()) - timedelta(days=15)
    for topic in resources.sns.topics.all():
        account_id = ARN(topic.arn).account_id
        try:
            bucket = resources.s3.Bucket("deploy-status-{}".format(account_id))
            status_objects = bucket.objects.filter(Prefix=ARN(topic.arn).resource)
            recent_status_objects = {o.key: o for o in status_objects if o.last_modified > max_age}
        except ClientError:
            continue
        if ARN(topic.arn).resource.startswith("github"):
            for queue in queues:
                queue_name = os.path.basename(queue.url)
                if queue_name.startswith(ARN(topic.arn).resource):
                    row = dict(Topic=topic, Queue=queue)
                    status_object = bucket.Object(os.path.join(queue_name, "status"))
                    if status_object.key not in recent_status_objects:
                        continue
                    try:
                        github, owner, repo, events, instance = os.path.dirname(status_object.key).split("-", 4)
                        status = json.loads(status_object.get()["Body"].read().decode("utf-8"))
                        row.update(status, Owner=owner, Repo=repo, Instance=instance,
                                   Updated=status_object.last_modified)
                    except Exception:
                        pass
                    table.append(row)
    args.columns = ["Owner", "Repo", "Instance", "Status", "Ref", "Commit", "Updated", "Topic", "Queue"]
    page_output(tabulate(table, args))
73890
def cmd(send, msg, args):
    
    repo = args['config']['api']['githubrepo']
    apikey = args['config']['api']['githubapikey']
    if not repo:
        send("GitHub repository undefined in config.cfg!")
        return
    parser = arguments.ArgParser(args['config'])
    parser.add_argument('title', nargs='*', default='')
    parser.add_argument('--get', '--show', action='store_true')
    parser.add_argument('--description', nargs='+', default="No description given.")
    cmdargs, remainder = parser.parse_known_args(msg)
    if isinstance(cmdargs.title, list):
        cmdargs.title = ' '.join(cmdargs.title)
    if isinstance(cmdargs.description, list):
        cmdargs.description = ' '.join(cmdargs.description)
    if remainder:
        cmdargs.title = "%s %s" % (cmdargs.title, ' '.join(remainder))
    if args['type'] == 'privmsg':
        send('You want to let everybody know about your problems, right?')
    elif cmdargs.get or cmdargs.title.isdigit():
        issue = get('https://api.github.com/repos/%s/issues/%d' % (repo, int(cmdargs.title))).json()
        if 'message' in issue:
            send("Invalid Issue Number")
        else:
            send("%s (%s) -- %s" % (issue['title'], issue['state'], issue['html_url']))
    elif not cmdargs.title:
        issues = []
        n = 1
        while True:
            headers = {'Authorization': 'token %s' % apikey}
            page = get('https://api.github.com/repos/%s/issues' % repo, params={'per_page': '100', 'page': n}, headers=headers).json()
            n += 1
            if page:
                issues += page
            else:
                break
        if len(issues) == 0:
            send("No open issues to choose from!")
        else:
            issue = choice(issues)
            num_issues = len([x for x in issues if 'pull_request' not in x])
            send("There are %d open issues, here's one." % num_issues)
            send("#%d -- %s -- %s" % (issue['number'], issue['title'], issue['html_url']))
    elif cmdargs.title and args['is_admin'](args['nick']):
        url, success = create_issue(cmdargs.title, cmdargs.description, args['source'], repo, apikey)
        if success:
            send("Issue created -- %s -- %s -- %s" % (url, cmdargs.title, cmdargs.description))
        else:
            send("Error creating issue: %s" % url)
    elif cmdargs.title:
        row = Issues(title=cmdargs.title, description=cmdargs.description, source=str(args['source']))  # str needed to make mysqlconnector happy
        args['db'].add(row)
        args['db'].flush()
        send("New Issue: #%d -- %s -- %s, Submitted by %s" % (row.id, cmdargs.title, cmdargs.description, args['nick']),
             target=args['config']['core']['ctrlchan'])
        send("Issue submitted for approval.", target=args['nick'])
    else:
        send("Invalid arguments.")
1030683
def stats(args):
    
    p = OptionParser(stats.__doc__)
    p.set_outfile()
    opts, args = p.parse_args(args)

    if len(args) != 1:
        sys.exit(not p.print_help())

    folder, = args
    statsfiles = iglob(folder, "*.stats")
    after_equal = lambda x: x.split("=")[-1]
    header = "Library Assembled_reads Contigs".split()
    contents = []
    # label=M0096 total=7443 cnts=948 mean=7.851 std=35.96
    for statsfile in statsfiles:
        fp = open(statsfile)
        for row in fp:
            if row.startswith("label="):
                break
        label, total, cnts = row.split()[:3]
        label = after_equal(label)
        reads = int(after_equal(total))
        contigs = int(after_equal(cnts))
        contents.append((label, reads, contigs))

    all_labels, all_reads, all_contigs = zip(*contents)
    contents.append(("SUM", sum(all_reads), sum(all_contigs)))
    contents.append(("AVERAGE (per sample)", \
                    int(np.mean(all_reads)), int(np.mean(all_contigs))))
    contents.append(("MEDIAN (per sample)", \
                    int(np.median(all_reads)), int(np.median(all_contigs))))
    write_csv(header, contents, filename=opts.outfile)