iro/user.py
author Sandro Knauß <knauss@netzguerilla.net>
Fri, 23 Oct 2009 01:37:44 +0200
changeset 6 c5672760138b
parent 0 a3b6e531f0d2
child 7 07dd2663ac90
permissions -rw-r--r--
user interface erweitert

# -*- coding: utf-8 -*-
#Copyright (C) 2009  Sandro Knauß <bugs@sandroknauss.de>

#This program is free software; you can redistribute it and/or modify it under the terms
#of the GNU General Public License as published by the Free Software Foundation;
#either version 3 of the License, or any later version.
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
#without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#See the GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program; if not, see <http://www.gnu.org/licenses/>.

class NotSupportedFeature (Exception):
    def __init__(self,name):
        self.name=name
    
    def __str__(self):
        return ("This is not a supported feature:", self.name)

class User: 
    '''
    class for a xmlrpc user
    '''
    def __init__(self,jobqueue):
        self.jobqueue=jobqueue
        self.jobs={}
        self.features=["mail", "sms", "fax", ]

    def status(self,id=None,detailed=False):
        '''
        gets the status for a job
        if the id is None all Jobs of an user are given back
        '''
        if id==None:
            jobs=self.jobs
        else:
            try:
                jobs={id:self.jobs[id]}
            except:
                raise String("No Job with ID: %i" %(id))
        ret={}
        for key in jobs:
            job=jobs[key]
            ret[key]={"name":job.getName(),"status":job.getStatus(detailed)}
        
        return ret

    def stop(self,id):
        '''
        stops an job with id
        '''
        try:
            job=self.jobs[id]
            job.stop()
        except:
            raise String("No Job with ID: %i" %(id))
        job.stop()

    
    def startSMS(self,message,recipients):
        '''
        starts the SMS with message to recipients
        '''
        if not "sms" in self.features:
            raise NotSupportedFeature("sms")
        id = self.jobqueue.newSMS(message,recipients)
        self.jobs[id]=self.jobqueue[id]
        return id
    
    
    def startFAX(self):
        '''
        starts the FAX - not implemented
        '''
        raise NotSupportedFeature("fax")

    
        
    def startMail(self,subject,  body , recipients):
        if not "mail" in self.features:
            raise NotSupportedFeature("mail")
        id = self.jobqueue.newMail(subject,  body ,recipients)
        self.jobs[id]=self.jobqueue[id]
        return id    
       
    def getProvider(self, name):
        if not name in self.features:
            raise NotSupportedFeature(name)
        
class Admin(User):
    def __init__(self,jobqueue):
        User.__init__(self, jobqueue)
        self.jobs=jobqueue.jobs