Exemplo n.º 1
0
def cache_cmd(args):
    "Generates a release notes cache"
    reporoot = args.reporoot.rstrip('/') + '/'
    notesdir = utils.get_notes_dir(args)
    if args.output == '-':
        stream = sys.stdout
        close_stream = False
    elif args.output:
        stream = open(args.output, 'w')
        close_stream = True
    else:
        stream = open(loader.get_cache_filename(reporoot, notesdir), 'w')
        close_stream = True
    try:
        cache = build_cache_db(
            reporoot=reporoot,
            notesdir=notesdir,
            branch=args.branch,
            collapse_pre_releases=args.collapse_pre_releases,
            versions_to_include=args.version,
            earliest_version=args.earliest_version,
        )
        yaml.safe_dump(
            cache,
            stream,
            allow_unicode=True,
            explicit_start=True,
            encoding='utf-8',
        )
    finally:
        if close_stream:
            stream.close()
    return
Exemplo n.º 2
0
def cache_cmd(args):
    "Generates a release notes cache"
    reporoot = args.reporoot.rstrip('/') + '/'
    notesdir = utils.get_notes_dir(args)
    if args.output == '-':
        stream = sys.stdout
        close_stream = False
    elif args.output:
        stream = open(args.output, 'w')
        close_stream = True
    else:
        stream = open(loader.get_cache_filename(reporoot, notesdir), 'w')
        close_stream = True
    try:
        cache = build_cache_db(
            reporoot=reporoot,
            notesdir=notesdir,
            branch=args.branch,
            collapse_pre_releases=args.collapse_pre_releases,
            versions_to_include=args.version,
            earliest_version=args.earliest_version,
        )
        yaml.safe_dump(
            cache,
            stream,
            allow_unicode=True,
            explicit_start=True,
            encoding='utf-8',
        )
    finally:
        if close_stream:
            stream.close()
    return
Exemplo n.º 3
0
def load_config(distribution):
    """Utility method to parse distutils/setuptools configuration.

    This is for use by other libraries to extract the command configuration.

    :param distribution: A :class:`distutils.dist.Distribution` object
    :returns: A tuple of a :class:`reno.config.Config` object, the output path
        of the human-readable release notes file, and the output file of the
        reno cache file
    """
    option_dict = distribution.get_option_dict(COMMAND_NAME)

    if option_dict.get('repo_root') is not None:
        repo_root = option_dict.get('repo_root')[1]
    else:
        repo_root = defaults.REPO_ROOT

    if option_dict.get('rel_notes_dir') is not None:
        rel_notes_dir = option_dict.get('rel_notes_dir')[1]
    else:
        rel_notes_dir = defaults.RELEASE_NOTES_SUBDIR

    if option_dict.get('output_file') is not None:
        output_file = option_dict.get('output_file')[1]
    else:
        output_file = defaults.RELEASE_NOTES_FILENAME

    conf = config.Config(repo_root, rel_notes_dir)
    cache_file = loader.get_cache_filename(conf)

    return (conf, output_file, cache_file)
Exemplo n.º 4
0
def write_cache_db(conf, versions_to_include,
                   outfilename=None):
    """Create a cache database file for the release notes data.

    Build the cache database from scanning the project history and
    write it to a file within the project.

    By default, the data is written to the same file the scanner will
    try to read when it cannot look at the git history. If outfilename
    is given and is '-' the data is written to stdout
    instead. Otherwise, if outfilename is given, the data overwrites
    the named file.

    Return the name of the file created, if any.

    """
    if outfilename == '-':
        stream = sys.stdout
        close_stream = False
    elif outfilename:
        stream = open(outfilename, 'w')
        close_stream = True
    else:
        outfilename = loader.get_cache_filename(conf.reporoot, conf.notespath)
        if not os.path.exists(os.path.dirname(outfilename)):
            os.makedirs(os.path.dirname(outfilename))
        stream = open(outfilename, 'w')
        close_stream = True
    try:
        cache = build_cache_db(
            conf,
            versions_to_include=versions_to_include,
        )
        yaml.safe_dump(
            cache,
            stream,
            allow_unicode=True,
            explicit_start=True,
            encoding='utf-8',
        )
    finally:
        if close_stream:
            stream.close()
    return outfilename