Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 14968:b7dbe957585c
util: use safehasattr or getattr instead of hasattr
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Mon, 25 Jul 2011 16:04:40 -0500 |
parents | 5b072d4b62f2 |
children | f6a737357195 |
comparison
equal
deleted
inserted
replaced
14967:376091a4ad23 | 14968:b7dbe957585c |
---|---|
356 """return True if we are a frozen executable. | 356 """return True if we are a frozen executable. |
357 | 357 |
358 The code supports py2exe (most common, Windows only) and tools/freeze | 358 The code supports py2exe (most common, Windows only) and tools/freeze |
359 (portable, not much used). | 359 (portable, not much used). |
360 """ | 360 """ |
361 return (hasattr(sys, "frozen") or # new py2exe | 361 return (safehasattr(sys, "frozen") or # new py2exe |
362 hasattr(sys, "importers") or # old py2exe | 362 safehasattr(sys, "importers") or # old py2exe |
363 imp.is_frozen("__main__")) # tools/freeze | 363 imp.is_frozen("__main__")) # tools/freeze |
364 | 364 |
365 def hgexecutable(): | 365 def hgexecutable(): |
366 """return location of the 'hg' executable. | 366 """return location of the 'hg' executable. |
367 | 367 |
781 except OSError: | 781 except OSError: |
782 pass | 782 pass |
783 self._fp.close() | 783 self._fp.close() |
784 | 784 |
785 def __del__(self): | 785 def __del__(self): |
786 if hasattr(self, '_fp'): # constructor actually did something | 786 if safehasattr(self, '_fp'): # constructor actually did something |
787 self.close() | 787 self.close() |
788 | 788 |
789 def makedirs(name, mode=None): | 789 def makedirs(name, mode=None): |
790 """recursive directory creation with parent mode inheritance""" | 790 """recursive directory creation with parent mode inheritance""" |
791 parent = os.path.abspath(os.path.dirname(name)) | 791 parent = os.path.abspath(os.path.dirname(name)) |
1252 # us our child process terminated. | 1252 # us our child process terminated. |
1253 terminated = set() | 1253 terminated = set() |
1254 def handler(signum, frame): | 1254 def handler(signum, frame): |
1255 terminated.add(os.wait()) | 1255 terminated.add(os.wait()) |
1256 prevhandler = None | 1256 prevhandler = None |
1257 if hasattr(signal, 'SIGCHLD'): | 1257 SIGCHLD = getattr(signal, 'SIGCHLD', None) |
1258 prevhandler = signal.signal(signal.SIGCHLD, handler) | 1258 if SIGCHLD is not None: |
1259 prevhandler = signal.signal(SIGCHLD, handler) | |
1259 try: | 1260 try: |
1260 pid = spawndetached(args) | 1261 pid = spawndetached(args) |
1261 while not condfn(): | 1262 while not condfn(): |
1262 if ((pid in terminated or not testpid(pid)) | 1263 if ((pid in terminated or not testpid(pid)) |
1263 and not condfn()): | 1264 and not condfn()): |