]> git.sur5r.net Git - bacula/bacula/blob - bacula/examples/python/SDStartUp.py
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / examples / python / SDStartUp.py
1 #
2 # Bacula Python interface script for the Storage Daemon
3 #
4 # You must import both sys and bacula
5 import sys, bacula
6
7 # This is the list of Bacula daemon events that you
8 #  can receive.
9 class BaculaEvents(object):
10   def __init__(self):
11      # Called here when a new Bacula Events class is
12      #  is created. Normally not used 
13      noop = 1
14
15   def JobStart(self, job):
16      """
17        Called here when a new job is started. If you want
18        to do anything with the Job, you must register
19        events you want to receive.
20      """
21      events = JobEvents()         # create instance of Job class
22      events.job = job             # save Bacula's job pointer
23      job.set_events(events)       # register events desired
24      sys.stderr = events          # send error output to Bacula
25      sys.stdout = events          # send stdout to Bacula
26      jobid = job.JobId
27      client = job.Client
28      job.JobReport="Python SD JobStart: JobId=%d Client=%s \n" % (jobid,client)
29      return 1
30
31   # Bacula Job is going to terminate
32   def JobEnd(self, job):    
33      jobid = job.JobId
34      client = job.Client 
35      job.JobReport="Python SD JobEnd output: JobId=%d Client=%s.\n" % (jobid, client)
36 #    print "Python SD JobEnd\n"  
37      
38
39   # Called here when the Bacula daemon is going to exit
40   def Exit(self):
41       noop = 1
42      
43 bacula.set_events(BaculaEvents()) # register daemon events desired
44
45 """
46   There are the Job events that you can receive.
47 """
48 class JobEvents(object):
49   def __init__(self):
50      # Called here when you instantiate the Job. Not
51      # normally used
52      noop = 1
53
54   # Pass output back to Bacula
55   def write(self, text):
56      self.job.write(text)