[Pkg-bazaar-commits] ./bzr/unstable r59: lift out tracefile creation code
mbp at sourcefrog.net
mbp at sourcefrog.net
Fri Apr 10 07:27:02 UTC 2009
------------------------------------------------------------
revno: 59
committer: mbp at sourcefrog.net
timestamp: Tue 2005-03-22 11:37:17 +1100
message:
lift out tracefile creation code
modified:
bzrlib/commands.py
bzrlib/trace.py
-------------- next part --------------
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2005-03-22 00:24:14 +0000
+++ b/bzrlib/commands.py 2005-03-22 00:37:17 +0000
@@ -761,30 +761,10 @@
## TODO: If the arguments are wrong, give a usage message rather
## than just a backtrace.
+ bzrlib.trace.create_tracefile(argv)
+
try:
- # TODO: Lift into separate function in trace.py
- # TODO: Also show contents of /etc/lsb-release, if it can be parsed.
- # Perhaps that should eventually go into the platform library?
- # TODO: If the file doesn't exist, add a note describing it.
- t = bzrlib.trace._tracefile
- t.write('-' * 60 + '\n')
- t.write('bzr invoked at %s\n' % format_date(time.time()))
- t.write(' by %s on %s\n' % (bzrlib.osutils.username(), socket.getfqdn()))
- t.write(' arguments: %r\n' % argv)
-
- starttime = os.times()[4]
-
- import platform
- t.write(' platform: %s\n' % platform.platform())
- t.write(' python: %s\n' % platform.python_version())
-
ret = run_bzr(argv)
-
- times = os.times()
- mutter("finished, %.3fu/%.3fs cpu, %.3fu/%.3fs cum"
- % times[:4])
- mutter(" %.3f elapsed" % (times[4] - starttime))
-
return ret
except BzrError, e:
log_error('bzr: error: ' + e.args[0] + '\n')
=== modified file 'bzrlib/trace.py'
--- a/bzrlib/trace.py 2005-03-09 04:08:15 +0000
+++ b/bzrlib/trace.py 2005-03-22 00:37:17 +0000
@@ -20,19 +20,17 @@
__author__ = "Martin Pool <mbp at canonical.com>"
-import sys
+import sys, os, time, socket
+import bzrlib
######################################################################
# messages and logging
-# Messages are always written to here, so that we have some
-# information if something goes wrong. In a future version this
-# file will be removed on successful completion.
-_tracefile = file('.bzr.log', 'at')
-
## TODO: If --verbose is given then write to both stderr and
## _tracefile; perhaps replace _tracefile with a tee thing.
+global _tracefile, _starttime
+
# used to have % (os.environ['USER'], time.time(), os.getpid()), 'w')
@@ -63,3 +61,42 @@
sys.stderr.write(msg)
_tracefile.write(msg)
_tracefile.flush()
+
+
+
+def create_tracefile(argv):
+ # TODO: Also show contents of /etc/lsb-release, if it can be parsed.
+ # Perhaps that should eventually go into the platform library?
+ # TODO: If the file doesn't exist, add a note describing it.
+
+ # Messages are always written to here, so that we have some
+ # information if something goes wrong. In a future version this
+ # file will be removed on successful completion.
+ global _starttime, _tracefile
+
+ _starttime = os.times()[4]
+
+ _tracefile = file('.bzr.log', 'at')
+
+ t = _tracefile
+
+ t.write('-' * 60 + '\n')
+ t.write('bzr invoked at %s\n' % bzrlib.osutils.format_date(time.time()))
+ t.write(' by %s on %s\n' % (bzrlib.osutils.username(), socket.getfqdn()))
+ t.write(' arguments: %r\n' % argv)
+
+ import platform
+ t.write(' platform: %s\n' % platform.platform())
+ t.write(' python: %s\n' % platform.python_version())
+
+ import atexit
+ atexit.register(_close_trace)
+
+
+def _close_trace():
+ times = os.times()
+ mutter("finished, %.3fu/%.3fs cpu, %.3fu/%.3fs cum, %.3f elapsed"
+ % (times[:4] + ((times[4] - _starttime),)))
+
+
+
More information about the Pkg-bazaar-commits
mailing list