src/wstool/config_yaml.py
def generate_config_yaml(config, filename, header, pretty=False,
                         sort_with_localname=False, spec=True,
                         exact=False, vcs_only=False):
    """
    Writes file filename with header first and then the config as YAML.

    :param config: The configuration containing all the entries to be included
    in the generated YAML.
    :param filename: If filename is not an absolute path, it will be assumed to
    be relative to config.get_base_path(). If filename is None, the output will
    be sent to stdout instead of a file.
    :param header: A header to be included with the generated config YAML.
    :param pretty: If True, the generated config YAML will be printed in
    long-form YAML. If false, the default flow style will be used instead.
    :param sort_with_localname: If true, config entries will be sorted by their
    localname fields. If false, the order will be as passed in through config.
    :param spec: If True, the version information will come from the workspace
    .rosinstall. If False, the version information will come from the current
    work trees.
    :param exact: If True, the versions will be set to the exact commit UUIDs.
    If False, the version name will be used, which might be a branch name
    aut cetera.
    :param vcs_only: If True, the generated config YAML will include only
    version-controlled entries. If False, all entries in current workspace will
    be included.
    """
    if not os.path.exists(config.get_base_path()):
        os.makedirs(config.get_base_path())

    content = ""
    if header:
        content += header

    # Do a pass-through if just pulling versioning information straight from
    # the .rosinstall
    passthrough = spec and not exact
    items = config.get_source(not passthrough, vcs_only)
    if sort_with_localname:
        items = sorted(items, key=lambda x: x.get_local_name())
    items = [x.get_legacy_yaml(spec, exact) for x in items]

    if items:
        if pretty:
            content += yaml.safe_dump(items, allow_unicode=True,
                                      default_flow_style=False)
        else:
            content += yaml.safe_dump(items, default_flow_style=None)

    if filename:
        config_filepath = filename if os.path.isabs(filename) else \
            os.path.realpath(os.path.join(config.get_base_path(), filename))

        with open(config_filepath, 'w+b') as f:
            f.write(content.encode('UTF-8'))
    else:
        print(content)

    Writes file filename with header first and then the config as YAML.

    :param config: The configuration containing all the entries to be included
    in the generated YAML.
    :param filename: If filename is not an absolute path, it will be assumed to
    be relative to config.get_base_path(). If filename is None, the output will
    be sent to stdout instead of a file.
    :param header: A header to be included with the generated config YAML.
    :param pretty: If True, the generated config YAML will be printed in
    long-form YAML. If false, the default flow style will be used instead.
    :param sort_with_localname: If true, config entries will be sorted by their
    localname fields. If false, the order will be as passed in through config.
    :param spec: If True, the version information will come from the workspace
    .rosinstall. If False, the version information will come from the current
    work trees.
    :param exact: If True, the versions will be set to the exact commit UUIDs.
    If False, the version name will be used, which might be a branch name
    aut cetera.
    :param vcs_only: If True, the generated config YAML will include only
    version-controlled entries. If False, all entries in current workspace will
    be included.
    
Writes file filename with header first and then the config as YAML.
Writes file filename with header first and then the config as YAML .
def generate_config_yaml(config, filename, header, pretty=False,
                         sort_with_localname=False, spec=True,
                         exact=False, vcs_only=False):
    if not os.path.exists(config.get_base_path()):
        os.makedirs(config.get_base_path())
    content = ""
    if header:
        content += header
    passthrough = spec and not exact
    items = config.get_source(not passthrough, vcs_only)
    if sort_with_localname:
        items = sorted(items, key=lambda x: x.get_local_name())
    items = [x.get_legacy_yaml(spec, exact) for x in items]
    if items:
        if pretty:
            content += yaml.safe_dump(items, allow_unicode=True,
                                      default_flow_style=False)
        else:
            content += yaml.safe_dump(items, default_flow_style=None)
    if filename:
        config_filepath = filename if os.path.isabs(filename) else \
            os.path.realpath(os.path.join(config.get_base_path(), filename))
        with open(config_filepath, 'w+b') as f:
            f.write(content.encode('UTF-8'))
    else:
        print(content)
def generate_config_yaml ( config , filename , header , pretty = False , sort_with_localname = False , spec = True , exact = False , vcs_only = False ) : if not os . path . exists ( config . get_base_path ( ) ) : os . makedirs ( config . get_base_path ( ) ) content = "" if header : content += header passthrough = spec and not exact items = config . get_source ( not passthrough , vcs_only ) if sort_with_localname : items = sorted ( items , key = lambda x : x . get_local_name ( ) ) items = [ x . get_legacy_yaml ( spec , exact ) for x in items ] if items : if pretty : content += yaml . safe_dump ( items , allow_unicode = True , default_flow_style = False ) else : content += yaml . safe_dump ( items , default_flow_style = None ) if filename : config_filepath = filename if os . path . isabs ( filename ) else os . path . realpath ( os . path . join ( config . get_base_path ( ) , filename ) ) with open ( config_filepath , 'w+b' ) as f : f . write ( content . encode ( 'UTF-8' ) ) else : print ( content )
Writes file filename with header first and then the config as YAML.
Writes file filename with header first and then the config as YAML .
"""
    Writes file filename with header first and then the config as YAML.

    :param config: The configuration containing all the entries to be included
    in the generated YAML.
    :param filename: If filename is not an absolute path, it will be assumed to
    be relative to config.get_base_path(). If filename is None, the output will
    be sent to stdout instead of a file.
    :param header: A header to be included with the generated config YAML.
    :param pretty: If True, the generated config YAML will be printed in
    long-form YAML. If false, the default flow style will be used instead.
    :param sort_with_localname: If true, config entries will be sorted by their
    localname fields. If false, the order will be as passed in through config.
    :param spec: If True, the version information will come from the workspace
    .rosinstall. If False, the version information will come from the current
    work trees.
    :param exact: If True, the versions will be set to the exact commit UUIDs.
    If False, the version name will be used, which might be a branch name
    aut cetera.
    :param vcs_only: If True, the generated config YAML will include only
    version-controlled entries. If False, all entries in current workspace will
    be included.
    """ # Do a pass-through if just pulling versioning information straight from # the .rosinstall
config
The configuration containing all the entries to be included
in the generated YAML.
The configuration containing all the entries to be included in the generated YAML .
filename
If filename is not an absolute path, it will be assumed to
be relative to config.get_base_path(). If filename is None, the output will
be sent to stdout instead of a file.
If filename is not an absolute path it will be assumed to be relative to config . get_base_path () . If filename is None the output will be sent to stdout instead of a file .
header
A header to be included with the generated config YAML.
A header to be included with the generated config YAML .
pretty
If True, the generated config YAML will be printed in
long-form YAML. If false, the default flow style will be used instead.
If True the generated config YAML will be printed in long - form YAML . If false the default flow style will be used instead .
sort_with_localname
If true, config entries will be sorted by their
localname fields. If false, the order will be as passed in through config.
If true config entries will be sorted by their localname fields . If false the order will be as passed in through config .
spec
If True, the version information will come from the workspace
.rosinstall. If False, the version information will come from the current
work trees.
If True the version information will come from the workspace . rosinstall . If False the version information will come from the current work trees .
exact
If True, the versions will be set to the exact commit UUIDs.
If False, the version name will be used, which might be a branch name
aut cetera.
If True the versions will be set to the exact commit UUIDs . If False the version name will be used which might be a branch name aut cetera .
vcs_only
If True, the generated config YAML will include only
version-controlled entries. If False, all entries in current workspace will
be included.
If True the generated config YAML will include only version - controlled entries . If False all entries in current workspace will be included .