iro/view/xmlrpc_old.py
changeset 302 3f4bdea2abbf
parent 294 0e75bd39767d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/iro/view/xmlrpc_old.py	Thu Sep 27 17:15:46 2012 +0200
@@ -0,0 +1,206 @@
+# Copyright (c) 2012 netzguerilla.net <iro@netzguerilla.net>
+# 
+# This file is part of Iro.
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a copy of
+# this software and associated documentation files (the "Software"), to deal in
+# the Software without restriction, including without limitation the rights to use,
+# copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
+# #Software, and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+# 
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+# -*- coding: utf-8 -*-
+""".. deprecated:: 1.0a"""
+
+import logging
+logger=logging.getLogger("iro.user")
+class NotSupportedFeature (Exception):
+    def __init__(self,name):
+        self.name=name
+    
+    def __str__(self):
+        return ("This is not a supported feature:", self.name)
+
+class NoID(Exception):
+    def __init__(self,i):
+        self.i=i
+    
+    def __str__(self):
+        return ("No Job with id:", self.i)
+
+
+class User: 
+    '''class for a xmlrpc user
+    '''
+    def __init__(self, name, jobqueue):
+        self.jobqueue=jobqueue
+        self.jobs={}
+        self.name=name
+        self.features=["mail", "sms", "fax", ]
+
+    def status(self,id=None,detailed=False):
+        '''Gibt den aktuellen Status eines Auftrages zurück.
+
+        Keywords:
+        id[hash]: Eine Auftragsnummer
+        detailed[boolean]: Details ausgeben
+
+        Return:
+        jobs[list]: Eine Liste der Aufträge.
+        job.name[string]: Angebener Name
+        job.status[string]: Status des Auftrages
+
+
+        '''
+        try:
+            jobs={}
+            if id==None:
+                jobs=self.jobs
+            else:
+                try:
+                    jobs={id:self.jobs[id]}
+                except:
+                    logger.error("No Job ID %s",id)
+                    #raise NoID(id)
+            ret={}
+            if not jobs:
+                return {}
+
+            for key in jobs:
+                job=jobs[key]
+                ret[key]={"name":job.getName(),"status":job.getStatus(detailed)}
+            
+            return ret
+        except:
+            logger.exception("Fehler in iro.user.status")
+            return {}
+
+    def stop(self,id):
+        '''Stoppt den angegeben Auftrag.
+
+        Keywords:
+        id[hash]: Eine Auftragsnummer
+
+        Return:
+
+        '''
+        try:
+            job=self.jobs[id]
+            job.stop()
+        except:
+            raise NoID(id)
+        job.stop()
+
+    
+    def startSMS(self, message, recipients, provider="default"):
+        '''Versendet eine SMS.
+
+        Keywords:
+        message[string]: Nachricht
+        recipients[list]: eine Liste von Emfänger-Nummern (gemäß ITU-T E.123)
+        provider[string]: Provider über den geschickt werden soll
+
+        Return:
+        id[hash]: Die ID des Auftrages
+
+        '''
+        if not "sms" in self.features:
+            raise NotSupportedFeature("sms")
+        id = self.jobqueue.newSMS(message,recipients,provider,user=self.name)
+        self.jobs[id]=self.jobqueue[id]
+        return id
+    
+    
+    def startFAX(self, subject, fax, recipients, provider="default"):
+        '''Versendet ein FAX.
+
+        Keywords:
+        subject[string]: der Betreff
+        fax[string]: das pdf base64 kodiert
+        recipients[list]: eine Liste von Emfänger-Nummern (gemäß ITU-T E.123)
+        provider[string]: Provider über den geschickt werden soll
+
+        Return:
+        id[hash]: Die ID des Auftrages
+
+        '''
+        logger.debug("startFAX(%s,%s,%s,%s)"%(subject, fax, recipients, provider))
+        if not "fax" in self.features:
+            raise NotSupportedFeature("fax")
+        
+        if type(fax) != list:
+            fax=[fax]
+        f=[i.data for i in fax]
+
+        id = self.jobqueue.newFAX(subject, f,recipients,provider,user=self.name)
+        self.jobs[id]=self.jobqueue[id]
+        return id
+
+    def startMail(self, subject,  body, recipients, frm, provider="default"):
+        '''Versendet eine Email.
+
+        Keywords:
+        subject[string]: der Betreff
+        body[string]: der Email Body
+        recipients[list]: eine Liste von Emailadressen
+        frm[string]: Die Absender Emailadresse
+        provider[string]: Provider über den geschickt werden soll
+
+        Return:
+        id[hash]: Die ID des Auftrages
+
+        '''
+        if not "mail" in self.features:
+            raise NotSupportedFeature("mail")
+        logger.debug("startMail(%s,%s,%s,%s,%s)"%(subject, body, recipients, frm, provider))
+        id = self.jobqueue.newMail(subject, body, recipients, frm,  provider,user=self.name)
+        self.jobs[id]=self.jobqueue[id]
+        return id    
+       
+    def getProvider(self, typ):
+        '''Gibt eine Liste aller verfügbaren Provider zurück.
+
+        Keywords:
+        typ[string]: Der Typ zu dem die Providerloste ausgeben werden soll
+                     Einer der Liste ["sms","fax","mail"]
+
+        Return:
+        providerlist[list]: Eine Liste aller möglichen Provider
+
+        '''
+        if not typ in self.features:
+            raise NotSupportedFeature(typ)
+       
+        return self.jobqueue.providerlist.getProviderlist(typ)
+        
+    def getDefaultProvider(self, typ):
+        '''Gibt den Standardprovider zurück.
+ 
+        Keywords:
+        typ[string]: Der Typ zu dem die Providerloste ausgeben werden soll
+                     Einer der Liste ["sms","fax","mail"]
+
+        Return:
+        provider[string]: Der Standardprovider für den angeben Typ
+
+
+        '''
+        if not typ in self.features:
+            raise NotSupportedFeature(typ)
+       
+        return self.jobqueue.providerlist.getDefault(typ)["name"]
+        
+class Admin(User):
+    def __init__(self, name, jobqueue):
+        User.__init__(self, name, jobqueue)
+        self.jobs=jobqueue.jobs