Fix some regular expressions so that they pass lint checks with newer versions of pylint.
Signed-off-by: Michele Tartara <[email protected]> --- lib/backend.py | 2 +- lib/hypervisor/hv_base.py | 2 +- lib/hypervisor/hv_kvm.py | 2 +- lib/hypervisor/hv_xen.py | 2 +- lib/objects.py | 2 +- lib/ovf.py | 8 ++++---- lib/storage/bdev.py | 2 +- lib/utils/algo.py | 2 +- lib/utils/text.py | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/backend.py b/lib/backend.py index 466578c..6a38310 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -86,7 +86,7 @@ _IES_PID_FILE = "pid" _IES_CA_FILE = "ca" #: Valid LVS output line regex -_LVSLINE_REGEX = re.compile("^ *([^|]+)\|([^|]+)\|([0-9.]+)\|([^|]{6,})\|?$") +_LVSLINE_REGEX = re.compile(r"^ *([^|]+)\|([^|]+)\|([0-9.]+)\|([^|]{6,})\|?$") # Actions for the master setup script _MASTER_START = "start" diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py index bacb33f..38906fd 100644 --- a/lib/hypervisor/hv_base.py +++ b/lib/hypervisor/hv_base.py @@ -514,7 +514,7 @@ class BaseHypervisor(object): try: fh = open("/proc/cpuinfo") try: - cpu_total = len(re.findall("(?m)^processor\s*:\s*[0-9]+\s*$", + cpu_total = len(re.findall(r"(?m)^processor\s*:\s*[0-9]+\s*$", fh.read())) finally: fh.close() diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py index 14c5807..b4acee3 100644 --- a/lib/hypervisor/hv_kvm.py +++ b/lib/hypervisor/hv_kvm.py @@ -535,7 +535,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): _VIRTIO = "virtio" _VIRTIO_NET_PCI = "virtio-net-pci" - _MIGRATION_STATUS_RE = re.compile("Migration\s+status:\s+(\w+)", + _MIGRATION_STATUS_RE = re.compile(r"Migration\s+status:\s+(\w+)", re.M | re.I) _MIGRATION_PROGRESS_RE = \ re.compile(r"\s*transferred\s+ram:\s+(?P<transferred>\d+)\s+kbytes\s*\n" diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py index 7c07422..fa1cb0c 100644 --- a/lib/hypervisor/hv_xen.py +++ b/lib/hypervisor/hv_xen.py @@ -415,7 +415,7 @@ class XenHypervisor(hv_base.BaseHypervisor): if netinfo.mac_prefix: data.write("NETWORK_MAC_PREFIX=%s\n" % netinfo.mac_prefix) if netinfo.tags: - data.write("NETWORK_TAGS=%s\n" % "\ ".join(netinfo.tags)) + data.write("NETWORK_TAGS=%s\n" % r"\ ".join(netinfo.tags)) data.write("MAC=%s\n" % nic.mac) data.write("IP=%s\n" % nic.ip) diff --git a/lib/objects.py b/lib/objects.py index 0ca7363..758d5b3 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -281,7 +281,7 @@ class TaggableObject(ConfigObject): """ __slots__ = ["tags"] - VALID_TAG_RE = re.compile("^[\w.+*/:@-]+$") + VALID_TAG_RE = re.compile(r"^[\w.+*/:@-]+$") @classmethod def ValidateTag(cls, tag): diff --git a/lib/ovf.py b/lib/ovf.py index dc75816..be611d8 100644 --- a/lib/ovf.py +++ b/lib/ovf.py @@ -833,8 +833,8 @@ class OVFWriter(object): raw_string = ET.tostring(self.tree) parsed_xml = xml.dom.minidom.parseString(raw_string) xml_string = parsed_xml.toprettyxml(indent=" ") - text_re = re.compile(">\n\s+([^<>\s].*?)\n\s+</", re.DOTALL) - return text_re.sub(">\g<1></", xml_string) + text_re = re.compile(r">\n\s+([^<>\s].*?)\n\s+</", re.DOTALL) + return text_re.sub(r">\g<1></", xml_string) class Converter(object): @@ -1408,7 +1408,7 @@ class OVFImporter(Converter): _, disk_path = self._CompressDisk(disk_path, disk_compression, DECOMPRESS) disk, _ = os.path.splitext(disk) - if self._GetDiskQemuInfo(disk_path, "file format: (\S+)") != "raw": + if self._GetDiskQemuInfo(disk_path, r"file format: (\S+)") != "raw": logging.info("Conversion to raw format is required") ext, new_disk_path = self._ConvertDisk("raw", disk_path) @@ -1710,7 +1710,7 @@ class OVFExporter(Converter): ext, new_disk_path = self._ConvertDisk(self.options.disk_format, disk_path) results["format"] = self.options.disk_format results["virt-size"] = self._GetDiskQemuInfo( - new_disk_path, "virtual size: \S+ \((\d+) bytes\)") + new_disk_path, r"virtual size: \S+ \((\d+) bytes\)") if compression: ext2, new_disk_path = self._CompressDisk(new_disk_path, "gzip", COMPRESS) diff --git a/lib/storage/bdev.py b/lib/storage/bdev.py index 932bc98..0807333 100644 --- a/lib/storage/bdev.py +++ b/lib/storage/bdev.py @@ -63,7 +63,7 @@ class LogicalVolume(base.BlockDev): """ _VALID_NAME_RE = re.compile("^[a-zA-Z0-9+_.-]*$") - _PARSE_PV_DEV_RE = re.compile("^([^ ()]+)\([0-9]+\)$") + _PARSE_PV_DEV_RE = re.compile(r"^([^ ()]+)\([0-9]+\)$") _INVALID_NAMES = compat.UniqueFrozenset([".", "..", "snapshot", "pvmove"]) _INVALID_SUBSTRINGS = compat.UniqueFrozenset(["_mlog", "_mimage"]) diff --git a/lib/utils/algo.py b/lib/utils/algo.py index ec8ce34..b436f5a 100644 --- a/lib/utils/algo.py +++ b/lib/utils/algo.py @@ -31,7 +31,7 @@ from ganeti.utils import text _SORTER_GROUPS = 8 -_SORTER_RE = re.compile("^%s(.*)$" % (_SORTER_GROUPS * "(\D+|\d+)?")) +_SORTER_RE = re.compile("^%s(.*)$" % (_SORTER_GROUPS * r"(\D+|\d+)?")) def UniqueSequence(seq): diff --git a/lib/utils/text.py b/lib/utils/text.py index 14857ed..e768588 100644 --- a/lib/utils/text.py +++ b/lib/utils/text.py @@ -410,7 +410,7 @@ def SafeEncode(text): def UnescapeAndSplit(text, sep=","): - """Split and unescape a string based on a given separator. + r"""Split and unescape a string based on a given separator. This function splits a string based on a separator where the separator itself can be escape in order to be an element of the -- 1.8.3
