comparison mercurial/util.py @ 6499:479847ccabe0

Added hgexecutable support for py2exe/frozen scripts
author "Paul Moore <p.f.moore@gmail.com>"
date Thu, 20 Dec 2007 20:02:51 +0000
parents 3da652f2039c
children a3175cd7dbec
comparison
equal deleted inserted replaced
5666:9d6ad26fab10 6499:479847ccabe0
13 """ 13 """
14 14
15 from i18n import _ 15 from i18n import _
16 import cStringIO, errno, getpass, popen2, re, shutil, sys, tempfile, strutil 16 import cStringIO, errno, getpass, popen2, re, shutil, sys, tempfile, strutil
17 import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil 17 import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil
18 import re, urlparse 18 import re, urlparse, imp
19 19
20 try: 20 try:
21 set = set 21 set = set
22 frozenset = frozenset 22 frozenset = frozenset
23 except NameError: 23 except NameError:
551 551
552 return (roots, match, (inc or exc or anypats) and True) 552 return (roots, match, (inc or exc or anypats) and True)
553 553
554 _hgexecutable = None 554 _hgexecutable = None
555 555
556 def main_is_frozen():
557 """return True if we are a frozen executable.
558
559 The code supports py2exe (most common, Windows only) and tools/freeze
560 (portable, not much used).
561 """
562 return (hasattr(sys, "frozen") or # new py2exe
563 hasattr(sys, "importers") or # old py2exe
564 imp.is_frozen("__main__")) # tools/freeze
565
556 def hgexecutable(): 566 def hgexecutable():
557 """return location of the 'hg' executable. 567 """return location of the 'hg' executable.
558 568
559 Defaults to $HG or 'hg' in the search path. 569 Defaults to $HG or 'hg' in the search path.
560 """ 570 """
561 if _hgexecutable is None: 571 if _hgexecutable is None:
562 set_hgexecutable(os.environ.get('HG') or find_exe('hg', 'hg')) 572 if os.environ.has_key('HG'):
573 set_hgexecutable(os.environ.get('HG'))
574 elif main_is_frozen():
575 set_hgexecutable(sys.executable)
576 else:
577 sel_hgexecutable(find_exe('hg', 'hg'))
563 return _hgexecutable 578 return _hgexecutable
564 579
565 def set_hgexecutable(path): 580 def set_hgexecutable(path):
566 """set location of the 'hg' executable""" 581 """set location of the 'hg' executable"""
567 global _hgexecutable 582 global _hgexecutable