]> git.sur5r.net Git - bacula/bacula/blob - bacula/examples/python/FDStartUp.py
kes Extend new GUI API.
[bacula/bacula] / bacula / examples / python / FDStartUp.py
1 #
2 # Bacula Python interface script for the File 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 FD 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 FD JobEnd output: JobId=%d Client=%s.\n" % (jobid, client)
36      
37
38   # Called here when the Bacula daemon is going to exit
39   def Exit(self):
40       noop = 1
41      
42 bacula.set_events(BaculaEvents()) # register daemon events desired
43
44 """
45   There are the Job events that you can receive.
46 """
47 class JobEvents(object):
48   def __init__(self):
49      # Called here when you instantiate the Job. Not
50      # normally used
51      noop = 1
52
53   # Pass output back to Bacula
54   def write(self, text):
55      self.job.write(text)
56
57   # Open file to be backed up. file is the filename
58   def Python_open(self, file):
59      print "Open %s called" % file
60      self.fd = open(file, 'rb')
61      jobid = self.job.JobId
62      print "Open: %s" % file
63  
64   # Read file data into Bacula memory buffer (mem)
65   #  return length read. 0 => EOF, -1 => error
66   def Python_read(self, mem):
67      print "Read called\n"
68      len = self.fd.readinto(mem)
69      print "Read %s bytes into mem.\n" % len
70      return len
71
72   # Close file
73   def Python_close(self):
74      self.fd.close()