Changeset 516 for yum/trunk/utils.py
Legend:
- Unmodified
- Added
- Removed
-
yum/trunk
-
Property svn:mergeinfo
set to
/yum/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
yum/trunk/utils.py
r2 r516 22 22 from yum import Errors 23 23 from yum import _ 24 from yum.i18n import utf8_width 24 25 from yum import logginglevels 25 26 from optparse import OptionGroup … … 58 59 return 59 60 61 try: 62 pid = int(pid) 63 except ValueError, e: 64 return 65 60 66 # Maybe true if /proc isn't mounted, or not Linux ... or something. 61 67 if (not os.path.exists("/proc/%d/status" % pid) or … … 101 107 102 108 def show_lock_owner(pid, logger): 103 if not pid:104 return105 106 109 ps = get_process_info(pid) 110 if not ps: 111 return None 112 107 113 # This yumBackend isn't very friendly, so... 108 114 if ps['name'] == 'yumBackend.py': … … 120 126 (time.ctime(ps['start_time']), ago)) 121 127 logger.critical(_(" State : %s, pid: %d") % (ps['state'], pid)) 128 129 return ps 130 131 132 def exception2msg(e): 133 """ DIE python DIE! Which one works: 134 to_unicode(e.value); unicode(e); str(e); 135 Call this so you don't have to care. """ 136 try: 137 return to_unicode(e.value) 138 except: 139 pass 140 141 try: 142 return unicode(e) 143 except: 144 pass 145 146 try: 147 return str(e) 148 except: 149 pass 150 return "<exception failed to convert to text>" 151 122 152 123 153 class YumUtilBase(YumBaseCli): … … 133 163 logger = logging.getLogger("yum.util") 134 164 verbose_logger = logging.getLogger("yum.verbose.util") 165 # Add yum-utils version to history records. 166 if hasattr(self, 'run_with_package_names'): 167 self.run_with_package_names.add("yum-utils") 168 169 def exUserCancel(self): 170 self.logger.critical(_('\n\nExiting on user cancel')) 171 if self.unlock(): return 200 172 return 1 173 174 def exIOError(self, e): 175 if e.errno == 32: 176 self.logger.critical(_('\n\nExiting on Broken Pipe')) 177 else: 178 self.logger.critical(_('\n\n%s') % exception2msg(e)) 179 if self.unlock(): return 200 180 return 1 181 182 def exPluginExit(self, e): 183 '''Called when a plugin raises PluginYumExit. 184 185 Log the plugin's exit message if one was supplied. 186 ''' # ' xemacs hack 187 exitmsg = exception2msg(e) 188 if exitmsg: 189 self.logger.warn('\n\n%s', exitmsg) 190 if self.unlock(): return 200 191 return 1 192 193 def exFatal(self, e): 194 self.logger.critical('\n\n%s', exception2msg(e)) 195 if self.unlock(): return 200 196 return 1 197 198 def unlock(self): 199 try: 200 self.closeRpmDB() 201 self.doUnlock() 202 except Errors.LockError, e: 203 return 200 204 return 0 135 205 136 206 … … 148 218 self.doLock() 149 219 except Errors.LockError, e: 150 if "%s" %(e.msg,) != lockerr:151 lockerr = "%s" %(e.msg,)220 if exception2msg(e) != lockerr: 221 lockerr = exception2msg(e) 152 222 self.logger.critical(lockerr) 153 self.logger.critical("Another app is currently holding the yum lock; waiting for it to exit...") 154 show_lock_owner(e.pid, self.logger) 155 time.sleep(2) 223 if not self.conf.exit_on_lock: 224 self.logger.critical("Another app is currently holding the yum lock; waiting for it to exit...") 225 show_lock_owner(e.pid, self.logger) 226 time.sleep(2) 227 else: 228 raise Errors.YumBaseError, _("Another app is currently holding the yum lock; exiting as configured by exit_on_lock") 156 229 else: 157 230 break … … 163 236 # Parse only command line options that affect basic yum setup 164 237 opts = self._parser.firstParse(args) 238 239 # go through all the setopts and set the global ones 240 self._parseSetOpts(opts.setopts) 241 242 if self.main_setopts: 243 for opt in self.main_setopts.items: 244 setattr(opts, opt, getattr(self.main_setopts, opt)) 245 165 246 # Just print out the version if that's what the user wanted 166 247 if opts.version: … … 188 269 if hasattr(opts, "enableplugins"): 189 270 pc.enabled_plugins = self._parser._splitArg(opts.enableplugins) 271 if hasattr(opts, "releasever"): 272 pc.releasever = opts.releasever 190 273 self.conf 191 274 275 # now set all the non-first-start opts from main from our setopts 276 if self.main_setopts: 277 for opt in self.main_setopts.items: 278 setattr(self.conf, opt, getattr(self.main_setopts, opt)) 279 192 280 except Errors.ConfigError, e: 193 self.logger.critical(_('Config Error: %s'), e )281 self.logger.critical(_('Config Error: %s'), exception2msg(e)) 194 282 sys.exit(1) 195 283 except ValueError, e: 196 self.logger.critical(_('Options Error: %s'), e )284 self.logger.critical(_('Options Error: %s'), exception2msg(e)) 197 285 sys.exit(1) 198 286 except plugins.PluginYumExit, e: 199 self.logger.critical(_('PluginExit Error: %s'), e )287 self.logger.critical(_('PluginExit Error: %s'), exception2msg(e)) 200 288 sys.exit(1) 201 289 except Errors.YumBaseError, e: 202 self.logger.critical(_('Yum Error: %s'), e )290 self.logger.critical(_('Yum Error: %s'), exception2msg(e)) 203 291 sys.exit(1) 204 292 … … 228 316 self._getSacks() 229 317 except Errors.YumBaseError, msg: 230 self.logger.critical( str(msg))318 self.logger.critical(exception2msg(msg)) 231 319 sys.exit(1) 232 320 321 def doUtilBuildTransaction(self, unfinished_transactions_check=True): 322 try: 323 (result, resultmsgs) = self.buildTransaction(unfinished_transactions_check = unfinished_transactions_check) 324 except plugins.PluginYumExit, e: 325 return self.exPluginExit(e) 326 except Errors.YumBaseError, e: 327 result = 1 328 resultmsgs = [exception2msg(e)] 329 except KeyboardInterrupt: 330 return self.exUserCancel() 331 except IOError, e: 332 return self.exIOError(e) 333 334 # Act on the depsolve result 335 if result == 0: 336 # Normal exit 337 if self.unlock(): return 200 338 return 0 339 elif result == 1: 340 # Fatal error 341 for msg in resultmsgs: 342 prefix = _('Error: %s') 343 prefix2nd = (' ' * (utf8_width(prefix) - 2)) 344 self.logger.critical(prefix, msg.replace('\n', '\n' + prefix2nd)) 345 if not self.conf.skip_broken: 346 self.verbose_logger.info(_(" You could try using --skip-broken to work around the problem")) 347 if not self._rpmdb_warn_checks(out=self.verbose_logger.info, warn=False): 348 self.verbose_logger.info(_(" You could try running: rpm -Va --nofiles --nodigest")) 349 if self.unlock(): return 200 350 return 1 351 elif result == 2: 352 # Continue on 353 pass 354 else: 355 self.logger.critical(_('Unknown Error(s): Exit Code: %d:'), result) 356 for msg in resultmsgs: 357 self.logger.critical(msg) 358 if self.unlock(): return 200 359 return 3 360 361 self.verbose_logger.log(logginglevels.INFO_2, _('\nDependencies Resolved')) 362 233 363 def doUtilTransaction(self): 234 def exUserCancel():235 self.logger.critical(_('\n\nExiting on user cancel'))236 if unlock(): return 200237 return 1238 239 def exIOError(e):240 if e.errno == 32:241 self.logger.critical(_('\n\nExiting on Broken Pipe'))242 else:243 self.logger.critical(_('\n\n%s') % str(e))244 if unlock(): return 200245 return 1246 247 def exPluginExit(e):248 '''Called when a plugin raises PluginYumExit.249 250 Log the plugin's exit message if one was supplied.251 ''' # ' xemacs hack252 exitmsg = str(e)253 if exitmsg:254 self.logger.warn('\n\n%s', exitmsg)255 if unlock(): return 200256 return 1257 258 def exFatal(e):259 self.logger.critical('\n\n%s', to_unicode(e.value))260 if unlock(): return 200261 return 1262 263 def unlock():264 try:265 self.closeRpmDB()266 self.doUnlock()267 except Errors.LockError, e:268 return 200269 return 0270 364 271 365 try: 272 366 return_code = self.doTransaction() 273 367 except plugins.PluginYumExit, e: 274 return exPluginExit(e)368 return self.exPluginExit(e) 275 369 except Errors.YumBaseError, e: 276 return exFatal(e)370 return self.exFatal(e) 277 371 except KeyboardInterrupt: 278 return exUserCancel()372 return self.exUserCancel() 279 373 except IOError, e: 280 return exIOError(e)374 return self.exIOError(e,) 281 375 282 376 self.verbose_logger.log(logginglevels.INFO_2, _('Complete!')) 283 if unlock(): return 200377 if self.unlock(): return 200 284 378 return return_code 285 379
Note:
See TracChangeset
for help on using the changeset viewer.
