Skip to contentSkip to conversation

bin, toaster: Fix print and exception syntax

PATCH New Richard Purdie 1 participant 1 message May 9, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bin, toaster: Fix print and exception syntax

This updates the print "" syntax to print() and fixes some exception handling syntax such that its compatible with python v2 and v3.

bitbake/bin/bitbake-diffsigs +3 -3
index 196f0b7..67c60db 100755
@@ -95,7 +95,7 @@ def find_compare_task(bbhandler, pn, taskname):
         # Recurse into signature comparison
         output = bb.siggen.compare_sigfiles(latestfiles[0], latestfiles[1], recursecb)
         if output:
-            print '\n'.join(output)
+            print('\n'.join(output))
     sys.exit(0)
 
 
@@ -130,9 +130,9 @@ else:
         except IOError as e:
             logger.error(str(e))
             sys.exit(1)
-        except cPickle.UnpicklingError, EOFError:
+        except (pickle.UnpicklingError, EOFError):
             logger.error('Invalid signature data - ensure you are specifying sigdata/siginfo files')
             sys.exit(1)
 
         if output:
-            print '\n'.join(output)
+            print('\n'.join(output))
bitbake/bin/bitbake-dumpsig +2 -2
index 656d93a..ffaed1f 100755
@@ -57,9 +57,9 @@ else:
     except IOError as e:
         logger.error(str(e))
         sys.exit(1)
-    except cPickle.UnpicklingError, EOFError:
+    except (pickle.UnpicklingError, EOFError):
         logger.error('Invalid signature data - ensure you are specifying a sigdata/siginfo file')
         sys.exit(1)
 
     if output:
-        print '\n'.join(output)
+        print('\n'.join(output))
bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py +9 -9
index 5e70437..6b1da1b 100644
@@ -70,11 +70,11 @@ class Command(NoArgsCommand):
                     return True
 
                 if len(be.sourcedir) == 0:
-                    print "\n -- Validation: The layers checkout directory must be set."
+                    print("\n -- Validation: The layers checkout directory must be set.")
                     is_changed = _update_sourcedir()
 
                 if not be.sourcedir.startswith("/"):
-                    print "\n -- Validation: The layers checkout directory must be set to an absolute path."
+                    print("\n -- Validation: The layers checkout directory must be set to an absolute path.")
                     is_changed = _update_sourcedir()
 
                 if is_changed:
@@ -87,16 +87,16 @@ class Command(NoArgsCommand):
                     return True
 
                 if len(be.builddir) == 0:
-                    print "\n -- Validation: The build directory must be set."
+                    print("\n -- Validation: The build directory must be set.")
                     is_changed = _update_builddir()
 
                 if not be.builddir.startswith("/"):
-                    print "\n -- Validation: The build directory must to be set to an absolute path."
+                    print("\n -- Validation: The build directory must to be set to an absolute path.")
                     is_changed = _update_builddir()
 
 
                 if is_changed:
-                    print "\nBuild configuration saved"
+                    print("\nBuild configuration saved")
                     be.save()
                     return True
 
@@ -104,20 +104,20 @@ class Command(NoArgsCommand):
                 if be.needs_import:
                     try:
                         config_file = os.environ.get('TOASTER_CONF')
-                        print "\nImporting file: %s" % config_file
+                        print("\nImporting file: %s" % config_file)
                         from loadconf import Command as LoadConfigCommand
 
                         LoadConfigCommand()._import_layer_config(config_file)
                         # we run lsupdates after config update
-                        print "\nLayer configuration imported. Updating information from the layer sources, please wait.\nYou can re-update any time later by running bitbake/lib/toaster/manage.py lsupdates"
+                        print("\nLayer configuration imported. Updating information from the layer sources, please wait.\nYou can re-update any time later by running bitbake/lib/toaster/manage.py lsupdates")
                         from django.core.management import call_command
                         call_command("lsupdates")
 
                         # we don't look for any other config files
                         return is_changed
                     except Exception as e:
-                        print "Failure while trying to import the toaster config file %s: %s" %\
-                            (config_file, e)
+                        print("Failure while trying to import the toaster config file %s: %s" %\
+                            (config_file, e))
                         traceback.print_exc(e)
 
                 return is_changed
bitbake/lib/toaster/bldcontrol/tests.py +2 -2
index f20cc7d..32985c3 100644
@@ -53,7 +53,7 @@ class BEControllerTests(object):
             # setting layers, skip any layer info
             bc.setLayers(BITBAKE_LAYER, POKY_LAYERS)
         except NotImplementedError:
-            print "Test skipped due to command not implemented yet"
+            print("Test skipped due to command not implemented yet")
             return True
         # We are ok with the exception as we're handling the git already exists
         except BuildSetupException:
@@ -79,7 +79,7 @@ class BEControllerTests(object):
             # setting layers, skip any layer info
             layerSet = bc.setLayers(BITBAKE_LAYER, POKY_LAYERS)
         except NotImplementedError:
-            print "Test skipped due to command not implemented yet"
+            print("Test skipped due to command not implemented yet")
             return True
         # We are ok with the exception as we're handling the git already exists
         except BuildSetupException:
bitbake/lib/toaster/contrib/tts/toasteruitest/run_toastertests.py +2 -2
index 754636f..8ca45a8 100755
@@ -74,7 +74,7 @@ def get_tests_from_cfg(suite=None):
     try:
         tests_from_cfg = eval(config.get('toaster_test_' + target_suite, 'test_cases'))
     except:
-        print 'Failed to get test cases from cfg file. Make sure the format is correct.'
+        print('Failed to get test cases from cfg file. Make sure the format is correct.')
         return None
 
     prefix = 'toaster_automation_test.toaster_cases.test_'
@@ -100,7 +100,7 @@ def main():
         testslist = get_tests_from_cfg()
 
     if not testslist:
-        print 'Failed to get test cases.'
+        print('Failed to get test cases.')
         exit(1)
 
     suite = unittest.TestSuite()
bitbake/lib/toaster/contrib/tts/toasteruitest/toaster_automation_test.py +93 -93

573 lines not on this page · raw message

bitbake/lib/toaster/toastergui/views.py +1 -1
index 30295a7..ee184e9 100755
@@ -908,7 +908,7 @@ def _get_dir_entries(build_id, target_id, start):
             response.append(entry)
 
         except Exception as e:
-            print "Exception ", e
+            print("Exception ", e)
             traceback.print_exc(e)
 
     # sort by directories first, then by name
bitbake/lib/toaster/toastermain/management/commands/builddelete.py +1 -1
index ff93e54..0bef8d4 100644
@@ -15,7 +15,7 @@ class Command(BaseCommand):
             try:
                 b = Build.objects.get(pk = bid)
             except ObjectDoesNotExist:
-                print 'build %s does not exist, skipping...' %(bid)
+                print('build %s does not exist, skipping...' %(bid))
                 continue
             # theoretically, just b.delete() would suffice
             # however SQLite runs into problems when you try to
bitbake/lib/toaster/toastermain/management/commands/buildslist.py +1 -1
index cad987f..8dfef0a 100644
@@ -10,4 +10,4 @@ class Command(NoArgsCommand):
 
     def handle_noargs(self,**options):
         for b in Build.objects.all():
-            print "%d: %s %s %s" % (b.pk, b.machine, b.distro, ",".join([x.target for x in b.target_set.all()]))
+            print("%d: %s %s %s" % (b.pk, b.machine, b.distro, ",".join([x.target for x in b.target_set.all()])))
bitbake/lib/toaster/toastermain/management/commands/get-dburl.py +1 -1
index 22b3eb7..911296f 100644
@@ -6,4 +6,4 @@ class Command(NoArgsCommand):
     help    = "get database url"
 
     def handle_noargs(self,**options):
-        print getDATABASE_URL()
+        print(getDATABASE_URL())
bitbake/lib/toaster/toastermain/management/commands/perf.py +3 -3
index 71a48e9..6b450bb 100644
@@ -25,7 +25,7 @@ class Command(BaseCommand):
 			info = self.url_info(full_url)
 			status_code = info[0]
 			load_time = info[1]
-			print 'Trying \'' + full_url + '\', ' + str(status_code) + ', ' + str(load_time)
+			print('Trying \'' + full_url + '\', ' + str(status_code) + ', ' + str(load_time))
 
     def get_full_url(self, url_patt, url_root_res):
 	full_url = str(url_patt).split('^')[1].replace('$>', '').replace('(?P<file_path>(?:/[', '/bin/busybox').replace('.*', '')
@@ -54,5 +54,5 @@ class Command(BaseCommand):
 
     def error(self, *args):
 	for arg in args:
-	    print >>sys.stderr, arg,
-	print >>sys.stderr
+	    print(arg, end=' ', file=sys.stderr)
+	print(file=sys.stderr)
bitbake/lib/toaster/toastermain/settings.py +1 -1
index 74ab604..8662f39 100644
@@ -138,7 +138,7 @@ else:
                 try:
                     if pytz.timezone(zonename) is not None:
                         zonefilelist[hashlib.md5(open(filepath).read()).hexdigest()] = zonename
-                except UnknownTimeZoneError, ValueError:
+                except UnknownTimeZoneError as ValueError:
                     # we expect timezone failures here, just move over
                     pass
             except ImportError: