Lint improvements to regexps
authorMichele Tartara <mtartara@google.com>
Wed, 21 Aug 2013 12:19:19 +0000 (12:19 +0000)
committerMichele Tartara <mtartara@google.com>
Fri, 23 Aug 2013 12:12:30 +0000 (12:12 +0000)
Fix some regular expressions so that they pass lint checks with newer versions
of pylint.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>

lib/backend.py
lib/hypervisor/hv_base.py
lib/hypervisor/hv_kvm.py
lib/hypervisor/hv_xen.py
lib/objects.py
lib/ovf.py
lib/storage/bdev.py
lib/storage/drbd_info.py
lib/utils/algo.py
lib/utils/text.py

index 466578c..6a38310 100644 (file)
@@ -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"
index bacb33f..38906fd 100644 (file)
@@ -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()
index 14c5807..b4acee3 100644 (file)
@@ -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"
index 7c07422..fa1cb0c 100644 (file)
@@ -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)
index 0ca7363..758d5b3 100644 (file)
@@ -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):
index dc75816..be611d8 100644 (file)
@@ -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)
index 932bc98..0807333 100644 (file)
@@ -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"])
 
index 48f3ce1..3390179 100644 (file)
@@ -41,12 +41,12 @@ class DRBD8Status(object): # pylint: disable=R0902
   """
   UNCONF_RE = re.compile(r"\s*[0-9]+:\s*cs:Unconfigured$")
   LINE_RE = re.compile(r"\s*[0-9]+:\s*cs:(\S+)\s+(?:st|ro):([^/]+)/(\S+)"
-                       "\s+ds:([^/]+)/(\S+)\s+.*$")
+                       r"\s+ds:([^/]+)/(\S+)\s+.*$")
   SYNC_RE = re.compile(r"^.*\ssync'ed:\s*([0-9.]+)%.*"
                        # Due to a bug in drbd in the kernel, introduced in
                        # commit 4b0715f096 (still unfixed as of 2011-08-22)
-                       "(?:\s|M)"
-                       "finish: ([0-9]+):([0-9]+):([0-9]+)\s.*$")
+                       r"(?:\s|M)"
+                       r"finish: ([0-9]+):([0-9]+):([0-9]+)\s.*$")
 
   CS_UNCONFIGURED = "Unconfigured"
   CS_STANDALONE = "StandAlone"
index ec8ce34..b436f5a 100644 (file)
@@ -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):
index 14857ed..e768588 100644 (file)
@@ -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