From: Catalin Marinas Date: Wed, 1 Mar 2006 21:41:55 +0000 (+0000) Subject: Allow stg to be loaded in pydb and not run main() X-Git-Tag: v0.14.3~536 X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/commitdiff_plain/38242738db8f183958ecab18a3604497d0fa592c Allow stg to be loaded in pydb and not run main() This patch adds the __name__ == '__main__' condition to stg*. It also adds a stg-dbg file that starts pdb before invoking main(). Signed-off-by: Catalin Marinas --- diff --git a/stg b/stg index 5682dd4..def843c 100755 --- a/stg +++ b/stg @@ -39,4 +39,5 @@ if bin == 'bin' and prefix != sys.prefix: from stgit.main import main -main() +if __name__ == '__main__': + main() diff --git a/stg-dbg b/stg-dbg new file mode 100755 index 0000000..0c3ad39 --- /dev/null +++ b/stg-dbg @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# -*- python-mode -*- +"""Takes care of starting the Init function +""" + +__copyright__ = """ +Copyright (C) 2005, Catalin Marinas + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License version 2 as +published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +""" + +import sys, os, pdb + +# Try to detect where it is run from and set prefix and the search path. +# It is assumed that the user installed StGIT using the --prefix= option +prefix, bin = os.path.split(sys.path[0]) + +if bin == 'bin' and prefix != sys.prefix: + sys.prefix = prefix + sys.exec_prefix = prefix + + major, minor = sys.version_info[0:2] + local_path = [os.path.join(prefix, 'lib', 'python'), + os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor)), + os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor), + 'site-packages')] + sys.path = local_path + sys.path + +from stgit.main import main + +if __name__ == '__main__': + pdb.run('main()') diff --git a/stg-prof b/stg-prof index 8bbb623..de7bd13 100755 --- a/stg-prof +++ b/stg-prof @@ -40,13 +40,14 @@ if bin == 'bin' and prefix != sys.prefix: from stgit.main import main -start_time = time.time() -def timer(): - return time.time() - start_time - -prof = profile.Profile(timer) -try: - prof.run('main()') -except SystemExit: - pass -pstats.Stats(prof).strip_dirs().sort_stats(-1).print_stats().print_callees() +if __name__ == '__main__': + start_time = time.time() + def timer(): + return time.time() - start_time + + prof = profile.Profile(timer) + try: + prof.run('main()') + except SystemExit: + pass + pstats.Stats(prof).strip_dirs().sort_stats(-1).print_stats().print_callees()