Esempio n. 1
0
    def processObject(self, obj):
        """Operate on the provided job object."""

        # ask the user if we should continue
        if not obj.pre(self, "Change %s of the command?" % self.opts.key):
            return

        # represent value in type appropriate to member; it will be packed for transmission
        if self.opts.key in self.IntListAttrs:
            value = [int(v) for v in stringutil.str2list(self.opts.value)]
        elif self.opts.key in self.StrListAttrs:
            value = stringutil.str2list(self.opts.value)
        else:
            value = self.opts.value
        
        # try to run the operation
        query.cattr(obj, key=self.opts.key, value=value)
        obj.post(self, "%s changed" % self.opts.key)
import os

import tractor.api.query as tractor_query

from trixter.farmsubmit.query import initialize_engine
from trixter.farmsubmit.constants import LOGGING_NAMESPACE

LOG = logging.getLogger("{}.scripts".format(LOGGING_NAMESPACE))

initialize_engine()

# if a command runs he normally has access to the `TR_ENV_* vars,
# so we know where we want to neutralise all commands
job_id = os.getenv("TR_ENV_JID")
task_id = os.getenv("TR_ENV_TID")

assert job_id, "Not able to detect job id"
assert task_id, "Not able to detect task id"

LOG.info("Previous commands exited sucessfully. We are neutralising them!")

for command in tractor_query.commands("jid='{}' and tid='{}'".format(
        job_id, task_id)):
    # we don't want to lose the original command, so let us know what that was
    # but only echo it instead of letting it execute again
    new_argv = [
        "/bin/echo", "Command has been neutralised:",
        "{}".format(" ".join(command["argv"]))
    ]
    tractor_query.cattr(command, key="argv", value=new_argv)
Esempio n. 3
0
File: test.py Progetto: utsdab/usr
def test_command_ops(command):
    print "cattr"
    tq.cattr(command, key="tags", value=["new", "tags"])
    print "chkeys"
    tq.chkeys(command, keystr="newService")