コード例 #1
0
ファイル: __init__.py プロジェクト: TATUMTOT/SickRage
def upgrade_pkgs(user=False):
    import pip
    from pip.commands.list import ListCommand

    pip_list = ListCommand()
    pip_options = pip_list.parse_args(['--no-cache-dir', '-o'] + [('', '--user')[user]])

    while (True):
        # list packages that need upgrading
        try:
            packages = [p.project_name for p, y, _ in pip_list.find_packages_latest_versions(pip_options[0])
                        if p.version == y.available]
        except:
            packages = []

        for i, pkg_name in enumerate(packages, start=1):
            try:
                print(r"[%3.2f%%]::Upgrading %s package" % (i * 100 / len(packages), pkg_name.lower()))
                pip.main(['-q', 'install', '-U'] + [('', '--user')[user]] + [pkg_name])
            except IndexError:
                continue
            except KeyboardInterrupt:
                raise
        else:
            break
コード例 #2
0
ファイル: __init__.py プロジェクト: ipmcc/SiCKRAGE
def upgrade_packages(constraints, user=False):
    from pip.commands.list import ListCommand
    from pip.commands.install import InstallCommand
    from pip.exceptions import InstallationError

    packages = []

    pip_install_cmd = InstallCommand()
    pip_list_cmd = ListCommand()


    while True:
        # list packages that need upgrading
        try:
            options = pip_list_cmd.parse_args([])[0]
            options.use_user_site = user
            options.cache_dir = None
            options.outdated = True

            packages = [p.project_name for p, y, _ in pip_list_cmd.find_packages_latest_versions(options)
                        if getattr(p, 'version', 0) != getattr(y, 'public', 0)]
        except:
            packages = []

        # Never upgrade yourself. It doesn't end well. (Any sources already loaded are the old version, anything
        # loaded after this is the new version, it's a mess. It also borks development installs.)
        if "sickrage" in packages:
            packages.remove("sickrage")

        options = pip_install_cmd.parse_args([])[0]
        options.use_user_site = user
        options.constraints = [constraints]
        options.cache_dir = None
        options.upgrade = True
        options.quiet = 1

        for i, pkg_name in enumerate(packages, start=1):
            try:
                print(r"[%3.2f%%]::Upgrading %s package" % (i * 100 / len(packages), pkg_name.lower()))
                pip_install_cmd.run(options, [pkg_name])
            except InstallationError:
                try:
                    options.ignore_dependencies = True
                    pip_install_cmd.run(options, [pkg_name])
                except:continue
            except IndexError:
                continue
        else:
            break
コード例 #3
0
ファイル: __init__.py プロジェクト: Wuebit34/SiCKRAGE
def upgrade_packages(constraints, user=False):
    from pip.commands.list import ListCommand
    from pip.commands.install import InstallCommand
    from pip.exceptions import InstallationError

    packages = []

    pip_install_cmd = InstallCommand()
    pip_list_cmd = ListCommand()


    while True:
        # list packages that need upgrading
        try:
            options = pip_list_cmd.parse_args([])[0]
            options.use_user_site = user
            options.cache_dir = None
            options.outdated = True

            packages = [p.project_name for p, y, _ in pip_list_cmd.find_packages_latest_versions(options)
                        if getattr(p, 'version', 0) != getattr(y, 'public', 0)]
        except:
            packages = []

        options = pip_install_cmd.parse_args([])[0]
        options.use_user_site = user
        options.constraints = [constraints]
        options.cache_dir = None
        options.upgrade = True
        options.quiet = 1

        for i, pkg_name in enumerate(packages, start=1):
            try:
                print(r"[%3.2f%%]::Upgrading %s package" % (i * 100 / len(packages), pkg_name.lower()))
                pip_install_cmd.run(options, [pkg_name])
            except InstallationError:
                try:
                    options.ignore_dependencies = True
                    pip_install_cmd.run(options, [pkg_name])
                except:continue
            except IndexError:
                continue
        else:
            break
コード例 #4
0
def check_versions(only_leonardo=False):
    '''returns dictionary of modules with versions to could be updated

    return:: {
            'name': {
                        'old': '1.0.1',
                        'new': '1.0.2',
                        'type': wheel
                    }
            }
    '''

    global LEONARDO_ENV
    global GLOBAL_ENV

    if only_leonardo:
        if LEONARDO_ENV:
            return LEONARDO_ENV
    else:
        if GLOBAL_ENV:
            return GLOBAL_ENV

    listing = ListCommand()
    options, args = listing.parse_args([])

    update = {}

    for dist, version, typ in listing.find_packages_latest_versions(options):
        if only_leonardo:
            pkg_names = [k for k in dist._get_metadata("top_level.txt")]
            for pkg_name in pkg_names:
                try:
                    mod = import_module(pkg_name)
                except:
                    pass
                else:
                    if is_leonardo_module(mod):
                        if version > dist.parsed_version:
                            update.update({
                                dist.project_name: {
                                    'old': dist.version,
                                    'new': version,
                                    'type': typ
                                }
                            })
        else:
            if version > dist.parsed_version:
                update.update({
                    dist.project_name: {
                        'old': dist.version,
                        'new': version,
                        'type': typ
                    }
                })

    if only_leonardo:
        LEONARDO_ENV = update
    else:
        GLOBAL_ENV = update

    return update