Hi,

24.10.2007 13:15,, Rich wrote::
> On 2007.10.23. 22:02, Arno Lehmann wrote:
> ...
>> That requirement, by the way, is not very problematic. The sample 
>> given in the manual should almost work out of the box, and python is 
>> easier to learn than Baculas variable substitution language :-)
> 
> i do not agree with that ;)

Feel free to... I'm not a person to try to persuade anyone :-)

>>>> This is described in the manual, for example 
>>>> http://www.bacula.org/dev-manual/Python_Scripting.html#SECTION003560000000000000000
>>> ...
> 
> i'm now trying to understand at least something in all this...
> 
> 1. the example has a section that is not simply stating noop, but is 
> preceded by it :
> 
>    def JobInit(self, job):
>       noop = 1
>       if (job.JobId < 2):
>          startid = job.run("run kernsave")
>          job.JobReport = "Python started new Job: jobid=%d\n" % startid
>       print "name=%s version=%s conf=%s working=%s" % (bacula.Name, 
> bacula.Version, bacula.ConfigFile, bacula.WorkingDir)
> 
> manual says "If you do not want a particular event, simply replace the 
> existing code with a noop = 1."

Well... the manual is imperfect here.

The key thing is that, in python, each method needs a body, and even 
if you don't want any action taken by it. So the construct of "noop = 
1" is a more or less standard way of creating a method without any 
functionality.

> what does this section do then ? is preceding it with noop = 1 also 
> disabling it ?

No. To disable it, you'd have to remove the actual code (which only 
prints a message for JobId=1, by the way).

> 2. the volume label itself.
> i guess i should leave at least parts of "def JobStart", right ?
> it creates JobEvents class, which in turn includes what seems to be the 
> correct section - "def NewVolume".
> 
> i suppose this line should be modified :
> Vol = "TestA-%d" % numvol

In NewVolume, a method of the class JobEvents, yes.
Here the actual volume name is created.

> later two other lines have same string :
> 
> job.JobReport = "Exists=%d TestA-%d" % (job.DoesVolumeExist(Vol), numvol)
> job.VolumeName="TestA-%d" % numvol
> 
> must i replace all of these strings ?

No.

> if yes, can't they just be 
> referenced from the first string, "Vol" ?

Yes.

> now, as for constructing the volume labal string... it seems that most 
> variables map to something "job." - like job.Pool, job.Job, job.Level etc.
> 
> how would i use these variables to define the label ?
> 
> i am trying to imitate a volume label like
> "${Pool}_${Job}-${Level}-${Year}.${Month:p/2/0/r}.${Day:p/2/0/r}-${Hour:p/2/0/r}.${Minute:p/2/0/r}"
> 
> which would also require variables like year, month etc. how can i 
> include those ?

By using python's methods. The module datetime offers date objects, 
which can be used to print the current month, for example. The 
strftime method could be used to get the year, month and day nicely 
formatted as a string.

The pool and job name can be accessed using Baculas job methods, 
similar to the example.

In a real-world script, you should ensure you create unique names 
using the DoesVolumeExist method, by the way.

> i'm really lost with all this, but this probably is the best time to do 
> this as i have set up a test system before attempting a large upgrade, 
> so postponing the change can come back to me later...
> ...

As always... right.

Unfortunately, as I don't actually use python events myself (grin) I 
can't provide another working example.

Arno

>> Arno

-- 
Arno Lehmann
IT-Service Lehmann
www.its-lehmann.de

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users

Reply via email to