[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [HTCondor-users] condor chirp attribute update with non-string data structures



afais a classad object can not be easily flatten/serialized into a htchirp compatible string. For python dicts flatten()/printJson/printOld/... return strings in different formattings or fail.

I would only expect the str() method to work, but it doesn't because we included newlines in the output. Thus:

#!/usr/bin/python3

import classad
import htcondor.htchirp

ad = classad.ClassAd({"key1": "value1", 'key2':'value2'})
with htcondor.htchirp.HTChirp() as chirp:
    chirp.connect()
    chirp_str = str(ad).replace('\n', '')
    chirp.set_job_attr("TestAttr", chirp_str)
    chirp.disconnect()

btw: can python list be cast into classads? I tried something like [2] but failed. Max suggested to use enumerate for Lua-like lists with keys as consecutive numbers, but one would need to explicitly cast the int indices into strings in a second step.

	The following is awful but does seem to work:

pylist = ["foo", "bar", "baz"]
listdic = {"entry": pylist}
listad = classad.ClassAd(listdic)
classadlist = listad["entry"]

I suspect there isn't a good reason why

clasadlist = classad.ClassAd(pylist)

and

classadlist = classad.Literal(pylist)

don't work.

-- ToddM