diff -r eb04ac3a8327 -r 3f4bdea2abbf iro/joblist.py --- a/iro/joblist.py Wed Dec 21 22:07:48 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -# -*- coding: utf-8 -*- -#Copyright (C) 2009 Sandro Knauß - -#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 . - -from anbieter import content -import hashlib, os, time -import logging -logger=logging.getLogger("iro.joblist"); - -class Joblist: - ''' - Providing an list of jobs; each new job gets a hash id - ''' - def __init__(self,manager, queue,providerlist,dbconn=None): - self.jobs={} - self.manager=manager - self.queue=queue - self.providerlist=providerlist - self.dbconn=dbconn - - - def __getitem__(self,key): - return self.jobs[key] - - def __registerJob__(self, job, user): - id = self._createID() - if self.dbconn: - job.setAcounting(self.manager.Acounting(id,self.dbconn)) - job.setId(id, user) - self.jobs[id]=job - self.queue.put(job) - return id - - def newSMS(self, message, recipients, provider="default", user=None): - ''' - creates a new SMS - ''' - job=self.manager.SMSJob(self.providerlist, provider,message, content.SMS(message),recipients) - return self.__registerJob__(job,user) - - def newFAX(self,subject, fax,recipients,provider="default",user=None): - ''' - creates a new Fax - ''' - job=self.manager.FaxJob(self.providerlist, provider,subject, content.FAX(subject,'' ,fax),recipients) - return self.__registerJob__(job,user) - - def newMail(self, subject, body, recipients, frm, provider="default",user=None): - ''' - creates a new Mail - ''' - job=self.manager.MailJob(self.providerlist, provider,subject, content.Mail(subject, body, frm),recipients) - return self.__registerJob__(job,user) - - def _createID(self): - ''' - creats a random hash id - ''' - while True: - m = hashlib.sha1() - m.update(str(time.time())) - m.update(os.urandom(10)) - if not self.jobs.has_key(m.hexdigest): - if not self.dbconn: - self.jobs[m.hexdigest()]=None - break - if not self.manager.Acounting(m.hexdigest(),self.dbconn).getStatus(): - self.jobs[m.hexdigest()]=None - break - return m.hexdigest()