comparison hgext/blackbox.py @ 25660:328739ea70c3

global: mass rewrite to use modern exception syntax Python 2.6 introduced the "except type as instance" syntax, replacing the "except type, instance" syntax that came before. Python 3 dropped support for the latter syntax. Since we no longer support Python 2.4 or 2.5, we have no need to continue supporting the "except type, instance". This patch mass rewrites the exception syntax to be Python 2.6+ and Python 3 compatible. This patch was produced by running `2to3 -f except -w -n .`.
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 23 Jun 2015 22:20:08 -0700
parents 80c5b2666a96
children e8f9dffca36f
comparison
equal deleted inserted replaced
25659:d60678a567a9 25660:328739ea70c3
50 50
51 def _openlogfile(self): 51 def _openlogfile(self):
52 def rotate(oldpath, newpath): 52 def rotate(oldpath, newpath):
53 try: 53 try:
54 os.unlink(newpath) 54 os.unlink(newpath)
55 except OSError, err: 55 except OSError as err:
56 if err.errno != errno.ENOENT: 56 if err.errno != errno.ENOENT:
57 self.debug("warning: cannot remove '%s': %s\n" % 57 self.debug("warning: cannot remove '%s': %s\n" %
58 (newpath, err.strerror)) 58 (newpath, err.strerror))
59 try: 59 try:
60 if newpath: 60 if newpath:
61 os.rename(oldpath, newpath) 61 os.rename(oldpath, newpath)
62 except OSError, err: 62 except OSError as err:
63 if err.errno != errno.ENOENT: 63 if err.errno != errno.ENOENT:
64 self.debug("warning: cannot rename '%s' to '%s': %s\n" % 64 self.debug("warning: cannot rename '%s' to '%s': %s\n" %
65 (newpath, oldpath, err.strerror)) 65 (newpath, oldpath, err.strerror))
66 66
67 fp = self._bbopener('blackbox.log', 'a') 67 fp = self._bbopener('blackbox.log', 'a')
90 if util.safehasattr(self, '_blackbox'): 90 if util.safehasattr(self, '_blackbox'):
91 blackbox = self._blackbox 91 blackbox = self._blackbox
92 elif util.safehasattr(self, '_bbopener'): 92 elif util.safehasattr(self, '_bbopener'):
93 try: 93 try:
94 self._blackbox = self._openlogfile() 94 self._blackbox = self._openlogfile()
95 except (IOError, OSError), err: 95 except (IOError, OSError) as err:
96 self.debug('warning: cannot write to blackbox.log: %s\n' % 96 self.debug('warning: cannot write to blackbox.log: %s\n' %
97 err.strerror) 97 err.strerror)
98 del self._bbopener 98 del self._bbopener
99 self._blackbox = None 99 self._blackbox = None
100 blackbox = self._blackbox 100 blackbox = self._blackbox
108 date = util.datestr(None, '%Y/%m/%d %H:%M:%S') 108 date = util.datestr(None, '%Y/%m/%d %H:%M:%S')
109 user = util.getuser() 109 user = util.getuser()
110 formattedmsg = msg[0] % msg[1:] 110 formattedmsg = msg[0] % msg[1:]
111 try: 111 try:
112 blackbox.write('%s %s> %s' % (date, user, formattedmsg)) 112 blackbox.write('%s %s> %s' % (date, user, formattedmsg))
113 except IOError, err: 113 except IOError as err:
114 self.debug('warning: cannot write to blackbox.log: %s\n' % 114 self.debug('warning: cannot write to blackbox.log: %s\n' %
115 err.strerror) 115 err.strerror)
116 lastblackbox = blackbox 116 lastblackbox = blackbox
117 117
118 def setrepo(self, repo): 118 def setrepo(self, repo):