← Back to team overview

usb-creator-hackers team mailing list archive

[Merge] lp:~yuningdodo/usb-creator/usb-creator.lp1208129-detect-os-version-with-regex into lp:usb-creator

 

Yu Ning has proposed merging lp:~yuningdodo/usb-creator/usb-creator.lp1208129-detect-os-version-with-regex into lp:usb-creator.

Requested reviews:
  usb-creator hackers (usb-creator-hackers)
Related bugs:
  Bug #1208129 in usb-creator (Ubuntu): "Compares NoneType() and str(), hence fails to make bootable usb"
  https://bugs.launchpad.net/ubuntu/+source/usb-creator/+bug/1208129

For more details, see:
https://code.launchpad.net/~yuningdodo/usb-creator/usb-creator.lp1208129-detect-os-version-with-regex/+merge/250261

* usbcreator/install.py: detect os version with regex and check for the result. (LP: #1208129)

-- 
Your team usb-creator hackers is requested to review the proposed merge of lp:~yuningdodo/usb-creator/usb-creator.lp1208129-detect-os-version-with-regex into lp:usb-creator.
=== modified file 'usbcreator/install.py'
--- usbcreator/install.py	2013-01-28 12:44:46 +0000
+++ usbcreator/install.py	2015-02-19 07:11:31 +0000
@@ -212,17 +212,21 @@
 
         if os.path.exists(os.path.join(self.target, '.disk', 'info')):
             with open(os.path.join(self.target, '.disk', 'info'),'r') as f:
-                contents = f.readline().split()
-            if len(contents) > 2:
+                contents = f.readline()
+            import re
+            m = re.search('(\d+\.)+\d+', contents)
+            if m:
                 # Consider point releases the same as the initial release
                 # (10.04.4 -> 10.04)
-                target_os_ver = debian_support.Version(contents[1])
+                target_os_ver = debian_support.Version(m.group(0))
 
         return target_os_ver, our_os_ver
 
     def need_syslinux_legacy(self):
         target_os_ver, our_os_ver = self.os_vers()
-        return our_os_ver >= '10.10' and target_os_ver <= '10.04'
+        # FIXME: check for debian, linuxmint, etc.
+        return target_os_ver and our_os_ver \
+                and our_os_ver >= '10.10' and target_os_ver <= '10.04'
 
     def install_bootloader(self, grub_location=''):
         logging.debug('install_bootloader')