From 744471b290b9938b0e21a94dc64b86c127c7825d Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 27 Feb 2006 11:21:44 +0000 Subject: [PATCH] 27Feb06 - Modify the Python class examples to inherit object -- new way of defining classes. Patch from Felix Schwartz. - Implement jobuid to replace old usage of job in keywords as suggested by Eric Bollengier. - Apply patch for enhancing wait from Eric Bollengier. On can now: wait (wait for all jobs to stop) wait jobid=nn wait jobuid=unique id wait job=job-name - Implement write variables for Python to set Priority (anytime), and Job Level, only during JobInit event. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2820 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/examples/python/DirStartUp.py | 4 ++-- bacula/examples/python/FDStartUp.py | 4 ++-- bacula/examples/python/SDStartUp.py | 4 ++-- bacula/kes-1.39 | 13 +++++++++++++ bacula/src/cats/sql_list.c | 4 ++-- bacula/src/dird/pythondir.c | 24 +++++++++++++++++++++++- bacula/src/dird/ua_cmds.c | 12 +++++++++++- bacula/src/dird/ua_output.c | 22 ++++++++++++---------- bacula/src/dird/ua_select.c | 20 +++++++++++++++++--- bacula/src/version.h | 4 ++-- 10 files changed, 86 insertions(+), 25 deletions(-) diff --git a/bacula/examples/python/DirStartUp.py b/bacula/examples/python/DirStartUp.py index 5433ad8b87..a6f3995600 100644 --- a/bacula/examples/python/DirStartUp.py +++ b/bacula/examples/python/DirStartUp.py @@ -7,7 +7,7 @@ import sys, bacula # This is the list of Bacula daemon events that you # can receive. -class BaculaEvents: +class BaculaEvents(object): def __init__(self): # Called here when a new Bacula Events class is # is created. Normally not used @@ -43,7 +43,7 @@ bacula.set_events(BaculaEvents()) # register daemon events desired """ There are the Job events that you can receive. """ -class JobEvents: +class JobEvents(object): def __init__(self): # Called here when you instantiate the Job. Not # normally used diff --git a/bacula/examples/python/FDStartUp.py b/bacula/examples/python/FDStartUp.py index 0c274c8c0f..4d53e33bfc 100644 --- a/bacula/examples/python/FDStartUp.py +++ b/bacula/examples/python/FDStartUp.py @@ -6,7 +6,7 @@ import sys, bacula # This is the list of Bacula daemon events that you # can receive. -class BaculaEvents: +class BaculaEvents(object): def __init__(self): # Called here when a new Bacula Events class is # is created. Normally not used @@ -44,7 +44,7 @@ bacula.set_events(BaculaEvents()) # register daemon events desired """ There are the Job events that you can receive. """ -class JobEvents: +class JobEvents(object): def __init__(self): # Called here when you instantiate the Job. Not # normally used diff --git a/bacula/examples/python/SDStartUp.py b/bacula/examples/python/SDStartUp.py index 8430e4f1ce..1f08beda4c 100644 --- a/bacula/examples/python/SDStartUp.py +++ b/bacula/examples/python/SDStartUp.py @@ -6,7 +6,7 @@ import sys, bacula # This is the list of Bacula daemon events that you # can receive. -class BaculaEvents: +class BaculaEvents(object): def __init__(self): # Called here when a new Bacula Events class is # is created. Normally not used @@ -45,7 +45,7 @@ bacula.set_events(BaculaEvents()) # register daemon events desired """ There are the Job events that you can receive. """ -class JobEvents: +class JobEvents(object): def __init__(self): # Called here when you instantiate the Job. Not # normally used diff --git a/bacula/kes-1.39 b/bacula/kes-1.39 index f9f5da2f2a..5f3add3503 100644 --- a/bacula/kes-1.39 +++ b/bacula/kes-1.39 @@ -3,6 +3,19 @@ General: +27Feb06 +- Modify the Python class examples to inherit object -- new way + of defining classes. Patch from Felix Schwartz. +- Implement jobuid to replace old usage of job in keywords as + suggested by Eric Bollengier. +- Apply patch for enhancing wait from Eric Bollengier. On can now: + wait (wait for all jobs to stop) + wait jobid=nn + wait jobuid=unique id + wait job=job-name +- Implement write variables for Python to set Priority (anytime), and + Job Level, only during JobInit event. + 26Feb06 - Fix the block listing bug pointed out by Arno. - Update the po files at Eric's request. diff --git a/bacula/src/cats/sql_list.c b/bacula/src/cats/sql_list.c index 8d180198dc..c1b451e319 100644 --- a/bacula/src/cats/sql_list.c +++ b/bacula/src/cats/sql_list.c @@ -6,7 +6,7 @@ * Version $Id$ */ /* - Copyright (C) 2000-2005 Kern Sibbald + Copyright (C) 2000-2006 Kern Sibbald This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -282,7 +282,7 @@ db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, DB_LIST_HANDLER *sendit, Mmsg(mdb->cmd, "SELECT JobId,Name,StartTime,Type,Level,JobFiles,JobBytes,JobStatus " "FROM Job WHERE JobId=%s", edit_int64(jr->JobId, ed1)); - } else { /* single record */ + } else { /* all records */ Mmsg(mdb->cmd, "SELECT JobId,Name,StartTime,Type,Level,JobFiles,JobBytes,JobStatus " "FROM Job ORDER BY StartTime,JobId ASC%s", limit); diff --git a/bacula/src/dird/pythondir.c b/bacula/src/dird/pythondir.c index 17e2f58984..57557fbfaa 100644 --- a/bacula/src/dird/pythondir.c +++ b/bacula/src/dird/pythondir.c @@ -30,6 +30,7 @@ #include extern char *configfile; +extern struct s_jl joblevels[]; extern JCR *get_jcr_from_PyObject(PyObject *self); extern PyObject *find_method(PyObject *eventsObject, PyObject *method, const char *name); @@ -82,6 +83,7 @@ static struct s_vars setvars[] = { { "JobReport", "s"}, { "VolumeName", "s"}, { "Priority", "i"}, + { "JobLevel", "s"}, { NULL, NULL} }; @@ -235,7 +237,27 @@ int job_setattr(PyObject *self, char *attrname, PyObject *value) break; case 2: /* Priority */ Dmsg1(000, "Set priority=%d\n", intval); - return 0; + if (intval >= 1 && intval <= 100) { + jcr->JobPriority = intval; + } else { + PyErr_SetString(PyExc_ValueError, _("Priority must be 1-100")); + return -1; + } + case 3: /* Job Level */ + if (strcmp("JobInit", jcr->event) != 0) { + PyErr_SetString(PyExc_RuntimeError, _("Job Level can be set only during JobInit")); + return -1; + } + for (i=0; joblevels[i].level_name; i++) { + if (strcmp(strval, joblevels[i].level_name) == 0) { + if (joblevels[i].job_type == jcr->JobType) { + jcr->JobLevel = joblevels[i].level; + return 0; + } + } + } + PyErr_SetString(PyExc_ValueError, _("Bad JobLevel string")); + return -1; } bail_out: PyErr_SetString(PyExc_AttributeError, attrname); diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 1ecc80c819..d50a3c7be9 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -396,7 +396,18 @@ static int cancel_cmd(UAContext *ua, const char *cmd) bstrncpy(jcr->Job, ua->argv[i], sizeof(jcr->Job)); } break; + } else if (strcasecmp(ua->argk[i], _("jobuid")) == 0) { + if (!ua->argv[i]) { + break; + } + if (!(jcr=get_jcr_by_full_name(ua->argv[i]))) { + bsendmsg(ua, _("Warning Job %s is not running. Continuing anyway ...\n"), ua->argv[i]); + jcr = new_jcr(sizeof(JCR), dird_free_jcr); + bstrncpy(jcr->Job, ua->argv[i], sizeof(jcr->Job)); + } + break; } + } /* If we still do not have a jcr, * throw up a list and ask the user to select one. @@ -435,7 +446,6 @@ static int cancel_cmd(UAContext *ua, const char *cmd) return 1; } } - /* NOTE! This increments the ref_count */ sscanf(buf, "JobId=%d Job=%127s", &njobs, JobName); jcr = get_jcr_by_full_name(JobName); if (!jcr) { diff --git a/bacula/src/dird/ua_output.c b/bacula/src/dird/ua_output.c index c3f1ac1883..039a1db9c0 100644 --- a/bacula/src/dird/ua_output.c +++ b/bacula/src/dird/ua_output.c @@ -202,7 +202,9 @@ bail_out: * * list jobs - lists all jobs run * list jobid=nnn - list job data for jobid - * list job=name - list job data for job + * list jobuid=uname - list job data for unique jobid + * list job=name - list all jobs with "name" + * list jobname=name - same as above * list jobmedia jobid= * list jobmedia job=name * list files jobid= - list files saved for job nn @@ -277,23 +279,23 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist) } /* List JOB=xxx */ - } else if (strcasecmp(ua->argk[i], N_("job")) == 0 && ua->argv[i]) { - bstrncpy(jr.Job, ua->argv[i], MAX_NAME_LENGTH); + } else if ((strcasecmp(ua->argk[i], N_("job")) == 0 || + strcasecmp(ua->argk[i], N_("jobname")) == 0) && ua->argv[i]) { + bstrncpy(jr.Name, ua->argv[i], MAX_NAME_LENGTH); jr.JobId = 0; db_list_job_records(ua->jcr, ua->db, &jr, prtit, ua, llist); - /* List JOBNAME=xxx */ - } else if (strcasecmp(ua->argk[i], N_("job")) == 0 && ua->argv[i]) { - bstrncpy(jr.Name, ua->argv[i], MAX_NAME_LENGTH); + /* List JOBUID=xxx */ + } else if (strcasecmp(ua->argk[i], N_("jobuid")) == 0 && ua->argv[i]) { + bstrncpy(jr.Job, ua->argv[i], MAX_NAME_LENGTH); jr.JobId = 0; db_list_job_records(ua->jcr, ua->db, &jr, prtit, ua, llist); - /* List FILES */ } else if (strcasecmp(ua->argk[i], N_("files")) == 0) { for (j=i+1; jargc; j++) { - if (strcasecmp(ua->argk[j], N_("job")) == 0 && ua->argv[j]) { + if (strcasecmp(ua->argk[j], N_("jobuid")) == 0 && ua->argv[j]) { bstrncpy(jr.Job, ua->argv[j], MAX_NAME_LENGTH); jr.JobId = 0; db_get_job_record(ua->jcr, ua->db, &jr); @@ -312,7 +314,7 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist) } else if (strcasecmp(ua->argk[i], N_("jobmedia")) == 0) { int done = FALSE; for (j=i+1; jargc; j++) { - if (strcasecmp(ua->argk[j], N_("job")) == 0 && ua->argv[j]) { + if (strcasecmp(ua->argk[j], N_("jobuid")) == 0 && ua->argv[j]) { bstrncpy(jr.Job, ua->argv[j], MAX_NAME_LENGTH); jr.JobId = 0; db_get_job_record(ua->jcr, ua->db, &jr); @@ -350,7 +352,7 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist) strcasecmp(ua->argk[i], N_("volumes")) == 0) { bool done = false; for (j=i+1; jargc; j++) { - if (strcasecmp(ua->argk[j], N_("job")) == 0 && ua->argv[j]) { + if (strcasecmp(ua->argk[j], N_("jobuid")) == 0 && ua->argv[j]) { bstrncpy(jr.Job, ua->argv[j], MAX_NAME_LENGTH); jr.JobId = 0; db_get_job_record(ua->jcr, ua->db, &jr); diff --git a/bacula/src/dird/ua_select.c b/bacula/src/dird/ua_select.c index 17f9e1de7f..29c9efd997 100644 --- a/bacula/src/dird/ua_select.c +++ b/bacula/src/dird/ua_select.c @@ -626,7 +626,7 @@ int get_job_dbr(UAContext *ua, JOB_DBR *jr) int i; for (i=1; iargc; i++) { - if (strcasecmp(ua->argk[i], N_("job")) == 0 && ua->argv[i]) { + if (strcasecmp(ua->argk[i], N_("jobuid")) == 0 && ua->argv[i]) { jr->JobId = 0; bstrncpy(jr->Job, ua->argv[i], sizeof(jr->Job)); } else if (strcasecmp(ua->argk[i], N_("jobid")) == 0 && ua->argv[i]) { @@ -648,7 +648,8 @@ int get_job_dbr(UAContext *ua, JOB_DBR *jr) jr->Job[0] = 0; for (i=1; iargc; i++) { - if (strcasecmp(ua->argk[i], N_("jobname")) == 0 && ua->argv[i]) { + if ((strcasecmp(ua->argk[i], N_("jobname")) == 0 || + strcasecmp(ua->argk[i], N_("job")) == 0) && ua->argv[i]) { jr->JobId = 0; bstrncpy(jr->Name, ua->argv[i], sizeof(jr->Name)); break; @@ -831,7 +832,8 @@ STORE *get_storage_resource(UAContext *ua, bool use_default) free_jcr(jcr); break; - } else if (strcasecmp(ua->argk[i], N_("job")) == 0) { + } else if (strcasecmp(ua->argk[i], N_("job")) == 0 || + strcasecmp(ua->argk[i], N_("jobname")) == 0) { if (!ua->argv[i]) { bsendmsg(ua, _("Expecting job=xxx, got: %s.\n"), ua->argk[i]); return NULL; @@ -843,6 +845,18 @@ STORE *get_storage_resource(UAContext *ua, bool use_default) store = jcr->store; free_jcr(jcr); break; + } else if (strcasecmp(ua->argk[i], N_("jobuid")) == 0) { + if (!ua->argv[i]) { + bsendmsg(ua, _("Expecting jobuid=xxx, got: %s.\n"), ua->argk[i]); + return NULL; + } + if (!(jcr=get_jcr_by_full_name(ua->argv[i]))) { + bsendmsg(ua, _("Job \"%s\" is not running.\n"), ua->argv[i]); + return NULL; + } + store = jcr->store; + free_jcr(jcr); + break; } } } diff --git a/bacula/src/version.h b/bacula/src/version.h index f660ead03f..6b8ec0a68a 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "1.39.6" -#define BDATE "26 February 2006" -#define LSMDATE "26Feb06" +#define BDATE "27 February 2006" +#define LSMDATE "27Feb06" /* Debug flags */ #undef DEBUG -- 2.39.5