repo stringclasses 85
values | path stringlengths 8 121 | func_name stringlengths 1 82 | original_string stringlengths 112 65.5k | language stringclasses 1
value | code stringlengths 112 65.5k | code_tokens listlengths 20 4.09k | docstring stringlengths 3 46.3k | docstring_tokens listlengths 1 564 | sha stringclasses 85
values | url stringlengths 93 218 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
saltstack/salt | salt/modules/file.py | _sed_esc | def _sed_esc(string, escape_all=False):
'''
Escape single quotes and forward slashes
'''
special_chars = "^.[$()|*+?{"
string = string.replace("'", "'\"'\"'").replace("/", "\\/")
if escape_all is True:
for char in special_chars:
string = string.replace(char, "\\" + char)
... | python | def _sed_esc(string, escape_all=False):
'''
Escape single quotes and forward slashes
'''
special_chars = "^.[$()|*+?{"
string = string.replace("'", "'\"'\"'").replace("/", "\\/")
if escape_all is True:
for char in special_chars:
string = string.replace(char, "\\" + char)
... | [
"def",
"_sed_esc",
"(",
"string",
",",
"escape_all",
"=",
"False",
")",
":",
"special_chars",
"=",
"\"^.[$()|*+?{\"",
"string",
"=",
"string",
".",
"replace",
"(",
"\"'\"",
",",
"\"'\\\"'\\\"'\"",
")",
".",
"replace",
"(",
"\"/\"",
",",
"\"\\\\/\"",
")",
"... | Escape single quotes and forward slashes | [
"Escape",
"single",
"quotes",
"and",
"forward",
"slashes"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1037-L1046 | train |
saltstack/salt | salt/modules/file.py | sed | def sed(path,
before,
after,
limit='',
backup='.bak',
options='-r -e',
flags='g',
escape_all=False,
negate_match=False):
'''
.. deprecated:: 0.17.0
Use :py:func:`~salt.modules.file.replace` instead.
Make a simple edit to a file
Equ... | python | def sed(path,
before,
after,
limit='',
backup='.bak',
options='-r -e',
flags='g',
escape_all=False,
negate_match=False):
'''
.. deprecated:: 0.17.0
Use :py:func:`~salt.modules.file.replace` instead.
Make a simple edit to a file
Equ... | [
"def",
"sed",
"(",
"path",
",",
"before",
",",
"after",
",",
"limit",
"=",
"''",
",",
"backup",
"=",
"'.bak'",
",",
"options",
"=",
"'-r -e'",
",",
"flags",
"=",
"'g'",
",",
"escape_all",
"=",
"False",
",",
"negate_match",
"=",
"False",
")",
":",
"... | .. deprecated:: 0.17.0
Use :py:func:`~salt.modules.file.replace` instead.
Make a simple edit to a file
Equivalent to:
.. code-block:: bash
sed <backup> <options> "/<limit>/ s/<before>/<after>/<flags> <file>"
path
The full path to the file to be edited
before
A pat... | [
"..",
"deprecated",
"::",
"0",
".",
"17",
".",
"0",
"Use",
":",
"py",
":",
"func",
":",
"~salt",
".",
"modules",
".",
"file",
".",
"replace",
"instead",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1049-L1132 | train |
saltstack/salt | salt/modules/file.py | sed_contains | def sed_contains(path,
text,
limit='',
flags='g'):
'''
.. deprecated:: 0.17.0
Use :func:`search` instead.
Return True if the file at ``path`` contains ``text``. Utilizes sed to
perform the search (line-wise search).
Note: the ``p`` flag wil... | python | def sed_contains(path,
text,
limit='',
flags='g'):
'''
.. deprecated:: 0.17.0
Use :func:`search` instead.
Return True if the file at ``path`` contains ``text``. Utilizes sed to
perform the search (line-wise search).
Note: the ``p`` flag wil... | [
"def",
"sed_contains",
"(",
"path",
",",
"text",
",",
"limit",
"=",
"''",
",",
"flags",
"=",
"'g'",
")",
":",
"# Largely inspired by Fabric's contrib.files.contains()",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"if",
"not",
"os",
... | .. deprecated:: 0.17.0
Use :func:`search` instead.
Return True if the file at ``path`` contains ``text``. Utilizes sed to
perform the search (line-wise search).
Note: the ``p`` flag will be added to any flags you pass in.
CLI Example:
.. code-block:: bash
salt '*' file.contains /... | [
"..",
"deprecated",
"::",
"0",
".",
"17",
".",
"0",
"Use",
":",
"func",
":",
"search",
"instead",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1135-L1179 | train |
saltstack/salt | salt/modules/file.py | psed | def psed(path,
before,
after,
limit='',
backup='.bak',
flags='gMS',
escape_all=False,
multi=False):
'''
.. deprecated:: 0.17.0
Use :py:func:`~salt.modules.file.replace` instead.
Make a simple edit to a file (pure Python version)
Equ... | python | def psed(path,
before,
after,
limit='',
backup='.bak',
flags='gMS',
escape_all=False,
multi=False):
'''
.. deprecated:: 0.17.0
Use :py:func:`~salt.modules.file.replace` instead.
Make a simple edit to a file (pure Python version)
Equ... | [
"def",
"psed",
"(",
"path",
",",
"before",
",",
"after",
",",
"limit",
"=",
"''",
",",
"backup",
"=",
"'.bak'",
",",
"flags",
"=",
"'gMS'",
",",
"escape_all",
"=",
"False",
",",
"multi",
"=",
"False",
")",
":",
"# Largely inspired by Fabric's contrib.files... | .. deprecated:: 0.17.0
Use :py:func:`~salt.modules.file.replace` instead.
Make a simple edit to a file (pure Python version)
Equivalent to:
.. code-block:: bash
sed <backup> <options> "/<limit>/ s/<before>/<after>/<flags> <file>"
path
The full path to the file to be edited
... | [
"..",
"deprecated",
"::",
"0",
".",
"17",
".",
"0",
"Use",
":",
"py",
":",
"func",
":",
"~salt",
".",
"modules",
".",
"file",
".",
"replace",
"instead",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1182-L1280 | train |
saltstack/salt | salt/modules/file.py | _psed | def _psed(text,
before,
after,
limit,
flags):
'''
Does the actual work for file.psed, so that single lines can be passed in
'''
atext = text
if limit:
limit = re.compile(limit)
comps = text.split(limit)
atext = ''.join(comps[1:])
c... | python | def _psed(text,
before,
after,
limit,
flags):
'''
Does the actual work for file.psed, so that single lines can be passed in
'''
atext = text
if limit:
limit = re.compile(limit)
comps = text.split(limit)
atext = ''.join(comps[1:])
c... | [
"def",
"_psed",
"(",
"text",
",",
"before",
",",
"after",
",",
"limit",
",",
"flags",
")",
":",
"atext",
"=",
"text",
"if",
"limit",
":",
"limit",
"=",
"re",
".",
"compile",
"(",
"limit",
")",
"comps",
"=",
"text",
".",
"split",
"(",
"limit",
")"... | Does the actual work for file.psed, so that single lines can be passed in | [
"Does",
"the",
"actual",
"work",
"for",
"file",
".",
"psed",
"so",
"that",
"single",
"lines",
"can",
"be",
"passed",
"in"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1291-L1317 | train |
saltstack/salt | salt/modules/file.py | uncomment | def uncomment(path,
regex,
char='#',
backup='.bak'):
'''
.. deprecated:: 0.17.0
Use :py:func:`~salt.modules.file.replace` instead.
Uncomment specified commented lines in a file
path
The full path to the file to be edited
regex
A regu... | python | def uncomment(path,
regex,
char='#',
backup='.bak'):
'''
.. deprecated:: 0.17.0
Use :py:func:`~salt.modules.file.replace` instead.
Uncomment specified commented lines in a file
path
The full path to the file to be edited
regex
A regu... | [
"def",
"uncomment",
"(",
"path",
",",
"regex",
",",
"char",
"=",
"'#'",
",",
"backup",
"=",
"'.bak'",
")",
":",
"return",
"comment_line",
"(",
"path",
"=",
"path",
",",
"regex",
"=",
"regex",
",",
"char",
"=",
"char",
",",
"cmnt",
"=",
"False",
","... | .. deprecated:: 0.17.0
Use :py:func:`~salt.modules.file.replace` instead.
Uncomment specified commented lines in a file
path
The full path to the file to be edited
regex
A regular expression used to find the lines that are to be uncommented.
This regex should not include the... | [
"..",
"deprecated",
"::",
"0",
".",
"17",
".",
"0",
"Use",
":",
"py",
":",
"func",
":",
"~salt",
".",
"modules",
".",
"file",
".",
"replace",
"instead",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1320-L1354 | train |
saltstack/salt | salt/modules/file.py | comment | def comment(path,
regex,
char='#',
backup='.bak'):
'''
.. deprecated:: 0.17.0
Use :py:func:`~salt.modules.file.replace` instead.
Comment out specified lines in a file
path
The full path to the file to be edited
regex
A regular expression u... | python | def comment(path,
regex,
char='#',
backup='.bak'):
'''
.. deprecated:: 0.17.0
Use :py:func:`~salt.modules.file.replace` instead.
Comment out specified lines in a file
path
The full path to the file to be edited
regex
A regular expression u... | [
"def",
"comment",
"(",
"path",
",",
"regex",
",",
"char",
"=",
"'#'",
",",
"backup",
"=",
"'.bak'",
")",
":",
"return",
"comment_line",
"(",
"path",
"=",
"path",
",",
"regex",
"=",
"regex",
",",
"char",
"=",
"char",
",",
"cmnt",
"=",
"True",
",",
... | .. deprecated:: 0.17.0
Use :py:func:`~salt.modules.file.replace` instead.
Comment out specified lines in a file
path
The full path to the file to be edited
regex
A regular expression used to find the lines that are to be commented;
this pattern will be wrapped in parenthesis... | [
"..",
"deprecated",
"::",
"0",
".",
"17",
".",
"0",
"Use",
":",
"py",
":",
"func",
":",
"~salt",
".",
"modules",
".",
"file",
".",
"replace",
"instead",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1357-L1396 | train |
saltstack/salt | salt/modules/file.py | comment_line | def comment_line(path,
regex,
char='#',
cmnt=True,
backup='.bak'):
r'''
Comment or Uncomment a line in a text file.
:param path: string
The full path to the text file.
:param regex: string
A regex expression that begin... | python | def comment_line(path,
regex,
char='#',
cmnt=True,
backup='.bak'):
r'''
Comment or Uncomment a line in a text file.
:param path: string
The full path to the text file.
:param regex: string
A regex expression that begin... | [
"def",
"comment_line",
"(",
"path",
",",
"regex",
",",
"char",
"=",
"'#'",
",",
"cmnt",
"=",
"True",
",",
"backup",
"=",
"'.bak'",
")",
":",
"# Get the regex for comment or uncomment",
"if",
"cmnt",
":",
"regex",
"=",
"'{0}({1}){2}'",
".",
"format",
"(",
"... | r'''
Comment or Uncomment a line in a text file.
:param path: string
The full path to the text file.
:param regex: string
A regex expression that begins with ``^`` that will find the line you wish
to comment. Can be as simple as ``^color =``
:param char: string
The cha... | [
"r",
"Comment",
"or",
"Uncomment",
"a",
"line",
"in",
"a",
"text",
"file",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1399-L1578 | train |
saltstack/salt | salt/modules/file.py | _get_flags | def _get_flags(flags):
'''
Return an integer appropriate for use as a flag for the re module from a
list of human-readable strings
.. code-block:: python
>>> _get_flags(['MULTILINE', 'IGNORECASE'])
10
>>> _get_flags('MULTILINE')
8
>>> _get_flags(2)
2
... | python | def _get_flags(flags):
'''
Return an integer appropriate for use as a flag for the re module from a
list of human-readable strings
.. code-block:: python
>>> _get_flags(['MULTILINE', 'IGNORECASE'])
10
>>> _get_flags('MULTILINE')
8
>>> _get_flags(2)
2
... | [
"def",
"_get_flags",
"(",
"flags",
")",
":",
"if",
"isinstance",
"(",
"flags",
",",
"six",
".",
"string_types",
")",
":",
"flags",
"=",
"[",
"flags",
"]",
"if",
"isinstance",
"(",
"flags",
",",
"Iterable",
")",
"and",
"not",
"isinstance",
"(",
"flags",... | Return an integer appropriate for use as a flag for the re module from a
list of human-readable strings
.. code-block:: python
>>> _get_flags(['MULTILINE', 'IGNORECASE'])
10
>>> _get_flags('MULTILINE')
8
>>> _get_flags(2)
2 | [
"Return",
"an",
"integer",
"appropriate",
"for",
"use",
"as",
"a",
"flag",
"for",
"the",
"re",
"module",
"from",
"a",
"list",
"of",
"human",
"-",
"readable",
"strings"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1581-L1617 | train |
saltstack/salt | salt/modules/file.py | _add_flags | def _add_flags(flags, new_flags):
'''
Combine ``flags`` and ``new_flags``
'''
flags = _get_flags(flags)
new_flags = _get_flags(new_flags)
return flags | new_flags | python | def _add_flags(flags, new_flags):
'''
Combine ``flags`` and ``new_flags``
'''
flags = _get_flags(flags)
new_flags = _get_flags(new_flags)
return flags | new_flags | [
"def",
"_add_flags",
"(",
"flags",
",",
"new_flags",
")",
":",
"flags",
"=",
"_get_flags",
"(",
"flags",
")",
"new_flags",
"=",
"_get_flags",
"(",
"new_flags",
")",
"return",
"flags",
"|",
"new_flags"
] | Combine ``flags`` and ``new_flags`` | [
"Combine",
"flags",
"and",
"new_flags"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1620-L1626 | train |
saltstack/salt | salt/modules/file.py | _mkstemp_copy | def _mkstemp_copy(path,
preserve_inode=True):
'''
Create a temp file and move/copy the contents of ``path`` to the temp file.
Return the path to the temp file.
path
The full path to the file whose contents will be moved/copied to a temp file.
Whether it's moved or copi... | python | def _mkstemp_copy(path,
preserve_inode=True):
'''
Create a temp file and move/copy the contents of ``path`` to the temp file.
Return the path to the temp file.
path
The full path to the file whose contents will be moved/copied to a temp file.
Whether it's moved or copi... | [
"def",
"_mkstemp_copy",
"(",
"path",
",",
"preserve_inode",
"=",
"True",
")",
":",
"temp_file",
"=",
"None",
"# Create the temp file",
"try",
":",
"temp_file",
"=",
"salt",
".",
"utils",
".",
"files",
".",
"mkstemp",
"(",
"prefix",
"=",
"salt",
".",
"utils... | Create a temp file and move/copy the contents of ``path`` to the temp file.
Return the path to the temp file.
path
The full path to the file whose contents will be moved/copied to a temp file.
Whether it's moved or copied depends on the value of ``preserve_inode``.
preserve_inode
Pr... | [
"Create",
"a",
"temp",
"file",
"and",
"move",
"/",
"copy",
"the",
"contents",
"of",
"path",
"to",
"the",
"temp",
"file",
".",
"Return",
"the",
"path",
"to",
"the",
"temp",
"file",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1629-L1680 | train |
saltstack/salt | salt/modules/file.py | _starts_till | def _starts_till(src, probe, strip_comments=True):
'''
Returns True if src and probe at least matches at the beginning till some point.
'''
def _strip_comments(txt):
'''
Strip possible comments.
Usually comments are one or two symbols at the beginning of the line, separated with ... | python | def _starts_till(src, probe, strip_comments=True):
'''
Returns True if src and probe at least matches at the beginning till some point.
'''
def _strip_comments(txt):
'''
Strip possible comments.
Usually comments are one or two symbols at the beginning of the line, separated with ... | [
"def",
"_starts_till",
"(",
"src",
",",
"probe",
",",
"strip_comments",
"=",
"True",
")",
":",
"def",
"_strip_comments",
"(",
"txt",
")",
":",
"'''\n Strip possible comments.\n Usually comments are one or two symbols at the beginning of the line, separated with spac... | Returns True if src and probe at least matches at the beginning till some point. | [
"Returns",
"True",
"if",
"src",
"and",
"probe",
"at",
"least",
"matches",
"at",
"the",
"beginning",
"till",
"some",
"point",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1683-L1721 | train |
saltstack/salt | salt/modules/file.py | _regex_to_static | def _regex_to_static(src, regex):
'''
Expand regular expression to static match.
'''
if not src or not regex:
return None
try:
compiled = re.compile(regex, re.DOTALL)
src = [line for line in src if compiled.search(line) or line.count(regex)]
except Exception as ex:
... | python | def _regex_to_static(src, regex):
'''
Expand regular expression to static match.
'''
if not src or not regex:
return None
try:
compiled = re.compile(regex, re.DOTALL)
src = [line for line in src if compiled.search(line) or line.count(regex)]
except Exception as ex:
... | [
"def",
"_regex_to_static",
"(",
"src",
",",
"regex",
")",
":",
"if",
"not",
"src",
"or",
"not",
"regex",
":",
"return",
"None",
"try",
":",
"compiled",
"=",
"re",
".",
"compile",
"(",
"regex",
",",
"re",
".",
"DOTALL",
")",
"src",
"=",
"[",
"line",... | Expand regular expression to static match. | [
"Expand",
"regular",
"expression",
"to",
"static",
"match",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1724-L1737 | train |
saltstack/salt | salt/modules/file.py | _assert_occurrence | def _assert_occurrence(probe, target, amount=1):
'''
Raise an exception, if there are different amount of specified occurrences in src.
'''
occ = len(probe)
if occ > amount:
msg = 'more than'
elif occ < amount:
msg = 'less than'
elif not occ:
msg = 'no'
else:
... | python | def _assert_occurrence(probe, target, amount=1):
'''
Raise an exception, if there are different amount of specified occurrences in src.
'''
occ = len(probe)
if occ > amount:
msg = 'more than'
elif occ < amount:
msg = 'less than'
elif not occ:
msg = 'no'
else:
... | [
"def",
"_assert_occurrence",
"(",
"probe",
",",
"target",
",",
"amount",
"=",
"1",
")",
":",
"occ",
"=",
"len",
"(",
"probe",
")",
"if",
"occ",
">",
"amount",
":",
"msg",
"=",
"'more than'",
"elif",
"occ",
"<",
"amount",
":",
"msg",
"=",
"'less than'... | Raise an exception, if there are different amount of specified occurrences in src. | [
"Raise",
"an",
"exception",
"if",
"there",
"are",
"different",
"amount",
"of",
"specified",
"occurrences",
"in",
"src",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1740-L1757 | train |
saltstack/salt | salt/modules/file.py | _set_line_indent | def _set_line_indent(src, line, indent):
'''
Indent the line with the source line.
'''
if not indent:
return line
idt = []
for c in src:
if c not in ['\t', ' ']:
break
idt.append(c)
return ''.join(idt) + line.lstrip() | python | def _set_line_indent(src, line, indent):
'''
Indent the line with the source line.
'''
if not indent:
return line
idt = []
for c in src:
if c not in ['\t', ' ']:
break
idt.append(c)
return ''.join(idt) + line.lstrip() | [
"def",
"_set_line_indent",
"(",
"src",
",",
"line",
",",
"indent",
")",
":",
"if",
"not",
"indent",
":",
"return",
"line",
"idt",
"=",
"[",
"]",
"for",
"c",
"in",
"src",
":",
"if",
"c",
"not",
"in",
"[",
"'\\t'",
",",
"' '",
"]",
":",
"break",
... | Indent the line with the source line. | [
"Indent",
"the",
"line",
"with",
"the",
"source",
"line",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1760-L1773 | train |
saltstack/salt | salt/modules/file.py | _set_line_eol | def _set_line_eol(src, line):
'''
Add line ending
'''
line_ending = _get_eol(src) or os.linesep
return line.rstrip() + line_ending | python | def _set_line_eol(src, line):
'''
Add line ending
'''
line_ending = _get_eol(src) or os.linesep
return line.rstrip() + line_ending | [
"def",
"_set_line_eol",
"(",
"src",
",",
"line",
")",
":",
"line_ending",
"=",
"_get_eol",
"(",
"src",
")",
"or",
"os",
".",
"linesep",
"return",
"line",
".",
"rstrip",
"(",
")",
"+",
"line_ending"
] | Add line ending | [
"Add",
"line",
"ending"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1781-L1786 | train |
saltstack/salt | salt/modules/file.py | line | def line(path, content=None, match=None, mode=None, location=None,
before=None, after=None, show_changes=True, backup=False,
quiet=False, indent=True):
'''
.. versionadded:: 2015.8.0
Edit a line in the configuration file. The ``path`` and ``content``
arguments are required, as well as... | python | def line(path, content=None, match=None, mode=None, location=None,
before=None, after=None, show_changes=True, backup=False,
quiet=False, indent=True):
'''
.. versionadded:: 2015.8.0
Edit a line in the configuration file. The ``path`` and ``content``
arguments are required, as well as... | [
"def",
"line",
"(",
"path",
",",
"content",
"=",
"None",
",",
"match",
"=",
"None",
",",
"mode",
"=",
"None",
",",
"location",
"=",
"None",
",",
"before",
"=",
"None",
",",
"after",
"=",
"None",
",",
"show_changes",
"=",
"True",
",",
"backup",
"=",... | .. versionadded:: 2015.8.0
Edit a line in the configuration file. The ``path`` and ``content``
arguments are required, as well as passing in one of the ``mode``
options.
path
Filesystem path to the file to be edited.
content
Content of the line. Allowed to be empty if mode=delete.... | [
"..",
"versionadded",
"::",
"2015",
".",
"8",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L1805-L2068 | train |
saltstack/salt | salt/modules/file.py | replace | def replace(path,
pattern,
repl,
count=0,
flags=8,
bufsize=1,
append_if_not_found=False,
prepend_if_not_found=False,
not_found_content=None,
backup='.bak',
dry_run=False,
search_only=False... | python | def replace(path,
pattern,
repl,
count=0,
flags=8,
bufsize=1,
append_if_not_found=False,
prepend_if_not_found=False,
not_found_content=None,
backup='.bak',
dry_run=False,
search_only=False... | [
"def",
"replace",
"(",
"path",
",",
"pattern",
",",
"repl",
",",
"count",
"=",
"0",
",",
"flags",
"=",
"8",
",",
"bufsize",
"=",
"1",
",",
"append_if_not_found",
"=",
"False",
",",
"prepend_if_not_found",
"=",
"False",
",",
"not_found_content",
"=",
"Non... | .. versionadded:: 0.17.0
Replace occurrences of a pattern in a file. If ``show_changes`` is
``True``, then a diff of what changed will be returned, otherwise a
``True`` will be returned when changes are made, and ``False`` when
no changes are made.
This is a pure Python implementation that wraps P... | [
"..",
"versionadded",
"::",
"0",
".",
"17",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L2071-L2450 | train |
saltstack/salt | salt/modules/file.py | blockreplace | def blockreplace(path,
marker_start='#-- start managed zone --',
marker_end='#-- end managed zone --',
content='',
append_if_not_found=False,
prepend_if_not_found=False,
backup='.bak',
dry_run=False,
show_changes=True,
append_newline=False,
... | python | def blockreplace(path,
marker_start='#-- start managed zone --',
marker_end='#-- end managed zone --',
content='',
append_if_not_found=False,
prepend_if_not_found=False,
backup='.bak',
dry_run=False,
show_changes=True,
append_newline=False,
... | [
"def",
"blockreplace",
"(",
"path",
",",
"marker_start",
"=",
"'#-- start managed zone --'",
",",
"marker_end",
"=",
"'#-- end managed zone --'",
",",
"content",
"=",
"''",
",",
"append_if_not_found",
"=",
"False",
",",
"prepend_if_not_found",
"=",
"False",
",",
"ba... | .. versionadded:: 2014.1.0
Replace content of a text block in a file, delimited by line markers
A block of content delimited by comments can help you manage several lines
entries without worrying about old entries removal.
.. note::
This function will store two copies of the file in-memory (... | [
"..",
"versionadded",
"::",
"2014",
".",
"1",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L2453-L2776 | train |
saltstack/salt | salt/modules/file.py | search | def search(path,
pattern,
flags=8,
bufsize=1,
ignore_if_missing=False,
multiline=False
):
'''
.. versionadded:: 0.17.0
Search for occurrences of a pattern in a file
Except for multiline, params are identical to
:py:func:`~salt.modules.file.replace`.
... | python | def search(path,
pattern,
flags=8,
bufsize=1,
ignore_if_missing=False,
multiline=False
):
'''
.. versionadded:: 0.17.0
Search for occurrences of a pattern in a file
Except for multiline, params are identical to
:py:func:`~salt.modules.file.replace`.
... | [
"def",
"search",
"(",
"path",
",",
"pattern",
",",
"flags",
"=",
"8",
",",
"bufsize",
"=",
"1",
",",
"ignore_if_missing",
"=",
"False",
",",
"multiline",
"=",
"False",
")",
":",
"if",
"multiline",
":",
"flags",
"=",
"_add_flags",
"(",
"flags",
",",
"... | .. versionadded:: 0.17.0
Search for occurrences of a pattern in a file
Except for multiline, params are identical to
:py:func:`~salt.modules.file.replace`.
multiline
If true, inserts 'MULTILINE' into ``flags`` and sets ``bufsize`` to
'file'.
.. versionadded:: 2015.8.0
CL... | [
"..",
"versionadded",
"::",
"0",
".",
"17",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L2779-L2821 | train |
saltstack/salt | salt/modules/file.py | patch | def patch(originalfile, patchfile, options='', dry_run=False):
'''
.. versionadded:: 0.10.4
Apply a patch to a file or directory.
Equivalent to:
.. code-block:: bash
patch <options> -i <patchfile> <originalfile>
Or, when a directory is patched:
.. code-block:: bash
pat... | python | def patch(originalfile, patchfile, options='', dry_run=False):
'''
.. versionadded:: 0.10.4
Apply a patch to a file or directory.
Equivalent to:
.. code-block:: bash
patch <options> -i <patchfile> <originalfile>
Or, when a directory is patched:
.. code-block:: bash
pat... | [
"def",
"patch",
"(",
"originalfile",
",",
"patchfile",
",",
"options",
"=",
"''",
",",
"dry_run",
"=",
"False",
")",
":",
"patchpath",
"=",
"salt",
".",
"utils",
".",
"path",
".",
"which",
"(",
"'patch'",
")",
"if",
"not",
"patchpath",
":",
"raise",
... | .. versionadded:: 0.10.4
Apply a patch to a file or directory.
Equivalent to:
.. code-block:: bash
patch <options> -i <patchfile> <originalfile>
Or, when a directory is patched:
.. code-block:: bash
patch <options> -i <patchfile> -d <originalfile> -p0
originalfile
... | [
"..",
"versionadded",
"::",
"0",
".",
"10",
".",
"4"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L2824-L2903 | train |
saltstack/salt | salt/modules/file.py | contains | def contains(path, text):
'''
.. deprecated:: 0.17.0
Use :func:`search` instead.
Return ``True`` if the file at ``path`` contains ``text``
CLI Example:
.. code-block:: bash
salt '*' file.contains /etc/crontab 'mymaintenance.sh'
'''
path = os.path.expanduser(path)
if n... | python | def contains(path, text):
'''
.. deprecated:: 0.17.0
Use :func:`search` instead.
Return ``True`` if the file at ``path`` contains ``text``
CLI Example:
.. code-block:: bash
salt '*' file.contains /etc/crontab 'mymaintenance.sh'
'''
path = os.path.expanduser(path)
if n... | [
"def",
"contains",
"(",
"path",
",",
"text",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"return",
"False",
"stripped_text",
"=",
"six",
".",
... | .. deprecated:: 0.17.0
Use :func:`search` instead.
Return ``True`` if the file at ``path`` contains ``text``
CLI Example:
.. code-block:: bash
salt '*' file.contains /etc/crontab 'mymaintenance.sh' | [
"..",
"deprecated",
"::",
"0",
".",
"17",
".",
"0",
"Use",
":",
"func",
":",
"search",
"instead",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L2906-L2932 | train |
saltstack/salt | salt/modules/file.py | contains_regex | def contains_regex(path, regex, lchar=''):
'''
.. deprecated:: 0.17.0
Use :func:`search` instead.
Return True if the given regular expression matches on any line in the text
of a given file.
If the lchar argument (leading char) is specified, it
will strip `lchar` from the left side of e... | python | def contains_regex(path, regex, lchar=''):
'''
.. deprecated:: 0.17.0
Use :func:`search` instead.
Return True if the given regular expression matches on any line in the text
of a given file.
If the lchar argument (leading char) is specified, it
will strip `lchar` from the left side of e... | [
"def",
"contains_regex",
"(",
"path",
",",
"regex",
",",
"lchar",
"=",
"''",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"return",
"False",
"... | .. deprecated:: 0.17.0
Use :func:`search` instead.
Return True if the given regular expression matches on any line in the text
of a given file.
If the lchar argument (leading char) is specified, it
will strip `lchar` from the left side of each line before trying to match
CLI Example:
... | [
"..",
"deprecated",
"::",
"0",
".",
"17",
".",
"0",
"Use",
":",
"func",
":",
"search",
"instead",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L2935-L2967 | train |
saltstack/salt | salt/modules/file.py | contains_glob | def contains_glob(path, glob_expr):
'''
.. deprecated:: 0.17.0
Use :func:`search` instead.
Return ``True`` if the given glob matches a string in the named file
CLI Example:
.. code-block:: bash
salt '*' file.contains_glob /etc/foobar '*cheese*'
'''
path = os.path.expanduse... | python | def contains_glob(path, glob_expr):
'''
.. deprecated:: 0.17.0
Use :func:`search` instead.
Return ``True`` if the given glob matches a string in the named file
CLI Example:
.. code-block:: bash
salt '*' file.contains_glob /etc/foobar '*cheese*'
'''
path = os.path.expanduse... | [
"def",
"contains_glob",
"(",
"path",
",",
"glob_expr",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"return",
"False",
"try",
":",
"with",
"salt... | .. deprecated:: 0.17.0
Use :func:`search` instead.
Return ``True`` if the given glob matches a string in the named file
CLI Example:
.. code-block:: bash
salt '*' file.contains_glob /etc/foobar '*cheese*' | [
"..",
"deprecated",
"::",
"0",
".",
"17",
".",
"0",
"Use",
":",
"func",
":",
"search",
"instead",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L2970-L2995 | train |
saltstack/salt | salt/modules/file.py | append | def append(path, *args, **kwargs):
'''
.. versionadded:: 0.9.5
Append text to the end of a file
path
path to file
`*args`
strings to append to file
CLI Example:
.. code-block:: bash
salt '*' file.append /etc/motd \\
"With all thine offerings thou... | python | def append(path, *args, **kwargs):
'''
.. versionadded:: 0.9.5
Append text to the end of a file
path
path to file
`*args`
strings to append to file
CLI Example:
.. code-block:: bash
salt '*' file.append /etc/motd \\
"With all thine offerings thou... | [
"def",
"append",
"(",
"path",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"# Largely inspired by Fabric's contrib.files.append()",
"if",
"'args'",
"in",
"kwargs",
":",
"if",
"isi... | .. versionadded:: 0.9.5
Append text to the end of a file
path
path to file
`*args`
strings to append to file
CLI Example:
.. code-block:: bash
salt '*' file.append /etc/motd \\
"With all thine offerings thou shalt offer salt." \\
"Salt is... | [
"..",
"versionadded",
"::",
"0",
".",
"9",
".",
"5"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L2998-L3067 | train |
saltstack/salt | salt/modules/file.py | prepend | def prepend(path, *args, **kwargs):
'''
.. versionadded:: 2014.7.0
Prepend text to the beginning of a file
path
path to file
`*args`
strings to prepend to the file
CLI Example:
.. code-block:: bash
salt '*' file.prepend /etc/motd \\
"With all thi... | python | def prepend(path, *args, **kwargs):
'''
.. versionadded:: 2014.7.0
Prepend text to the beginning of a file
path
path to file
`*args`
strings to prepend to the file
CLI Example:
.. code-block:: bash
salt '*' file.prepend /etc/motd \\
"With all thi... | [
"def",
"prepend",
"(",
"path",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"if",
"'args'",
"in",
"kwargs",
":",
"if",
"isinstance",
"(",
"kwargs",
"[",
"'args'",
"]",
"... | .. versionadded:: 2014.7.0
Prepend text to the beginning of a file
path
path to file
`*args`
strings to prepend to the file
CLI Example:
.. code-block:: bash
salt '*' file.prepend /etc/motd \\
"With all thine offerings thou shalt offer salt." \\
... | [
"..",
"versionadded",
"::",
"2014",
".",
"7",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3070-L3125 | train |
saltstack/salt | salt/modules/file.py | write | def write(path, *args, **kwargs):
'''
.. versionadded:: 2014.7.0
Write text to a file, overwriting any existing contents.
path
path to file
`*args`
strings to write to the file
CLI Example:
.. code-block:: bash
salt '*' file.write /etc/motd \\
"W... | python | def write(path, *args, **kwargs):
'''
.. versionadded:: 2014.7.0
Write text to a file, overwriting any existing contents.
path
path to file
`*args`
strings to write to the file
CLI Example:
.. code-block:: bash
salt '*' file.write /etc/motd \\
"W... | [
"def",
"write",
"(",
"path",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"if",
"'args'",
"in",
"kwargs",
":",
"if",
"isinstance",
"(",
"kwargs",
"[",
"'args'",
"]",
","... | .. versionadded:: 2014.7.0
Write text to a file, overwriting any existing contents.
path
path to file
`*args`
strings to write to the file
CLI Example:
.. code-block:: bash
salt '*' file.write /etc/motd \\
"With all thine offerings thou shalt offer salt.... | [
"..",
"versionadded",
"::",
"2014",
".",
"7",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3128-L3173 | train |
saltstack/salt | salt/modules/file.py | touch | def touch(name, atime=None, mtime=None):
'''
.. versionadded:: 0.9.5
Just like the ``touch`` command, create a file if it doesn't exist or
simply update the atime and mtime if it already does.
atime:
Access time in Unix epoch time. Set it to 0 to set atime of the
file with Unix dat... | python | def touch(name, atime=None, mtime=None):
'''
.. versionadded:: 0.9.5
Just like the ``touch`` command, create a file if it doesn't exist or
simply update the atime and mtime if it already does.
atime:
Access time in Unix epoch time. Set it to 0 to set atime of the
file with Unix dat... | [
"def",
"touch",
"(",
"name",
",",
"atime",
"=",
"None",
",",
"mtime",
"=",
"None",
")",
":",
"name",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"name",
")",
"if",
"atime",
"and",
"atime",
".",
"isdigit",
"(",
")",
":",
"atime",
"=",
"int",
... | .. versionadded:: 0.9.5
Just like the ``touch`` command, create a file if it doesn't exist or
simply update the atime and mtime if it already does.
atime:
Access time in Unix epoch time. Set it to 0 to set atime of the
file with Unix date of birth. If this parameter isn't set, atime
... | [
"..",
"versionadded",
"::",
"0",
".",
"9",
".",
"5"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3176-L3224 | train |
saltstack/salt | salt/modules/file.py | tail | def tail(path, lines):
'''
.. versionadded:: Neon
Read the last n lines from a file
path
path to file
lines
number of lines to read
CLI Example:
.. code-block:: bash
salt '*' file.tail /path/to/file 10
'''
path = os.path.expanduser(path)
lines_found ... | python | def tail(path, lines):
'''
.. versionadded:: Neon
Read the last n lines from a file
path
path to file
lines
number of lines to read
CLI Example:
.. code-block:: bash
salt '*' file.tail /path/to/file 10
'''
path = os.path.expanduser(path)
lines_found ... | [
"def",
"tail",
"(",
"path",
",",
"lines",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"lines_found",
"=",
"[",
"]",
"buffer_size",
"=",
"4098",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"path",
")",
":... | .. versionadded:: Neon
Read the last n lines from a file
path
path to file
lines
number of lines to read
CLI Example:
.. code-block:: bash
salt '*' file.tail /path/to/file 10 | [
"..",
"versionadded",
"::",
"Neon"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3227-L3287 | train |
saltstack/salt | salt/modules/file.py | seek_read | def seek_read(path, size, offset):
'''
.. versionadded:: 2014.1.0
Seek to a position on a file and read it
path
path to file
seek
amount to read at once
offset
offset to start into the file
CLI Example:
.. code-block:: bash
salt '*' file.seek_read /... | python | def seek_read(path, size, offset):
'''
.. versionadded:: 2014.1.0
Seek to a position on a file and read it
path
path to file
seek
amount to read at once
offset
offset to start into the file
CLI Example:
.. code-block:: bash
salt '*' file.seek_read /... | [
"def",
"seek_read",
"(",
"path",
",",
"size",
",",
"offset",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"seek_fh",
"=",
"os",
".",
"open",
"(",
"path",
",",
"os",
".",
"O_RDONLY",
")",
"try",
":",
"os",
".",
... | .. versionadded:: 2014.1.0
Seek to a position on a file and read it
path
path to file
seek
amount to read at once
offset
offset to start into the file
CLI Example:
.. code-block:: bash
salt '*' file.seek_read /path/to/file 4096 0 | [
"..",
"versionadded",
"::",
"2014",
".",
"1",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3290-L3318 | train |
saltstack/salt | salt/modules/file.py | seek_write | def seek_write(path, data, offset):
'''
.. versionadded:: 2014.1.0
Seek to a position on a file and write to it
path
path to file
data
data to write to file
offset
position in file to start writing
CLI Example:
.. code-block:: bash
salt '*' file.see... | python | def seek_write(path, data, offset):
'''
.. versionadded:: 2014.1.0
Seek to a position on a file and write to it
path
path to file
data
data to write to file
offset
position in file to start writing
CLI Example:
.. code-block:: bash
salt '*' file.see... | [
"def",
"seek_write",
"(",
"path",
",",
"data",
",",
"offset",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"seek_fh",
"=",
"os",
".",
"open",
"(",
"path",
",",
"os",
".",
"O_WRONLY",
")",
"try",
":",
"os",
".",
... | .. versionadded:: 2014.1.0
Seek to a position on a file and write to it
path
path to file
data
data to write to file
offset
position in file to start writing
CLI Example:
.. code-block:: bash
salt '*' file.seek_write /path/to/file 'some data' 4096 | [
"..",
"versionadded",
"::",
"2014",
".",
"1",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3321-L3350 | train |
saltstack/salt | salt/modules/file.py | truncate | def truncate(path, length):
'''
.. versionadded:: 2014.1.0
Seek to a position on a file and delete everything after that point
path
path to file
length
offset into file to truncate
CLI Example:
.. code-block:: bash
salt '*' file.truncate /path/to/file 512
''... | python | def truncate(path, length):
'''
.. versionadded:: 2014.1.0
Seek to a position on a file and delete everything after that point
path
path to file
length
offset into file to truncate
CLI Example:
.. code-block:: bash
salt '*' file.truncate /path/to/file 512
''... | [
"def",
"truncate",
"(",
"path",
",",
"length",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"with",
"salt",
".",
"utils",
".",
"files",
".",
"fopen",
"(",
"path",
",",
"'rb+'",
")",
"as",
"seek_fh",
":",
"seek_fh",... | .. versionadded:: 2014.1.0
Seek to a position on a file and delete everything after that point
path
path to file
length
offset into file to truncate
CLI Example:
.. code-block:: bash
salt '*' file.truncate /path/to/file 512 | [
"..",
"versionadded",
"::",
"2014",
".",
"1",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3353-L3373 | train |
saltstack/salt | salt/modules/file.py | link | def link(src, path):
'''
.. versionadded:: 2014.1.0
Create a hard link to a file
CLI Example:
.. code-block:: bash
salt '*' file.link /path/to/file /path/to/link
'''
src = os.path.expanduser(src)
if not os.path.isabs(src):
raise SaltInvocationError('File path must be... | python | def link(src, path):
'''
.. versionadded:: 2014.1.0
Create a hard link to a file
CLI Example:
.. code-block:: bash
salt '*' file.link /path/to/file /path/to/link
'''
src = os.path.expanduser(src)
if not os.path.isabs(src):
raise SaltInvocationError('File path must be... | [
"def",
"link",
"(",
"src",
",",
"path",
")",
":",
"src",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"src",
")",
"if",
"not",
"os",
".",
"path",
".",
"isabs",
"(",
"src",
")",
":",
"raise",
"SaltInvocationError",
"(",
"'File path must be absolute.'... | .. versionadded:: 2014.1.0
Create a hard link to a file
CLI Example:
.. code-block:: bash
salt '*' file.link /path/to/file /path/to/link | [
"..",
"versionadded",
"::",
"2014",
".",
"1",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3376-L3398 | train |
saltstack/salt | salt/modules/file.py | symlink | def symlink(src, path):
'''
Create a symbolic link (symlink, soft link) to a file
CLI Example:
.. code-block:: bash
salt '*' file.symlink /path/to/file /path/to/link
'''
path = os.path.expanduser(path)
try:
if os.path.normpath(os.readlink(path)) == os.path.normpath(src):
... | python | def symlink(src, path):
'''
Create a symbolic link (symlink, soft link) to a file
CLI Example:
.. code-block:: bash
salt '*' file.symlink /path/to/file /path/to/link
'''
path = os.path.expanduser(path)
try:
if os.path.normpath(os.readlink(path)) == os.path.normpath(src):
... | [
"def",
"symlink",
"(",
"src",
",",
"path",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"try",
":",
"if",
"os",
".",
"path",
".",
"normpath",
"(",
"os",
".",
"readlink",
"(",
"path",
")",
")",
"==",
"os",
".",
... | Create a symbolic link (symlink, soft link) to a file
CLI Example:
.. code-block:: bash
salt '*' file.symlink /path/to/file /path/to/link | [
"Create",
"a",
"symbolic",
"link",
"(",
"symlink",
"soft",
"link",
")",
"to",
"a",
"file"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3419-L3446 | train |
saltstack/salt | salt/modules/file.py | rename | def rename(src, dst):
'''
Rename a file or directory
CLI Example:
.. code-block:: bash
salt '*' file.rename /path/to/src /path/to/dst
'''
src = os.path.expanduser(src)
dst = os.path.expanduser(dst)
if not os.path.isabs(src):
raise SaltInvocationError('File path must b... | python | def rename(src, dst):
'''
Rename a file or directory
CLI Example:
.. code-block:: bash
salt '*' file.rename /path/to/src /path/to/dst
'''
src = os.path.expanduser(src)
dst = os.path.expanduser(dst)
if not os.path.isabs(src):
raise SaltInvocationError('File path must b... | [
"def",
"rename",
"(",
"src",
",",
"dst",
")",
":",
"src",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"src",
")",
"dst",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"dst",
")",
"if",
"not",
"os",
".",
"path",
".",
"isabs",
"(",
"src",
... | Rename a file or directory
CLI Example:
.. code-block:: bash
salt '*' file.rename /path/to/src /path/to/dst | [
"Rename",
"a",
"file",
"or",
"directory"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3449-L3472 | train |
saltstack/salt | salt/modules/file.py | copy | def copy(src, dst, recurse=False, remove_existing=False):
'''
Copy a file or directory from source to dst
In order to copy a directory, the recurse flag is required, and
will by default overwrite files in the destination with the same path,
and retain all other existing files. (similar to cp -r on ... | python | def copy(src, dst, recurse=False, remove_existing=False):
'''
Copy a file or directory from source to dst
In order to copy a directory, the recurse flag is required, and
will by default overwrite files in the destination with the same path,
and retain all other existing files. (similar to cp -r on ... | [
"def",
"copy",
"(",
"src",
",",
"dst",
",",
"recurse",
"=",
"False",
",",
"remove_existing",
"=",
"False",
")",
":",
"src",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"src",
")",
"dst",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"dst",
... | Copy a file or directory from source to dst
In order to copy a directory, the recurse flag is required, and
will by default overwrite files in the destination with the same path,
and retain all other existing files. (similar to cp -r on unix)
remove_existing will remove all files in the target directo... | [
"Copy",
"a",
"file",
"or",
"directory",
"from",
"source",
"to",
"dst"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3475-L3536 | train |
saltstack/salt | salt/modules/file.py | lstat | def lstat(path):
'''
.. versionadded:: 2014.1.0
Returns the lstat attributes for the given file or dir. Does not support
symbolic links.
CLI Example:
.. code-block:: bash
salt '*' file.lstat /path/to/file
'''
path = os.path.expanduser(path)
if not os.path.isabs(path):
... | python | def lstat(path):
'''
.. versionadded:: 2014.1.0
Returns the lstat attributes for the given file or dir. Does not support
symbolic links.
CLI Example:
.. code-block:: bash
salt '*' file.lstat /path/to/file
'''
path = os.path.expanduser(path)
if not os.path.isabs(path):
... | [
"def",
"lstat",
"(",
"path",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"if",
"not",
"os",
".",
"path",
".",
"isabs",
"(",
"path",
")",
":",
"raise",
"SaltInvocationError",
"(",
"'Path to file must be absolute.'",
")",... | .. versionadded:: 2014.1.0
Returns the lstat attributes for the given file or dir. Does not support
symbolic links.
CLI Example:
.. code-block:: bash
salt '*' file.lstat /path/to/file | [
"..",
"versionadded",
"::",
"2014",
".",
"1",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3539-L3562 | train |
saltstack/salt | salt/modules/file.py | access | def access(path, mode):
'''
.. versionadded:: 2014.1.0
Test whether the Salt process has the specified access to the file. One of
the following modes must be specified:
.. code-block::text
f: Test the existence of the path
r: Test the readability of the path
w: Test the wr... | python | def access(path, mode):
'''
.. versionadded:: 2014.1.0
Test whether the Salt process has the specified access to the file. One of
the following modes must be specified:
.. code-block::text
f: Test the existence of the path
r: Test the readability of the path
w: Test the wr... | [
"def",
"access",
"(",
"path",
",",
"mode",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"if",
"not",
"os",
".",
"path",
".",
"isabs",
"(",
"path",
")",
":",
"raise",
"SaltInvocationError",
"(",
"'Path to link must be a... | .. versionadded:: 2014.1.0
Test whether the Salt process has the specified access to the file. One of
the following modes must be specified:
.. code-block::text
f: Test the existence of the path
r: Test the readability of the path
w: Test the writability of the path
x: Tes... | [
"..",
"versionadded",
"::",
"2014",
".",
"1",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3565-L3601 | train |
saltstack/salt | salt/modules/file.py | read | def read(path, binary=False):
'''
.. versionadded:: 2017.7.0
Return the content of the file.
CLI Example:
.. code-block:: bash
salt '*' file.read /path/to/file
'''
access_mode = 'r'
if binary is True:
access_mode += 'b'
with salt.utils.files.fopen(path, access_mod... | python | def read(path, binary=False):
'''
.. versionadded:: 2017.7.0
Return the content of the file.
CLI Example:
.. code-block:: bash
salt '*' file.read /path/to/file
'''
access_mode = 'r'
if binary is True:
access_mode += 'b'
with salt.utils.files.fopen(path, access_mod... | [
"def",
"read",
"(",
"path",
",",
"binary",
"=",
"False",
")",
":",
"access_mode",
"=",
"'r'",
"if",
"binary",
"is",
"True",
":",
"access_mode",
"+=",
"'b'",
"with",
"salt",
".",
"utils",
".",
"files",
".",
"fopen",
"(",
"path",
",",
"access_mode",
")... | .. versionadded:: 2017.7.0
Return the content of the file.
CLI Example:
.. code-block:: bash
salt '*' file.read /path/to/file | [
"..",
"versionadded",
"::",
"2017",
".",
"7",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3604-L3620 | train |
saltstack/salt | salt/modules/file.py | readlink | def readlink(path, canonicalize=False):
'''
.. versionadded:: 2014.1.0
Return the path that a symlink points to
If canonicalize is set to True, then it return the final target
CLI Example:
.. code-block:: bash
salt '*' file.readlink /path/to/link
'''
path = os.path.expanduser... | python | def readlink(path, canonicalize=False):
'''
.. versionadded:: 2014.1.0
Return the path that a symlink points to
If canonicalize is set to True, then it return the final target
CLI Example:
.. code-block:: bash
salt '*' file.readlink /path/to/link
'''
path = os.path.expanduser... | [
"def",
"readlink",
"(",
"path",
",",
"canonicalize",
"=",
"False",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"if",
"not",
"os",
".",
"path",
".",
"isabs",
"(",
"path",
")",
":",
"raise",
"SaltInvocationError",
"("... | .. versionadded:: 2014.1.0
Return the path that a symlink points to
If canonicalize is set to True, then it return the final target
CLI Example:
.. code-block:: bash
salt '*' file.readlink /path/to/link | [
"..",
"versionadded",
"::",
"2014",
".",
"1",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3623-L3647 | train |
saltstack/salt | salt/modules/file.py | readdir | def readdir(path):
'''
.. versionadded:: 2014.1.0
Return a list containing the contents of a directory
CLI Example:
.. code-block:: bash
salt '*' file.readdir /path/to/dir/
'''
path = os.path.expanduser(path)
if not os.path.isabs(path):
raise SaltInvocationError('Dir... | python | def readdir(path):
'''
.. versionadded:: 2014.1.0
Return a list containing the contents of a directory
CLI Example:
.. code-block:: bash
salt '*' file.readdir /path/to/dir/
'''
path = os.path.expanduser(path)
if not os.path.isabs(path):
raise SaltInvocationError('Dir... | [
"def",
"readdir",
"(",
"path",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"if",
"not",
"os",
".",
"path",
".",
"isabs",
"(",
"path",
")",
":",
"raise",
"SaltInvocationError",
"(",
"'Dir path must be absolute.'",
")",
... | .. versionadded:: 2014.1.0
Return a list containing the contents of a directory
CLI Example:
.. code-block:: bash
salt '*' file.readdir /path/to/dir/ | [
"..",
"versionadded",
"::",
"2014",
".",
"1",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3650-L3672 | train |
saltstack/salt | salt/modules/file.py | statvfs | def statvfs(path):
'''
.. versionadded:: 2014.1.0
Perform a statvfs call against the filesystem that the file resides on
CLI Example:
.. code-block:: bash
salt '*' file.statvfs /path/to/file
'''
path = os.path.expanduser(path)
if not os.path.isabs(path):
raise SaltIn... | python | def statvfs(path):
'''
.. versionadded:: 2014.1.0
Perform a statvfs call against the filesystem that the file resides on
CLI Example:
.. code-block:: bash
salt '*' file.statvfs /path/to/file
'''
path = os.path.expanduser(path)
if not os.path.isabs(path):
raise SaltIn... | [
"def",
"statvfs",
"(",
"path",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"if",
"not",
"os",
".",
"path",
".",
"isabs",
"(",
"path",
")",
":",
"raise",
"SaltInvocationError",
"(",
"'File path must be absolute.'",
")",
... | .. versionadded:: 2014.1.0
Perform a statvfs call against the filesystem that the file resides on
CLI Example:
.. code-block:: bash
salt '*' file.statvfs /path/to/file | [
"..",
"versionadded",
"::",
"2014",
".",
"1",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3675-L3699 | train |
saltstack/salt | salt/modules/file.py | stats | def stats(path, hash_type=None, follow_symlinks=True):
'''
Return a dict containing the stats for a given file
CLI Example:
.. code-block:: bash
salt '*' file.stats /etc/passwd
'''
path = os.path.expanduser(path)
ret = {}
if not os.path.exists(path):
try:
... | python | def stats(path, hash_type=None, follow_symlinks=True):
'''
Return a dict containing the stats for a given file
CLI Example:
.. code-block:: bash
salt '*' file.stats /etc/passwd
'''
path = os.path.expanduser(path)
ret = {}
if not os.path.exists(path):
try:
... | [
"def",
"stats",
"(",
"path",
",",
"hash_type",
"=",
"None",
",",
"follow_symlinks",
"=",
"True",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"ret",
"=",
"{",
"}",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"... | Return a dict containing the stats for a given file
CLI Example:
.. code-block:: bash
salt '*' file.stats /etc/passwd | [
"Return",
"a",
"dict",
"containing",
"the",
"stats",
"for",
"a",
"given",
"file"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3702-L3760 | train |
saltstack/salt | salt/modules/file.py | rmdir | def rmdir(path):
'''
.. versionadded:: 2014.1.0
Remove the specified directory. Fails if a directory is not empty.
CLI Example:
.. code-block:: bash
salt '*' file.rmdir /tmp/foo/
'''
path = os.path.expanduser(path)
if not os.path.isabs(path):
raise SaltInvocationErro... | python | def rmdir(path):
'''
.. versionadded:: 2014.1.0
Remove the specified directory. Fails if a directory is not empty.
CLI Example:
.. code-block:: bash
salt '*' file.rmdir /tmp/foo/
'''
path = os.path.expanduser(path)
if not os.path.isabs(path):
raise SaltInvocationErro... | [
"def",
"rmdir",
"(",
"path",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"if",
"not",
"os",
".",
"path",
".",
"isabs",
"(",
"path",
")",
":",
"raise",
"SaltInvocationError",
"(",
"'File path must be absolute.'",
")",
... | .. versionadded:: 2014.1.0
Remove the specified directory. Fails if a directory is not empty.
CLI Example:
.. code-block:: bash
salt '*' file.rmdir /tmp/foo/ | [
"..",
"versionadded",
"::",
"2014",
".",
"1",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3763-L3787 | train |
saltstack/salt | salt/modules/file.py | remove | def remove(path, **kwargs):
'''
Remove the named file. If a directory is supplied, it will be recursively
deleted.
CLI Example:
.. code-block:: bash
salt '*' file.remove /tmp/foo
'''
path = os.path.expanduser(path)
if not os.path.isabs(path):
raise SaltInvocationError... | python | def remove(path, **kwargs):
'''
Remove the named file. If a directory is supplied, it will be recursively
deleted.
CLI Example:
.. code-block:: bash
salt '*' file.remove /tmp/foo
'''
path = os.path.expanduser(path)
if not os.path.isabs(path):
raise SaltInvocationError... | [
"def",
"remove",
"(",
"path",
",",
"*",
"*",
"kwargs",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"if",
"not",
"os",
".",
"path",
".",
"isabs",
"(",
"path",
")",
":",
"raise",
"SaltInvocationError",
"(",
"'File p... | Remove the named file. If a directory is supplied, it will be recursively
deleted.
CLI Example:
.. code-block:: bash
salt '*' file.remove /tmp/foo | [
"Remove",
"the",
"named",
"file",
".",
"If",
"a",
"directory",
"is",
"supplied",
"it",
"will",
"be",
"recursively",
"deleted",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3790-L3817 | train |
saltstack/salt | salt/modules/file.py | path_exists_glob | def path_exists_glob(path):
'''
Tests to see if path after expansion is a valid path (file or directory).
Expansion allows usage of ? * and character ranges []. Tilde expansion
is not supported. Returns True/False.
.. versionadded:: 2014.7.0
CLI Example:
.. code-block:: bash
salt... | python | def path_exists_glob(path):
'''
Tests to see if path after expansion is a valid path (file or directory).
Expansion allows usage of ? * and character ranges []. Tilde expansion
is not supported. Returns True/False.
.. versionadded:: 2014.7.0
CLI Example:
.. code-block:: bash
salt... | [
"def",
"path_exists_glob",
"(",
"path",
")",
":",
"return",
"True",
"if",
"glob",
".",
"glob",
"(",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
")",
"else",
"False"
] | Tests to see if path after expansion is a valid path (file or directory).
Expansion allows usage of ? * and character ranges []. Tilde expansion
is not supported. Returns True/False.
.. versionadded:: 2014.7.0
CLI Example:
.. code-block:: bash
salt '*' file.path_exists_glob /etc/pam*/pas... | [
"Tests",
"to",
"see",
"if",
"path",
"after",
"expansion",
"is",
"a",
"valid",
"path",
"(",
"file",
"or",
"directory",
")",
".",
"Expansion",
"allows",
"usage",
"of",
"?",
"*",
"and",
"character",
"ranges",
"[]",
".",
"Tilde",
"expansion",
"is",
"not",
... | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3848-L3863 | train |
saltstack/salt | salt/modules/file.py | restorecon | def restorecon(path, recursive=False):
'''
Reset the SELinux context on a given path
CLI Example:
.. code-block:: bash
salt '*' file.restorecon /home/user/.ssh/authorized_keys
'''
if recursive:
cmd = ['restorecon', '-FR', path]
else:
cmd = ['restorecon', '-F', pat... | python | def restorecon(path, recursive=False):
'''
Reset the SELinux context on a given path
CLI Example:
.. code-block:: bash
salt '*' file.restorecon /home/user/.ssh/authorized_keys
'''
if recursive:
cmd = ['restorecon', '-FR', path]
else:
cmd = ['restorecon', '-F', pat... | [
"def",
"restorecon",
"(",
"path",
",",
"recursive",
"=",
"False",
")",
":",
"if",
"recursive",
":",
"cmd",
"=",
"[",
"'restorecon'",
",",
"'-FR'",
",",
"path",
"]",
"else",
":",
"cmd",
"=",
"[",
"'restorecon'",
",",
"'-F'",
",",
"path",
"]",
"return"... | Reset the SELinux context on a given path
CLI Example:
.. code-block:: bash
salt '*' file.restorecon /home/user/.ssh/authorized_keys | [
"Reset",
"the",
"SELinux",
"context",
"on",
"a",
"given",
"path"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3866-L3880 | train |
saltstack/salt | salt/modules/file.py | get_selinux_context | def get_selinux_context(path):
'''
Get an SELinux context from a given path
CLI Example:
.. code-block:: bash
salt '*' file.get_selinux_context /etc/hosts
'''
out = __salt__['cmd.run'](['ls', '-Z', path], python_shell=False)
try:
ret = re.search(r'\w+:\w+:\w+:\w+', out).g... | python | def get_selinux_context(path):
'''
Get an SELinux context from a given path
CLI Example:
.. code-block:: bash
salt '*' file.get_selinux_context /etc/hosts
'''
out = __salt__['cmd.run'](['ls', '-Z', path], python_shell=False)
try:
ret = re.search(r'\w+:\w+:\w+:\w+', out).g... | [
"def",
"get_selinux_context",
"(",
"path",
")",
":",
"out",
"=",
"__salt__",
"[",
"'cmd.run'",
"]",
"(",
"[",
"'ls'",
",",
"'-Z'",
",",
"path",
"]",
",",
"python_shell",
"=",
"False",
")",
"try",
":",
"ret",
"=",
"re",
".",
"search",
"(",
"r'\\w+:\\w... | Get an SELinux context from a given path
CLI Example:
.. code-block:: bash
salt '*' file.get_selinux_context /etc/hosts | [
"Get",
"an",
"SELinux",
"context",
"from",
"a",
"given",
"path"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3883-L3902 | train |
saltstack/salt | salt/modules/file.py | set_selinux_context | def set_selinux_context(path,
user=None,
role=None,
type=None, # pylint: disable=W0622
range=None, # pylint: disable=W0622
persist=False):
'''
.. versionchanged:: Neon
Added pers... | python | def set_selinux_context(path,
user=None,
role=None,
type=None, # pylint: disable=W0622
range=None, # pylint: disable=W0622
persist=False):
'''
.. versionchanged:: Neon
Added pers... | [
"def",
"set_selinux_context",
"(",
"path",
",",
"user",
"=",
"None",
",",
"role",
"=",
"None",
",",
"type",
"=",
"None",
",",
"# pylint: disable=W0622",
"range",
"=",
"None",
",",
"# pylint: disable=W0622",
"persist",
"=",
"False",
")",
":",
"if",
"not",
"... | .. versionchanged:: Neon
Added persist option
Set a specific SELinux label on a given path
CLI Example:
.. code-block:: bash
salt '*' file.set_selinux_context path <user> <role> <type> <range>
salt '*' file.set_selinux_context /etc/yum.repos.d/epel.repo system_u object_r system_... | [
"..",
"versionchanged",
"::",
"Neon"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3905-L3952 | train |
saltstack/salt | salt/modules/file.py | source_list | def source_list(source, source_hash, saltenv):
'''
Check the source list and return the source to use
CLI Example:
.. code-block:: bash
salt '*' file.source_list salt://http/httpd.conf '{hash_type: 'md5', 'hsum': <md5sum>}' base
'''
contextkey = '{0}_|-{1}_|-{2}'.format(source, source... | python | def source_list(source, source_hash, saltenv):
'''
Check the source list and return the source to use
CLI Example:
.. code-block:: bash
salt '*' file.source_list salt://http/httpd.conf '{hash_type: 'md5', 'hsum': <md5sum>}' base
'''
contextkey = '{0}_|-{1}_|-{2}'.format(source, source... | [
"def",
"source_list",
"(",
"source",
",",
"source_hash",
",",
"saltenv",
")",
":",
"contextkey",
"=",
"'{0}_|-{1}_|-{2}'",
".",
"format",
"(",
"source",
",",
"source_hash",
",",
"saltenv",
")",
"if",
"contextkey",
"in",
"__context__",
":",
"return",
"__context... | Check the source list and return the source to use
CLI Example:
.. code-block:: bash
salt '*' file.source_list salt://http/httpd.conf '{hash_type: 'md5', 'hsum': <md5sum>}' base | [
"Check",
"the",
"source",
"list",
"and",
"return",
"the",
"source",
"to",
"use"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L3955-L4062 | train |
saltstack/salt | salt/modules/file.py | apply_template_on_contents | def apply_template_on_contents(
contents,
template,
context,
defaults,
saltenv):
'''
Return the contents after applying the templating engine
contents
template string
template
template format
context
Overrides default context variabl... | python | def apply_template_on_contents(
contents,
template,
context,
defaults,
saltenv):
'''
Return the contents after applying the templating engine
contents
template string
template
template format
context
Overrides default context variabl... | [
"def",
"apply_template_on_contents",
"(",
"contents",
",",
"template",
",",
"context",
",",
"defaults",
",",
"saltenv",
")",
":",
"if",
"template",
"in",
"salt",
".",
"utils",
".",
"templates",
".",
"TEMPLATE_REGISTRY",
":",
"context_dict",
"=",
"defaults",
"i... | Return the contents after applying the templating engine
contents
template string
template
template format
context
Overrides default context variables passed to the template.
defaults
Default context passed to the template.
CLI Example:
.. code-block:: bash
... | [
"Return",
"the",
"contents",
"after",
"applying",
"the",
"templating",
"engine"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L4065-L4122 | train |
saltstack/salt | salt/modules/file.py | get_managed | def get_managed(
name,
template,
source,
source_hash,
source_hash_name,
user,
group,
mode,
attrs,
saltenv,
context,
defaults,
skip_verify=False,
**kwargs):
'''
Return the managed file data for file.ma... | python | def get_managed(
name,
template,
source,
source_hash,
source_hash_name,
user,
group,
mode,
attrs,
saltenv,
context,
defaults,
skip_verify=False,
**kwargs):
'''
Return the managed file data for file.ma... | [
"def",
"get_managed",
"(",
"name",
",",
"template",
",",
"source",
",",
"source_hash",
",",
"source_hash_name",
",",
"user",
",",
"group",
",",
"mode",
",",
"attrs",
",",
"saltenv",
",",
"context",
",",
"defaults",
",",
"skip_verify",
"=",
"False",
",",
... | Return the managed file data for file.managed
name
location where the file lives on the server
template
template format
source
managed source file
source_hash
hash of the source file
source_hash_name
When ``source_hash`` refers to a remote file, this spec... | [
"Return",
"the",
"managed",
"file",
"data",
"for",
"file",
".",
"managed"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L4125-L4333 | train |
saltstack/salt | salt/modules/file.py | extract_hash | def extract_hash(hash_fn,
hash_type='sha256',
file_name='',
source='',
source_hash_name=None):
'''
.. versionchanged:: 2016.3.5
Prior to this version, only the ``file_name`` argument was considered
for filename matches in the ha... | python | def extract_hash(hash_fn,
hash_type='sha256',
file_name='',
source='',
source_hash_name=None):
'''
.. versionchanged:: 2016.3.5
Prior to this version, only the ``file_name`` argument was considered
for filename matches in the ha... | [
"def",
"extract_hash",
"(",
"hash_fn",
",",
"hash_type",
"=",
"'sha256'",
",",
"file_name",
"=",
"''",
",",
"source",
"=",
"''",
",",
"source_hash_name",
"=",
"None",
")",
":",
"hash_len",
"=",
"HASHES",
".",
"get",
"(",
"hash_type",
")",
"if",
"hash_len... | .. versionchanged:: 2016.3.5
Prior to this version, only the ``file_name`` argument was considered
for filename matches in the hash file. This would be problematic for
cases in which the user was relying on a remote checksum file that they
do not control, and they wished to use a differe... | [
"..",
"versionchanged",
"::",
"2016",
".",
"3",
".",
"5",
"Prior",
"to",
"this",
"version",
"only",
"the",
"file_name",
"argument",
"was",
"considered",
"for",
"filename",
"matches",
"in",
"the",
"hash",
"file",
".",
"This",
"would",
"be",
"problematic",
"... | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L4336-L4563 | train |
saltstack/salt | salt/modules/file.py | check_perms | def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False, seuser=None,
serole=None, setype=None, serange=None):
'''
.. versionchanged:: Neon
Added selinux options
Check the permissions on files, modify attributes and chown if needed. File
attributes are o... | python | def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False, seuser=None,
serole=None, setype=None, serange=None):
'''
.. versionchanged:: Neon
Added selinux options
Check the permissions on files, modify attributes and chown if needed. File
attributes are o... | [
"def",
"check_perms",
"(",
"name",
",",
"ret",
",",
"user",
",",
"group",
",",
"mode",
",",
"attrs",
"=",
"None",
",",
"follow_symlinks",
"=",
"False",
",",
"seuser",
"=",
"None",
",",
"serole",
"=",
"None",
",",
"setype",
"=",
"None",
",",
"serange"... | .. versionchanged:: Neon
Added selinux options
Check the permissions on files, modify attributes and chown if needed. File
attributes are only verified if lsattr(1) is installed.
CLI Example:
.. code-block:: bash
salt '*' file.check_perms /etc/sudoers '{}' root root 400 ai
.. v... | [
"..",
"versionchanged",
"::",
"Neon"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L4566-L4857 | train |
saltstack/salt | salt/modules/file.py | check_managed | def check_managed(
name,
source,
source_hash,
source_hash_name,
user,
group,
mode,
attrs,
template,
context,
defaults,
saltenv,
contents=None,
skip_verify=False,
seuser=None,
serole=None,
... | python | def check_managed(
name,
source,
source_hash,
source_hash_name,
user,
group,
mode,
attrs,
template,
context,
defaults,
saltenv,
contents=None,
skip_verify=False,
seuser=None,
serole=None,
... | [
"def",
"check_managed",
"(",
"name",
",",
"source",
",",
"source_hash",
",",
"source_hash_name",
",",
"user",
",",
"group",
",",
"mode",
",",
"attrs",
",",
"template",
",",
"context",
",",
"defaults",
",",
"saltenv",
",",
"contents",
"=",
"None",
",",
"s... | Check to see what changes need to be made for a file
CLI Example:
.. code-block:: bash
salt '*' file.check_managed /etc/httpd/conf.d/httpd.conf salt://http/httpd.conf '{hash_type: 'md5', 'hsum': <md5sum>}' root, root, '755' jinja True None None base | [
"Check",
"to",
"see",
"what",
"changes",
"need",
"to",
"be",
"made",
"for",
"a",
"file"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L4860-L4933 | train |
saltstack/salt | salt/modules/file.py | check_managed_changes | def check_managed_changes(
name,
source,
source_hash,
source_hash_name,
user,
group,
mode,
attrs,
template,
context,
defaults,
saltenv,
contents=None,
skip_verify=False,
keep_mode=False,
seuse... | python | def check_managed_changes(
name,
source,
source_hash,
source_hash_name,
user,
group,
mode,
attrs,
template,
context,
defaults,
saltenv,
contents=None,
skip_verify=False,
keep_mode=False,
seuse... | [
"def",
"check_managed_changes",
"(",
"name",
",",
"source",
",",
"source_hash",
",",
"source_hash_name",
",",
"user",
",",
"group",
",",
"mode",
",",
"attrs",
",",
"template",
",",
"context",
",",
"defaults",
",",
"saltenv",
",",
"contents",
"=",
"None",
"... | Return a dictionary of what changes need to be made for a file
.. versionchanged:: Neon
selinux attributes added
CLI Example:
.. code-block:: bash
salt '*' file.check_managed_changes /etc/httpd/conf.d/httpd.conf salt://http/httpd.conf '{hash_type: 'md5', 'hsum': <md5sum>}' root, root, '... | [
"Return",
"a",
"dictionary",
"of",
"what",
"changes",
"need",
"to",
"be",
"made",
"for",
"a",
"file"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L4936-L5014 | train |
saltstack/salt | salt/modules/file.py | check_file_meta | def check_file_meta(
name,
sfn,
source,
source_sum,
user,
group,
mode,
attrs,
saltenv,
contents=None,
seuser=None,
serole=None,
setype=None,
serange=None):
'''
Check for the changes in the file metada... | python | def check_file_meta(
name,
sfn,
source,
source_sum,
user,
group,
mode,
attrs,
saltenv,
contents=None,
seuser=None,
serole=None,
setype=None,
serange=None):
'''
Check for the changes in the file metada... | [
"def",
"check_file_meta",
"(",
"name",
",",
"sfn",
",",
"source",
",",
"source_sum",
",",
"user",
",",
"group",
",",
"mode",
",",
"attrs",
",",
"saltenv",
",",
"contents",
"=",
"None",
",",
"seuser",
"=",
"None",
",",
"serole",
"=",
"None",
",",
"set... | Check for the changes in the file metadata.
CLI Example:
.. code-block:: bash
salt '*' file.check_file_meta /etc/httpd/conf.d/httpd.conf salt://http/httpd.conf '{hash_type: 'md5', 'hsum': <md5sum>}' root, root, '755' base
.. note::
Supported hash types include sha512, sha384, sha256, sh... | [
"Check",
"for",
"the",
"changes",
"in",
"the",
"file",
"metadata",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L5017-L5202 | train |
saltstack/salt | salt/modules/file.py | get_diff | def get_diff(file1,
file2,
saltenv='base',
show_filenames=True,
show_changes=True,
template=False,
source_hash_file1=None,
source_hash_file2=None):
'''
Return unified diff of two files
file1
The first file to... | python | def get_diff(file1,
file2,
saltenv='base',
show_filenames=True,
show_changes=True,
template=False,
source_hash_file1=None,
source_hash_file2=None):
'''
Return unified diff of two files
file1
The first file to... | [
"def",
"get_diff",
"(",
"file1",
",",
"file2",
",",
"saltenv",
"=",
"'base'",
",",
"show_filenames",
"=",
"True",
",",
"show_changes",
"=",
"True",
",",
"template",
"=",
"False",
",",
"source_hash_file1",
"=",
"None",
",",
"source_hash_file2",
"=",
"None",
... | Return unified diff of two files
file1
The first file to feed into the diff utility
.. versionchanged:: 2018.3.0
Can now be either a local or remote file. In earlier releases,
thuis had to be a file local to the minion.
file2
The second file to feed into the di... | [
"Return",
"unified",
"diff",
"of",
"two",
"files"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L5205-L5327 | train |
saltstack/salt | salt/modules/file.py | manage_file | def manage_file(name,
sfn,
ret,
source,
source_sum,
user,
group,
mode,
attrs,
saltenv,
backup,
makedirs=False,
template=None, ... | python | def manage_file(name,
sfn,
ret,
source,
source_sum,
user,
group,
mode,
attrs,
saltenv,
backup,
makedirs=False,
template=None, ... | [
"def",
"manage_file",
"(",
"name",
",",
"sfn",
",",
"ret",
",",
"source",
",",
"source_sum",
",",
"user",
",",
"group",
",",
"mode",
",",
"attrs",
",",
"saltenv",
",",
"backup",
",",
"makedirs",
"=",
"False",
",",
"template",
"=",
"None",
",",
"# pyl... | Checks the destination against what was retrieved with get_managed and
makes the appropriate modifications (if necessary).
name
location to place the file
sfn
location of cached file on the minion
This is the path to the file stored on the minion. This file is placed
on th... | [
"Checks",
"the",
"destination",
"against",
"what",
"was",
"retrieved",
"with",
"get_managed",
"and",
"makes",
"the",
"appropriate",
"modifications",
"(",
"if",
"necessary",
")",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L5330-L5847 | train |
saltstack/salt | salt/modules/file.py | mkdir | def mkdir(dir_path,
user=None,
group=None,
mode=None):
'''
Ensure that a directory is available.
CLI Example:
.. code-block:: bash
salt '*' file.mkdir /opt/jetty/context
'''
dir_path = os.path.expanduser(dir_path)
directory = os.path.normpath(dir_pat... | python | def mkdir(dir_path,
user=None,
group=None,
mode=None):
'''
Ensure that a directory is available.
CLI Example:
.. code-block:: bash
salt '*' file.mkdir /opt/jetty/context
'''
dir_path = os.path.expanduser(dir_path)
directory = os.path.normpath(dir_pat... | [
"def",
"mkdir",
"(",
"dir_path",
",",
"user",
"=",
"None",
",",
"group",
"=",
"None",
",",
"mode",
"=",
"None",
")",
":",
"dir_path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"dir_path",
")",
"directory",
"=",
"os",
".",
"path",
".",
"normpa... | Ensure that a directory is available.
CLI Example:
.. code-block:: bash
salt '*' file.mkdir /opt/jetty/context | [
"Ensure",
"that",
"a",
"directory",
"is",
"available",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L5850-L5873 | train |
saltstack/salt | salt/modules/file.py | makedirs_ | def makedirs_(path,
user=None,
group=None,
mode=None):
'''
Ensure that the directory containing this path is available.
.. note::
The path must end with a trailing slash otherwise the directory/directories
will be created up to the parent directory... | python | def makedirs_(path,
user=None,
group=None,
mode=None):
'''
Ensure that the directory containing this path is available.
.. note::
The path must end with a trailing slash otherwise the directory/directories
will be created up to the parent directory... | [
"def",
"makedirs_",
"(",
"path",
",",
"user",
"=",
"None",
",",
"group",
"=",
"None",
",",
"mode",
"=",
"None",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"if",
"mode",
":",
"mode",
"=",
"salt",
".",
"utils",
... | Ensure that the directory containing this path is available.
.. note::
The path must end with a trailing slash otherwise the directory/directories
will be created up to the parent directory. For example if path is
``/opt/code``, then it would be treated as ``/opt/`` but if the path
... | [
"Ensure",
"that",
"the",
"directory",
"containing",
"this",
"path",
"is",
"available",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L5876-L5939 | train |
saltstack/salt | salt/modules/file.py | makedirs_perms | def makedirs_perms(name,
user=None,
group=None,
mode='0755'):
'''
Taken and modified from os.makedirs to set user, group and mode for each
directory created.
CLI Example:
.. code-block:: bash
salt '*' file.makedirs_perms /opt/code
... | python | def makedirs_perms(name,
user=None,
group=None,
mode='0755'):
'''
Taken and modified from os.makedirs to set user, group and mode for each
directory created.
CLI Example:
.. code-block:: bash
salt '*' file.makedirs_perms /opt/code
... | [
"def",
"makedirs_perms",
"(",
"name",
",",
"user",
"=",
"None",
",",
"group",
"=",
"None",
",",
"mode",
"=",
"'0755'",
")",
":",
"name",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"name",
")",
"path",
"=",
"os",
".",
"path",
"head",
",",
"ta... | Taken and modified from os.makedirs to set user, group and mode for each
directory created.
CLI Example:
.. code-block:: bash
salt '*' file.makedirs_perms /opt/code | [
"Taken",
"and",
"modified",
"from",
"os",
".",
"makedirs",
"to",
"set",
"user",
"group",
"and",
"mode",
"for",
"each",
"directory",
"created",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L5942-L5976 | train |
saltstack/salt | salt/modules/file.py | get_devmm | def get_devmm(name):
'''
Get major/minor info from a device
CLI Example:
.. code-block:: bash
salt '*' file.get_devmm /dev/chr
'''
name = os.path.expanduser(name)
if is_chrdev(name) or is_blkdev(name):
stat_structure = os.stat(name)
return (
os.majo... | python | def get_devmm(name):
'''
Get major/minor info from a device
CLI Example:
.. code-block:: bash
salt '*' file.get_devmm /dev/chr
'''
name = os.path.expanduser(name)
if is_chrdev(name) or is_blkdev(name):
stat_structure = os.stat(name)
return (
os.majo... | [
"def",
"get_devmm",
"(",
"name",
")",
":",
"name",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"name",
")",
"if",
"is_chrdev",
"(",
"name",
")",
"or",
"is_blkdev",
"(",
"name",
")",
":",
"stat_structure",
"=",
"os",
".",
"stat",
"(",
"name",
")... | Get major/minor info from a device
CLI Example:
.. code-block:: bash
salt '*' file.get_devmm /dev/chr | [
"Get",
"major",
"/",
"minor",
"info",
"from",
"a",
"device"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L5979-L5997 | train |
saltstack/salt | salt/modules/file.py | is_chrdev | def is_chrdev(name):
'''
Check if a file exists and is a character device.
CLI Example:
.. code-block:: bash
salt '*' file.is_chrdev /dev/chr
'''
name = os.path.expanduser(name)
stat_structure = None
try:
stat_structure = os.stat(name)
except OSError as exc:
... | python | def is_chrdev(name):
'''
Check if a file exists and is a character device.
CLI Example:
.. code-block:: bash
salt '*' file.is_chrdev /dev/chr
'''
name = os.path.expanduser(name)
stat_structure = None
try:
stat_structure = os.stat(name)
except OSError as exc:
... | [
"def",
"is_chrdev",
"(",
"name",
")",
":",
"name",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"name",
")",
"stat_structure",
"=",
"None",
"try",
":",
"stat_structure",
"=",
"os",
".",
"stat",
"(",
"name",
")",
"except",
"OSError",
"as",
"exc",
"... | Check if a file exists and is a character device.
CLI Example:
.. code-block:: bash
salt '*' file.is_chrdev /dev/chr | [
"Check",
"if",
"a",
"file",
"exists",
"and",
"is",
"a",
"character",
"device",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L6000-L6021 | train |
saltstack/salt | salt/modules/file.py | mknod_chrdev | def mknod_chrdev(name,
major,
minor,
user=None,
group=None,
mode='0660'):
'''
.. versionadded:: 0.17.0
Create a character device.
CLI Example:
.. code-block:: bash
salt '*' file.mknod_chrdev /dev/chr 180 ... | python | def mknod_chrdev(name,
major,
minor,
user=None,
group=None,
mode='0660'):
'''
.. versionadded:: 0.17.0
Create a character device.
CLI Example:
.. code-block:: bash
salt '*' file.mknod_chrdev /dev/chr 180 ... | [
"def",
"mknod_chrdev",
"(",
"name",
",",
"major",
",",
"minor",
",",
"user",
"=",
"None",
",",
"group",
"=",
"None",
",",
"mode",
"=",
"'0660'",
")",
":",
"name",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"name",
")",
"ret",
"=",
"{",
"'nam... | .. versionadded:: 0.17.0
Create a character device.
CLI Example:
.. code-block:: bash
salt '*' file.mknod_chrdev /dev/chr 180 31 | [
"..",
"versionadded",
"::",
"0",
".",
"17",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L6024-L6072 | train |
saltstack/salt | salt/modules/file.py | is_blkdev | def is_blkdev(name):
'''
Check if a file exists and is a block device.
CLI Example:
.. code-block:: bash
salt '*' file.is_blkdev /dev/blk
'''
name = os.path.expanduser(name)
stat_structure = None
try:
stat_structure = os.stat(name)
except OSError as exc:
if... | python | def is_blkdev(name):
'''
Check if a file exists and is a block device.
CLI Example:
.. code-block:: bash
salt '*' file.is_blkdev /dev/blk
'''
name = os.path.expanduser(name)
stat_structure = None
try:
stat_structure = os.stat(name)
except OSError as exc:
if... | [
"def",
"is_blkdev",
"(",
"name",
")",
":",
"name",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"name",
")",
"stat_structure",
"=",
"None",
"try",
":",
"stat_structure",
"=",
"os",
".",
"stat",
"(",
"name",
")",
"except",
"OSError",
"as",
"exc",
"... | Check if a file exists and is a block device.
CLI Example:
.. code-block:: bash
salt '*' file.is_blkdev /dev/blk | [
"Check",
"if",
"a",
"file",
"exists",
"and",
"is",
"a",
"block",
"device",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L6075-L6096 | train |
saltstack/salt | salt/modules/file.py | is_fifo | def is_fifo(name):
'''
Check if a file exists and is a FIFO.
CLI Example:
.. code-block:: bash
salt '*' file.is_fifo /dev/fifo
'''
name = os.path.expanduser(name)
stat_structure = None
try:
stat_structure = os.stat(name)
except OSError as exc:
if exc.errno ... | python | def is_fifo(name):
'''
Check if a file exists and is a FIFO.
CLI Example:
.. code-block:: bash
salt '*' file.is_fifo /dev/fifo
'''
name = os.path.expanduser(name)
stat_structure = None
try:
stat_structure = os.stat(name)
except OSError as exc:
if exc.errno ... | [
"def",
"is_fifo",
"(",
"name",
")",
":",
"name",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"name",
")",
"stat_structure",
"=",
"None",
"try",
":",
"stat_structure",
"=",
"os",
".",
"stat",
"(",
"name",
")",
"except",
"OSError",
"as",
"exc",
":"... | Check if a file exists and is a FIFO.
CLI Example:
.. code-block:: bash
salt '*' file.is_fifo /dev/fifo | [
"Check",
"if",
"a",
"file",
"exists",
"and",
"is",
"a",
"FIFO",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L6150-L6171 | train |
saltstack/salt | salt/modules/file.py | mknod_fifo | def mknod_fifo(name,
user=None,
group=None,
mode='0660'):
'''
.. versionadded:: 0.17.0
Create a FIFO pipe.
CLI Example:
.. code-block:: bash
salt '*' file.mknod_fifo /dev/fifo
'''
name = os.path.expanduser(name)
ret = {'name': name... | python | def mknod_fifo(name,
user=None,
group=None,
mode='0660'):
'''
.. versionadded:: 0.17.0
Create a FIFO pipe.
CLI Example:
.. code-block:: bash
salt '*' file.mknod_fifo /dev/fifo
'''
name = os.path.expanduser(name)
ret = {'name': name... | [
"def",
"mknod_fifo",
"(",
"name",
",",
"user",
"=",
"None",
",",
"group",
"=",
"None",
",",
"mode",
"=",
"'0660'",
")",
":",
"name",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"name",
")",
"ret",
"=",
"{",
"'name'",
":",
"name",
",",
"'chang... | .. versionadded:: 0.17.0
Create a FIFO pipe.
CLI Example:
.. code-block:: bash
salt '*' file.mknod_fifo /dev/fifo | [
"..",
"versionadded",
"::",
"0",
".",
"17",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L6174-L6216 | train |
saltstack/salt | salt/modules/file.py | mknod | def mknod(name,
ntype,
major=0,
minor=0,
user=None,
group=None,
mode='0600'):
'''
.. versionadded:: 0.17.0
Create a block device, character device, or fifo pipe.
Identical to the gnu mknod.
CLI Examples:
.. code-block:: bash
... | python | def mknod(name,
ntype,
major=0,
minor=0,
user=None,
group=None,
mode='0600'):
'''
.. versionadded:: 0.17.0
Create a block device, character device, or fifo pipe.
Identical to the gnu mknod.
CLI Examples:
.. code-block:: bash
... | [
"def",
"mknod",
"(",
"name",
",",
"ntype",
",",
"major",
"=",
"0",
",",
"minor",
"=",
"0",
",",
"user",
"=",
"None",
",",
"group",
"=",
"None",
",",
"mode",
"=",
"'0600'",
")",
":",
"ret",
"=",
"False",
"makedirs_",
"(",
"name",
",",
"user",
",... | .. versionadded:: 0.17.0
Create a block device, character device, or fifo pipe.
Identical to the gnu mknod.
CLI Examples:
.. code-block:: bash
salt '*' file.mknod /dev/chr c 180 31
salt '*' file.mknod /dev/blk b 8 999
salt '*' file.nknod /dev/fifo p | [
"..",
"versionadded",
"::",
"0",
".",
"17",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L6219-L6253 | train |
saltstack/salt | salt/modules/file.py | list_backups | def list_backups(path, limit=None):
'''
.. versionadded:: 0.17.0
Lists the previous versions of a file backed up using Salt's :ref:`file
state backup <file-state-backups>` system.
path
The path on the minion to check for backups
limit
Limit the number of results to the most rec... | python | def list_backups(path, limit=None):
'''
.. versionadded:: 0.17.0
Lists the previous versions of a file backed up using Salt's :ref:`file
state backup <file-state-backups>` system.
path
The path on the minion to check for backups
limit
Limit the number of results to the most rec... | [
"def",
"list_backups",
"(",
"path",
",",
"limit",
"=",
"None",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"try",
":",
"limit",
"=",
"int",
"(",
"limit",
")",
"except",
"TypeError",
":",
"pass",
"except",
"ValueErro... | .. versionadded:: 0.17.0
Lists the previous versions of a file backed up using Salt's :ref:`file
state backup <file-state-backups>` system.
path
The path on the minion to check for backups
limit
Limit the number of results to the most recent N backups
CLI Example:
.. code-blo... | [
"..",
"versionadded",
"::",
"0",
".",
"17",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L6256-L6324 | train |
saltstack/salt | salt/modules/file.py | list_backups_dir | def list_backups_dir(path, limit=None):
'''
Lists the previous versions of a directory backed up using Salt's :ref:`file
state backup <file-state-backups>` system.
path
The directory on the minion to check for backups
limit
Limit the number of results to the most recent N backups
... | python | def list_backups_dir(path, limit=None):
'''
Lists the previous versions of a directory backed up using Salt's :ref:`file
state backup <file-state-backups>` system.
path
The directory on the minion to check for backups
limit
Limit the number of results to the most recent N backups
... | [
"def",
"list_backups_dir",
"(",
"path",
",",
"limit",
"=",
"None",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"try",
":",
"limit",
"=",
"int",
"(",
"limit",
")",
"except",
"TypeError",
":",
"pass",
"except",
"Value... | Lists the previous versions of a directory backed up using Salt's :ref:`file
state backup <file-state-backups>` system.
path
The directory on the minion to check for backups
limit
Limit the number of results to the most recent N backups
CLI Example:
.. code-block:: bash
s... | [
"Lists",
"the",
"previous",
"versions",
"of",
"a",
"directory",
"backed",
"up",
"using",
"Salt",
"s",
":",
"ref",
":",
"file",
"state",
"backup",
"<file",
"-",
"state",
"-",
"backups",
">",
"system",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L6330-L6388 | train |
saltstack/salt | salt/modules/file.py | restore_backup | def restore_backup(path, backup_id):
'''
.. versionadded:: 0.17.0
Restore a previous version of a file that was backed up using Salt's
:ref:`file state backup <file-state-backups>` system.
path
The path on the minion to check for backups
backup_id
The numeric id for the backup ... | python | def restore_backup(path, backup_id):
'''
.. versionadded:: 0.17.0
Restore a previous version of a file that was backed up using Salt's
:ref:`file state backup <file-state-backups>` system.
path
The path on the minion to check for backups
backup_id
The numeric id for the backup ... | [
"def",
"restore_backup",
"(",
"path",
",",
"backup_id",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"# Note: This only supports minion backups, so this function will need to be",
"# modified if/when master backups are implemented.",
"ret",
... | .. versionadded:: 0.17.0
Restore a previous version of a file that was backed up using Salt's
:ref:`file state backup <file-state-backups>` system.
path
The path on the minion to check for backups
backup_id
The numeric id for the backup you wish to restore, as found using
:mod:... | [
"..",
"versionadded",
"::",
"0",
".",
"17",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L6391-L6450 | train |
saltstack/salt | salt/modules/file.py | delete_backup | def delete_backup(path, backup_id):
'''
.. versionadded:: 0.17.0
Delete a previous version of a file that was backed up using Salt's
:ref:`file state backup <file-state-backups>` system.
path
The path on the minion to check for backups
backup_id
The numeric id for the backup yo... | python | def delete_backup(path, backup_id):
'''
.. versionadded:: 0.17.0
Delete a previous version of a file that was backed up using Salt's
:ref:`file state backup <file-state-backups>` system.
path
The path on the minion to check for backups
backup_id
The numeric id for the backup yo... | [
"def",
"delete_backup",
"(",
"path",
",",
"backup_id",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"ret",
"=",
"{",
"'result'",
":",
"False",
",",
"'comment'",
":",
"'Invalid backup_id \\'{0}\\''",
".",
"format",
"(",
"... | .. versionadded:: 0.17.0
Delete a previous version of a file that was backed up using Salt's
:ref:`file state backup <file-state-backups>` system.
path
The path on the minion to check for backups
backup_id
The numeric id for the backup you wish to delete, as found using
:mod:`f... | [
"..",
"versionadded",
"::",
"0",
".",
"17",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L6453-L6497 | train |
saltstack/salt | salt/modules/file.py | grep | def grep(path,
pattern,
*opts):
'''
Grep for a string in the specified file
.. note::
This function's return value is slated for refinement in future
versions of Salt
path
Path to the file to be searched
.. note::
Globbing is supported (i.... | python | def grep(path,
pattern,
*opts):
'''
Grep for a string in the specified file
.. note::
This function's return value is slated for refinement in future
versions of Salt
path
Path to the file to be searched
.. note::
Globbing is supported (i.... | [
"def",
"grep",
"(",
"path",
",",
"pattern",
",",
"*",
"opts",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"# Backup the path in case the glob returns nothing",
"_path",
"=",
"path",
"path",
"=",
"glob",
".",
"glob",
"(",
... | Grep for a string in the specified file
.. note::
This function's return value is slated for refinement in future
versions of Salt
path
Path to the file to be searched
.. note::
Globbing is supported (i.e. ``/var/log/foo/*.log``, but if globbing
is bein... | [
"Grep",
"for",
"a",
"string",
"in",
"the",
"specified",
"file"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L6503-L6577 | train |
saltstack/salt | salt/modules/file.py | open_files | def open_files(by_pid=False):
'''
Return a list of all physical open files on the system.
CLI Examples:
.. code-block:: bash
salt '*' file.open_files
salt '*' file.open_files by_pid=True
'''
# First we collect valid PIDs
pids = {}
procfs = os.listdir('/proc/')
for ... | python | def open_files(by_pid=False):
'''
Return a list of all physical open files on the system.
CLI Examples:
.. code-block:: bash
salt '*' file.open_files
salt '*' file.open_files by_pid=True
'''
# First we collect valid PIDs
pids = {}
procfs = os.listdir('/proc/')
for ... | [
"def",
"open_files",
"(",
"by_pid",
"=",
"False",
")",
":",
"# First we collect valid PIDs",
"pids",
"=",
"{",
"}",
"procfs",
"=",
"os",
".",
"listdir",
"(",
"'/proc/'",
")",
"for",
"pfile",
"in",
"procfs",
":",
"try",
":",
"pids",
"[",
"int",
"(",
"pf... | Return a list of all physical open files on the system.
CLI Examples:
.. code-block:: bash
salt '*' file.open_files
salt '*' file.open_files by_pid=True | [
"Return",
"a",
"list",
"of",
"all",
"physical",
"open",
"files",
"on",
"the",
"system",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L6580-L6657 | train |
saltstack/salt | salt/modules/file.py | move | def move(src, dst):
'''
Move a file or directory
CLI Example:
.. code-block:: bash
salt '*' file.move /path/to/src /path/to/dst
'''
src = os.path.expanduser(src)
dst = os.path.expanduser(dst)
if not os.path.isabs(src):
raise SaltInvocationError('Source path must be ab... | python | def move(src, dst):
'''
Move a file or directory
CLI Example:
.. code-block:: bash
salt '*' file.move /path/to/src /path/to/dst
'''
src = os.path.expanduser(src)
dst = os.path.expanduser(dst)
if not os.path.isabs(src):
raise SaltInvocationError('Source path must be ab... | [
"def",
"move",
"(",
"src",
",",
"dst",
")",
":",
"src",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"src",
")",
"dst",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"dst",
")",
"if",
"not",
"os",
".",
"path",
".",
"isabs",
"(",
"src",
"... | Move a file or directory
CLI Example:
.. code-block:: bash
salt '*' file.move /path/to/src /path/to/dst | [
"Move",
"a",
"file",
"or",
"directory"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L6773-L6804 | train |
saltstack/salt | salt/modules/file.py | diskusage | def diskusage(path):
'''
Recursively calculate disk usage of path and return it
in bytes
CLI Example:
.. code-block:: bash
salt '*' file.diskusage /path/to/check
'''
total_size = 0
seen = set()
if os.path.isfile(path):
stat_structure = os.stat(path)
ret = ... | python | def diskusage(path):
'''
Recursively calculate disk usage of path and return it
in bytes
CLI Example:
.. code-block:: bash
salt '*' file.diskusage /path/to/check
'''
total_size = 0
seen = set()
if os.path.isfile(path):
stat_structure = os.stat(path)
ret = ... | [
"def",
"diskusage",
"(",
"path",
")",
":",
"total_size",
"=",
"0",
"seen",
"=",
"set",
"(",
")",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"path",
")",
":",
"stat_structure",
"=",
"os",
".",
"stat",
"(",
"path",
")",
"ret",
"=",
"stat_structure"... | Recursively calculate disk usage of path and return it
in bytes
CLI Example:
.. code-block:: bash
salt '*' file.diskusage /path/to/check | [
"Recursively",
"calculate",
"disk",
"usage",
"of",
"path",
"and",
"return",
"it",
"in",
"bytes"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/file.py#L6807-L6843 | train |
saltstack/salt | salt/sdb/sqlite3.py | set_ | def set_(key, value, profile=None):
'''
Set a key/value pair in sqlite3
'''
if not profile:
return False
conn, cur, table = _connect(profile)
if six.PY2:
value = buffer(salt.utils.msgpack.packb(value))
else:
value = memoryview(salt.utils.msgpack.packb(value))
q = ... | python | def set_(key, value, profile=None):
'''
Set a key/value pair in sqlite3
'''
if not profile:
return False
conn, cur, table = _connect(profile)
if six.PY2:
value = buffer(salt.utils.msgpack.packb(value))
else:
value = memoryview(salt.utils.msgpack.packb(value))
q = ... | [
"def",
"set_",
"(",
"key",
",",
"value",
",",
"profile",
"=",
"None",
")",
":",
"if",
"not",
"profile",
":",
"return",
"False",
"conn",
",",
"cur",
",",
"table",
"=",
"_connect",
"(",
"profile",
")",
"if",
"six",
".",
"PY2",
":",
"value",
"=",
"b... | Set a key/value pair in sqlite3 | [
"Set",
"a",
"key",
"/",
"value",
"pair",
"in",
"sqlite3"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/sdb/sqlite3.py#L119-L134 | train |
saltstack/salt | salt/sdb/sqlite3.py | get | def get(key, profile=None):
'''
Get a value from sqlite3
'''
if not profile:
return None
_, cur, table = _connect(profile)
q = profile.get('get_query', ('SELECT value FROM {0} WHERE '
'key=:key'.format(table)))
res = cur.execute(q, {'key': key})
... | python | def get(key, profile=None):
'''
Get a value from sqlite3
'''
if not profile:
return None
_, cur, table = _connect(profile)
q = profile.get('get_query', ('SELECT value FROM {0} WHERE '
'key=:key'.format(table)))
res = cur.execute(q, {'key': key})
... | [
"def",
"get",
"(",
"key",
",",
"profile",
"=",
"None",
")",
":",
"if",
"not",
"profile",
":",
"return",
"None",
"_",
",",
"cur",
",",
"table",
"=",
"_connect",
"(",
"profile",
")",
"q",
"=",
"profile",
".",
"get",
"(",
"'get_query'",
",",
"(",
"'... | Get a value from sqlite3 | [
"Get",
"a",
"value",
"from",
"sqlite3"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/sdb/sqlite3.py#L137-L150 | train |
saltstack/salt | salt/sdb/sqlite3.py | delete | def delete(key, profile=None):
'''
Delete a key/value pair from sqlite3
'''
if not profile:
return None
conn, cur, table = _connect(profile)
q = profile.get('delete_query', ('DELETE FROM {0} WHERE '
'key=:key'.format(table)))
res = cur.execute(q, ... | python | def delete(key, profile=None):
'''
Delete a key/value pair from sqlite3
'''
if not profile:
return None
conn, cur, table = _connect(profile)
q = profile.get('delete_query', ('DELETE FROM {0} WHERE '
'key=:key'.format(table)))
res = cur.execute(q, ... | [
"def",
"delete",
"(",
"key",
",",
"profile",
"=",
"None",
")",
":",
"if",
"not",
"profile",
":",
"return",
"None",
"conn",
",",
"cur",
",",
"table",
"=",
"_connect",
"(",
"profile",
")",
"q",
"=",
"profile",
".",
"get",
"(",
"'delete_query'",
",",
... | Delete a key/value pair from sqlite3 | [
"Delete",
"a",
"key",
"/",
"value",
"pair",
"from",
"sqlite3"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/sdb/sqlite3.py#L153-L164 | train |
saltstack/salt | salt/modules/napalm_route.py | show | def show(destination, protocol=None, **kwargs): # pylint: disable=unused-argument
'''
Displays all details for a certain route learned via a specific protocol.
If the protocol is not specified, will return all possible routes.
.. note::
This function return the routes from the RIB.
I... | python | def show(destination, protocol=None, **kwargs): # pylint: disable=unused-argument
'''
Displays all details for a certain route learned via a specific protocol.
If the protocol is not specified, will return all possible routes.
.. note::
This function return the routes from the RIB.
I... | [
"def",
"show",
"(",
"destination",
",",
"protocol",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# pylint: disable=unused-argument",
"return",
"salt",
".",
"utils",
".",
"napalm",
".",
"call",
"(",
"napalm_device",
",",
"# pylint: disable=undefined-variable",
... | Displays all details for a certain route learned via a specific protocol.
If the protocol is not specified, will return all possible routes.
.. note::
This function return the routes from the RIB.
In case the destination prefix is too short,
there may be too many routes matched.
... | [
"Displays",
"all",
"details",
"for",
"a",
"certain",
"route",
"learned",
"via",
"a",
"specific",
"protocol",
".",
"If",
"the",
"protocol",
"is",
"not",
"specified",
"will",
"return",
"all",
"possible",
"routes",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/napalm_route.py#L59-L158 | train |
saltstack/salt | salt/states/docker_network.py | present | def present(name,
skip_translate=None,
ignore_collisions=False,
validate_ip_addrs=True,
containers=None,
reconnect=True,
**kwargs):
'''
.. versionchanged:: 2018.3.0
Support added for network configuration options other than ``driver... | python | def present(name,
skip_translate=None,
ignore_collisions=False,
validate_ip_addrs=True,
containers=None,
reconnect=True,
**kwargs):
'''
.. versionchanged:: 2018.3.0
Support added for network configuration options other than ``driver... | [
"def",
"present",
"(",
"name",
",",
"skip_translate",
"=",
"None",
",",
"ignore_collisions",
"=",
"False",
",",
"validate_ip_addrs",
"=",
"True",
",",
"containers",
"=",
"None",
",",
"reconnect",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"ret",
"="... | .. versionchanged:: 2018.3.0
Support added for network configuration options other than ``driver``
and ``driver_opts``, as well as IPAM configuration.
Ensure that a network is present
.. note::
This state supports all arguments for network and IPAM pool
configuration which are ... | [
"..",
"versionchanged",
"::",
"2018",
".",
"3",
".",
"0",
"Support",
"added",
"for",
"network",
"configuration",
"options",
"other",
"than",
"driver",
"and",
"driver_opts",
"as",
"well",
"as",
"IPAM",
"configuration",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/states/docker_network.py#L95-L890 | train |
saltstack/salt | salt/states/docker_network.py | absent | def absent(name):
'''
Ensure that a network is absent.
name
Name of the network
Usage Example:
.. code-block:: yaml
network_foo:
docker_network.absent
'''
ret = {'name': name,
'changes': {},
'result': False,
'comment': ''}
t... | python | def absent(name):
'''
Ensure that a network is absent.
name
Name of the network
Usage Example:
.. code-block:: yaml
network_foo:
docker_network.absent
'''
ret = {'name': name,
'changes': {},
'result': False,
'comment': ''}
t... | [
"def",
"absent",
"(",
"name",
")",
":",
"ret",
"=",
"{",
"'name'",
":",
"name",
",",
"'changes'",
":",
"{",
"}",
",",
"'result'",
":",
"False",
",",
"'comment'",
":",
"''",
"}",
"try",
":",
"network",
"=",
"__salt__",
"[",
"'docker.inspect_network'",
... | Ensure that a network is absent.
name
Name of the network
Usage Example:
.. code-block:: yaml
network_foo:
docker_network.absent | [
"Ensure",
"that",
"a",
"network",
"is",
"absent",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/states/docker_network.py#L893-L933 | train |
saltstack/salt | salt/states/docker_network.py | _remove_network | def _remove_network(network):
'''
Remove network, including all connected containers
'''
ret = {'name': network['Name'],
'changes': {},
'result': False,
'comment': ''}
errors = []
for cid in network['Containers']:
try:
cinfo = __salt__['docke... | python | def _remove_network(network):
'''
Remove network, including all connected containers
'''
ret = {'name': network['Name'],
'changes': {},
'result': False,
'comment': ''}
errors = []
for cid in network['Containers']:
try:
cinfo = __salt__['docke... | [
"def",
"_remove_network",
"(",
"network",
")",
":",
"ret",
"=",
"{",
"'name'",
":",
"network",
"[",
"'Name'",
"]",
",",
"'changes'",
":",
"{",
"}",
",",
"'result'",
":",
"False",
",",
"'comment'",
":",
"''",
"}",
"errors",
"=",
"[",
"]",
"for",
"ci... | Remove network, including all connected containers | [
"Remove",
"network",
"including",
"all",
"connected",
"containers"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/states/docker_network.py#L936-L978 | train |
saltstack/salt | salt/transport/mixins/auth.py | AESReqServerMixin.pre_fork | def pre_fork(self, _):
'''
Pre-fork we need to create the zmq router device
'''
if 'aes' not in salt.master.SMaster.secrets:
# TODO: This is still needed only for the unit tests
# 'tcp_test.py' and 'zeromq_test.py'. Fix that. In normal
# cases, 'aes' i... | python | def pre_fork(self, _):
'''
Pre-fork we need to create the zmq router device
'''
if 'aes' not in salt.master.SMaster.secrets:
# TODO: This is still needed only for the unit tests
# 'tcp_test.py' and 'zeromq_test.py'. Fix that. In normal
# cases, 'aes' i... | [
"def",
"pre_fork",
"(",
"self",
",",
"_",
")",
":",
"if",
"'aes'",
"not",
"in",
"salt",
".",
"master",
".",
"SMaster",
".",
"secrets",
":",
"# TODO: This is still needed only for the unit tests",
"# 'tcp_test.py' and 'zeromq_test.py'. Fix that. In normal",
"# cases, 'aes'... | Pre-fork we need to create the zmq router device | [
"Pre",
"-",
"fork",
"we",
"need",
"to",
"create",
"the",
"zmq",
"router",
"device"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/transport/mixins/auth.py#L75-L89 | train |
saltstack/salt | salt/transport/mixins/auth.py | AESReqServerMixin._encrypt_private | def _encrypt_private(self, ret, dictkey, target):
'''
The server equivalent of ReqChannel.crypted_transfer_decode_dictentry
'''
# encrypt with a specific AES key
pubfn = os.path.join(self.opts['pki_dir'],
'minions',
target... | python | def _encrypt_private(self, ret, dictkey, target):
'''
The server equivalent of ReqChannel.crypted_transfer_decode_dictentry
'''
# encrypt with a specific AES key
pubfn = os.path.join(self.opts['pki_dir'],
'minions',
target... | [
"def",
"_encrypt_private",
"(",
"self",
",",
"ret",
",",
"dictkey",
",",
"target",
")",
":",
"# encrypt with a specific AES key",
"pubfn",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"opts",
"[",
"'pki_dir'",
"]",
",",
"'minions'",
",",
"target"... | The server equivalent of ReqChannel.crypted_transfer_decode_dictentry | [
"The",
"server",
"equivalent",
"of",
"ReqChannel",
".",
"crypted_transfer_decode_dictentry"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/transport/mixins/auth.py#L110-L141 | train |
saltstack/salt | salt/transport/mixins/auth.py | AESReqServerMixin._update_aes | def _update_aes(self):
'''
Check to see if a fresh AES key is available and update the components
of the worker
'''
if salt.master.SMaster.secrets['aes']['secret'].value != self.crypticle.key_string:
self.crypticle = salt.crypt.Crypticle(self.opts, salt.master.SMaster... | python | def _update_aes(self):
'''
Check to see if a fresh AES key is available and update the components
of the worker
'''
if salt.master.SMaster.secrets['aes']['secret'].value != self.crypticle.key_string:
self.crypticle = salt.crypt.Crypticle(self.opts, salt.master.SMaster... | [
"def",
"_update_aes",
"(",
"self",
")",
":",
"if",
"salt",
".",
"master",
".",
"SMaster",
".",
"secrets",
"[",
"'aes'",
"]",
"[",
"'secret'",
"]",
".",
"value",
"!=",
"self",
".",
"crypticle",
".",
"key_string",
":",
"self",
".",
"crypticle",
"=",
"s... | Check to see if a fresh AES key is available and update the components
of the worker | [
"Check",
"to",
"see",
"if",
"a",
"fresh",
"AES",
"key",
"is",
"available",
"and",
"update",
"the",
"components",
"of",
"the",
"worker"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/transport/mixins/auth.py#L143-L151 | train |
saltstack/salt | salt/transport/mixins/auth.py | AESReqServerMixin._auth | def _auth(self, load):
'''
Authenticate the client, use the sent public key to encrypt the AES key
which was generated at start up.
This method fires an event over the master event manager. The event is
tagged "auth" and returns a dict with information about the auth
eve... | python | def _auth(self, load):
'''
Authenticate the client, use the sent public key to encrypt the AES key
which was generated at start up.
This method fires an event over the master event manager. The event is
tagged "auth" and returns a dict with information about the auth
eve... | [
"def",
"_auth",
"(",
"self",
",",
"load",
")",
":",
"if",
"not",
"salt",
".",
"utils",
".",
"verify",
".",
"valid_id",
"(",
"self",
".",
"opts",
",",
"load",
"[",
"'id'",
"]",
")",
":",
"log",
".",
"info",
"(",
"'Authentication request from invalid id ... | Authenticate the client, use the sent public key to encrypt the AES key
which was generated at start up.
This method fires an event over the master event manager. The event is
tagged "auth" and returns a dict with information about the auth
event
# Verify that the key we are re... | [
"Authenticate",
"the",
"client",
"use",
"the",
"sent",
"public",
"key",
"to",
"encrypt",
"the",
"AES",
"key",
"which",
"was",
"generated",
"at",
"start",
"up",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/transport/mixins/auth.py#L164-L520 | train |
saltstack/salt | salt/utils/decorators/path.py | which | def which(exe):
'''
Decorator wrapper for salt.utils.path.which
'''
def wrapper(function):
def wrapped(*args, **kwargs):
if salt.utils.path.which(exe) is None:
raise CommandNotFoundError(
'The \'{0}\' binary was not found in $PATH.'.format(exe)
... | python | def which(exe):
'''
Decorator wrapper for salt.utils.path.which
'''
def wrapper(function):
def wrapped(*args, **kwargs):
if salt.utils.path.which(exe) is None:
raise CommandNotFoundError(
'The \'{0}\' binary was not found in $PATH.'.format(exe)
... | [
"def",
"which",
"(",
"exe",
")",
":",
"def",
"wrapper",
"(",
"function",
")",
":",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"salt",
".",
"utils",
".",
"path",
".",
"which",
"(",
"exe",
")",
"is",
"None",
":",... | Decorator wrapper for salt.utils.path.which | [
"Decorator",
"wrapper",
"for",
"salt",
".",
"utils",
".",
"path",
".",
"which"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/utils/decorators/path.py#L13-L25 | train |
saltstack/salt | salt/utils/decorators/path.py | which_bin | def which_bin(exes):
'''
Decorator wrapper for salt.utils.path.which_bin
'''
def wrapper(function):
def wrapped(*args, **kwargs):
if salt.utils.path.which_bin(exes) is None:
raise CommandNotFoundError(
'None of provided binaries({0}) was not found ... | python | def which_bin(exes):
'''
Decorator wrapper for salt.utils.path.which_bin
'''
def wrapper(function):
def wrapped(*args, **kwargs):
if salt.utils.path.which_bin(exes) is None:
raise CommandNotFoundError(
'None of provided binaries({0}) was not found ... | [
"def",
"which_bin",
"(",
"exes",
")",
":",
"def",
"wrapper",
"(",
"function",
")",
":",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"salt",
".",
"utils",
".",
"path",
".",
"which_bin",
"(",
"exes",
")",
"is",
"Non... | Decorator wrapper for salt.utils.path.which_bin | [
"Decorator",
"wrapper",
"for",
"salt",
".",
"utils",
".",
"path",
".",
"which_bin"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/utils/decorators/path.py#L28-L43 | train |
saltstack/salt | salt/runners/doc.py | runner | def runner():
'''
Return all inline documentation for runner modules
CLI Example:
.. code-block:: bash
salt-run doc.runner
'''
client = salt.runner.RunnerClient(__opts__)
ret = client.get_docs()
return ret | python | def runner():
'''
Return all inline documentation for runner modules
CLI Example:
.. code-block:: bash
salt-run doc.runner
'''
client = salt.runner.RunnerClient(__opts__)
ret = client.get_docs()
return ret | [
"def",
"runner",
"(",
")",
":",
"client",
"=",
"salt",
".",
"runner",
".",
"RunnerClient",
"(",
"__opts__",
")",
"ret",
"=",
"client",
".",
"get_docs",
"(",
")",
"return",
"ret"
] | Return all inline documentation for runner modules
CLI Example:
.. code-block:: bash
salt-run doc.runner | [
"Return",
"all",
"inline",
"documentation",
"for",
"runner",
"modules"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/runners/doc.py#L27-L39 | train |
saltstack/salt | salt/runners/doc.py | wheel | def wheel():
'''
Return all inline documentation for wheel modules
CLI Example:
.. code-block:: bash
salt-run doc.wheel
'''
client = salt.wheel.Wheel(__opts__)
ret = client.get_docs()
return ret | python | def wheel():
'''
Return all inline documentation for wheel modules
CLI Example:
.. code-block:: bash
salt-run doc.wheel
'''
client = salt.wheel.Wheel(__opts__)
ret = client.get_docs()
return ret | [
"def",
"wheel",
"(",
")",
":",
"client",
"=",
"salt",
".",
"wheel",
".",
"Wheel",
"(",
"__opts__",
")",
"ret",
"=",
"client",
".",
"get_docs",
"(",
")",
"return",
"ret"
] | Return all inline documentation for wheel modules
CLI Example:
.. code-block:: bash
salt-run doc.wheel | [
"Return",
"all",
"inline",
"documentation",
"for",
"wheel",
"modules"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/runners/doc.py#L42-L54 | train |
saltstack/salt | salt/runners/doc.py | execution | def execution():
'''
Collect all the sys.doc output from each minion and return the aggregate
CLI Example:
.. code-block:: bash
salt-run doc.execution
'''
client = salt.client.get_local_client(__opts__['conf_file'])
docs = {}
try:
for ret in client.cmd_iter('*', 'sys.... | python | def execution():
'''
Collect all the sys.doc output from each minion and return the aggregate
CLI Example:
.. code-block:: bash
salt-run doc.execution
'''
client = salt.client.get_local_client(__opts__['conf_file'])
docs = {}
try:
for ret in client.cmd_iter('*', 'sys.... | [
"def",
"execution",
"(",
")",
":",
"client",
"=",
"salt",
".",
"client",
".",
"get_local_client",
"(",
"__opts__",
"[",
"'conf_file'",
"]",
")",
"docs",
"=",
"{",
"}",
"try",
":",
"for",
"ret",
"in",
"client",
".",
"cmd_iter",
"(",
"'*'",
",",
"'sys.... | Collect all the sys.doc output from each minion and return the aggregate
CLI Example:
.. code-block:: bash
salt-run doc.execution | [
"Collect",
"all",
"the",
"sys",
".",
"doc",
"output",
"from",
"each",
"minion",
"and",
"return",
"the",
"aggregate"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/runners/doc.py#L57-L81 | train |
saltstack/salt | salt/modules/temp.py | file | def file(suffix='', prefix='tmp', parent=None):
'''
Create a temporary file
CLI Example:
.. code-block:: bash
salt '*' temp.file
salt '*' temp.file prefix='mytemp-' parent='/var/run/'
'''
fh_, tmp_ = tempfile.mkstemp(suffix, prefix, parent)
os.close(fh_)
return tmp_ | python | def file(suffix='', prefix='tmp', parent=None):
'''
Create a temporary file
CLI Example:
.. code-block:: bash
salt '*' temp.file
salt '*' temp.file prefix='mytemp-' parent='/var/run/'
'''
fh_, tmp_ = tempfile.mkstemp(suffix, prefix, parent)
os.close(fh_)
return tmp_ | [
"def",
"file",
"(",
"suffix",
"=",
"''",
",",
"prefix",
"=",
"'tmp'",
",",
"parent",
"=",
"None",
")",
":",
"fh_",
",",
"tmp_",
"=",
"tempfile",
".",
"mkstemp",
"(",
"suffix",
",",
"prefix",
",",
"parent",
")",
"os",
".",
"close",
"(",
"fh_",
")"... | Create a temporary file
CLI Example:
.. code-block:: bash
salt '*' temp.file
salt '*' temp.file prefix='mytemp-' parent='/var/run/' | [
"Create",
"a",
"temporary",
"file"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/temp.py#L33-L46 | train |
saltstack/salt | salt/runner.py | RunnerClient._reformat_low | def _reformat_low(self, low):
'''
Format the low data for RunnerClient()'s master_call() function
This also normalizes the following low data formats to a single, common
low data structure.
Old-style low: ``{'fun': 'jobs.lookup_jid', 'jid': '1234'}``
New-style: ``{'fun'... | python | def _reformat_low(self, low):
'''
Format the low data for RunnerClient()'s master_call() function
This also normalizes the following low data formats to a single, common
low data structure.
Old-style low: ``{'fun': 'jobs.lookup_jid', 'jid': '1234'}``
New-style: ``{'fun'... | [
"def",
"_reformat_low",
"(",
"self",
",",
"low",
")",
":",
"fun",
"=",
"low",
".",
"pop",
"(",
"'fun'",
")",
"verify_fun",
"(",
"self",
".",
"functions",
",",
"fun",
")",
"eauth_creds",
"=",
"dict",
"(",
"[",
"(",
"i",
",",
"low",
".",
"pop",
"("... | Format the low data for RunnerClient()'s master_call() function
This also normalizes the following low data formats to a single, common
low data structure.
Old-style low: ``{'fun': 'jobs.lookup_jid', 'jid': '1234'}``
New-style: ``{'fun': 'jobs.lookup_jid', 'kwarg': {'jid': '1234'}}``
... | [
"Format",
"the",
"low",
"data",
"for",
"RunnerClient",
"()",
"s",
"master_call",
"()",
"function"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/runner.py#L66-L107 | train |
saltstack/salt | salt/runner.py | RunnerClient.cmd_async | def cmd_async(self, low):
'''
Execute a runner function asynchronously; eauth is respected
This function requires that :conf_master:`external_auth` is configured
and the user is authorized to execute runner functions: (``@runner``).
.. code-block:: python
runner.ea... | python | def cmd_async(self, low):
'''
Execute a runner function asynchronously; eauth is respected
This function requires that :conf_master:`external_auth` is configured
and the user is authorized to execute runner functions: (``@runner``).
.. code-block:: python
runner.ea... | [
"def",
"cmd_async",
"(",
"self",
",",
"low",
")",
":",
"reformatted_low",
"=",
"self",
".",
"_reformat_low",
"(",
"low",
")",
"return",
"mixins",
".",
"AsyncClientMixin",
".",
"cmd_async",
"(",
"self",
",",
"reformatted_low",
")"
] | Execute a runner function asynchronously; eauth is respected
This function requires that :conf_master:`external_auth` is configured
and the user is authorized to execute runner functions: (``@runner``).
.. code-block:: python
runner.eauth_async({
'fun': 'jobs.list_... | [
"Execute",
"a",
"runner",
"function",
"asynchronously",
";",
"eauth",
"is",
"respected"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/runner.py#L109-L127 | train |
saltstack/salt | salt/runner.py | RunnerClient.cmd_sync | def cmd_sync(self, low, timeout=None, full_return=False):
'''
Execute a runner function synchronously; eauth is respected
This function requires that :conf_master:`external_auth` is configured
and the user is authorized to execute runner functions: (``@runner``).
.. code-block:... | python | def cmd_sync(self, low, timeout=None, full_return=False):
'''
Execute a runner function synchronously; eauth is respected
This function requires that :conf_master:`external_auth` is configured
and the user is authorized to execute runner functions: (``@runner``).
.. code-block:... | [
"def",
"cmd_sync",
"(",
"self",
",",
"low",
",",
"timeout",
"=",
"None",
",",
"full_return",
"=",
"False",
")",
":",
"reformatted_low",
"=",
"self",
".",
"_reformat_low",
"(",
"low",
")",
"return",
"mixins",
".",
"SyncClientMixin",
".",
"cmd_sync",
"(",
... | Execute a runner function synchronously; eauth is respected
This function requires that :conf_master:`external_auth` is configured
and the user is authorized to execute runner functions: (``@runner``).
.. code-block:: python
runner.eauth_sync({
'fun': 'jobs.list_jo... | [
"Execute",
"a",
"runner",
"function",
"synchronously",
";",
"eauth",
"is",
"respected"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/runner.py#L129-L146 | train |
saltstack/salt | salt/runner.py | Runner.print_docs | def print_docs(self):
'''
Print out the documentation!
'''
arg = self.opts.get('fun', None)
docs = super(Runner, self).get_docs(arg)
for fun in sorted(docs):
display_output('{0}:'.format(fun), 'text', self.opts)
print(docs[fun]) | python | def print_docs(self):
'''
Print out the documentation!
'''
arg = self.opts.get('fun', None)
docs = super(Runner, self).get_docs(arg)
for fun in sorted(docs):
display_output('{0}:'.format(fun), 'text', self.opts)
print(docs[fun]) | [
"def",
"print_docs",
"(",
"self",
")",
":",
"arg",
"=",
"self",
".",
"opts",
".",
"get",
"(",
"'fun'",
",",
"None",
")",
"docs",
"=",
"super",
"(",
"Runner",
",",
"self",
")",
".",
"get_docs",
"(",
"arg",
")",
"for",
"fun",
"in",
"sorted",
"(",
... | Print out the documentation! | [
"Print",
"out",
"the",
"documentation!"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/runner.py#L169-L177 | train |
saltstack/salt | salt/runner.py | Runner.run | def run(self):
'''
Execute the runner sequence
'''
# Print documentation only
if self.opts.get('doc', False):
self.print_docs()
else:
return self._run_runner() | python | def run(self):
'''
Execute the runner sequence
'''
# Print documentation only
if self.opts.get('doc', False):
self.print_docs()
else:
return self._run_runner() | [
"def",
"run",
"(",
"self",
")",
":",
"# Print documentation only",
"if",
"self",
".",
"opts",
".",
"get",
"(",
"'doc'",
",",
"False",
")",
":",
"self",
".",
"print_docs",
"(",
")",
"else",
":",
"return",
"self",
".",
"_run_runner",
"(",
")"
] | Execute the runner sequence | [
"Execute",
"the",
"runner",
"sequence"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/runner.py#L180-L188 | train |
saltstack/salt | salt/runner.py | Runner._run_runner | def _run_runner(self):
'''
Actually execute specific runner
:return:
'''
import salt.minion
ret = {}
low = {'fun': self.opts['fun']}
try:
# Allocate a jid
async_pub = self._gen_async_pub()
self.jid = async_pub['jid']
... | python | def _run_runner(self):
'''
Actually execute specific runner
:return:
'''
import salt.minion
ret = {}
low = {'fun': self.opts['fun']}
try:
# Allocate a jid
async_pub = self._gen_async_pub()
self.jid = async_pub['jid']
... | [
"def",
"_run_runner",
"(",
"self",
")",
":",
"import",
"salt",
".",
"minion",
"ret",
"=",
"{",
"}",
"low",
"=",
"{",
"'fun'",
":",
"self",
".",
"opts",
"[",
"'fun'",
"]",
"}",
"try",
":",
"# Allocate a jid",
"async_pub",
"=",
"self",
".",
"_gen_async... | Actually execute specific runner
:return: | [
"Actually",
"execute",
"specific",
"runner",
":",
"return",
":"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/runner.py#L190-L312 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.