Author: eallen
Date: 2008-09-17 14:11:12 -0400 (Wed, 17 Sep 2008)
New Revision: 2493
Modified:
mgmt/trunk/cumin/python/cumin/job.py
Log:
Setting and getting original property value to determine which properties were changed by
the user.
Returning blank dict if GetAd times out.
Modified: mgmt/trunk/cumin/python/cumin/job.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/job.py 2008-09-17 18:08:41 UTC (rev 2492)
+++ mgmt/trunk/cumin/python/cumin/job.py 2008-09-17 18:11:12 UTC (rev 2493)
@@ -396,8 +396,9 @@
cls = self.app.model.get_class_by_object(job)
# wait for up to 20 seconds for completion to be called
- timedout = wait(predicate, timeout=20)
-
+ succeeded = wait(predicate, timeout=20)
+ if not succeeded:
+ self.job_ads = {"": ""}
# list of dictionaries
# each disctionary has:
# name:, value:, type: [, error:] [, property:] [,path:]
@@ -405,7 +406,7 @@
#TODO: handle case where completion status isn't OK
- def gen_item(self, name, value, cls, path=None, dtype=None, error=None):
+ def gen_item(self, name, value, cls, path=None, dtype=None, error=None, orig=None):
""" Generate a dict with name, value, type, error, path, property
This is called with raw GetAd data and with processed data from
@@ -417,6 +418,7 @@
idict = dict()
idict["name"] = name
idict["value"] = value
+ idict["orig"] = value
if dtype:
idict["type"] = dtype
if dtype == "number":
@@ -424,7 +426,9 @@
if nval:
idict["value"] = nval
else:
- idict["type"] = self.get_type(value)
+ idict["type"], idict["value"] = self.get_type(value)
+ if orig:
+ idict["orig"] = orig
if error:
if "error" in error:
idict["error"] = error["error"]
@@ -436,7 +440,17 @@
return idict
def get_type(self, value):
- return isinstance(value, int) and "number" or "string"
+ dvalue = value
+ if isinstance(value, int):
+ dtype = "number"
+ else:
+ dquote = value.split("\"")
+ if len(dquote) == 3 and (not dquote[0] and not dquote[2]):
+ dtype = "string"
+ dvalue = dquote[1]
+ else:
+ dtype = "expression"
+ return dtype, dvalue
class JobPropertyRenderer(TemplateRenderer):
def render_title(self, session, item):
@@ -531,7 +545,7 @@
ads = self.ads.get(session)
if len(ads):
return [self.gen_item(x, ads[x]["value"], cls, path=self.ads.path,
- dtype=ads[x]["type"], error=ads[x]) for x in
ads
+ dtype=ads[x]["type"], error=ads[x],
orig=ads[x]["orig"]) for x in ads
if self.is_group(x, cls, group)]
else:
items = super(JobAdsEditor, self).do_get_items(session, args)
@@ -564,13 +578,21 @@
if fval is None:
ads[field]["error"] = "Numeric value expected"
errors = True
+ elif ftype == "string":
+ fval = "\"%s\"" % fval
else:
fval = unicode(fval)
- just_ads[unicode(field)] = fval
+ if "orig" in ads[field]:
+ orig = ads[field]["orig"]
+ if ftype == "number":
+ orig = convertStr(orig)
+ if fval != orig:
+ just_ads[unicode(field)] = fval
if not errors:
- action = self.app.model.job.savead
- action.invoke(job, just_ads)
+ for field in just_ads:
+ action = self.app.model.job.setattribute
+ action.invoke(job, [field, just_ads[field]])
self.process_cancel(session, job)
class JobOutput(Form):