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

Proposed by Yu Ning
Status: Merged
Approved by: Mathieu Trudel-Lapierre
Approved revision: 463
Merged at revision: 464
Proposed branch: lp:~yuningdodo/usb-creator/usb-creator.lp1208129-detect-os-version-with-regex
Merge into: lp:usb-creator
Diff against target: 29 lines (+8/-4)
1 file modified
usbcreator/install.py (+8/-4)
To merge this branch: bzr merge lp:~yuningdodo/usb-creator/usb-creator.lp1208129-detect-os-version-with-regex
Reviewer Review Type Date Requested Status
Mathieu Trudel-Lapierre Approve
Review via email: mp+250261@code.launchpad.net

Description of the change

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

To post a comment you must log in.
Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

Seems like that regex would be bugged, and would match with the full version number including point release with group(0) (full match), and only match the last block satisfying "\d+\." for group(1). You can work around this by modifying it a bit: ((\d+\.)\d+)+?

This further passes a quick unscientific test with a full .disk/info line:

Previously:

In [2]: m = re.search("(\d+\.)+\d+", "Ubuntu 15.04.1 \"Vivid Vervet\" - Alpha amd64 (20150224.3)")

In [3]: m.group(0)
Out[3]: '15.04.1'

In [4]: m.group(1)
Out[4]: '04.'

With changes:

In [5]: m = re.search("((\d+\.)\d+)+?", "Ubuntu 15.04.1 \"Vivid Vervet\" - Alpha amd64 (20150224.3)")

In [6]: m.group(0)
Out[6]: '15.04'

In [7]: m.group(1)
Out[7]: '15.04'

review: Needs Fixing
Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

Actually, perhaps "((\d+)(\.\d+))((\.\d+)+)?" is an even better regex for this; given that it will also record the point release number should they ever be needed.

Revision history for this message
Yu Ning (yuningdodo) wrote :

Mathieu, thanks for the review.

According to the context, my understanding is we should find out the whole version number, such as 14.04.1, then let debian_support.Version() to extract the major version (14.04). Do you think this is reasonable?

Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

Hmm, looks like you may be right. In that sense, the regex would be absolutely fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'usbcreator/install.py'
2--- usbcreator/install.py 2013-01-28 12:44:46 +0000
3+++ usbcreator/install.py 2015-02-19 07:11:31 +0000
4@@ -212,17 +212,21 @@
5
6 if os.path.exists(os.path.join(self.target, '.disk', 'info')):
7 with open(os.path.join(self.target, '.disk', 'info'),'r') as f:
8- contents = f.readline().split()
9- if len(contents) > 2:
10+ contents = f.readline()
11+ import re
12+ m = re.search('(\d+\.)+\d+', contents)
13+ if m:
14 # Consider point releases the same as the initial release
15 # (10.04.4 -> 10.04)
16- target_os_ver = debian_support.Version(contents[1])
17+ target_os_ver = debian_support.Version(m.group(0))
18
19 return target_os_ver, our_os_ver
20
21 def need_syslinux_legacy(self):
22 target_os_ver, our_os_ver = self.os_vers()
23- return our_os_ver >= '10.10' and target_os_ver <= '10.04'
24+ # FIXME: check for debian, linuxmint, etc.
25+ return target_os_ver and our_os_ver \
26+ and our_os_ver >= '10.10' and target_os_ver <= '10.04'
27
28 def install_bootloader(self, grub_location=''):
29 logging.debug('install_bootloader')

Subscribers

People subscribed via source and target branches

to all changes: