iro/user.py
changeset 0 a3b6e531f0d2
child 6 c5672760138b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/iro/user.py	Thu Oct 22 10:00:01 2009 +0200
@@ -0,0 +1,69 @@
+# -*- 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 User: 
+    '''
+    class for a xmlrpc user
+    '''
+    def __init__(self,jobqueue):
+        self.jobqueue=jobqueue
+        self.jobs={}
+
+    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
+        '''
+        id = self.jobqueue.newSMS(message,recipients)
+        self.jobs[id]=self.jobqueue[id]
+        return id
+        
+        
+    def startMail(self,subject,  body , recipients):
+        id = self.jobqueue.newMail(subject,  body ,recipients)
+        self.jobs[id]=self.jobqueue[id]
+        return id     
+        
+class Admin(User):
+    def __init__(self,jobqueue):
+        User.__init__(self, jobqueue)
+        self.jobs=jobqueue.jobs