Manage packages on remote hosts.
4376
def make(parser):
    

    action = parser.add_mutually_exclusive_group()

    action.add_argument(
        '--install',
        metavar='PKG(s)',
        help='Comma-separated package(s) to install',
    )

    action.add_argument(
        '--remove',
        metavar='PKG(s)',
        help='Comma-separated package(s) to remove',
    )

    parser.add_argument(
        'hosts',
        nargs='+',
    )

    parser.set_defaults(
        func=pkg,
    )
211498
def install_packages():
    

    if env.verbosity:
        print env.host, "INSTALLING & CONFIGURING NODE PACKAGES:"
    #Get a list of installed packages
    p = run("dpkg -l | awk '/ii/ {print $2}'").split('\n')
    
    #Remove apparmor - TODO we may enable this later
    if env.overwrite or not server_state('apparmor-disabled') and 'apparmor' in p:
        with settings(warn_only=True):
            sudo('/etc/init.d/apparmor stop')
            sudo('update-rc.d -f apparmor remove')
            set_server_state('apparmor-disabled')

    #The principle we will use is to only install configurations and packages
    #if they do not already exist (ie not manually installed or other method)
    env.installed_packages[env.host] = []
    role = env.role_lookup[env.host_string]
    packages = get_packages()
    for package in packages:
        if not package in p:
            install_package(package)
            if env.verbosity:
                print ' * installed',package
            env.installed_packages[env.host].append(package)
    if env.overwrite or env.installed_packages[env.host]: #always store the latest complete list
        set_server_state('packages_installed', packages)
        env.installed_packages[env.host] = packages

    if env.overwrite and 'apache2' in env.installed_packages[env.host]: 
            #some sensible defaults -might move to putting this config in a template
            sudo("rm -f /etc/apache2/sites-enabled/000-default")
            sed('/etc/apache2/apache2.conf',before='KeepAlive On',after='KeepAlive Off',use_sudo=True, backup='')
            sed('/etc/apache2/apache2.conf',before='StartServers          2', after='StartServers          1', use_sudo=True, backup='')
            sed('/etc/apache2/apache2.conf',before='MaxClients          150', after='MaxClients          100', use_sudo=True, backup='')
            for module in env.APACHE_DISABLE_MODULES:
                sudo('rm -f /etc/apache2/mods-enabled/%s*'% module)
    #Install base python packages
    #We'll use easy_install at this stage since it doesn't download if the package
    #is current whereas pip always downloads.
    #Once both these packages mature we'll move to using the standard Ubuntu packages
    if (env.overwrite or not server_state('pip-venv-wrapper-installed')) and 'python-setuptools' in packages:
        sudo("easy_install virtualenv")
        sudo("easy_install pip")
        sudo("easy_install virtualenvwrapper")
        if env.verbosity:
            print " * easy installed pip, virtualenv, virtualenvwrapper"
        set_server_state('pip-venv-wrapper-installed')
    if not contains("/home/%s/.profile"% env.user,"source /usr/local/bin/virtualenvwrapper.sh"):
        append("/home/%s/.profile"% env.user, "export WORKON_HOME=$HOME/env")
        append("/home/%s/.profile"% env.user, "source /usr/local/bin/virtualenvwrapper.sh")

    #cleanup after easy_install
    sudo("rm -rf build")
509495
def install(packages, options=None, fatal=False):
    """"""
    cmd = ['yum', '--assumeyes']
    if options is not None:
        cmd.extend(options)
    cmd.append('install')
    if isinstance(packages, six.string_types):
        cmd.append(packages)
    else:
        cmd.extend(packages)
    log("Installing {} with options: {}".format(packages,
                                                options))
    _run_yum_command(cmd, fatal)
606824
def freeze():
    """"""
    echo_waiting('Verifying collected packages...')
    catalog, errors = make_catalog()
    if errors:
        for error in errors:
            echo_failure(error)
        abort()

    static_file = get_agent_requirements()

    echo_info('Static file: {}'.format(static_file))

    pre_packages = list(read_packages(static_file))

    catalog.write_packages(static_file)

    post_packages = list(read_packages(static_file))
    display_package_changes(pre_packages, post_packages)
872367
def other_dependencies(ctx, server, environment):
    """"""
    if 'extra_packages' in ctx.releaser:
        server = server.lower()
        extra_pkgs = []
        if server in ["local"]:
            if 'local' in ctx.releaser.extra_packages:
                extra_pkgs.extend(ctx.releaser.extra_packages.local)
        elif server in ["testpypi", "pypitest"]:
            # these are packages not available on the test server, so install them
            # off the regular pypi server
            if 'test' in ctx.releaser.extra_packages and \
                                ctx.releaser.extra_packages.test is not None:
                extra_pkgs.extend(ctx.releaser.extra_packages.test)
        elif server in ["pypi"]:
            if 'pypi' in ctx.releaser.extra_packages and \
                                ctx.releaser.extra_packages.pypi is not None:
                extra_pkgs.extend(ctx.releaser.extra_packages.pypi)
        else:
            print("** Nothing more to install **")

        if extra_pkgs:
            print('** Other Dependencies, based on server', server, '**')

        for pkg in extra_pkgs:
            result = invoke.run('env{0}{1}{0}Scripts{0}pip{2} install {3}'
                                .format(os.sep, environment, PIP_EXT, pkg),
                                hide=True)
            if result.ok:
                print('{}[{}GOOD{}] Installed {}'.format("", GOOD_COLOR,
                                                         RESET_COLOR, pkg))
            else:
                print('{}[{}ERROR{}] Something broke trying to install '
                      'package: {}'.format("", ERROR_COLOR, RESET_COLOR, pkg))
                print(result.stderr)
                sys.exit(1)
760885
def deploy_dotfiles(self, dotfiles):
        """"""
        if self.args.server:
            return self.deploy_remote(dotfiles)
        else:
            return self.deploy_local(dotfiles)
78487
def cli(ctx, packages, all, list, force, platform):
    """"""

    if packages:
        for package in packages:
            Installer(package, platform, force).install()
    elif all:  # pragma: no cover
        packages = Resources(platform).packages
        for package in packages:
            Installer(package, platform, force).install()
    elif list:
        Resources(platform).list_packages(installed=True, notinstalled=True)
    else:
        click.secho(ctx.get_help())
320571
def main():
    """"""
    try:
        pkg_version = Update()
        if pkg_version.updatable():
            pkg_version.show_message()
        metadata = control.retreive_metadata()
        parser = parse_options(metadata)
        argvs = sys.argv
        if len(argvs) <= 1:
            parser.print_help()
            sys.exit(1)
        args = parser.parse_args()
        control.print_licences(args, metadata)
        control.check_repository_existence(args)
        control.check_package_existence(args)
        control.generate_package(args)
    except (RuntimeError, BackendFailure, Conflict) as exc:
        sys.stderr.write('{0}\n'.format(exc))
        sys.exit(1)
270287
def attach(cls, name, vhost, remote_name):
        """"""
        paas_access = cls.get('paas_access')

        if not paas_access:
            paas_info = cls.info(name)
            paas_access = '%s@%s' \
                          % (paas_info['user'], paas_info['git_server'])

        remote_url = 'ssh+git://%s/%s.git' % (paas_access, vhost)

        ret = cls.execute('git remote add %s %s' % (remote_name, remote_url,))

        if ret:
            cls.echo('Added remote `%s` to your local git repository.'
                     % (remote_name))
            cls.echo('Use `git push %s master` to push your code to the '
                     'instance.' % (remote_name))
            cls.echo('Then `$ gandi deploy` to build and deploy your '
                     'application.')
1234947
def _instantiate_remote_sources(self, kwargs):
    """"""
    kwargs['dest'] = _DestWrapper((self._target_types[kwargs['dest']],))
    return RemoteSources(build_graph=self, **kwargs)
124625
def web(host, port):
    """"""
    from .webserver.web import get_app
    get_app().run(host=host, port=port)
387717
def setup_package():
    """"""
    import json
    from setuptools import setup, find_packages

    filename_setup_json = 'setup.json'
    filename_description = 'README.md'

    with open(filename_setup_json, 'r') as handle:
        setup_json = json.load(handle)

    with open(filename_description, 'r') as handle:
        description = handle.read()

    setup(
        include_package_data=True,
        packages=find_packages(),
        setup_requires=['reentry'],
        reentry_register=True,
        long_description=description,
        long_description_content_type='text/markdown',
        **setup_json)
453181
def setInstallMode(self, remote, on=True, t=60, mode=1, address=None):
        """"""
        if self._server is not None:
            return self._server.setInstallMode(remote, on, t, mode, address)
267398
function(req, res) {
            var packages = {};
            var appJSON = require('../../package.json');
            packages[appJSON.name] = appJSON;
            packages['onm'] = require('../onm/package.json');
            res.send(packages);
        }
887705
def copy_package(owner, repo, identifier, destination):
    """"""
    client = get_packages_api()

    with catch_raise_api_exception():
        data, _, headers = client.packages_copy_with_http_info(
            owner=owner,
            repo=repo,
            identifier=identifier,
            data={"destination": destination},
        )

    ratelimits.maybe_rate_limit(client, headers)
    return data.slug_perm, data.slug
506000
def add_package(
    self, target=None, package_manager=None, 
    package=None, type_option=None, version_option=None,
    node_paths=None, workunit_name=None, workunit_labels=None):
    """"""
    package_manager = package_manager or self.get_package_manager(target=target)
    command = package_manager.add_package(
      package,
      type_option=type_option,
      version_option=version_option,
      node_paths=node_paths,
    )
    return self._execute_command(
      command, workunit_name=workunit_name, workunit_labels=workunit_labels)
1012847
def update_package_files(srcdir, extensions, package_data, packagenames,
                         package_dirs):
    

    info = get_package_info(srcdir)
    extensions.extend(info['ext_modules'])
    package_data.update(info['package_data'])
    packagenames = list(set(packagenames + info['packages']))
    package_dirs.update(info['package_dir'])