def build_context(self): self.next_context = command_context.CommandContext( dict(foo='bar', next_foo='next_bar'), ) self.context = command_context.CommandContext( dict(), self.next_context, )
def build_context(self): class MyObject(object): pass obj = MyObject() obj.foo = 'bar' self.next_context = command_context.CommandContext( dict(foo='your mom', next_foo='next_bar')) self.context = command_context.CommandContext(obj, self.next_context)
def build_context(self): class MyObject(object): pass obj = MyObject() obj.foo = "bar" self.next_context = command_context.CommandContext( dict(foo="your mom")) self.context = command_context.CommandContext(obj, self.next_context)
def build_context(self): class MyObject(object): pass obj = MyObject() obj.foo = "bar" self.context = command_context.CommandContext(obj)
def __init__(self, working_dir, config_path): super(MasterControlProgram, self).__init__() self.jobs = JobCollection() self.working_dir = working_dir self.config = manager.ConfigManager(config_path) self.context = command_context.CommandContext() self.state_watcher = statemanager.StateChangeWatcher() log.info('initialized')
def __init__(self, working_dir, config_path): super(MasterControlProgram, self).__init__() self.jobs = job.JobCollection() self.services = service.ServiceCollection() self.working_dir = working_dir self.crash_reporter = None self.config = manager.ConfigManager(config_path) self.context = command_context.CommandContext() self.event_recorder = event.get_recorder() self.event_recorder.ok('started') self.state_watcher = statemanager.StateChangeWatcher()
def __init__(self, job, run_num=None): self.run_num = job.next_num() if run_num is None else run_num self.job = job self.state_callback = job.state_callback self.id = "%s.%s" % (job.name, self.run_num) self.output_dir = os.path.join(job.output_dir, self.id) self.run_time = None self.start_time = None self.end_time = None self.node = None self.runs = [] self.context = command_context.CommandContext(self, job.context)
def validator(value, config_context): if config_context.partial: return valid_string(value, config_context) context = command_context.CommandContext( context_object, config_context.command_context) try: value % context return value except (KeyError, ValueError), e: error_msg = "Unknown context variable %s at %s: %s" raise ConfigError(error_msg % (e, config_context.path, value))
def validator(value, config_context): if config_context.partial: return valid_string(value, config_context) context = command_context.CommandContext( context_object, config_context.command_context, ) try: StringFormatter(context).format(value) return value except (KeyError, ValueError) as e: error_msg = "Unknown context variable %s at %s: %s" raise ConfigError(error_msg % (e, config_context.path, value)) except (TypeError) as e: error_msg = "Wrong command format %s: %s at %s" raise ConfigError(error_msg % (value, e, config_context.path))
def parse_time_variables(input_string, parse_time=None): """Parses an input string and uses the Tron-style dateparsing to replace time variables. Currently supports only the date/time variables listed in the tron documentation: https://pythonhosted.org/tron/command_context.html#built-in-command-context-variables :param input_string: input string to be parsed :param parse_time: Reference Datetime object to parse the date and time strings, defaults to now. :returns: A string with the date and time variables replaced """ if parse_time is None: parse_time = datetime.datetime.now() # We build up a tron context object that has the right # methods to parse tron-style time syntax job_context = command_context.JobRunContext(command_context.CommandContext()) # The tron context object needs the run_time attibute set so it knows # how to interpret the date strings job_context.job_run.run_time = parse_time # The job_context object works like a normal dictionary for string replacement return input_string % job_context
def __init__(self, name=None, action=None, context=None): self.name = name self.topo_actions = [action] if action else [] self.scheduler = None self.runs = deque() self.queueing = True self.all_nodes = False self.enabled = True self.constant = False self.last_success = None self.run_limit = RUN_LIMIT self.node_pool = None self.output_dir = None self.state_callback = lambda: None self.context = command_context.CommandContext(self) # Service Data self.enable_act = None self.disable_act = None self.enable_runs = deque() self.disable_runs = deque()
def build_run(self, job_run): """Build an instance of ActionRun for this action This is used by the scheduler when scheduling a run """ new_run = ActionRun(self) new_run.id = "%s.%s" % (job_run.id, self.name) new_run.state_callback = job_run.state_callback new_run.complete_callback = job_run.run_completed new_run.node = self.node_pool.next( ) if self.node_pool else job_run.node new_run.stdout_path = os.path.join(job_run.output_dir, self.name + '.stdout') new_run.stderr_path = os.path.join(job_run.output_dir, self.name + '.stderr') action_run_context = ActionRunContext(new_run) new_run.context = command_context.CommandContext( action_run_context, job_run.context) return new_run
def apply(self, mcp): """Apply the configuration to the specified master control program""" working_dir = self._get_working_dir(mcp) if not os.path.isdir(working_dir): raise ConfigError("Specified working directory \'%s\' is not a directory" % working_dir) if not os.access(working_dir, os.W_OK): raise ConfigError("Specified working directory \'%s\' is not writable" % working_dir) mcp.state_handler.working_dir = working_dir if hasattr(self, 'command_context'): mcp.context = command_context.CommandContext(self.command_context) self._apply_nodes(mcp) self._apply_jobs(mcp) if hasattr(self, 'ssh_options'): self.ssh_options = default_or_from_tag(self.ssh_options, SSHOptions) self.ssh_options._apply(mcp) if hasattr(self, 'notification_options'): self.notification_options = default_or_from_tag(self.notification_options, NotificationOptions) self.notification_options._apply(mcp)
def build_context(self): self.next_context = command_context.CommandContext( dict(foo='your mom', next_foo='next_bar')) self.context = command_context.CommandContext(dict(foo='bar'), self.next_context)
def build_context(self): class Obj(object): foo = 'bar' self.context = command_context.CommandContext(Obj)
def build_context(self): self.context = command_context.CommandContext(dict(foo='bar'))
def build_context(self): self.context = command_context.CommandContext(None)
def set_context(self, context): self.context = command_context.CommandContext(self.context, context)
def build_context(self): self.next_context = command_context.CommandContext( dict(foo="your mom")) self.context = command_context.CommandContext(dict(foo="bar"), self.next_context)