iro/view/xmlrpc_old.py
changeset 302 3f4bdea2abbf
parent 294 0e75bd39767d
equal deleted inserted replaced
90:eb04ac3a8327 302:3f4bdea2abbf
       
     1 # Copyright (c) 2012 netzguerilla.net <iro@netzguerilla.net>
       
     2 # 
       
     3 # This file is part of Iro.
       
     4 # 
       
     5 # Permission is hereby granted, free of charge, to any person obtaining a copy of
       
     6 # this software and associated documentation files (the "Software"), to deal in
       
     7 # the Software without restriction, including without limitation the rights to use,
       
     8 # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
       
     9 # #Software, and to permit persons to whom the Software is furnished to do so,
       
    10 # subject to the following conditions:
       
    11 # 
       
    12 # The above copyright notice and this permission notice shall be included in
       
    13 # all copies or substantial portions of the Software.
       
    14 # 
       
    15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
       
    16 # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
       
    17 # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
       
    18 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
       
    19 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
       
    20 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
       
    21 
       
    22 # -*- coding: utf-8 -*-
       
    23 """.. deprecated:: 1.0a"""
       
    24 
       
    25 import logging
       
    26 logger=logging.getLogger("iro.user")
       
    27 class NotSupportedFeature (Exception):
       
    28     def __init__(self,name):
       
    29         self.name=name
       
    30     
       
    31     def __str__(self):
       
    32         return ("This is not a supported feature:", self.name)
       
    33 
       
    34 class NoID(Exception):
       
    35     def __init__(self,i):
       
    36         self.i=i
       
    37     
       
    38     def __str__(self):
       
    39         return ("No Job with id:", self.i)
       
    40 
       
    41 
       
    42 class User: 
       
    43     '''class for a xmlrpc user
       
    44     '''
       
    45     def __init__(self, name, jobqueue):
       
    46         self.jobqueue=jobqueue
       
    47         self.jobs={}
       
    48         self.name=name
       
    49         self.features=["mail", "sms", "fax", ]
       
    50 
       
    51     def status(self,id=None,detailed=False):
       
    52         '''Gibt den aktuellen Status eines Auftrages zurück.
       
    53 
       
    54         Keywords:
       
    55         id[hash]: Eine Auftragsnummer
       
    56         detailed[boolean]: Details ausgeben
       
    57 
       
    58         Return:
       
    59         jobs[list]: Eine Liste der Aufträge.
       
    60         job.name[string]: Angebener Name
       
    61         job.status[string]: Status des Auftrages
       
    62 
       
    63 
       
    64         '''
       
    65         try:
       
    66             jobs={}
       
    67             if id==None:
       
    68                 jobs=self.jobs
       
    69             else:
       
    70                 try:
       
    71                     jobs={id:self.jobs[id]}
       
    72                 except:
       
    73                     logger.error("No Job ID %s",id)
       
    74                     #raise NoID(id)
       
    75             ret={}
       
    76             if not jobs:
       
    77                 return {}
       
    78 
       
    79             for key in jobs:
       
    80                 job=jobs[key]
       
    81                 ret[key]={"name":job.getName(),"status":job.getStatus(detailed)}
       
    82             
       
    83             return ret
       
    84         except:
       
    85             logger.exception("Fehler in iro.user.status")
       
    86             return {}
       
    87 
       
    88     def stop(self,id):
       
    89         '''Stoppt den angegeben Auftrag.
       
    90 
       
    91         Keywords:
       
    92         id[hash]: Eine Auftragsnummer
       
    93 
       
    94         Return:
       
    95 
       
    96         '''
       
    97         try:
       
    98             job=self.jobs[id]
       
    99             job.stop()
       
   100         except:
       
   101             raise NoID(id)
       
   102         job.stop()
       
   103 
       
   104     
       
   105     def startSMS(self, message, recipients, provider="default"):
       
   106         '''Versendet eine SMS.
       
   107 
       
   108         Keywords:
       
   109         message[string]: Nachricht
       
   110         recipients[list]: eine Liste von Emfänger-Nummern (gemäß ITU-T E.123)
       
   111         provider[string]: Provider über den geschickt werden soll
       
   112 
       
   113         Return:
       
   114         id[hash]: Die ID des Auftrages
       
   115 
       
   116         '''
       
   117         if not "sms" in self.features:
       
   118             raise NotSupportedFeature("sms")
       
   119         id = self.jobqueue.newSMS(message,recipients,provider,user=self.name)
       
   120         self.jobs[id]=self.jobqueue[id]
       
   121         return id
       
   122     
       
   123     
       
   124     def startFAX(self, subject, fax, recipients, provider="default"):
       
   125         '''Versendet ein FAX.
       
   126 
       
   127         Keywords:
       
   128         subject[string]: der Betreff
       
   129         fax[string]: das pdf base64 kodiert
       
   130         recipients[list]: eine Liste von Emfänger-Nummern (gemäß ITU-T E.123)
       
   131         provider[string]: Provider über den geschickt werden soll
       
   132 
       
   133         Return:
       
   134         id[hash]: Die ID des Auftrages
       
   135 
       
   136         '''
       
   137         logger.debug("startFAX(%s,%s,%s,%s)"%(subject, fax, recipients, provider))
       
   138         if not "fax" in self.features:
       
   139             raise NotSupportedFeature("fax")
       
   140         
       
   141         if type(fax) != list:
       
   142             fax=[fax]
       
   143         f=[i.data for i in fax]
       
   144 
       
   145         id = self.jobqueue.newFAX(subject, f,recipients,provider,user=self.name)
       
   146         self.jobs[id]=self.jobqueue[id]
       
   147         return id
       
   148 
       
   149     def startMail(self, subject,  body, recipients, frm, provider="default"):
       
   150         '''Versendet eine Email.
       
   151 
       
   152         Keywords:
       
   153         subject[string]: der Betreff
       
   154         body[string]: der Email Body
       
   155         recipients[list]: eine Liste von Emailadressen
       
   156         frm[string]: Die Absender Emailadresse
       
   157         provider[string]: Provider über den geschickt werden soll
       
   158 
       
   159         Return:
       
   160         id[hash]: Die ID des Auftrages
       
   161 
       
   162         '''
       
   163         if not "mail" in self.features:
       
   164             raise NotSupportedFeature("mail")
       
   165         logger.debug("startMail(%s,%s,%s,%s,%s)"%(subject, body, recipients, frm, provider))
       
   166         id = self.jobqueue.newMail(subject, body, recipients, frm,  provider,user=self.name)
       
   167         self.jobs[id]=self.jobqueue[id]
       
   168         return id    
       
   169        
       
   170     def getProvider(self, typ):
       
   171         '''Gibt eine Liste aller verfügbaren Provider zurück.
       
   172 
       
   173         Keywords:
       
   174         typ[string]: Der Typ zu dem die Providerloste ausgeben werden soll
       
   175                      Einer der Liste ["sms","fax","mail"]
       
   176 
       
   177         Return:
       
   178         providerlist[list]: Eine Liste aller möglichen Provider
       
   179 
       
   180         '''
       
   181         if not typ in self.features:
       
   182             raise NotSupportedFeature(typ)
       
   183        
       
   184         return self.jobqueue.providerlist.getProviderlist(typ)
       
   185         
       
   186     def getDefaultProvider(self, typ):
       
   187         '''Gibt den Standardprovider zurück.
       
   188  
       
   189         Keywords:
       
   190         typ[string]: Der Typ zu dem die Providerloste ausgeben werden soll
       
   191                      Einer der Liste ["sms","fax","mail"]
       
   192 
       
   193         Return:
       
   194         provider[string]: Der Standardprovider für den angeben Typ
       
   195 
       
   196 
       
   197         '''
       
   198         if not typ in self.features:
       
   199             raise NotSupportedFeature(typ)
       
   200        
       
   201         return self.jobqueue.providerlist.getDefault(typ)["name"]
       
   202         
       
   203 class Admin(User):
       
   204     def __init__(self, name, jobqueue):
       
   205         User.__init__(self, name, jobqueue)
       
   206         self.jobs=jobqueue.jobs