enable --profile/--time/--traceback/--debug options as mercurial axtension (closes #83309)

authorAlain Leufroy <alain.leufroy@logilab.fr>
changeset76e2e9a3d14f
branchdefault
phasepublic
hiddenno
parent revision#4a4bf50245b0 [fix core] raise ApplicationError and do not display traceback for NotImplementedErro (closes #78004 #83307)
child revision#b7d8554f52ea [curses] fancier graph highlighting for nodes (imrpove #79263)
files modified by this revision
hgext/hgview.py
hgviewlib/application.py
hgviewlib/curses/application.py
hgviewlib/qt4/application.py
# HG changeset patch
# User Alain Leufroy <alain.leufroy@logilab.fr>
# Date 1321811092 -3600
# Sun Nov 20 18:44:52 2011 +0100
# Node ID 76e2e9a3d14fe74baafae280d3bf59aebe3ba883
# Parent 4a4bf50245b00da51cd971a7f89fafadfacb1c65
enable --profile/--time/--traceback/--debug options as mercurial axtension (closes #83309)

diff --git a/hgext/hgview.py b/hgext/hgview.py
@@ -61,11 +61,12 @@
1              """process errors"""
2              raise(error.Abort(text))
3          options = Values(opts)
4          start(repo, options, pats, fnerror)
5      except Exception, e:
6 -        print e
7 +        if ui.config('ui', 'traceback'):
8 +            raise
9          # If we're unable to start hgviewlib from here, try to
10          # run the application directly.
11          # You can specificy it's location in ~/.hgrc via
12          #   [hgview]
13          #   path=
@@ -73,10 +74,19 @@
14          cmd += ['--%s %s' % (name, value)
15                  for name, value in opts.iteritems() if value]
16          cmd += ['-R %s' % repo.root]
17          if pats:
18              cmd += list(pats)
19 +        if ui.configlist('ui', 'debug'):
20 +            sys.stdout.write('Enable to run Hg extension: ')
21 +            sys.stdout.write(str(e))
22 +            sys.stdout.write('\n')
23 +            sys.stdout.write('-> starting alternative command:')
24 +            sys.stdout.write('\n')
25 +            sys.stdout.write(' '.join(cmd))
26 +            sys.stdout.write('\n')
27 +            sys.stdout.flush()
28          os.system(' '.join(cmd))
29 
30  import sys
31  sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
32  import hgviewlib.hgviewhelp as hghelp
diff --git a/hgviewlib/application.py b/hgviewlib/application.py
@@ -136,11 +136,11 @@
33      try:
34          app = Application(repo, opts, args)
35      except (ApplicationError, NotImplementedError), err:
36          fnerror(str(err))
37 
38 -    sys.exit(app.exec_())
39 +    return app.exec_()
40 
41  def main():
42      """
43      Main application acces point.
44      """
@@ -184,11 +184,13 @@
45          repo = hg.repository(u, dir_)
46      except RepoError, e:
47          parser.error(e)
48      except:
49          parser.error("There is no Mercurial repository here (.hg not found)!")
50 -    start(repo, opts, args, parser.error)
51 -
52 +    try:
53 +        sys.exit(start(repo, opts, args, parser.error))
54 +    except KeyboardInterrupt:
55 +        print 'interrupted!'
56 
57  if __name__ == "__main__":
58      main()
59 
diff --git a/hgviewlib/curses/application.py b/hgviewlib/curses/application.py
@@ -18,10 +18,11 @@
60  """
61  Application utilities.
62  """
63  import threading
64  import logging
65 +import sys
66 
67  from urwid import AttrWrap, MainLoop
68 
69  from hgviewlib.application import HgViewApplication
70  from hgviewlib.curses.hgrepoviewer import RepoViewer
@@ -81,10 +82,12 @@
71              if optimize_inotify:
72                  ctypes.util.find_library = orig
73 
74      def exec_(self):
75          '''main entry point'''
76 +        if '--profile' in sys.argv or '--time' in sys.argv:
77 +            self.mainloop._run = self.mainloop.draw_screen
78          out = self.mainloop.run()
79          self.mainframe.unregister_commands()
80          return out
81 
82  # _____________________________________________________________________ inotify
diff --git a/hgviewlib/qt4/application.py b/hgviewlib/qt4/application.py
@@ -51,9 +51,11 @@
83 
84          self.app = app
85 
86      def exec_(self):
87          self.viewer.show()
88 +        if '--profile' in sys.argv or '--time' in sys.argv:
89 +            return 0
90          return self.app.exec_()
91 
92 
93