Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
---------------------------------------------------------------
commit 4e49ca1dc39421d976e329c010258dc29ec4be0c
Author: Peter Hatina <phatina(a)redhat.com>
Date: Tue Aug 6 08:49:33 2013 +0200
add missing LMIJob module
---------------------------------------------------------------
cli/lmi/shell/LMIJob.py | 94 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 94 insertions(+), 0 deletions(-)
diff --git a/cli/lmi/shell/LMIJob.py b/cli/lmi/shell/LMIJob.py
new file mode 100644
index 0000000..c89cc58
--- /dev/null
+++ b/cli/lmi/shell/LMIJob.py
@@ -0,0 +1,94 @@
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <
http://www.gnu.org/licenses/>.
+
+import pywbem
+from LMIObjectFactory import LMIObjectFactory
+
+# NOTE: the enumeration comes from DMTF standard.
+JOB_STATE_COMPLETED, \
+JOB_STATE_TERMINATED, \
+JOB_STATE_KILLED, \
+JOB_STATE_EXCEPTION = range(7, 11)
+
+# Job finish states -- used in LMIMethod.__handle_synchro_method_call_indication()
+# JOB_FINISH_DELAYED -- a job has completed its action later,
+# an indication or polling method was used
+# JOB_FINISHED_EARLY -- no waiting method was used
+JOB_NOT_FINISHED, \
+JOB_FINISH_DELAYED, \
+JOB_FINISH_EARLY = range(3)
+
+def _lmi_get_job_state(job):
+ """
+ Helper function, which returns a numeric Job state value.
+
+ Arguments:
+ job -- LMIInstance or CIMInstance representing a job
+ """
+ if isinstance(job, LMIObjectFactory().LMIInstance):
+ return job.JobState
+ elif isinstance(job, pywbem.CIMInstance):
+ return job["JobState"]
+ raise TypeError("'job' object needs to be instance of either LMIInstance
or CIMInstance")
+
+def lmi_is_job_finished(job):
+ """
+ Helper function, which returns bool flag, if the job is in finished state.
+
+ Arguments:
+ job -- LMIInstance or CIMInstance representing a job
+ """
+ return _lmi_get_job_state(job) in ( \
+ JOB_STATE_COMPLETED, \
+ JOB_STATE_TERMINATED, \
+ JOB_STATE_KILLED, \
+ JOB_STATE_EXCEPTION
+ )
+
+def lmi_is_job_completed(job):
+ """
+ Helper function, which returns bool flag, if the job is in completed state.
+
+ Arguments:
+ job -- LMIInstance or CIMInstance representing a job
+ """
+ return _lmi_get_job_state(job) == JOB_STATE_COMPLETED
+
+def lmi_is_job_terminated(job):
+ """
+ Helper function, which returns bool flag, if the job is in terminated state.
+
+ Arguments:
+ job -- LMIInstance or CIMInstance representing a job
+ """
+ return _lmi_get_job_state(job) == JOB_STATE_TERMINATED
+
+def lmi_is_job_killed(job):
+ """
+ Helper function, which returns bool flag, if the job is killed.
+
+ Arguments:
+ job -- LMIInstance or CIMInstance representing a job
+ """
+ return _lmi_get_job_state(job) == JOB_STATE_KILLED
+
+def lmi_is_job_exception(job):
+ """
+ Helper function, which returns bool flag, if the job is in the exception state.
+
+ Arguments:
+ job -- LMIInstance or CIMInstance representing a job
+ """
+ return _lmi_get_job_state(job) == JOB_STATE_EXCEPTION