def declaw_name(name): name = macpath.normpath(name) while len(name) and name[0] == ':': name = name[1:] name = string.lower(name) name = string.replace(name,":","_") name = string.replace(name,"_makefile","") name = string.replace(name,".mak","") return name
def fix_path_mac(path): """Macintosh implementation of fix_path() seperated out for clarity. This is called by fix_path().""" if not path or not len(path): return "" if ':' in path and '/' not in path and '\\' not in path: ## The path is already a mac path! return path path = string.replace(path, "/", ":") mac_path = "" last_backdir = 0 last_curdir = 0 # no directory info defaults to current dir if path[0] == ":": import macpath mac_path = string.split(macpath.normpath(os.getcwd()), ":")[0] elif path[0] != ".": mac_path = ":" i = 0 while i < len(path): # translate current directory if path[i:i + 2] == ".:": if not last_curdir and not last_backdir: mac_path = mac_path + ":" last_curdir = 1 i = i + 2 continue # translate stepping back a directory if path[i:i + 3] == "..:": if last_backdir or last_curdir: mac_path = mac_path + ":" else: mac_path = mac_path + "::" last_backdir = 1 i = i + 3 continue # append to mac_path mac_path = mac_path + path[i] i = i + 1 last_curdir = 0 last_backdir = 0 return mac_path
def fix_path_mac(path): """Macintosh implementation of fix_path() seperated out for clarity. This is called by fix_path().""" if not path or not len(path): return "" if ':' in path and '/' not in path and '\\' not in path: ## The path is already a mac path! return path path = string.replace(path, "/", ":") mac_path = "" last_backdir = 0 last_curdir = 0 # no directory info defaults to current dir if path[0] == ":": import macpath mac_path=string.split(macpath.normpath(os.getcwd()),":")[0] elif path[0] != ".": mac_path = ":" i = 0 while i < len(path): # translate current directory if path[i:i+2] == ".:": if not last_curdir and not last_backdir: mac_path = mac_path + ":" last_curdir = 1 i = i + 2 continue # translate stepping back a directory if path[i:i+3] == "..:": if last_backdir or last_curdir: mac_path = mac_path + ":" else: mac_path = mac_path + "::" last_backdir = 1 i = i + 3 continue # append to mac_path mac_path = mac_path + path[i] i = i + 1 last_curdir = 0 last_backdir = 0 return mac_path
def Clean(self): """Emits a AppleScript function to clean the target, project file, and project file data for a target.""" self.script.Append( '-- Allow the items to be made clean', 'on Clean()', ) for sumake in self.mprj.project.submakes: m_path = macpath.normpath(macpath.join(os.getcwd(), sumake.makefile())) self.script.Append( ' set scriptobj to (load script file "%s")' % (m_path), ' tell scriptobj', ' Clean()', ' end tell' ) if self.mprj.project.getTargetType() != "": self.script.Append( ' tell application "Finder"', ' with timeout of 99999 seconds', ' if file "%s" exists then' % (self.mprj.project_file_path), ' delete file "%s"' % (self.mprj.project_file_path), ' end if', ' if folder "%s" exists then' % (self.mprj.project_data_path), ' delete folder "%s"' % (self.mprj.project_data_path), ' end if') if self.mprj.rtarget: self.script.Append( ' if file "%s" exists then' % (self.mprj.rproject_file_path), ' delete file "%s"' % (self.mprj.rproject_file_path), ' end if', ' if folder "%s" exists then' % (self.mprj.rproject_data_path), ' delete folder "%s"' % (self.mprj.rproject_data_path), ' end if') self.script.Append( ' end timeout', ' end tell') self.script.Append( 'end Clean', '')
def __init__(self, mprj): self.mprj = mprj ## start the script and define subroutines script = ascript.CreateAppleScript() self.script = script all = [] self.all = all for sumake in mprj.project.submakes: m_path = macpath.normpath(macpath.join(os.getcwd(), sumake.makefile())) all.extend( [ 'set scriptobj to (load script file "%s")' % (m_path), 'tell scriptobj', ' set myerrors to myerrors & return & all()', 'end tell' ] ) script.Extend(mprj.project.pre_target_buff) self.Clean() if mprj.project.getTargetType() != "": WritePrefixFile(mprj) WriteResourcePrefixFile(mprj) WriteExportFile(mprj) self.VerifyPath() self.ExtractCWErrors() if len(mprj.weak_link_list): self.SetWeakLink() if len(mprj.post_build_script): self.PostBuildScript() if mprj.rtarget: self.DefineResourceProject() ## FIXME, only do this for if asked to 'clean' build all.extend( [ ' --clean out old project and data by default', ' Clean()' ]) ## write the "all" function, like "make all" in a Makefile all.extend( [ ' --make the output directory, and target directory', ' verifypath("%s")' % (mprj.output_dir_path), ' verifypath("%s")' % (mprj.target_dir_path) ] ) if mprj.rtarget: all.extend( [ '--build the windows resource dll', 'myerrors = myerrors & return & ResourceProject()' ] ) self.RunProject() ## for DLL target types, we make a alias to the dll with a .lib ## extention so developers can do implicit linking to DLL's the ## same way they do on Windows ## ## Note: when Windows compiles a DLL, it creates a companion .LIB ## library with the same name; you link to the DLL by linking ## in the stub .LIB absolute_output_dir = os.path.join(os.getcwd(), mprj.output_dir) absolute_output_path = os.path.join(absolute_output_dir, mprj.output_name) if mprj.target_type == "dll": if mprj.project.opt_target_name: alias_name= mprj.project.opt_target_name else: alias_name= mprj.target_name alias_name = "%s.LIB" % (string.upper(alias_name)) absolute_alias_path = os.path.join(absolute_output_dir, alias_name) all.extend( [ 'tell application "Finder"', ' try', ' if (file "%s") exists then' % (absolute_alias_path), ' else', ' make new alias file to (file "%s") at (folder "%s") '\ ' with properties {name:"%s"}' % ( absolute_output_path, absolute_output_dir, alias_name), ' end if', ' on error', ' end try', 'end tell' ]) if len(mprj.post_build_script): all.extend( [ '--execute the custom subroutine', 'DoPostBuild()' ]) ## copy the built target and finish off the script all.extend( [ '-- Copy results to common output folder', 'tell application "Finder"', ' if (file "%s") exists then' % (absolute_output_path), ' Duplicate file "%s" to folder "%s" with replacing' % ( absolute_output_path, mprj.target_dir_path), ' end if', 'end tell' ]) if len(all): script.Append('on all()', 'set myerrors to ""') script.Extend(all) script.Append( 'return myerrors', 'end all', '-- run the "all()" function', 'return all()') script.Extend(mprj.project.post_target_buff) ## for DRM signing if mprj.project.getTargetType() == "dll" and \ mprj.project.BuildOption("drmsign") and \ mprj.project.CheckDRMSign(): import shell shell.mkdir(os.path.dirname(absolute_output_path)) open(absolute_output_path+"--drmsign","w").write("signme!")
''' macpath 模块 macpath 模块( 参见 Example 13-2 )提供了 Macintosh 平台下的 os.path 功能. 你也可以使用它在其他平台处理 Macintosh 路径. ''' import macpath file = 'my:little:pony' print("isabs", "=>", macpath.isabs(file)) print("dirname", "=>", macpath.dirname(file)) print("basename", "=>", macpath.basename(file)) print("normpath", "=>", macpath.normpath(file)) print("split", "=>", macpath.split(file)) print("join", "=>", macpath.join(file, "zorba")) ''' isabs => True dirname => my:little basename => pony normpath => my:little:pony split => ('my:little', 'pony') join => my:little:pony:zorba '''
def test_normpath(self): # Issue 5827: Make sure normpath preserves unicode for path in (u'', u'.', u'/', u'\\', u':', u'///foo/.//bar//'): self.assertIsInstance( macpath.normpath(path), unicode, 'normpath() returned str instead of unicode')
def test_normpath(self): # Issue 5827: Make sure normpath preserves unicode for path in (u'', u'.', u'/', u'\\', u':', u'///foo/.//bar//'): self.assertIsInstance(macpath.normpath(path), unicode, 'normpath() returned str instead of unicode')
def WriteProjectSettingsXML(mprj, templateName): """ Writes out the Applescript which writes the <SETTINGS> section of the CodeWarrior XML. This includes all the CW project preferences, source file list and link order. This function is used to write out the settings for 'project.xml' and 'project_uber.xml' """ template_filename = os.path.join(os.environ['BUILD_ROOT'],"bin","mac", templateName) template_text = open(template_filename,"r").read() ## set access paths user_list = [] if templateName == "project_uber.xml": # uber can't have local paths eg. ':', ':pub:' # they must be like '::pndebug:', '::pndebug:pub:' module_path = os.getcwd() src_root_path = macpath.normpath(os.path.join(module_path,mprj.project.src_root_path))+":" for (path, recursive, origin) in mprj.user_paths: umake_lib.debug("USER_PATH: %s => (%s)" % (repr(path), repr(mprj.project.src_root_path))) path = macpath.normpath(macpath.join(module_path, path)) if path[:len(src_root_path)] == src_root_path: path = "#SRC_ROOT_PATH#" + path[len(src_root_path):] umake_lib.debug("USER_PATH: => %s (%s)" % (repr(path), repr(src_root_path))) user_list.append(path) else: for (path, recursive, origin) in mprj.user_paths: path = macpath.normpath(path) user_list.append(path) ## Set CodeWarrior prefs empty_list = [] template_text = SetAccessPathBlock(template_text, user_list, empty_list, empty_list, "#USER_SEARCH_PATHS#") system_list = [] recursive_list = [] origin_list = [] for (path, recursive, origin) in mprj.system_paths: system_list.append(path) recursive_list.append(recursive) origin_list.append(origin) template_text = SetAccessPathBlock(template_text, system_list, recursive_list, origin_list, "#SYSTEM_SEARCH_PATHS#") ## add files file_list = string.join(mprj.source_list, ',') source_dir,output_dir = macpath.split(mprj.output_dir_path) target_type = '' if output_dir == "debug": target_type = "debug" template_text = SetFileListBlock(template_text, file_list, "#TEXT_FILE_LIST#", "Text", target_type) source_list = [] for file_name in mprj.source_list: source_list.append(file_name) if len(mprj.library_list): library_list = string.join(mprj.library_list, ',') template_text = SetFileListBlock(template_text, library_list, "#LIB_FILE_LIST#", "Library", "") # add libs to source list since they need to be # included with groups, link order iterms for library in mprj.library_list: lib_path, lib_name = os.path.split(library) if lib_name not in mprj.source_list: source_list.append(lib_name) else: template_text=string.replace(template_text, "#LIB_FILE_LIST#", "") # link order file_list = string.join(source_list, ',') gLinkOrderBlockString=""" <FILEREF> <PATHTYPE>Name</PATHTYPE> <PATH>#THE_VALUE#</PATH> <PATHFORMAT>MacOS</PATHFORMAT> </FILEREF> """ template_text = SetPreferenceBlock(template_text, file_list, gLinkOrderBlockString, "#LINK_ORDER_ITEMS#") ## add frameworks if len(mprj.project.sys_frameworks): framework_string_list = string.join(mprj.project.sys_frameworks, ',') template_text=SetFrameworkBlock(template_text, framework_string_list, "#FRAMEWORK_LIST#") else: template_text=string.replace(template_text, "#FRAMEWORK_LIST#", "") ## group order template_text=SetGroupBlock(template_text, file_list, "#GROUP_LIST_ITEMS#", mprj.cwtarget_name) template_text = string.replace(template_text, "#GROUP_NAME#", mprj.cwtarget_name) ## CW project preferences template_text=SetPreferenceValue(template_text, "MWFrontEnd_C_prefixname", mprj.prefix_file) template_text=SetPreferenceValue(template_text, "MWRez_Language_prefixname", mprj.rprefix_file) ## set remaining preferences - theses are defined in macos-carbon-powerpc-cw6.cf for (panel, pref) in mprj.preferences.items(): for (pref_key, pref_value) in pref.items(): template_text = SetPreferenceValue(template_text, pref_key, pref_value) # set target dir to debug/release if templateName == "project_uber.xml": module_path = mprj.project_file_path[:-1] module_path, module_name = os.path.split(module_path) module_path, module_name = os.path.split(module_path) template_text = string.replace(template_text, "#TARGET_DIR#", "#SRC_ROOT_PATH#%s:%s:" % (module_name,output_dir)) template_text = string.replace(template_text, "#OUTPUT_FILE_NAME#", "%s:%s" % (output_dir,mprj.output_name)) else: template_text = string.replace(template_text, "#TARGET_DIR#", ":%s:" % (output_dir)) template_text = string.replace(template_text, "#TARGET_NAME#", mprj.cwtarget_name) return template_text