iro/job.py
changeset 7 07dd2663ac90
child 11 f25033cf93e0
equal deleted inserted replaced
6:c5672760138b 7:07dd2663ac90
       
     1 # -*- coding: utf-8 -*-
       
     2 #Copyright (C) 2009  Sandro Knauß <bugs@sandroknauss.de>
       
     3 
       
     4 #This program is free software; you can redistribute it and/or modify it under the terms
       
     5 #of the GNU General Public License as published by the Free Software Foundation;
       
     6 #either version 3 of the License, or any later version.
       
     7 #This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
       
     8 #without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
       
     9 #See the GNU General Public License for more details.
       
    10 
       
    11 #You should have received a copy of the GNU General Public License
       
    12 #along with this program; if not, see <http://www.gnu.org/licenses/>.
       
    13 
       
    14 
       
    15 class Job(object):
       
    16     '''
       
    17     Basic class for all jobs
       
    18     '''   
       
    19     def __init__(self,provider,name):
       
    20         self.provider=provider
       
    21         self.name=name
       
    22         self.status = "init"
       
    23         self.dStatus={"good":[], "failed":[]}
       
    24 
       
    25     def start(self):
       
    26         self.status = "started"
       
    27         
       
    28     def stop(self):
       
    29         self.status = "stopped"
       
    30         
       
    31     def getStatus(self,detailed):
       
    32         if detailed and self.status == "started" or self.status == "sended":
       
    33             return self.status, self.dStatus
       
    34         return self.status, {}
       
    35     
       
    36     def getName(self):
       
    37         return self.name
       
    38         
       
    39     def getProvider(self):
       
    40         return self.provider
       
    41         
       
    42     def addGood(self, good):
       
    43         if type(good) == list:
       
    44             self.dStatus['good']=self.dStatus['good']+good
       
    45         else:
       
    46             self.dStatus['good'].append(good)
       
    47     
       
    48     def addFailed(self, failed):
       
    49         if type(failed) == list:
       
    50             self.dStatus['failed']=self.dStatus['failed']+failed
       
    51         else:
       
    52             self.dStatus['failed'].append(failed)
       
    53 
       
    54 class MessageJob(Job):
       
    55     '''
       
    56     A specialized class for smsjobs
       
    57     '''
       
    58     def __init__(self,provider,name, message,recipients):
       
    59         self.message=message
       
    60         self.recipients=recipients
       
    61         Job.__init__(self,provider, name)
       
    62         
       
    63     def stop(self):
       
    64         pass
       
    65         
       
    66     def start(self):
       
    67         Job.start(self)
       
    68         self.provider.setJob(self)
       
    69         self.message.sendto(self.provider, self.recipients)
       
    70         self.status="sended"
       
    71 
       
    72     def getMessage(self):
       
    73         return self.message
       
    74         
       
    75     def getRecipients(self):
       
    76         return self.recipients
       
    77 
       
    78 
       
    79