flake8: resolve W605 'invalid escape sequence' warnings

This patch scares me since every fix involves adding a character
to a regex.  I am /pretty sure/ that this is a no-op but I don't
have the capacity to test this beyond what tox can do.
This commit is contained in:
Andrew Bogott 2019-03-05 19:01:05 +00:00
parent bfe2d1f3ba
commit b9dda552db
10 changed files with 18 additions and 18 deletions

View file

@ -69,9 +69,9 @@ class AbstractPartitionMap(FSMProxy):
# Ask kpartx how the partitions will be mapped before actually attaching them.
mappings = log_check_call(['kpartx', '-l', volume.device_path])
import re
regexp = re.compile('^(?P<name>.+[^\d](?P<p_idx>\d+)) : '
'(?P<start_blk>\d) (?P<num_blks>\d+) '
'{device_path} (?P<blk_offset>\d+)$'
regexp = re.compile('^(?P<name>.+[^\\d](?P<p_idx>\\d+)) : '
'(?P<start_blk>\\d) (?P<num_blks>\\d+) '
'{device_path} (?P<blk_offset>\\d+)$'
.format(device_path=volume.device_path))
log_check_call(['kpartx', '-as', volume.device_path])

View file

@ -56,11 +56,11 @@ class Source(object):
# The format is taken from `man sources.list`
# or: http://manpages.debian.org/cgi-bin/man.cgi?sektion=5&query=sources.list&apropos=0&manpath=sid&locale=en
import re
regexp = re.compile('^(?P<type>deb|deb-src)\s+'
'(\[\s*(?P<options>.+\S)?\s*\]\s+)?'
'(?P<uri>\S+)\s+'
'(?P<distribution>\S+)'
'(\s+(?P<components>.+\S))?\s*$')
regexp = re.compile('^(?P<type>deb|deb-src)\\s+'
'(\\[\\s*(?P<options>.+\\S)?\\s*\\]\\s+)?'
'(?P<uri>\\S+)\\s+'
'(?P<distribution>\\S+)'
'(\\s+(?P<components>.+\\S))?\\s*$')
match = regexp.match(line).groupdict()
if match is None:
from .exceptions import SourceError

View file

@ -29,7 +29,7 @@ class Bytes(object):
@staticmethod
def parse(qty_str):
import re
regex = re.compile('^(?P<qty>\d+)(?P<unit>[KMGT]i?B|B)$')
regex = re.compile('^(?P<qty>\\d+)(?P<unit>[KMGT]i?B|B)$')
parsed = regex.match(qty_str)
if parsed is None:
raise UnitError('Unable to parse ' + qty_str)

View file

@ -3,7 +3,7 @@ from contextlib import contextmanager
def get_partitions():
import re
regexp = re.compile('^ *(?P<major>\d+) *(?P<minor>\d+) *(?P<num_blks>\d+) (?P<dev_name>\S+)$')
regexp = re.compile('^ *(?P<major>\\d+) *(?P<minor>\\d+) *(?P<num_blks>\\d+) (?P<dev_name>\\S+)$')
matches = {}
path = '/proc/partitions'
with open(path) as partitions:

View file

@ -21,7 +21,7 @@ class CheckExternalCommands(Task):
log.debug('Checking availability of ' + command)
path = find_executable(command)
if path is None or not os.access(path, os.X_OK):
if re.match('^https?:\/\/', package):
if re.match('^https?:\\/\\/', package):
msg = ('The command `{command}\' is not available, '
'you can download the software at `{package}\'.'
.format(command=command, package=package))

View file

@ -51,8 +51,8 @@ class SetGroups(Task):
from bootstrapvz.common.tools import sed_i
cloud_cfg = os.path.join(info.root, 'etc/cloud/cloud.cfg')
groups = info.manifest.plugins['cloud_init']['groups']
search = ('^ groups: \[adm, audio, cdrom, dialout, floppy, video,'
' plugdev, dip\]$')
search = ('^ groups: \\[adm, audio, cdrom, dialout, floppy, video,'
' plugdev, dip\\]$')
replace = (' groups: [adm, audio, cdrom, dialout, floppy, video,'
' plugdev, dip, {groups}]').format(groups=', '.join(groups))
sed_i(cloud_cfg, search, replace)
@ -92,7 +92,7 @@ class DisableModules(Task):
if patterns != "":
patterns = patterns + "|" + pattern
else:
patterns = "^\s+-\s+(" + pattern
patterns = "^\\s+-\\s+(" + pattern
patterns = patterns + ")$"
regex = re.compile(patterns)

View file

@ -44,7 +44,7 @@ class CreateBootstrapFilterScripts(Task):
# The pattern matching when excluding is needed in order to filter
# everything below e.g. /usr/share/locale but not the folder itself
filter_lists = info._minimize_size['bootstrap_filter']
exclude_list = '\|'.join(map(lambda p: '.' + p + '.\+', filter_lists['exclude']))
exclude_list = '\\|'.join(map(lambda p: '.' + p + '.\\+', filter_lists['exclude']))
include_list = '\n'.join(map(lambda p: '.' + p, filter_lists['include']))
sed_i(filter_script, r'EXCLUDE_PATTERN', exclude_list)
sed_i(filter_script, r'INCLUDE_PATHS', include_list)

View file

@ -24,7 +24,7 @@ class SetNtpServers(Task):
import re
ntp_path = os.path.join(info.root, 'etc/ntp.conf')
servers = list(info.manifest.plugins['ntp']['servers'])
debian_ntp_server = re.compile('.*[0-9]\.debian\.pool\.ntp\.org.*')
debian_ntp_server = re.compile('.*[0-9]\\.debian\\.pool\\.ntp\\.org.*')
for line in fileinput.input(files=ntp_path, inplace=True):
# Will write all the specified servers on the first match, then supress all other default servers
if re.match(debian_ntp_server, line):

View file

@ -147,7 +147,7 @@ class ApplyPuppetManifest(Task):
log_check_call(['chroot', info.root, 'puppet', 'apply', '--verbose', '--debug', manifest_path])
os.remove(manifest_dst)
hosts_path = os.path.join(info.root, 'etc/hosts')
sed_i(hosts_path, '127.0.0.1\s*{hostname}\n?'.format(hostname=hostname), '')
sed_i(hosts_path, '127.0.0.1\\s*{hostname}\n?'.format(hostname=hostname), '')
class EnableAgent(Task):

View file

@ -53,7 +53,7 @@ class CreatePVGrubCustomRule(Task):
grub_device = 'GRUB_DEVICE=/dev/xvda' + str(root_idx)
sed_i(script_dst, '^GRUB_DEVICE=/dev/xvda$', grub_device)
grub_root = '\troot (hd0,{idx})'.format(idx=root_idx - 1)
sed_i(script_dst, '^\troot \(hd0\)$', grub_root)
sed_i(script_dst, r'^\troot \(hd0\)$', grub_root)
if info.manifest.volume['backing'] == 's3':
from bootstrapvz.common.tools import sed_i