def save(self, path): """ Save the version to dest .py file. This is a command for internal build process. :param path: the python file to save the version. """ # pylint: disable=no-self-use,unused-argument log = clog.get_log(console_format=clog.FMT_NORMAL, overwrite=True) local_host = ssh_host.get_local_host(ssh=False) source_dir = os.path.dirname(os.path.dirname(__file__)) version_string = coral_get_version_string(log, source_dir) if version_string is None: cmd_general.cmd_exit(log, -1) version_string = coral_uniformed_version(version_string) version_data = '"""' version_data += """ Please DO NOT edit this file directly! This file is generated by "coral" command. """ version_data += '"""' version_data += "\n" version_data += "CORAL_VERSION = \"%s\"\n" % (version_string) try: with open(path, 'w') as version_file: version_file.write(version_data) except: log.cl_error("failed to write version to file [%s] on host [%s]: %s", path, local_host.sh_hostname, traceback.format_exc()) cmd_general.cmd_exit(log, -1) cmd_general.cmd_exit(log, 0)
def build_bootstrap(): """ Bootstrap the command by installing the dependencies. """ # pylint: disable=unused-variable local_host = ssh_host.get_local_host(ssh=False) log = clog.get_log(console_format=clog.FMT_NORMAL) distro = local_host.sh_distro(log) if distro is None: log.cl_error("failed to get distro of host [%s]", local_host.sh_hostname) sys.exit(-1) missing_rpms, missing_pips = \ install_common.command_missing_packages(distro) if missing_rpms is None: log.cl_error("failed to get the missing packages of host [%s]", local_host.sh_hostname) sys.exit(-1) command = "mkdir -p %s" % constant.CORAL_BUILD_CACHE_PIP_DIR retval = local_host.sh_run(log, command, timeout=None) if retval.cr_exit_status: log.cl_error("failed to run command [%s] on host [%s], " "ret = %d, stdout = [%s], stderr = [%s]", command, local_host.sh_hostname, retval.cr_exit_status, retval.cr_stdout, retval.cr_stderr) sys.exit(-1) ret = install_common.bootstrap_from_internet(log, local_host, missing_rpms, missing_pips, pip_dir=constant.CORAL_BUILD_CACHE_PIP_DIR) if ret: sys.exit(ret)
def urls(self): """ Print the URLs to download dependency packages. """ # pylint: disable=no-self-use log = clog.get_log(console_format=clog.FMT_NORMAL, overwrite=True) for package, url in PACAKGE_URL_DICT.items(): log.cl_stdout("%s: %s", package, url) cmd_general.cmd_exit(log, 0)
def check(self): """ check whether the documents. """ # pylint: disable=no-self-use log = clog.get_log(console_format=clog.FMT_NORMAL, overwrite=True) doc_dir = os.getcwd() + "/doc" rc = check_doc(log, doc_dir) cmd_general.cmd_exit(log, rc)
def show(self): """ Print version to stdout. All '-' will be replaced to "_" to make RPM naming happy. """ # pylint: disable=no-self-use log = clog.get_log(console_format=clog.FMT_NORMAL, overwrite=True) source_dir = os.getcwd() version_string = coral_get_version_string(log, source_dir) if version_string is None: cmd_general.cmd_exit(log, -1) sys.stdout.write(coral_uniformed_version(version_string)) cmd_general.cmd_exit(log, 0)
def init_env_noconfig(logdir, log_to_file, logdir_is_default, prefix="", identity=None, force_stdout_color=False, force_stderr_color=False, console_format=clog.FMT_NORMAL): """ Init log and workspace for commands that needs it """ # pylint: disable=too-many-branches if identity is None: identity = prefix + get_identity() else: if (not isinstance(identity, bool)) and isinstance(identity, int): identity = str(identity) elif not isinstance(identity, str): print("ERROR: invalid identity [%s]" % (identity), file=sys.stderr) sys.exit(1) if (not isinstance(logdir, bool)) and isinstance(logdir, int): logdir = str(logdir) if not isinstance(logdir, str): print("ERROR: invalid log dir [%s], should be a string" % (logdir), file=sys.stderr) sys.exit(1) elif len(logdir) == 0: print("ERROR: empty log dir", file=sys.stderr) sys.exit(1) if logdir_is_default: workspace = logdir + "/" + identity else: workspace = logdir if not isinstance(log_to_file, bool): print("ERROR: invalid debug option [%s], should be a bool type" % (log_to_file), file=sys.stderr) sys.exit(1) if log_to_file: command = "mkdir -p %s" % workspace retval = utils.run(command) if retval.cr_exit_status != 0: print("failed to run command [%s], " "ret = [%d], stdout = [%s], stderr = [%s]" % (command, retval.cr_exit_status, retval.cr_stdout, retval.cr_stderr), file=sys.stderr) sys.exit(1) resultsdir = workspace print("INFO: log saved to dir [%s]" % resultsdir, file=sys.stderr) else: resultsdir = None if force_stdout_color: stdout_color = True else: stdout_color = None if force_stderr_color: stderr_color = True else: stderr_color = None log = clog.get_log(resultsdir=resultsdir, overwrite=True, console_level=logging.INFO, console_format=console_format, stdout_color=stdout_color, stderr_color=stderr_color) return log, workspace