Seth Vidal has a better solution. Rather than just catching the exception, you can prevent it by correcting the error in the code, as noted by Anonymous in the comments:
Patch from Seth Vidal: https://bugzilla.redhat.com/show_bug.cgi?id=538118#c41 diff --git a/preupgrade/__init__.py b/preupgrade/__init__.py index 2e82f1e..d79ec4b 100644 --- a/preupgrade/__init__.py +++ b/preupgrade/__init__.py @@ -325,7 +325,7 @@ class PreUpgrade(yum.YumBase): rf = open(repofile,"w") for repo in [self.instrepo] + self.repos.listEnabled(): # adapted from YumRepository.write() - repo._grabfunc.opts.user_agent = __user_agent__ + repo.grabfunc.opts.user_agent = __user_agent__ yc = yumConfigParser() yc.add_section(repo.id) for k,v in repo.iteritems():
So the problem is that it tried to use _grabfunc, which doesn't exist, instead of grabfunc. Yay.
I was trying to upgrade to Fedora 12 today via preupgrade but had to stop my upgrade session due to a network issue. When I tried to resume, as you're supposed to be able to do, it started getting the metadata again and then it suddenly crashed!
[root@localhost ~]# preupgrade /usr/lib/python2.6/site-packages/yum/__init__.py:203: UserWarning: Use .preconf instead of passing args to _getConfig warnings.warn('Use .preconf instead of passing args to _getConfig') Loaded plugins: blacklist, dellsysidplugin2, presto, refresh-packagekit, : whiteout Detected in-progress upgrade to Fedora 12 (Constantine) .... preupgrade-updates (mirrorlist) url: https://mirrors.fedoraproject.org/metalink?repo=updates-released-f12&arch=i386 now: https://mirrors.fedoraproject.org/metalink?repo=updates-released-f12&arch=i386 unknown metadata being downloaded: metalink Traceback (most recent call last): File "/usr/share/preupgrade/preupgrade-gtk.py", line 764, in
widgets = PreUpgradeGtk() File "/usr/share/preupgrade/preupgrade-gtk.py", line 376, in __init__ self._do_main() File "/usr/share/preupgrade/preupgrade-gtk.py", line 259, in _do_main self.main_preupgrade() File "/usr/share/preupgrade/preupgrade-gtk.py", line 436, in main_preupgrade download_progressbar=self.dnlProgress) File "/usr/lib/python2.6/site-packages/preupgrade/__init__.py", line 130, in setup self.complete_repo_setup() File "/usr/lib/python2.6/site-packages/preupgrade/__init__.py", line 328, in complete_repo_setup repo._grabfunc.opts.user_agent = __user_agent__ AttributeError: 'NoneType' object has no attribute 'opts'
That's obnoxious. I didn't want to restart it, as I'd already downloaded over a hundred MB of files. So, as root I looked at the file tripping the AttributeError, /usr/lib/python2.6/site-packages/preupgrade/__init__.py, and decided to catch the error:
repo._grabfunc.opts.user_agent = __user_agent__
try: repo._grabfunc.opts.user_agent = __user_agent__ except AttributeError: print "Can't set user_agent, repo._grabfunc = NoneType :( "
I then ran it again, and this caught two exceptions, but allowed me to proceed with seemingly no loss of functionality. I am now happily downloading still more amazing amounts of MB. Hurrah!
Now to file a relevant bug if it doesn't already exist. The oft duplicated, already existent RH bug is 538118.