def __CheckAllPath(self): if utility.CheckPath(self.__sln_path) == False: self.__last_error = '自检--1路径非法,error:' + utility.GetLastError() if utility.CheckPath(self.__sln_path + '\\tools\\python\\') == False: self.__last_error = '自检--2路径非法,error:' + utility.GetLastError() return True
def __CheckPath(self): if utility.CheckPath(self.__temp_path, False) == False: self.__last_error = '未检测到模板目录--' + utility.GetLastError() return False if utility.CheckPath(self.__prj_src_path) == False: self.__last_error = '检测源码路径错误--' + utility.GetLastError() return False if utility.CheckPath(self.__prj_src_path + '\\test') == False: self.__last_error = '检测测试路径错误--' + utility.GetLastError() return False return True
def __GetSlnInfo(self): info_path = self.__sln_path + '\\tools\\project_info.txt' lines = utility.ReadFileToLines(info_path) if lines == None: self.__last_error = '读取工程信息错误--' + utility.GetLastError() return False sln_map = {} for line in lines: line = utility.DelBeginChar(line) line = utility.DelEndChar(line) if len(line) == 0: continue i = line.find(':') if i == -1: continue key = line[:i] val = line[i + 1:] sln_map[key] = val self.__sln_name = sln_map['sln_name'] self.__sln_namespace = sln_map['namespace'] print('获取到 name:' + self.__sln_name) print('获取到 namespace:' + self.__sln_namespace) return True
def __GetTempInfo(self): lines = utility.ReadFileToLines(self.__temp_info_name) if lines == None: __last_error = '复制模板--读取模板信息错误,Error:' + utility.GetLastError() return False files_list = [] macro_list = [] temp_type = 0 # 获取模板信息 for line in lines: line = utility.DelBeginChar(line) line = utility.DelEndChar(line) if len(line) == 0 or utility.IsComments(line) == True: continue elif line == 'dirs': temp_type = 1 elif line == 'files': temp_type = 2 elif line == 'macro': temp_type = 3 else: if temp_type == 1: self.__temp_dirs.append(CreateSln.__ParseTempKeyVal(line)) if temp_type == 2: self.__temp_files.append(CreateSln.__ParseTempKeyVal(line)) elif temp_type == 3: self.__temp_macro.append(CreateSln.__ParseTempKeyVal(line)) return True
def AddCMake(self): cmake_path = self.__sln_path + '\\src\\CMakeLists.txt' data = utility.ReadFileToStr(cmake_path) if data == None: self.__last_error = '读取CMake主工程文件错误' + utility.GetLastError() return False data = utility.DelEndChar(data) data += '\r\n\r\n# ' + self.__prj_name + '\r\n' data += 'add_subdirectory(${PROJECT_SOURCE_DIR}/' + \ self.__prj_folder + '/' + self.__prj_name + '/)' if utility.WriteFileToStr(cmake_path, data) == False: self.__last_error = '写入CMake主工程文件错误' + utility.GetLastError() return False return True
def CreateInfoFile(self): str_s = '' str_s += 'sln_name:' + self.__sln_name + '\r\n' str_s += 'namespace:' + self.__sln_namespace + '\r\n' path = self.__sln_path + '\\project\\project_info.txt' if utility.WriteFileToStr(path, str_s) == False: self.__last_error = '写入工程信息错误--' + utility.GetLastError() return False return True
def __GetTempFilesList(self): temp_info = self.__temp_path + '\\temp_list.txt' lines = utility.ReadFileToLines(temp_info) if lines == None: self.__last_error = '获取模板信息错误--' + utility.GetLastError() return False for line in lines: line = utility.DelBeginChar(line) line = utility.DelEndChar(line) if len(line) == 0: continue i = line.find('-->') if i == -1: continue key = line[:i] val = line[i + 3:] self.__temp_files.append([key, val]) return True