#    Copyright 2015 ARM Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import collections
import sys

from wlauto import ResultProcessor
from wlauto.core.result import IterationResult
from wlauto.exceptions import ResultProcessorError

try:
    import pynotify
except ImportError:
    pynotify = None


class NotifyProcessor(ResultProcessor):

    name = 'notify'
    description = '''Display a desktop notification when the run finishes

    Notifications only work in linux systems. It uses the generic
    freedesktop notification specification. For this results processor
    to work, you need to have python-notify installed in your system.

    '''

    def initialize(self, context):
        if sys.platform != 'linux2':
            raise ResultProcessorError('Notifications are only supported in linux')

        if not pynotify:
            raise ResultProcessorError('pynotify not installed.  Please install the python-notify package')

        pynotify.init("Workload Automation")

    def process_run_result(self, result, context):
        num_iterations = sum(context.job_iteration_counts.values())

        counter = collections.Counter()
        for result in result.iteration_results:
            counter[result.status] += 1

        score_board = []
        for status in IterationResult.values:
            if status in counter:
                score_board.append('{} {}'.format(counter[status], status))

        summary = 'Workload Automation run finised'
        body = 'Ran a total of {} iterations: '.format(num_iterations)
        body += ', '.join(score_board)
        notification = pynotify.Notification(summary, body)

        if not notification.show():
            self.logger.warning('Notification failed to show')

@@ -755,24 +755,23 @@
  import 
-py
 notify
+2
 %0Aexcept 
@@ -787,24 +787,23 @@
 or:%0A    
-py
 notify
+2
  = None%0A
@@ -1329,24 +1329,23 @@
  if not 
-py
 notify
+2
 :%0A      
@@ -1378,24 +1378,23 @@
 rError('
-py
 notify
+2
  not ins
@@ -1421,29 +1421,23 @@
 all the 
-python-
 notify
+2
  package
@@ -1448,24 +1448,23 @@
         
-py
 notify
+2
 .init(%22W
@@ -2105,16 +2105,15 @@
 n = 
-py
 notify
+2
 .Not

Move the notify results processor to notify2