|
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 class User: |
|
14 ''' |
|
15 class for a xmlrpc user |
|
16 ''' |
|
17 def __init__(self,jobqueue): |
|
18 self.jobqueue=jobqueue |
|
19 self.jobs={} |
|
20 |
|
21 def status(self,id=None,detailed=False): |
|
22 ''' |
|
23 gets the status for a job |
|
24 if the id is None all Jobs of an user are given back |
|
25 ''' |
|
26 if id==None: |
|
27 jobs=self.jobs |
|
28 else: |
|
29 try: |
|
30 jobs={id:self.jobs[id]} |
|
31 except: |
|
32 raise String("No Job with ID: %i" %(id)) |
|
33 ret={} |
|
34 for key in jobs: |
|
35 job=jobs[key] |
|
36 ret[key]={"name":job.getName(),"status":job.getStatus(detailed)} |
|
37 |
|
38 return ret |
|
39 |
|
40 def stop(self,id): |
|
41 ''' |
|
42 stops an job with id |
|
43 ''' |
|
44 try: |
|
45 job=self.jobs[id] |
|
46 job.stop() |
|
47 except: |
|
48 raise String("No Job with ID: %i" %(id)) |
|
49 job.stop() |
|
50 |
|
51 |
|
52 def startSMS(self,message,recipients): |
|
53 ''' |
|
54 starts the SMS with message to recipients |
|
55 ''' |
|
56 id = self.jobqueue.newSMS(message,recipients) |
|
57 self.jobs[id]=self.jobqueue[id] |
|
58 return id |
|
59 |
|
60 |
|
61 def startMail(self,subject, body , recipients): |
|
62 id = self.jobqueue.newMail(subject, body ,recipients) |
|
63 self.jobs[id]=self.jobqueue[id] |
|
64 return id |
|
65 |
|
66 class Admin(User): |
|
67 def __init__(self,jobqueue): |
|
68 User.__init__(self, jobqueue) |
|
69 self.jobs=jobqueue.jobs |