def run(self, package): """Run the load operation on the specified port(s). Unfortunately, there's no way to query if a port is already loaded. To get already this, we make the operation itempotent: we try the port load. If it fails, we scan the results to see if we get the error message indicating the port was already loaded. In that case, we ignore the error. """ port_exe = self.ctx.props.input_ports.macports.macports_exe action._check_file_exists(port_exe, self) try: re_map = {"already_loaded": concat(lit("Error: Target org.macports.load returned:"), one_or_more(any_except_newline()), line_ends_with(lit("Already loaded"))).get_value()} (rc, result_map) = \ iuprocess.run_sudo_program_and_scan_results([port_exe, "load", package], re_map, self.ctx.logger, self.ctx._get_sudo_password(self), log_output=True, cwd=os.path.dirname(port_exe), env=ENV) except iuprocess.SudoError, e: self.ctx.logger.exception("Port load for %s failed, unexpected exception" % package) exc_info = sys.exc_info() sys.exc_clear() raise convert_exc_to_user_error(exc_info, errors[ERR_MACPORTS_LOAD], msg_args={"pkg":package, "id":self.ctx.props.id}, nested_exc_info=e.get_nested_exc_info())
def _run_rabbitmqctl(self, re_map): rc, remap = procutils.run_sudo_program_and_scan_results( [get_rabbitmq_executable(self.ctx.props.input_ports.host), 'status'], re_map, self.ctx.logger, self.ctx._get_sudo_password(self), return_mos=True, log_output=True) return rc, remap
def is_running(self, svcname): ## rc = procutils.run_and_log_program([SERVICE_EXE, svcname, "status"], None, ## self.ctx.logger) re_map = {"running": re.escape("%s start/running" % svcname), "stopped": re.escape("%s stop/waiting" % svcname)} (rc, m) = procutils.run_sudo_program_and_scan_results( [SERVICE_EXE, svcname, "status"], re_map, self.ctx.logger, self.ctx._get_sudo_password(self), log_output=True ) if rc == 1: return False elif rc != 0: raise UserError(errors[ERR_BAD_STATUS], msg_args={"svc": svcname}, developer_msg="Return code was %d" % rc) elif m["running"]: return True elif m["stopped"]: return False else: raise UserError(errors[ERR_BAD_STATUS], msg_args={"svc": svcname}, developer_msg="Did not find status patterns")