diff mbox series

[kteam-tools] ktl/tracking_bug.py: fix snap tasks lookup

Message ID 20171016145144.9584-1-kleber.souza@canonical.com
State New
Headers show
Series [kteam-tools] ktl/tracking_bug.py: fix snap tasks lookup | expand

Commit Message

Kleber Sacilotto de Souza Oct. 16, 2017, 2:51 p.m. UTC
The layout of the snap-related information has been changed on
kernel-series-info.yaml. So change ktl/tracking_bug.py for the new
layout.

Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
---
 ktl/tracking_bug.py | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

Comments

Juerg Haefliger Oct. 17, 2017, 6:12 a.m. UTC | #1
On 10/16/2017 04:51 PM, Kleber Sacilotto de Souza wrote:
> The layout of the snap-related information has been changed on
> kernel-series-info.yaml. So change ktl/tracking_bug.py for the new
> layout.
> 
> Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
> ---
>  ktl/tracking_bug.py | 24 +++++++++++++++++++++++-
>  1 file changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/ktl/tracking_bug.py b/ktl/tracking_bug.py
> index 426d39b0..8ce69170 100644
> --- a/ktl/tracking_bug.py
> +++ b/ktl/tracking_bug.py
> @@ -16,6 +16,7 @@ class TrackingBug:
>          self.wf = Workflow()
>          self.ub = Ubuntu()
>          self.__dependency_list = None
> +        self.__dependency_snaps = None
>          self._targeted_series_name = None
>          self._series_specified = None
>          self._series_target = None
> @@ -40,6 +41,27 @@ class TrackingBug:
>          retval = dependent_package in self.__dependency_list
>          return retval
>  
> +    # get_dependent_snap
> +    def get_dependent_snap(self, series, main_package):
> +        '''
> +        Return the name of the dependent snap for the specified series/package.
> +        Return None if not found.
> +        '''
> +        if self.__dependency_snaps is None:
> +            try:
> +                record = self.ub.lookup(series)
> +                try:
> +                    self.__dependency_snaps = record['dependent-snaps'][main_package]
> +                except KeyboardInterrupt:

KeyboardInterrupt?


> +                    self.__dependency_snaps = {}
> +            except KeyError:
> +                self.__dependency_snaps = {}

You can simplify this by folding the two try-excepts into a single one.

Or use get() so you don't need try-except blocks. Untested:
self.__dependency_snaps = record.get('dependent-snaps', {}).get('snap', {})


> +
> +        try:
> +            return self.__dependency_snaps['snap']
> +        except KeyError:
> +            return None

return self.__dependency_snaps.get('snap', None)

Python exceptions are somewhat expensive.

...Juerg



> +
>      # valid_series
>      #
>      def valid_series(s, lp_series, series_specified, targeted_series_name, package):
> @@ -64,7 +86,7 @@ class TrackingBug:
>              if lp_series.name == 'prepare-package-signed' and not s.has_dependent_package(targeted_series_name, package, 'signed'):
>                  cdebug('    no prepare-package-signed', 'yellow')
>                  break
> -            if not s.has_dependent_package(targeted_series_name, package, 'snap'):
> +            if s.get_dependent_snap(targeted_series_name, package) is None:
>                  if lp_series.name == 'snap-release-to-edge':
>                      cdebug('    no snap-release-to-edge', 'yellow')
>                      break
>
Kleber Sacilotto de Souza Oct. 17, 2017, 8:04 a.m. UTC | #2
On 10/17/17 08:12, Juerg Haefliger wrote:
> 
> 
> On 10/16/2017 04:51 PM, Kleber Sacilotto de Souza wrote:
>> The layout of the snap-related information has been changed on
>> kernel-series-info.yaml. So change ktl/tracking_bug.py for the new
>> layout.
>>
>> Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
>> ---
>>  ktl/tracking_bug.py | 24 +++++++++++++++++++++++-
>>  1 file changed, 23 insertions(+), 1 deletion(-)
>>
>> diff --git a/ktl/tracking_bug.py b/ktl/tracking_bug.py
>> index 426d39b0..8ce69170 100644
>> --- a/ktl/tracking_bug.py
>> +++ b/ktl/tracking_bug.py
>> @@ -16,6 +16,7 @@ class TrackingBug:
>>          self.wf = Workflow()
>>          self.ub = Ubuntu()
>>          self.__dependency_list = None
>> +        self.__dependency_snaps = None
>>          self._targeted_series_name = None
>>          self._series_specified = None
>>          self._series_target = None
>> @@ -40,6 +41,27 @@ class TrackingBug:
>>          retval = dependent_package in self.__dependency_list
>>          return retval
>>  
>> +    # get_dependent_snap
>> +    def get_dependent_snap(self, series, main_package):
>> +        '''
>> +        Return the name of the dependent snap for the specified series/package.
>> +        Return None if not found.
>> +        '''
>> +        if self.__dependency_snaps is None:
>> +            try:
>> +                record = self.ub.lookup(series)
>> +                try:
>> +                    self.__dependency_snaps = record['dependent-snaps'][main_package]
>> +                except KeyboardInterrupt:
> 
> KeyboardInterrupt?

Oops, it was supposed to be KeyError.

> 
> 
>> +                    self.__dependency_snaps = {}
>> +            except KeyError:
>> +                self.__dependency_snaps = {}
> 
> You can simplify this by folding the two try-excepts into a single one.
> 
> Or use get() so you don't need try-except blocks. Untested:
> self.__dependency_snaps = record.get('dependent-snaps', {}).get('snap', {})
> 
> 
>> +
>> +        try:
>> +            return self.__dependency_snaps['snap']
>> +        except KeyError:
>> +            return None
> 
> return self.__dependency_snaps.get('snap', None)
> 
> Python exceptions are somewhat expensive.
> 
> ...Juerg

Thanks for the suggestions, I will send a v2.

> 
> 
> 
>> +
>>      # valid_series
>>      #
>>      def valid_series(s, lp_series, series_specified, targeted_series_name, package):
>> @@ -64,7 +86,7 @@ class TrackingBug:
>>              if lp_series.name == 'prepare-package-signed' and not s.has_dependent_package(targeted_series_name, package, 'signed'):
>>                  cdebug('    no prepare-package-signed', 'yellow')
>>                  break
>> -            if not s.has_dependent_package(targeted_series_name, package, 'snap'):
>> +            if s.get_dependent_snap(targeted_series_name, package) is None:
>>                  if lp_series.name == 'snap-release-to-edge':
>>                      cdebug('    no snap-release-to-edge', 'yellow')
>>                      break
>>
>
diff mbox series

Patch

diff --git a/ktl/tracking_bug.py b/ktl/tracking_bug.py
index 426d39b0..8ce69170 100644
--- a/ktl/tracking_bug.py
+++ b/ktl/tracking_bug.py
@@ -16,6 +16,7 @@  class TrackingBug:
         self.wf = Workflow()
         self.ub = Ubuntu()
         self.__dependency_list = None
+        self.__dependency_snaps = None
         self._targeted_series_name = None
         self._series_specified = None
         self._series_target = None
@@ -40,6 +41,27 @@  class TrackingBug:
         retval = dependent_package in self.__dependency_list
         return retval
 
+    # get_dependent_snap
+    def get_dependent_snap(self, series, main_package):
+        '''
+        Return the name of the dependent snap for the specified series/package.
+        Return None if not found.
+        '''
+        if self.__dependency_snaps is None:
+            try:
+                record = self.ub.lookup(series)
+                try:
+                    self.__dependency_snaps = record['dependent-snaps'][main_package]
+                except KeyboardInterrupt:
+                    self.__dependency_snaps = {}
+            except KeyError:
+                self.__dependency_snaps = {}
+
+        try:
+            return self.__dependency_snaps['snap']
+        except KeyError:
+            return None
+
     # valid_series
     #
     def valid_series(s, lp_series, series_specified, targeted_series_name, package):
@@ -64,7 +86,7 @@  class TrackingBug:
             if lp_series.name == 'prepare-package-signed' and not s.has_dependent_package(targeted_series_name, package, 'signed'):
                 cdebug('    no prepare-package-signed', 'yellow')
                 break
-            if not s.has_dependent_package(targeted_series_name, package, 'snap'):
+            if s.get_dependent_snap(targeted_series_name, package) is None:
                 if lp_series.name == 'snap-release-to-edge':
                     cdebug('    no snap-release-to-edge', 'yellow')
                     break