def _describe(package_name, cli, app, options_path): """Describe the specified package. :param package_name: The package to describe :type package_name: str :returns: Process status :rtype: int """ config = util.get_config() pkg = package.resolve_package(package_name, config) if pkg is None: raise DCOSException("Package [{}] not found".format(package_name)) # TODO(CD): Make package version to describe configurable pkg_version = pkg.latest_version() pkg_json = pkg.package_json(pkg_version) version_map = pkg.software_versions() versions = [version_map[pkg_ver] for pkg_ver in version_map] del pkg_json['version'] pkg_json['versions'] = versions if cli or app: user_options = _user_options(options_path) options = pkg.options(pkg_version, user_options) if cli: pkg_json['command'] = pkg.command_json(pkg_version, options) if app: pkg_json['app'] = pkg.marathon_json(pkg_version, options) emitter.publish(pkg_json) return 0
def _install(package_name, package_version, options_path, app_id, cli, app, yes): """Install the specified package. :param package_name: the package to install :type package_name: str :param package_version: package version to install :type package_version: str :param options_path: path to file containing option values :type options_path: str :param app_id: app ID for installation of this package :type app_id: str :param cli: indicates if the cli should be installed :type cli: bool :param app: indicate if the application should be installed :type app: bool :param yes: automatically assume yes to all prompts :type yes: bool :returns: process status :rtype: int """ if cli is False and app is False: # Install both if neither flag is specified cli = app = True config = util.get_config() pkg = package.resolve_package(package_name, config) if pkg is None: msg = "Package [{}] not found\n".format(package_name) + \ "You may need to run 'dcos package update' to update your " + \ "repositories" raise DCOSException(msg) pkg_revision = pkg.latest_package_revision(package_version) if pkg_revision is None: if package_version is not None: msg = "Version {} of package [{}] is not available".format( package_version, package_name) else: msg = "Package [{}] not available".format(package_name) raise DCOSException(msg) user_options = _user_options(options_path) pkg_json = pkg.package_json(pkg_revision) pre_install_notes = pkg_json.get('preInstallNotes') if pre_install_notes: emitter.publish(pre_install_notes) if not _confirm('Continue installing?', yes): emitter.publish('Exiting installation.') return 0 options = pkg.options(pkg_revision, user_options) revision_map = pkg.package_revisions_map() package_version = revision_map.get(pkg_revision) if app and pkg.has_marathon_definition(pkg_revision): # Install in Marathon msg = 'Installing Marathon app for package [{}] version [{}]'.format( pkg.name(), package_version) if app_id is not None: msg += ' with app id [{}]'.format(app_id) emitter.publish(msg) init_client = marathon.create_client(config) package.install_app( pkg, pkg_revision, init_client, options, app_id) if cli and pkg.has_command_definition(pkg_revision): # Install subcommand msg = 'Installing CLI subcommand for package [{}] version [{}]'.format( pkg.name(), package_version) emitter.publish(msg) subcommand.install(pkg, pkg_revision, options) subcommand_paths = subcommand.get_package_commands(package_name) new_commands = [os.path.basename(p).replace('-', ' ', 1) for p in subcommand_paths] if new_commands: commands = ', '.join(new_commands) plural = "s" if len(new_commands) > 1 else "" emitter.publish("New command{} available: {}".format(plural, commands)) post_install_notes = pkg_json.get('postInstallNotes') if post_install_notes: emitter.publish(post_install_notes) return 0
def _describe(package_name, app, cli, options_path, render, package_versions, package_version, config): """Describe the specified package. :param package_name: The package to describe :type package_name: str :param app: If True, marathon.json will be printed :type app: boolean :param cli: If True, command.json should be printed :type cli: boolean :param options_path: Path to json file with options to override config.json defaults. :type options_path: str :param render: If True, marathon.json and/or command.json templates will be rendered :type render: boolean :param package_versions: If True, a list of all package versions will be printed :type package_versions: boolean :param package_version: package version :type package_version: str | None :param config: If True, config.json will be printed :type config: boolean :returns: Process status :rtype: int """ # If the user supplied template options, they definitely want to # render the template if options_path: render = True if package_versions and \ (app or cli or options_path or render or package_version or config): raise DCOSException( 'If --package-versions is provided, no other option can be ' 'provided') pkg = package.resolve_package(package_name) if pkg is None: raise DCOSException("Package [{}] not found".format(package_name)) pkg_revision = pkg.latest_package_revision(package_version) if pkg_revision is None: raise DCOSException("Version {} of package [{}] is not available". format(package_version, package_name)) pkg_json = pkg.package_json(pkg_revision) if package_version is None: revision_map = pkg.package_revisions_map() pkg_versions = list(revision_map.values()) del pkg_json['version'] pkg_json['versions'] = pkg_versions if package_versions: emitter.publish('\n'.join(pkg_json['versions'])) elif cli or app or config: user_options = _user_options(options_path) options = pkg.options(pkg_revision, user_options) if cli: if render: cli_output = pkg.command_json(pkg_revision, options) else: cli_output = pkg.command_template(pkg_revision) if cli_output and cli_output[-1] == '\n': cli_output = cli_output[:-1] emitter.publish(cli_output) if app: if render: app_output = pkg.marathon_json(pkg_revision, options) else: app_output = pkg.marathon_template(pkg_revision) if app_output and app_output[-1] == '\n': app_output = app_output[:-1] emitter.publish(app_output) if config: config_output = pkg.config_json(pkg_revision) emitter.publish(config_output) else: pkg_json = pkg.package_json(pkg_revision) emitter.publish(pkg_json) return 0
def _install(package_name, package_version, options_path, app_id, cli, app, yes): """Install the specified package. :param package_name: the package to install :type package_name: str :param package_version: package version to install :type package_version: str :param options_path: path to file containing option values :type options_path: str :param app_id: app ID for installation of this package :type app_id: str :param cli: indicates if the cli should be installed :type cli: bool :param app: indicate if the application should be installed :type app: bool :param yes: automatically assume yes to all prompts :type yes: bool :returns: process status :rtype: int """ if cli is False and app is False: # Install both if neither flag is specified cli = app = True config = util.get_config() pkg = package.resolve_package(package_name, config) if pkg is None: msg = "Package [{}] not found\n".format(package_name) + \ "You may need to run 'dcos package update' to update your " + \ "repositories" raise DCOSException(msg) pkg_revision = pkg.latest_package_revision(package_version) if pkg_revision is None: if package_version is not None: msg = "Version {} of package [{}] is not available".format( package_version, package_name) else: msg = "Package [{}] not available".format(package_name) raise DCOSException(msg) user_options = _user_options(options_path) pkg_json = pkg.package_json(pkg_revision) pre_install_notes = pkg_json.get('preInstallNotes') if pre_install_notes: emitter.publish(pre_install_notes) if not _confirm('Continue installing?', yes): emitter.publish('Exiting installation.') return 0 options = pkg.options(pkg_revision, user_options) revision_map = pkg.package_revisions_map() package_version = revision_map.get(pkg_revision) if app and (pkg.has_marathon_definition(pkg_revision) or pkg.has_marathon_mustache_definition(pkg_revision)): # Install in Marathon msg = 'Installing Marathon app for package [{}] version [{}]'.format( pkg.name(), package_version) if app_id is not None: msg += ' with app id [{}]'.format(app_id) emitter.publish(msg) init_client = marathon.create_client(config) package.install_app(pkg, pkg_revision, init_client, options, app_id) if cli and pkg.has_command_definition(pkg_revision): # Install subcommand msg = 'Installing CLI subcommand for package [{}] version [{}]'.format( pkg.name(), package_version) emitter.publish(msg) subcommand.install(pkg, pkg_revision, options) subcommand_paths = subcommand.get_package_commands(package_name) new_commands = [ os.path.basename(p).replace('-', ' ', 1) for p in subcommand_paths ] if new_commands: commands = ', '.join(new_commands) plural = "s" if len(new_commands) > 1 else "" emitter.publish("New command{} available: {}".format( plural, commands)) post_install_notes = pkg_json.get('postInstallNotes') if post_install_notes: emitter.publish(post_install_notes) return 0
def _describe(package_name, app, cli, options_path, render, package_versions, package_version, config): """Describe the specified package. :param package_name: The package to describe :type package_name: str :param app: If True, marathon.json will be printed :type app: boolean :param cli: If True, command.json should be printed :type cli: boolean :param options_path: Path to json file with options to override config.json defaults. :type options_path: str :param render: If True, marathon.json and/or command.json templates will be rendered :type render: boolean :param package_versions: If True, a list of all package versions will be printed :type package_versions: boolean :param package_version: package version :type package_version: str | None :param config: If True, config.json will be printed :type config: boolean :returns: Process status :rtype: int """ # If the user supplied template options, they definitely want to # render the template if options_path: render = True if package_versions and \ (app or cli or options_path or render or package_version or config): raise DCOSException( 'If --package-versions is provided, no other option can be ' 'provided') pkg = package.resolve_package(package_name) if pkg is None: raise DCOSException("Package [{}] not found".format(package_name)) pkg_revision = pkg.latest_package_revision(package_version) if pkg_revision is None: raise DCOSException( "Version {} of package [{}] is not available".format( package_version, package_name)) pkg_json = pkg.package_json(pkg_revision) if package_version is None: revision_map = pkg.package_revisions_map() pkg_versions = list(revision_map.values()) del pkg_json['version'] pkg_json['versions'] = pkg_versions if package_versions: emitter.publish('\n'.join(pkg_json['versions'])) elif cli or app or config: user_options = _user_options(options_path) options = pkg.options(pkg_revision, user_options) if cli: if render: cli_output = pkg.command_json(pkg_revision, options) else: cli_output = pkg.command_template(pkg_revision) if cli_output and cli_output[-1] == '\n': cli_output = cli_output[:-1] emitter.publish(cli_output) if app: if render: app_output = pkg.marathon_json(pkg_revision, options) else: app_output = pkg.marathon_template(pkg_revision) if app_output and app_output[-1] == '\n': app_output = app_output[:-1] emitter.publish(app_output) if config: config_output = pkg.config_json(pkg_revision) emitter.publish(config_output) else: pkg_json = pkg.package_json(pkg_revision) emitter.publish(pkg_json) return 0
def _install(package_name, options_path, app_id, cli, app, yes): """Install the specified package. :param package_name: the package to install :type package_name: str :param options_path: path to file containing option values :type options_path: str :param app_id: app ID for installation of this package :type app_id: str :param cli: indicates if the cli should be installed :type cli: bool :param app: indicate if the application should be installed :type app: bool :param yes: automatically assume yes to all prompts :type yes: bool :returns: process status :rtype: int """ if cli is False and app is False: # Install both if neither flag is specified cli = app = True config = util.get_config() pkg = package.resolve_package(package_name, config) if pkg is None: msg = "Package [{}] not found\n".format(package_name) + \ "You may need to run 'dcos package update' to update your " + \ "repositories" raise DCOSException(msg) # TODO(CD): Make package version to install configurable pkg_version = pkg.latest_version() pre_install_notes = pkg.package_json(pkg_version).get('preInstallNotes') if pre_install_notes: emitter.publish(pre_install_notes) if not _confirm('Continue installing?', yes): emitter.publish('Exiting installation.') return 0 user_options = _user_options(options_path) options = pkg.options(pkg_version, user_options) if app and pkg.has_marathon_definition(pkg_version): # Install in Marathon version_map = pkg.software_versions() sw_version = version_map.get(pkg_version, '?') message = 'Installing package [{}] version [{}]'.format( pkg.name(), sw_version) if app_id is not None: message += ' with app id [{}]'.format(app_id) emitter.publish(message) init_client = marathon.create_client(config) package.install_app( pkg, pkg_version, init_client, options, app_id) if cli and pkg.has_command_definition(pkg_version): # Install subcommand emitter.publish('Installing CLI subcommand for package [{}]'.format( pkg.name())) subcommand.install(pkg, pkg_version, options) post_install_notes = pkg.package_json(pkg_version).get('postInstallNotes') if post_install_notes: emitter.publish(post_install_notes) return 0