📄 macemu.py
字号:
# # ***** BEGIN LICENSE BLOCK *****# Source last modified: $Id: macemu.py,v 1.12 2004/07/07 22:00:04 hubbe Exp $# # Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.# # The contents of this file, and the files included with this file,# are subject to the current version of the RealNetworks Public# Source License (the "RPSL") available at# http://www.helixcommunity.org/content/rpsl unless you have licensed# the file under the current version of the RealNetworks Community# Source License (the "RCSL") available at# http://www.helixcommunity.org/content/rcsl, in which case the RCSL# will apply. You may also obtain the license terms directly from# RealNetworks. You may not use this file except in compliance with# the RPSL or, if you have a valid RCSL with RealNetworks applicable# to this file, the RCSL. Please see the applicable RPSL or RCSL for# the rights, obligations and limitations governing use of the# contents of the file.# # Alternatively, the contents of this file may be used under the# terms of the GNU General Public License Version 2 or later (the# "GPL") in which case the provisions of the GPL are applicable# instead of those above. If you wish to allow use of your version of# this file only under the terms of the GPL, and not to allow others# to use your version of this file under the terms of either the RPSL# or RCSL, indicate your decision by deleting the provisions above# and replace them with the notice and other provisions required by# the GPL. If you do not delete the provisions above, a recipient may# use your version of this file under the terms of any one of the# RPSL, the RCSL or the GPL.# # This file is part of the Helix DNA Technology. RealNetworks is the# developer of the Original Code and owns the copyrights in the# portions it created.# # This file, and the files included with this file, is distributed# and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY# KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS# ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET# ENJOYMENT OR NON-INFRINGEMENT.# # Technology Compatibility Kit Test Suite(s) Location:# http://www.helixcommunity.org/content/tck# # Contributor(s):# # ***** END LICENSE BLOCK *****# #### This file allows a posix-style system to emulate macpython## Only import this on darwin when running codewarrior builds#### Relies heavily on:## /Developer/Tools/SetFile## /Developer/Tools/GetFileInfo## /usr/bin/open## /usr/bin/osascript## /usr/bin/osacompile## StuffIt## Mactools (patched) (esp. the binhex command)##import stringimport osimport sysif os.environ.get("PYTHON_FULL_PATH_KLUGE","NO") != "YES": os.environ["PYTHON_FULL_PATH_KLUGE"]="YES" os.execvp(sys.executable, [ sys.executable ] + sys.argv )print "Initiating MacPython emulation mode, expecting one import error."import MacOSimport macfsimport macpathimport timeimport posixpathimport typesimport __builtin__## Copied from archive.py_mac_second_diff = 2082816000.0 os.name='mac'sys.platform='mac'def __volume(): return os.environ.get("BUILD_VOL","MacOS X") ## Convert a MAC path to a posix pathdef _path_mtop(path): path = string.replace(path, "\xb5","0xb5") path = string.replace(path, "\xc4","0xc4") if path == ":": return "." # print "_path_mtop: %s" % path tmp=string.split(path,":") if(macpath.isabs(path)): if tmp[0] == __volume(): tmp[0]="" return string.join(tmp,"/") ## Kluge for mixed posix/mac path if string.count(tmp[0],"/"): return apply(os_path_join,tmp) if(_real_isdir("/Volumes/"+tmp[0])): return "/Volumes/"+string.join(tmp,"/") ## Another Kluge, path lacks volume name return "/" + string.join(tmp,"/") if len(tmp) == 1: return tmp up=1 while up < len(tmp)-1 and tmp[up] == '': up = up + 1 if up == 1: return "./" + string.join(tmp[up:],"/") return "../"*(up-1) + string.join(tmp[up:],"/")def _is_mac_path(path): if ":" in path: return 1 return 0## Convert a mac path to a posix path, but only if it is## (probably) a mac pathdef _path_dtop(path): if type(path) != types.StringType: return path path = string.replace(path,"\\","/") if(_is_mac_path(path)): return _path_mtop(path) return path_real_normpath=posixpath.normpath_real_isabs=posixpath.isabs## Convert a posix path to a mac pathdef _path_ptom(path): if path == ".": return ":" orig = path path=_real_normpath(path) tmp=string.split(path,"/") if _real_isabs(path): if tmp[1] == "Volumes": path=string.join(tmp[2:],":") else: path=__volume() + string.join(tmp,":") else: path=":" p = 0 while p < len(tmp) and tmp[p]=="..": path=path+":" p = p + 1 path=path+string.join(tmp[p:],":") if orig[-1] == '/' and path[-1]!=':': path = path + ":" if orig[:2] == "./" and path[0]!=':': path = ":" + path return pathdef _is_posix_path(path): if "/" in path: return 1 if "\\" in path: return 1 if path in [".", ".."]: return 1 return 0## DWIM to macdef _path_dtom(path): if type(path) != types.StringType: return path if(_is_posix_path(path)): return _path_ptom(path) return path#### These functions try to batch update notifications for the Finder##to_update = {}def queue_dir_update(filename): global to_update if string.count(filename,"..namedfork"): return filename = os.path.join(getcwd(), filename) filename = os.path.normpath(filename) filename = _path_dtom(filename) if filename[-1:] != ':': filename = filename + ':' to_update[filename] = 1 filename = macpath.dirname(macpath.dirname(filename))+":" to_update[filename] = 1 filename = macpath.dirname(macpath.dirname(filename))+":" to_update[filename] = 1def queue_file_update(filename): global to_update filename = os.path.join(getcwd(), filename) filename = os.path.normpath(filename) filename = _path_dtom(filename) to_update[filename] = 1 filename = macpath.dirname(filename)+":" to_update[filename] = 1 filename = macpath.dirname(macpath.dirname(filename))+":" to_update[filename] = 1def update_finder(): global to_update if len(to_update): script = ['tell Application "Finder"' ] tmp = [] for path in to_update.keys(): tmp.append( (len(path), path) ) tmp.sort() for path in tmp: script.append(' update "%s"' % path[1]) script.append('end tell') to_update = {} tmpfilename = "atmp-%d-%f.ascript" % (os.getpid(), time.time()) s = string.join(script,"\n") # print s open(tmpfilename,"w").write(s) err=os.popen("/usr/bin/osascript -s o %s" % tmpfilename).read() if len(err): print "Warning, update failed: %s" % err print "script =\n%s" % s print "-------------------------------------------" os.remove(tmpfilename) ## Patch os.*__old_getcwd = os.getcwddef getcwd(): return _path_ptom(__old_getcwd() + "/")os.getcwd = getcwd## This is a very very ugly kluge to avoid## Using the Mac-specific SOURCE_ROOT variableif os.environ.get("SOURCE_ROOT","") == "": cmd=os.path.split(sys.argv[0])[1] if cmd == "umake": os.environ["SOURCE_ROOT"] = _path_ptom(os.path.dirname(__old_getcwd())+"/") if cmd == "build": os.environ["SOURCE_ROOT"] = getcwd()_real_isdir = os.path.isdir_real_join = os.path.joindef os_path_join(base, *args): na = [ _path_dtop(base) ] for arg in args: arg=_path_dtop(arg) while arg[:2] == "./": arg=arg[2:] na.append(arg) ret = apply(_real_join, na) # print " os.path.join %r => %r " % ( (base,)+args, ret) return retos.path.join=os_path_join## Patch os.stat__old_stat = os.statdef os_stat(file): file = _path_dtop(file) s = list(__old_stat(file)) s[7] = s[7] + _mac_second_diff s[8] = s[8] + _mac_second_diff s[9] = s[9] + _mac_second_diff s=tuple(s) try: s=os.stat_result(s) except: pass return sos.stat = os_stat## Patch os.utime__old_utime = os.utimedef os_utime(file, times): file = _path_dtop(file) if type(times[0]) == types.FloatType: times = (int(times[0] - _mac_second_diff), int(times[1] - _mac_second_diff) ) return __old_utime(file, times)os.utime = os_utime## Generic wrappersclass WrapCall: def __init__(self,module,callname, filter_func): self.filter_func=filter_func self.module=module self.name=callname self.fun = module.__dict__[callname] module.__dict__[callname] = self.wrapper def wrapper(self,*args): #print " %s.%s %r " % ( self.module.__name__, self.name, args) #print " >>> %s.%s %r " % ( self.module.__name__, self.name, map(self.filter_func, args)) ret = apply(self.fun, map(self.filter_func, args)) # print " %s.%s %r => %s " % ( self.module.__name__, self.name, args, ret)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -