📄 macemu.py
字号:
return retWrapCall(os,"mkdir",_path_dtop)WrapCall(os,"rmdir",_path_dtop)WrapCall(os,"chdir",_path_dtop)WrapCall(os,"remove",_path_dtop)WrapCall(os,"rename",_path_dtop)WrapCall(os,"unlink",_path_dtop)WrapCall(os,"listdir",_path_dtop)#WrapCall(__builtin__,"open",_path_dtop)#WrapCall(os.path,"join",_path_dtop)WrapCall(os.path,"split",_path_dtop)WrapCall(os.path,"normpath",_path_dtop)WrapCall(os.path,"isfile",_path_dtop)WrapCall(os.path,"isdir",_path_dtop)WrapCall(os.path,"isabs",_path_dtop)WrapCall(macpath,"join",_path_dtom)WrapCall(macpath,"split",_path_dtom)WrapCall(macpath,"normpath",_path_dtom)def openrf(file, mode): file = _path_dtop(file) + "/..namedfork/rsrc" mode = string.replace(mode,"*","") return open(file, mode) MacOS.openrf = openrftry: real_fsspec = macfs.FSSpecexcept: passclass FSSpec: def __init__(self, p): if type(p) == types.TupleType: global real_fsspec p = real_fsspec(p).as_pathname() self.path = os.path.normpath(os.path.join(os.getcwd(),p)) def as_pathname(self): return self.path def SetCreatorType(self, crea, type): if os.environ.get("NO_SETFILE", "NO") == "YES": return cmd = "/Developer/Tools/Setfile" if crea != "\x00\x00\x00\x00": cmd = cmd + ' -c "%s"' % crea if type != "\x00\x00\x00\x00": cmd = cmd + ' -t "%s"' % type cmd = cmd + ' "%s"' % self.path try: err = os.popen(cmd).read() except: print "SetCreatorType%s ..." % repr( (self.path, crea, type) ) raise if string.count(err, "ERROR"): print "SetCreatorType%s: %s" % ( repr( (self.path, crea, type) ), err ) def GetCreatorType(self): o1 = os.popen("/Developer/Tools/GetFileInfo -c '%s'" % self.path).read() o2 = os.popen("/Developer/Tools/GetFileInfo -t '%s'" % self.path).read() o1 = string.split(o1,'"') o2 = string.split(o2,'"') if len(o1) < 2 or len(o2) < 2: raise "Failed to get creator type for file '%s' (File does not exist?)" % self.path return (o1[1], o2[1]) def SetDates(self, ctime, mtime, backup): os.utime(self.path, ( int(backup - _mac_second_diff), int(mtime - _mac_second_diff) ))macfs.FSSpec = FSSpecclass OSAm: def __fix_posix_paths(self, data): # print "Magic glue in: %r" % (data,) data=string.replace(data,"\r","\n") tmpdata=string.split(data,'"/') x=1 while x < len(tmpdata): tmpdata[x] = "/"+tmpdata[x] try: eq = string.index(tmpdata[x], '"') path=tmpdata[x][:eq] if string.split(path,"/")[1] != "Developer": tmpdata[x] = _path_ptom(path)+tmpdata[x][eq:] except: pass x = x + 1 data=string.join(tmpdata, '"') #tmpdata=string.split(data,',../') #x=1 #while x < len(tmpdata): # try: # eq = string.index(tmpdata[x], '"') # try: # eq2 = string.index(tmpdata[x], ',') # if eq2 < eq: # eq = eq2 # except: # pass # # tmpdata[x] = _path_ptom("../"+tmpdata[x][:eq])+tmpdata[x][eq:] # except: # pass # x = x + 1 #data=string.join(tmpdata, ',') # print "Magic glue out: %r" % (data,) return data def CompileAndExecute(self, text): import time import os update_finder() tmpfilename = "atmp-%d-%f.ascript" % (os.getpid(), time.time()) text=self.__fix_posix_paths(text) # print "COMPILEANDEXECUTE: %r" % (text,) # print "COMPILEANDEXECUTE:\n%s\n\n" % (text,) open(tmpfilename,"w").write(text) err = os.popen("/usr/bin/osascript -s o %s" % tmpfilename).read() #print "COMPILEANDEXECUTE: %r" % (err,) os.remove(tmpfilename) return err def CompileAndSave(self, text, path): path=_path_dtop(path) text=self.__fix_posix_paths(text) # print "COMPILEANDSAVE: %r" % (text,) open(path+".ascript","w").write(text) err = os.popen("/usr/bin/osacompile -o %s %s.ascript" % (path,path)).read() # print "COMPILEANDSAVE: %r" % (err,) return err sys.modules["OSAm"]=OSAm()import socket## NOTA BENE## DropStuff must be configured to generate both sit and hqx files,## and it should be configured to drop the .sit extention when## making hqx files! /Hubbeclass StuffIt: def run(self, app, file, newfile): cmd='/usr/bin/open -a "%s" "%s"' % (app, _path_dtop(file)); retry = 1 while retry < 100: try: os.remove(newfile) except OSError: pass print "Attempt %d: %s" % (retry, cmd) os.popen(cmd).read() time.sleep(1) w=0 while 1: num=string.count(os.popen("ps -auxwwwww").read(),app) if not num or w > 900: break time.sleep(2) w = w + 2 if num > 1: os.popen("""/usr/bin/osascript -e 'tell application "%s" to quit'""" % app).read() retry = retry + 1 s=os.stat(newfile) if s and s[6]: return print "DropStuff failed, retrying...." def RunStuffitDeluxe(self, op, file, to, script): stuffit = os.environ.get("STUFFIT_DELUXE") if stuffit: print "%s:ing %s into %s using %s" %(op, file, to, stuffit) m_to= _path_dtom(to) m_file = _path_dtom(file) script = [ 'tell application %s' % stuffit, ## Create new stuffit file ' activate', ' with timeout of 9999 seconds', ] + script + [ ' end timeout', ' quit', 'end tell' ] if os.path.exists(to): script = [ 'tell application %s' % stuffit, ## quit stuffit deluxe ' quit', 'end tell', 'tell application "Finder"', ' delete file "%s"' % m_to, 'end tell', ] + script script.append('return "noerror"') script = string.join(script, "\n") script = string.replace(script,"$file$",m_file) script = string.replace(script,"$to$",m_to) ret=OSAm().CompileAndExecute(script) if not string.count(ret,"noerror"): raise "Failed to %s %s => %s\nApplescript Error: %s" % (op, file, to, ret) return 1 return None def Stuff(self, file, to = None): print "STUFF STUFF STUFF" cmd="stuff -l 16" if to: cmd = "%s -n \"%s\"" %( cmd, _path_dtop(to)) if not os.system("%s \"%s\"" % (cmd, _path_dtop(file))): return if not os.system("/usr/local/bin/%s \"%s\"" % (cmd, _path_dtop(file))): return if self.RunStuffitDeluxe("Stuff",file, to, [ ' make new archive with properties {location:file "$to$"}', ' stuff {alias "$file$"} into archive "%s" compression level maximum ' % os.path.basename(to) ]): return self.run("DropStuff", file, file + ".sit") if to and to != file + ".sit": os.rename(file+".sit", to) def HQXEncode(self, file, to = None): if not to: to = file+".hqx" if not os.system("stuff -f hqx -n \"%s\" \"%s\"" % (_path_dtop(to), _path_dtop(file))): return if not os.system("/usr/local/bin/stuff -f hqx -n \"%s\" \"%s\"" % (_path_dtop(to), _path_dtop(file))): return if self.RunStuffitDeluxe("HQX", file, to, [ ' encode {alias "$file$"} with binhex into file "$to$"']): return # This must be the special modified MacOS X binhex if not os.system('binhex -d "%s" >"%s"' % (_path_dtop(file), _path_dtop(to))): return sitfile=file+".sit" hqxfile=file+".hqx" self.Stuff(file, sitfile); s=os.stat(hqxfile) if not (s and s[6]): self.run("DropStuff", sitfile, hqxfile) if to and to != hqxfile: os.rename(hqxfile, to) def MacBinEncode(self,file, to = None): if not to: to = file+".bin" if not os.system("stuff -f bin -n \"%s\" \"%s\"" % (_path_dtop(to), _path_dtop(file))): return if not os.system("/usr/local/bin/stuff -f bin -n \"%s\" \"%s\"" % (_path_dtop(to), _path_dtop(file))): return if self.RunStuffitDeluxe("macbinencode", file, to, [ ' encode {alias "$file$"} with macbinary into file "$to$"']): return # This must be the special modified MacOS X binhex if not os.system('macstream -d "%s" >"%s"' % (_path_dtop(file), _path_dtop(to))): return def Expand(self, *args): ##FIXME: run /usr/local/bin/unstuff here ### This does not work, does it? self.run("StuffIt Expander", args, args)sys.modules["StuffIt"]=StuffIt()## open()real_open=opendef my_open(file, mode = "r"): file = _path_dtop(file); ## Tell finder to update it's cache before running ## Next applescript... if string.count(mode,"w") or string.count(mode,"c"): queue_dir_update(os.path.dirname(file)) return real_open(file,mode)__builtin__.open=my_open## Trap this to make sure updates are done after cvs has runreal_fork = os.forkdef os_fork(): queue_dir_update(getcwd()) return real_fork()os.environ["FAKE_MAC"]="YES"class myMACFS: kOnAppropriateDisk=-32767 kPreferencesFolderType='pref'sys.modules["MACFS"]=myMACFS()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -