mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Fix invalid string escape sequences.
This commit is contained in:
@@ -144,20 +144,20 @@ def parse_lv(data):
|
||||
name = None
|
||||
|
||||
for line in data.splitlines():
|
||||
match = re.search("LOGICAL VOLUME:\s+(\w+)\s+VOLUME GROUP:\s+(\w+)", line)
|
||||
match = re.search(r"LOGICAL VOLUME:\s+(\w+)\s+VOLUME GROUP:\s+(\w+)", line)
|
||||
if match is not None:
|
||||
name = match.group(1)
|
||||
vg = match.group(2)
|
||||
continue
|
||||
match = re.search("LPs:\s+(\d+).*PPs", line)
|
||||
match = re.search(r"LPs:\s+(\d+).*PPs", line)
|
||||
if match is not None:
|
||||
lps = int(match.group(1))
|
||||
continue
|
||||
match = re.search("PP SIZE:\s+(\d+)", line)
|
||||
match = re.search(r"PP SIZE:\s+(\d+)", line)
|
||||
if match is not None:
|
||||
pp_size = int(match.group(1))
|
||||
continue
|
||||
match = re.search("INTER-POLICY:\s+(\w+)", line)
|
||||
match = re.search(r"INTER-POLICY:\s+(\w+)", line)
|
||||
if match is not None:
|
||||
policy = match.group(1)
|
||||
continue
|
||||
@@ -174,22 +174,22 @@ def parse_vg(data):
|
||||
|
||||
for line in data.splitlines():
|
||||
|
||||
match = re.search("VOLUME GROUP:\s+(\w+)", line)
|
||||
match = re.search(r"VOLUME GROUP:\s+(\w+)", line)
|
||||
if match is not None:
|
||||
name = match.group(1)
|
||||
continue
|
||||
|
||||
match = re.search("TOTAL PP.*\((\d+)", line)
|
||||
match = re.search(r"TOTAL PP.*\((\d+)", line)
|
||||
if match is not None:
|
||||
size = int(match.group(1))
|
||||
continue
|
||||
|
||||
match = re.search("PP SIZE:\s+(\d+)", line)
|
||||
match = re.search(r"PP SIZE:\s+(\d+)", line)
|
||||
if match is not None:
|
||||
pp_size = int(match.group(1))
|
||||
continue
|
||||
|
||||
match = re.search("FREE PP.*\((\d+)", line)
|
||||
match = re.search(r"FREE PP.*\((\d+)", line)
|
||||
if match is not None:
|
||||
free = int(match.group(1))
|
||||
continue
|
||||
|
||||
@@ -404,7 +404,7 @@ def parsekey(module, raw_key, rank=None):
|
||||
type_index = None # index of keytype in key string|list
|
||||
|
||||
# remove comment yaml escapes
|
||||
raw_key = raw_key.replace('\#', '#')
|
||||
raw_key = raw_key.replace(r'\#', '#')
|
||||
|
||||
# split key safely
|
||||
lex = shlex.shlex(raw_key)
|
||||
|
||||
@@ -74,7 +74,7 @@ def activate(module):
|
||||
def is_policy_enabled(module, name):
|
||||
cmd = "%s list" % (AWALL_PATH)
|
||||
rc, stdout, stderr = module.run_command(cmd)
|
||||
if re.search("^%s\s+enabled" % name, stdout, re.MULTILINE):
|
||||
if re.search(r"^%s\s+enabled" % name, stdout, re.MULTILINE):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@@ -261,7 +261,7 @@ def get_quotas(name, nofail):
|
||||
out = run_gluster(['volume', 'quota', name, 'list'])
|
||||
for row in out.split('\n'):
|
||||
if row[:1] == '/':
|
||||
q = re.split('\s+', row)
|
||||
q = re.split(r'\s+', row)
|
||||
quotas[q[0]] = q[1]
|
||||
return quotas
|
||||
|
||||
|
||||
@@ -161,14 +161,14 @@ def optionDict(line, iface, option, value):
|
||||
|
||||
|
||||
def getValueFromLine(s):
|
||||
spaceRe = re.compile('\s+')
|
||||
spaceRe = re.compile(r'\s+')
|
||||
for m in spaceRe.finditer(s):
|
||||
pass
|
||||
valueEnd = m.start()
|
||||
option = s.split()[0]
|
||||
optionStart = s.find(option)
|
||||
optionLen = len(option)
|
||||
valueStart = re.search('\s', s[optionLen + optionStart:]).end() + optionLen + optionStart
|
||||
valueStart = re.search(r'\s', s[optionLen + optionStart:]).end() + optionLen + optionStart
|
||||
return s[valueStart:valueEnd]
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ def setInterfaceOption(module, lines, iface, option, raw_value, state):
|
||||
old_value = target_option['value']
|
||||
prefix_start = old_line.find(option)
|
||||
optionLen = len(option)
|
||||
old_value_position = re.search("\s+".join(old_value.split()), old_line[prefix_start + optionLen:])
|
||||
old_value_position = re.search(r"\s+".join(old_value.split()), old_line[prefix_start + optionLen:])
|
||||
start = old_value_position.start() + prefix_start + optionLen
|
||||
end = old_value_position.end() + prefix_start + optionLen
|
||||
line = old_line[:start] + value + old_line[end:]
|
||||
|
||||
@@ -66,7 +66,7 @@ class Blacklist(object):
|
||||
return False
|
||||
|
||||
def get_pattern(self):
|
||||
return '^blacklist\s*' + self.module + '$'
|
||||
return r'^blacklist\s*' + self.module + '$'
|
||||
|
||||
def readlines(self):
|
||||
f = open(self.filename, 'r')
|
||||
|
||||
@@ -70,10 +70,10 @@ def is_available(name, ubuntuMode):
|
||||
* if the locale is present in /etc/locales.gen
|
||||
* or if the locale is present in /usr/share/i18n/SUPPORTED"""
|
||||
if ubuntuMode:
|
||||
__regexp = '^(?P<locale>\S+_\S+) (?P<charset>\S+)\s*$'
|
||||
__regexp = r'^(?P<locale>\S+_\S+) (?P<charset>\S+)\s*$'
|
||||
__locales_available = '/usr/share/i18n/SUPPORTED'
|
||||
else:
|
||||
__regexp = '^#{0,1}\s*(?P<locale>\S+_\S+) (?P<charset>\S+)\s*$'
|
||||
__regexp = r'^#{0,1}\s*(?P<locale>\S+_\S+) (?P<charset>\S+)\s*$'
|
||||
__locales_available = '/etc/locale.gen'
|
||||
|
||||
re_compiled = re.compile(__regexp)
|
||||
@@ -117,11 +117,11 @@ def replace_line(existing_line, new_line):
|
||||
|
||||
def set_locale(name, enabled=True):
|
||||
""" Sets the state of the locale. Defaults to enabled. """
|
||||
search_string = '#{0,1}\s*%s (?P<charset>.+)' % name
|
||||
search_string = r'#{0,1}\s*%s (?P<charset>.+)' % name
|
||||
if enabled:
|
||||
new_string = '%s \g<charset>' % (name)
|
||||
new_string = r'%s \g<charset>' % (name)
|
||||
else:
|
||||
new_string = '# %s \g<charset>' % (name)
|
||||
new_string = r'# %s \g<charset>' % (name)
|
||||
try:
|
||||
f = open("/etc/locale.gen", "r")
|
||||
lines = [re.sub(search_string, new_string, line) for line in f]
|
||||
|
||||
@@ -226,7 +226,7 @@ def get_lvm_version(module):
|
||||
rc, out, err = module.run_command("%s version" % (ver_cmd))
|
||||
if rc != 0:
|
||||
return None
|
||||
m = re.search("LVM version:\s+(\d+)\.(\d+)\.(\d+).*(\d{4}-\d{2}-\d{2})", out)
|
||||
m = re.search(r"LVM version:\s+(\d+)\.(\d+)\.(\d+).*(\d{4}-\d{2}-\d{2})", out)
|
||||
if not m:
|
||||
return None
|
||||
return mkversion(m.group(1), m.group(2), m.group(3))
|
||||
|
||||
@@ -169,11 +169,11 @@ class Sv(object):
|
||||
else:
|
||||
self.full_state = out
|
||||
|
||||
m = re.search('\(pid (\d+)\)', out)
|
||||
m = re.search(r'\(pid (\d+)\)', out)
|
||||
if m:
|
||||
self.pid = m.group(1)
|
||||
|
||||
m = re.search(' (\d+)s', out)
|
||||
m = re.search(r' (\d+)s', out)
|
||||
if m:
|
||||
self.duration = m.group(1)
|
||||
|
||||
|
||||
@@ -672,10 +672,10 @@ class LinuxService(Service):
|
||||
|
||||
initpath = '/etc/init'
|
||||
if self.upstart_version >= LooseVersion('0.6.7'):
|
||||
manreg = re.compile('^manual\s*$', re.M | re.I)
|
||||
manreg = re.compile(r'^manual\s*$', re.M | re.I)
|
||||
config_line = 'manual\n'
|
||||
else:
|
||||
manreg = re.compile('^start on manual\s*$', re.M | re.I)
|
||||
manreg = re.compile(r'^start on manual\s*$', re.M | re.I)
|
||||
config_line = 'start on manual\n'
|
||||
conf_file_name = "%s/%s.conf" % (initpath, self.name)
|
||||
override_file_name = "%s/%s.override" % (initpath, self.name)
|
||||
@@ -1308,7 +1308,7 @@ class SunOSService(Service):
|
||||
# Support for synchronous restart/refresh is only supported on
|
||||
# Oracle Solaris >= 11.2
|
||||
for line in open('/etc/release', 'r').readlines():
|
||||
m = re.match('\s+Oracle Solaris (\d+\.\d+).*', line.rstrip())
|
||||
m = re.match(r'\s+Oracle Solaris (\d+\.\d+).*', line.rstrip())
|
||||
if m and m.groups()[0] >= 11.2:
|
||||
return True
|
||||
|
||||
|
||||
@@ -180,11 +180,11 @@ class Svc(object):
|
||||
else:
|
||||
self.full_state = out
|
||||
|
||||
m = re.search('\(pid (\d+)\)', out)
|
||||
m = re.search(r'\(pid (\d+)\)', out)
|
||||
if m:
|
||||
self.pid = m.group(1)
|
||||
|
||||
m = re.search('(\d+) seconds', out)
|
||||
m = re.search(r'(\d+) seconds', out)
|
||||
if m:
|
||||
self.duration = m.group(1)
|
||||
|
||||
|
||||
@@ -517,7 +517,7 @@ class SmartOSTimezone(Timezone):
|
||||
|
||||
# sm-set-timezone knows no state and will always set the timezone.
|
||||
# XXX: https://github.com/joyent/smtools/pull/2
|
||||
m = re.match('^\* Changed (to)? timezone (to)? (%s).*' % value, stdout.splitlines()[1])
|
||||
m = re.match(r'^\* Changed (to)? timezone (to)? (%s).*' % value, stdout.splitlines()[1])
|
||||
if not (m and m.groups()[-1] == value):
|
||||
self.module.fail_json(msg='Failed to set timezone')
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user