Skip to content

Add utility functions to slsutil module#49396

Merged
cachedout merged 3 commits into
saltstack:developfrom
amendlik:slsutil
Sep 2, 2018
Merged

Add utility functions to slsutil module#49396
cachedout merged 3 commits into
saltstack:developfrom
amendlik:slsutil

Conversation

@amendlik
Copy link
Copy Markdown
Contributor

What does this PR do?

Add two utility functions to the slsutil execution module. These functions are for convenience when creating template files.

Banner

slsutil.banner creates a standard warning banner like this:

        ########################################################################
        #                                                                      #
        #              THIS FILE IS MANAGED BY SALT - DO NOT EDIT              #
        #                                                                      #
        # The contents of this file are managed by Salt. Any changes to this   #
        # file may be overwritten automatically and without warning.           #
        ########################################################################

The banner is fully customizable in its content and appearance.

Boolstr

slsutil.boolstr is for converting boolean values stored in Pillar to an appropriate string representation within templated files. This can obviously be done in Jinja, but it requires an entire if/else block and managing whitespace becomes difficult.

See embedded documentation for more details.

What issues does this PR fix or reference?

None

Tests written?

Yes

Commits signed with GPG?

Yes

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.

Comment thread salt/modules/slsutil.py Outdated
block.append(blockend)

# Convert list to multiline string
result = '\n'.join(block)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better multi-platform support we should probably use os.linesep here instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That suggestion sounded right to me, but the documentation is making me think not:

Do not use os.linesep as a line terminator when writing files opened in text mode (the default); use a single '\n' instead, on all platforms.

It seems that Python converts \n to os.linesep when it writes out the file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files aren't ultimately opened in text mode, though. That's the thing. :)

@cachedout cachedout merged commit 5fac9eb into saltstack:develop Sep 2, 2018
@amendlik amendlik deleted the slsutil branch November 21, 2018 16:01
@s0undt3ch s0undt3ch mentioned this pull request Apr 21, 2020
1 task
@s0undt3ch
Copy link
Copy Markdown
Contributor

Port to master #56761

@s0undt3ch s0undt3ch added the has master-port port to master has been created label Apr 21, 2020
@amendlik
Copy link
Copy Markdown
Contributor Author

@s0undt3ch Please consider bringing #53499 along with this one. It includes a few fixes to the original PR.

@s0undt3ch
Copy link
Copy Markdown
Contributor

@amendlik Thank You! Will do.

dwoz added a commit that referenced this pull request Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-jam has master-port port to master has been created

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants