本文整理汇总了Python中salt.modules.file.replace函数的典型用法代码示例。如果您正苦于以下问题:Python replace函数的具体用法?Python replace怎么用?Python replace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了replace函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_nobackup
def test_nobackup(self):
fext = '.bak'
bak_file = '{0}{1}'.format(self.tfile.name, fext)
filemod.replace(self.tfile.name, r'Etiam', 'Salticus', backup=False)
self.assertFalse(os.path.exists(bak_file))
开发者ID:HowardMei,项目名称:saltstack,代码行数:7,代码来源:file_test.py
示例2: test_backup
def test_backup(self):
fext = '.bak'
bak_file = '{0}{1}'.format(self.tfile.name, fext)
filemod.replace(self.tfile.name, r'Etiam', 'Salticus', backup=fext)
self.assertTrue(os.path.exists(bak_file))
os.unlink(bak_file)
开发者ID:HowardMei,项目名称:saltstack,代码行数:8,代码来源:file_test.py
示例3: test_numeric_repl
def test_numeric_repl(self):
'''
This test covers cases where the replacement string is numeric, and the
CLI parser yamlifies it into a numeric type. If not converted back to a
string type in file.replace, a TypeError occurs when the replacemen is
attempted. See https://github.com/saltstack/salt/issues/9097 for more
information.
'''
filemod.replace(self.tfile.name, r'Etiam', 123)
开发者ID:HowardMei,项目名称:saltstack,代码行数:9,代码来源:file_test.py
示例4: test_replace_append_if_not_found
def test_replace_append_if_not_found(self):
'''
Check that file.replace append_if_not_found works
'''
args = {
'pattern': '#*baz=(?P<value>.*)',
'repl': 'baz=\\g<value>',
'append_if_not_found': True,
}
base = 'foo=1\nbar=2'
expected = '{base}\n{repl}\n'.format(base=base, **args)
# File ending with a newline, no match
with tempfile.NamedTemporaryFile(mode='w+') as tfile:
tfile.write(base + '\n')
tfile.flush()
filemod.replace(tfile.name, **args)
with salt.utils.fopen(tfile.name) as tfile2:
self.assertEqual(tfile2.read(), expected)
# File not ending with a newline, no match
with tempfile.NamedTemporaryFile('w+') as tfile:
tfile.write(base)
tfile.flush()
filemod.replace(tfile.name, **args)
with salt.utils.fopen(tfile.name) as tfile2:
self.assertEqual(tfile2.read(), expected)
# A newline should not be added in empty files
with tempfile.NamedTemporaryFile('w+') as tfile:
filemod.replace(tfile.name, **args)
with salt.utils.fopen(tfile.name) as tfile2:
self.assertEqual(tfile2.read(), args['repl'] + '\n')
# Using not_found_content, rather than repl
with tempfile.NamedTemporaryFile('w+') as tfile:
args['not_found_content'] = 'baz=3'
expected = '{base}\n{not_found_content}\n'.format(base=base, **args)
tfile.write(base)
tfile.flush()
filemod.replace(tfile.name, **args)
with salt.utils.fopen(tfile.name) as tfile2:
self.assertEqual(tfile2.read(), expected)
# not appending if matches
with tempfile.NamedTemporaryFile('w+') as tfile:
base = 'foo=1\n#baz=42\nbar=2\n'
expected = 'foo=1\nbaz=42\nbar=2\n'
tfile.write(base)
tfile.flush()
filemod.replace(tfile.name, **args)
with salt.utils.fopen(tfile.name) as tfile2:
self.assertEqual(tfile2.read(), expected)
开发者ID:HowardMei,项目名称:saltstack,代码行数:48,代码来源:file_test.py
示例5: test_replace
def test_replace(self):
filemod.replace(self.tfile.name, r'Etiam', 'Salticus', backup=False)
with salt.utils.fopen(self.tfile.name, 'r') as fp:
self.assertIn('Salticus', fp.read())
开发者ID:HowardMei,项目名称:saltstack,代码行数:5,代码来源:file_test.py
示例6: test_re_int_flags
def test_re_int_flags(self):
filemod.replace(self.tfile.name, r'Etiam', 'Salticus', flags=10)
开发者ID:HowardMei,项目名称:saltstack,代码行数:2,代码来源:file_test.py
示例7: test_re_str_flags
def test_re_str_flags(self):
# upper- & lower-case
filemod.replace(self.tfile.name,
r'Etiam', 'Salticus',
flags=['MULTILINE', 'ignorecase'])
开发者ID:HowardMei,项目名称:saltstack,代码行数:5,代码来源:file_test.py
示例8: test_noshow_changes
def test_noshow_changes(self):
ret = filemod.replace(self.tfile.name,
r'Etiam', 'Salticus',
show_changes=False)
self.assertIsInstance(ret, bool)
开发者ID:HowardMei,项目名称:saltstack,代码行数:6,代码来源:file_test.py
示例9: test_show_changes
def test_show_changes(self):
ret = filemod.replace(self.tfile.name,
r'Etiam', 'Salticus',
show_changes=True)
self.assertTrue(ret.startswith('---')) # looks like a diff
开发者ID:HowardMei,项目名称:saltstack,代码行数:6,代码来源:file_test.py
示例10: test_dry_run
def test_dry_run(self):
before_ctime = os.stat(self.tfile.name).st_mtime
filemod.replace(self.tfile.name, r'Etiam', 'Salticus', dry_run=True)
after_ctime = os.stat(self.tfile.name).st_mtime
self.assertEqual(before_ctime, after_ctime)
开发者ID:HowardMei,项目名称:saltstack,代码行数:6,代码来源:file_test.py
注:本文中的salt.modules.file.replace函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论