def update(self, fn): current_vars = RcReader().extract(fn) possible_vars = dict() possible_vars.update(self._get_general_envs()) possible_vars.update(self._get_ec2_envs()) possible_vars.update(self._get_password_envs()) possible_vars.update(self._get_os_envs()) possible_vars.update(self._get_euca_envs()) possible_vars.update(self._get_nova_envs()) new_vars = dict() updated_vars = dict() for (key, value) in possible_vars.items(): if value is not None: if key in current_vars and (current_vars.get(key) != value): updated_vars[key] = value elif key not in current_vars: new_vars[key] = value if new_vars or updated_vars: lines = list() lines.append("") lines.append('# Updated on %s' % (date.rcf8222date())) lines.append("") if new_vars: lines.append('# New stuff') lines.extend(self._make_dict_export(new_vars)) lines.append("") if updated_vars: lines.append('# Updated stuff') lines.extend(self._make_dict_export(updated_vars)) lines.append("") append_contents = utils.joinlinesep(*lines) sh.append_file(fn, append_contents) return len(new_vars) + len(updated_vars) else: return 0
def mark_unexecute_file(fn, kvs, comment_start='#'): add_lines = list() add_lines.append('') add_lines.append(comment_start + ' Ran on %s by %s' % (date.rcf8222date(), sh.getuser())) add_lines.append(comment_start + ' With data:') for (k, v) in kvs.items(): add_lines.append(comment_start + ' %s => %s' % (k, v)) sh.append_file(fn, joinlinesep(*add_lines)) sh.chmod(fn, 0644)
def trace(self, cmd, action=None): if action is None: action = date.rcf8222date() if cmd is not None: sh.append_file(self.trace_fn, TRACE_FMT % (cmd, action))
def trace(self, cmd, action=None): if action is None: action = date.rcf8222date() line = TRACE_FMT % (cmd, action) sh.append_file(self.tracefn, line)