\section*{Python Scripting}
\label{_ChapterStart60}
\index[general]{Python Scripting}
-\index[general]{Scripting!Pyton}
+\index[general]{Scripting!Python}
\addcontentsline{toc}{section}{Python Scripting}
You may be asking what Python is and why a scripting language is
\end{verbatim}
\normalsize
-The following are the methods (subroutines) provided within the
-directory by the {\bf job} object.
+When a job event is triggered, the appropriate event definition is
+called in the JobEvents class. This is the means by which your Python
+script or code gets control. Once it has control, it may read job
+attributes, or set them. See below for a list of read-only attributes,
+and those that are writable.
+
+In addition, the Bacula {\bf job} obbject in the Director has
+a number of methods (subroutines) that can be called. They
+are:
\begin{description}
\item [set\_events] The set\_events takes a single
argument, which is the instantation of the Job Events class
for the {\bf job} object.
\begin{description}
-\item [Level]
-\item [Type]
-\item [JobId]
-\item [Client]
-\item [NumVols]
-\item [Pool]
-\item [Storage]
-\item [Catalog]
-\item [MediaType]
-\item [JobName]
-\item [JobStatus]
+
+\item [Level] This attribute contains a string representing the Job
+ level, e.g. Full, Differential, Incremental, ...
+\item [Type] This attribute contains a string representing the Job
+ type, e.g. Backup, Restore, Verify, ...
+\item [JobId] This attribute contains an integer representing the
+ JobId.
+\item [Client] This attribute contains a string with the name of the
+ Client for this job.
+\item [NumVols] This attribute contains an integer with the number of
+ Volumes in the Pool being used by the Job.
+\item [Pool] This attribute contains a string with the name of the Pool
+ being used by the Job.
+\item [Storage] This attribute contains a string with the name of the
+ Storage resource being used by the Job.
+\item [Catalog] This attribute contains a string with the name of the
+ Catalog resource being used by the Job.
+\item [MediaType] This attribute contains a string with the name of the
+ Media Type associated with the Storage resource being used by the Job.
+\item [Job] This attribute contains a string containing the name of the
+ Job resource used by this job (not unique).
+\item [JobName] This attribute contains a string representing the full
+ unique Job name.
+\item [JobStatus] This attribute contains a single character string
+ representing the current Job status. The status may change
+ during execution of the job.
+\item [Priority] This attribute contains an integer with the priority
+ assigned to the job.
\item [CatalogRes] tuple consisting of (DBName, Address, User,
Password, Socket, Port, Database Vendor) taken from the Catalog resource
for the Job with the exception of Database Vendor, which is
one of the following: MySQL, PostgreSQL, SQLite, Internal,
depending on what database you configured.
+\item [VolumeName]
+ After a Volume has been purged, this attribute will contain the
+ name of that Volume. At other times, this value may have no meaning.
\end{description}
The following write-only attributes are available within the
noop = 1
def NewVolume(self, job):
+ # Called when Bacula wants a new Volume name. The Volume
+ # name returned, if any, must be stored in job.VolumeName
jobid = job.JobId
client = job.Client
numvol = job.NumVols
job.JobReport="Python before New Volume set for Job.\n"
job.VolumeName=volname
+ def VolumePurged(self, job):
+ # Called when a Volume is purged. The Volume name can be referenced
+ # with job.VolumeName
+ noop = 1
+
+
\end{verbatim}
\normalsize