Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 173657 Details for
Bug 249177
Alternative to app-admin/python-updater
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
python-updater.py
python-updater.py (text/plain), 4.77 KB, created by
michael@smith-li.com
on 2008-11-28 16:44:51 UTC
(
hide
)
Description:
python-updater.py
Filename:
MIME Type:
Creator:
michael@smith-li.com
Created:
2008-11-28 16:44:51 UTC
Size:
4.77 KB
patch
obsolete
>#!/usr/bin/python > >import sys >from getopt import getopt, GetoptError >from os.path import exists >from os import system, execve # Don't use subprocess -- it could break older pythons >import portage > >__author__ = "Michael Alexander Smith" >__email__ = "michael@smith-li.com" >__version__ = 0.1 >__productname__ = "python-updater" >__license__ = "Distributed under the terms of the GNU General Public License v2" >__copyright__ = """ >Copyright 2008 Michael Alexander Smith >Copyright 2008 Gentoo Technologies, Inc. >""" >__description__ = """ >Rewrite of bash script by the same name. > >Tries to update everything that maybe related to an older version of python. >This script can be run as many times as you like. >""" > >pkgs_except = ( > "dev-lang/python", > "sys-apps/portage", >) >pkgs_manual = ( > "app-office/gnumeric", > "app-office/dia", > "x11-libs/vte", >) > ># python versions: ># (only interested in MAJOR.MINOR >versions = {'new': sys.version_info[0:2],} > >options = { > "help": ("h", "This help text",), > "direct-only": ("d", "Don't consider indirect (a.k.a. manually added) packages",), > "ignore-versions": ("i", "Remerge based on package slot, not specific version",), > "pretend": ("p", "Show what the package manager would do, but don't actually do it",), > "old-version=": ("o:", "Override the detected old version of python",), >} > >def help(): > print "usage: python-updater [options]" > for longopt in options.keys().sort(): > shortopt, optdesc = options[longopt] > if longopt.endswith("="): > longopt = longopt[0:-1] + " NAME" > shortopt = shortopt[0:-1] + " NAME" > print "--%s (-%s) %s" % (longopt, shortopt, optdesc,) >usage = help > >config = { > 'direct-only': False, > 'ignore-versions': False, > 'pretend': False, >} > >## ># Determine old python version >def get_old_python_version(): > if versions.has_key("old"): > return > > for old in [(2,x) for x in range(5,1,-1)]: > if old != versions['new']: > if exists("/usr/bin/python%s.%s" % old): > versions['old'] = old > return > > if not versions.has_key("old"): > print >> sys.stderr, "Can't determine previous Python version" > sys.exit(1) > >def initialize(): > > try: > # longopts needs to be a list > longopts = options.keys() > # shortopts needs to be a string > shortopts = "".join([o[0] for k, o in options.items()]) > opts, args = getopt(sys.argv[1:], shortopts, longopts) > except GetoptError, err: > print >> sys.stderr, str(err) > help() > sys.exit(1) > > for o, a in opts: > if o in ("-h", "--help",): > help() > sys.exit() > elif o in ("-d", "--direct-only",): > config['direct-only'] = True > elif o in ("-i", "--ignore-versions",): > config['ignore-versions'] = True > elif o in ("-p", "--pretend",): > config['pretend'] = True > elif o in ("-o", "--old-version",): > config['old-version'] = a > else: > assert False, "unhandled option %s=%s" % (o, a,) > > get_old_python_version() > > ## > # Test where portage is, in python2.2 or somewhere else? > for py in ( > "/usr/bin/python", > "/usr/bin/python%s.%s" % versions['old'], > "/usr/bin/python%s.%s" % versions['new'], > ): > # Will only be zero if the command is successful > if not system("%s -c 'import portage' > /dev/null 2>&1" % py): > portage_python = py > break > > assert portage_python, "portage_python should be set to some value." > >## ># Find all packages that have installed something in ># /usr/lib/python${OLD_PY_VER} >def main(): > initialize() > > old_search_paths = [p % versions['old'] for p in ( > "/usr/lib/python%s.%s", > "/usr/lib32/python%s.%s", > "/usr/lib64/python%s.%s", > "/usr/include/python%s.%s", > )] > old_search_paths = [p for p in old_search_paths if exists(p)] > > print "Starting Python Updater from %s.%s to %s.%s:" % (versions['old'] + versions['new']) > print "Searching for packages with files in %s" % ", ".join(old_search_paths) > # portage variables > portage_config = portage.config() > > rebuild_list = [] > # iterate thru all the installed packages' contents > for cpv in portage.vardbapi(portage.root).cpv_all(): > # Skip exceptions > if portage.getCPFromCPV(cpv) in pkgs_except: > continue > cat, pkg = (cpv.split("/")) > dblink = portage.dblink(cat, pkg, portage.root, portage_config) > for search_path in old_search_paths: > if [f for f in dblink.getcontents() if f.startswith(search_path)]: > rebuild_list += ["%s:%s" % (portage.getCPFromCPV(cpv), portage.portagetree().getslot(cpv),)] > break; > # Check if package is in PKGS_MANUAL > #if [[ DIRECT_ONLY -ne 1 ]]; then > # for pkg in ${PKGS_MANUAL}; do > # if [ -n "$(echo ${CATPKGVER} | grep ${pkg})" ]; then > # exception=2 > # break; > # fi > # done > # fi > > if not rebuild_list: > print "No packages found build on Python %s.%s" % versions['old'] > sys.exit() > > #portage_config['EMERGE_DEFAULT_OPTS'] = "--pretend --verbose" > #execve("/usr/bin/emerge", rebuild_list, portage_config,) > print " ".join(rebuild_list) > > >if __name__ == "__main__": > main()
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 249177
: 173657