diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 599: Fixed regression: missing check on None string.

Message ID 20130109094914.20121.27599.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Milo Casagrande Jan. 9, 2013, 9:49 a.m. UTC
Merge authors:
  Milo Casagrande (milo)
Related merge proposals:
  https://code.launchpad.net/~milo/linaro-image-tools/regression-fix/+merge/142460
  proposed by: Milo Casagrande (milo)
  review: Approve - Fathi Boudra (fboudra)
------------------------------------------------------------
revno: 599 [merge]
committer: Milo Casagrande <milo@ubuntu.com>
branch nick: trunk
timestamp: Wed 2013-01-09 10:48:18 +0100
message:
  Fixed regression: missing check on None string.
modified:
  linaro_image_tools/media_create/boards.py
  linaro_image_tools/media_create/tests/test_media_create.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro_image_tools/media_create/boards.py'
--- linaro_image_tools/media_create/boards.py	2013-01-07 12:40:41 +0000
+++ linaro_image_tools/media_create/boards.py	2013-01-09 09:22:50 +0000
@@ -212,10 +212,13 @@ 
 
     # XXX: can be removed when killing v1 hwpack.
     def _get_live_serial_options(self):
-        return_value = self._live_serial_options
-        if self._check_placeholder_presence(return_value, r'%s'):
-            return_value = self._live_serial_options % self.serial_tty
-        return return_value
+        live_serial = self._live_serial_options
+        if live_serial:
+            if isinstance(live_serial, list):
+                live_serial = ' '.join(live_serial)
+            if self._check_placeholder_presence(live_serial, r'%s'):
+                live_serial = live_serial % self.serial_tty
+        return live_serial
 
     def _set_live_serial_options(self, value):
         self._live_serial_options = value
@@ -225,16 +228,19 @@ 
 
     # XXX: can be removed when killing v1 hwpack.
     def _get_extra_serial_options(self):
-        return_value = self._extra_serial_options
-        if self._check_placeholder_presence(return_value, r'%s'):
-            return_value = return_value % self.serial_tty
-        return return_value
+        extra_serial = self._extra_serial_options
+        if extra_serial:
+            if isinstance(extra_serial, list):
+                extra_serial = ' '.join(extra_serial)
+            if self._check_placeholder_presence(extra_serial, r'%s'):
+                extra_serial = extra_serial % self.serial_tty
+        return extra_serial
 
     def _set_extra_serial_options(self, value):
         self._extra_serial_options = value
 
     extra_serial_options = property(_get_extra_serial_options,
-                                   _set_extra_serial_options)
+                                    _set_extra_serial_options)
 
     def get_metadata_field(self, field_name):
         """ Return the metadata value for field_name if it can be found.
@@ -539,9 +545,11 @@ 
         In general subclasses should not have to override this.
         """
         boot_args_options = 'rootwait ro'
+        serial_options = ''
         if self.extra_boot_args_options:
             boot_args_options += ' %s' % self.extra_boot_args_options
-        serial_options = self.extra_serial_options
+        if self.extra_serial_options:
+            serial_options = self.extra_serial_options
         for console in consoles:
             serial_options += ' console=%s' % console
 
@@ -553,14 +561,13 @@ 
             if is_lowmem:
                 lowmem_opt = 'only-ubiquity'
 
-        replacements = dict(
-            serial_options=serial_options,
-            lowmem_opt=lowmem_opt, boot_snippet=boot_snippet,
-            boot_args_options=boot_args_options)
-        return (
-            "%(serial_options)s %(lowmem_opt)s "
-                "%(boot_snippet)s %(boot_args_options)s"
-             % replacements)
+        replacements = dict(serial_options=serial_options.strip(),
+                            lowmem_opt=lowmem_opt,
+                            boot_snippet=boot_snippet,
+                            boot_args_options=boot_args_options)
+        boot_args = ("%(serial_options)s %(lowmem_opt)s %(boot_snippet)s"
+                     " %(boot_args_options)s" % replacements).strip()
+        return boot_args
 
     def _get_boot_env(self, is_live, is_lowmem, consoles, rootfs_id,
                       i_img_data, d_img_data):
@@ -859,7 +866,7 @@ 
         """Checks if the passed string contains the particular placeholder."""
         # Very simple way of achieving that.
         presence = False
-        if placeholder in string:
+        if string and placeholder in string:
             presence = True
         return presence
 

=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
--- linaro_image_tools/media_create/tests/test_media_create.py	2012-12-27 14:58:24 +0000
+++ linaro_image_tools/media_create/tests/test_media_create.py	2013-01-09 09:22:50 +0000
@@ -2123,7 +2123,7 @@ 
             is_live=False, is_lowmem=False, consoles=['ttyXXX'],
             rootfs_id="UUID=deadbeef", i_img_data=None, d_img_data=None)
         expected = (
-            ' console=ttyXXX  root=UUID=deadbeef rootwait ro %s' % boot_args)
+            'console=ttyXXX  root=UUID=deadbeef rootwait ro %s' % boot_args)
         self.assertEqual(expected, boot_commands['bootargs'])
 
     def test_passing_None_to_add_boot_args(self):