def cache_remove(): dotrc = Glo.dot_buildc_rc_path() if not os.path.exists(dotrc): print 'Can not found ' + dotrc print 'Please run buildc init and then config .buildc.rc!' sys.exit(Errors.conf_file_not_found) buildc_rc = Load.load_dot_buildc_rc(dotrc) for repository in buildc_rc.external_repositories: svn_path = repository[0] cache_path = Glo.get_local_cache_path(svn_path, buildc_rc.external_repositories) print "\n===>Begin remove local cache of repository [" + svn_path + ']' ret = Util.execute_and_return('rm -rf ' + cache_path) if (ret != 0): print 'Remove [' + cache_path + '] Failed!' sys.exit(ret) else: print 'Remove [' + cache_path + '] OK!' print "\n<=== End remove local cache of repository [" + svn_path + ']' dotrepository = Glo.dot_buildc_repository_path() svn_tree = SvnTree() svn_tree.import_format_tree_from_file(dotrepository) svn_tree.take_item_data_by_browse(None, SvnTree.set_empty_node, 1) svn_tree.export_format_tree_to_file(dotrepository)
def cache_remove(): dotrc = Glo.dot_buildc_rc_path() if not os.path.exists(dotrc): print 'Can not found ' + dotrc print 'Please run buildc init and then config .buildc.rc!' sys.exit(Errors.conf_file_not_found) buildc_rc = Load.load_dot_buildc_rc(dotrc) for repository in buildc_rc.external_repositories: svn_path = repository[0] cache_path = Glo.get_local_cache_path( svn_path, buildc_rc.external_repositories) print "\n===>Begin remove local cache of repository [" + svn_path + ']' ret = Util.execute_and_return('rm -rf ' + cache_path) if (ret != 0): print 'Remove [' + cache_path + '] Failed!' sys.exit(ret) else: print 'Remove [' + cache_path + '] OK!' print "\n<=== End remove local cache of repository [" + svn_path + ']' dotrepository = Glo.dot_buildc_repository_path() svn_tree = SvnTree() svn_tree.import_format_tree_from_file(dotrepository) svn_tree.take_item_data_by_browse(None, SvnTree.set_empty_node, 1) svn_tree.export_format_tree_to_file(dotrepository)
def __copy_dependent(dependence, svn_tree, buildc_rc, build_home, cmode, dirname): if dirname != "include" and dirname != "lib" and dirname != "": print 'dirname args invalid' sys.exit(Errors.args_invalid) (dep_libname, dep_libversion, dep_tagfile) = Glo.get_dependent_name_and_version(dependence) h_child_item = svn_tree.get_root_item() while(h_child_item != None): svn_root_path = svn_tree.get_item_text(h_child_item) full_svn_path = svn_root_path + '|' + dep_libname + '|' + dep_libversion + '|' + Glo.CPU + '_' + cmode[0:2] + '_' + Glo.SYSTEM leaf_node = svn_tree.find_item(full_svn_path, '|', False, 1) if leaf_node != None: cache_root_path = Glo.get_local_cache_path(svn_root_path, buildc_rc.external_repositories) if cache_root_path == None: print svn_root_path + ' does not exist in .buildc.rc' sys.exit(Errors.conf_item_not_found) lib_path = cache_root_path + '/' + dep_libname + '/' + dep_libversion + '/' + Glo.CPU + '_' + cmode[0:2] + '_' + Glo.SYSTEM + '/' + dirname deps_lib_path = build_home + '/src/deps/' + dep_libname + '/' + dep_libversion + '/' + Glo.CPU + '_' + cmode[0:2] + '_' + Glo.SYSTEM + '/' + dirname if dirname == "lib": Pack.__copy_dependent_file(lib_path, deps_lib_path, dep_tagfile) else: Pack.__copy_dependent_file(lib_path, deps_lib_path, None) return h_child_item = svn_tree.get_next_sibling_item(h_child_item) print('Can not found ' + dep_libname + '/' + dep_libversion + '/' + Glo.CPU + '_' + cmode[0:2] + '_' + Glo.SYSTEM + \ ' in external repositories.') sys.exit(Errors.file_or_dir_exists)
def get_cache_libs(self, item, cmode, cache_libs): if (item == None): h_child_item = self.get_root_item() else: h_child_item = self.get_child_item(item) while(h_child_item != None): if (self.get_child_item(h_child_item) == None): item_text = self.get_item_text(h_child_item) if item_text == Glo.CPU + '_' + cmode[0:2] + '_' + Glo.SYSTEM: full_svn_path = self.get_full_path(h_child_item, '|')[0] svn_root_path = full_svn_path[:str(full_svn_path).find('|')] cache_root_path = Glo.get_local_cache_path(svn_root_path, self.__repositories) if cache_root_path == None: print svn_root_path + ' does not exist in .buildc.rc' sys.exit(Errors.conf_item_not_found) full_cache_path = cache_root_path + '|' + full_svn_path[str(full_svn_path).find('|')+1:] real_cache_path = str(full_cache_path).replace('|', '/') real_cache_version_path = real_cache_path[:str(real_cache_path).rfind('/')] real_cache_name_path = real_cache_version_path[:str(real_cache_version_path).rfind('/')] cache_libversion = real_cache_version_path[str(real_cache_version_path).rfind('/')+1:] cache_libname = real_cache_name_path[str(real_cache_name_path).rfind('/')+1:] cache_libs.append((cache_libname, cache_libversion, os.path.expanduser(cache_root_path))) self.get_cache_libs(h_child_item, cmode, cache_libs) h_child_item = self.get_next_sibling_item(h_child_item)
def remove_tree(self, item, cmode): if (item == None): h_child_item = self.get_root_item() else: h_child_item = self.get_child_item(item) while(h_child_item != None): if (self.get_child_item(h_child_item) == None): item_text = self.get_item_text(h_child_item) if str(item_text).find("_" + cmode[0:2] + "_") != -1: full_svn_path = self.get_full_path(h_child_item, '|')[0] svn_root_path = full_svn_path[:str(full_svn_path).find('|')] cache_root_path = Glo.get_local_cache_path(svn_root_path, self.__repositories) if cache_root_path == None: print svn_root_path + ' does not exist in .buildc.rc' sys.exit(Errors.conf_item_not_found) full_cache_path = cache_root_path + '|' + full_svn_path[str(full_svn_path).find('|')+1:] real_cache_path = str(full_cache_path).replace('|', '/') real_cache_version_path = real_cache_path[:str(real_cache_path).rfind('/')] real_cache_name_path = real_cache_version_path[:str(real_cache_version_path).rfind('/')] if h_child_item.data == 'none': if os.path.exists(real_cache_path): ret = Util.execute_and_return("rm -rf " + real_cache_path + "/.svn " + real_cache_path) if (ret != 0): print 'Remove [' + real_cache_path + '] Failed!' sys.exit(ret) else: print 'Remove [' + real_cache_path + '] OK!' else: if not os.path.exists(real_cache_path): pass else: ret = Util.execute_and_return("rm -rf " + real_cache_path + "/.svn " + real_cache_path) if (ret != 0): print 'Remove [' + real_cache_path + '] Failed!' sys.exit(ret) else: print 'Remove [' + real_cache_path + '] OK!' if os.path.exists(real_cache_version_path): if len(os.listdir(real_cache_version_path)) == 0: os.rmdir(real_cache_version_path) if os.path.exists(real_cache_name_path): if len(os.listdir(real_cache_name_path)) == 0: os.rmdir(real_cache_name_path) if os.path.exists(cache_root_path): if len(os.listdir(cache_root_path)) == 0: os.rmdir(cache_root_path) h_child_item.data = 'none' self.remove_tree(h_child_item, cmode) h_child_item = self.get_next_sibling_item(h_child_item)
def update_tree(self, item, cmode, ignore_error): if (item == None): h_child_item = self.get_root_item() else: h_child_item = self.get_child_item(item) while(h_child_item != None): if (self.get_child_item(h_child_item) == None): item_text = self.get_item_text(h_child_item) if str(item_text).find("_" + cmode[0:2] + "_") != -1: full_svn_path = self.get_full_path(h_child_item, '|')[0] real_svn_path = str(full_svn_path).replace('|', '/') svn_root_path = full_svn_path[:str(full_svn_path).find('|')] cache_root_path = Glo.get_local_cache_path(svn_root_path, self.__repositories) if cache_root_path == None: print svn_root_path + ' does not exist in .buildc.rc' sys.exit(Errors.conf_item_not_found) full_cache_path = cache_root_path + '|' + full_svn_path[str(full_svn_path).find('|')+1:] real_cache_path = str(full_cache_path).replace('|', '/') real_cache_version_path = real_cache_path[:str(real_cache_path).rfind('/')] real_cache_name_path = real_cache_version_path[:str(real_cache_version_path).rfind('/')] dep_libname = real_cache_name_path[str(real_cache_name_path).rfind('/')+1:] dep_libversion = real_cache_version_path[str(real_cache_version_path).rfind('/')+1:] (trunk_user, trunk_passwd) = self.__get_user_and_passwd_by_url(svn_root_path) svn_revision_code = SvnLocalOper.get_svn_info_revision_code(real_svn_path, True, trunk_user, trunk_passwd) if h_child_item.data == 'none': if os.path.exists(real_cache_path): Util.execute_and_return("rm -rf " + real_cache_path) else: if not os.path.exists(real_cache_path): print 'library [' + dep_libname + ' ' + dep_libversion + '] does not exist!' print 'Checkout [' + real_svn_path + ']...' SvnLocalOper.checkout(real_svn_path, real_cache_path, ignore_error, trunk_user, trunk_passwd) print 'Checkout [' + real_svn_path + '] OK!' else: cache_revision_code = SvnLocalOper.get_svn_info_revision_code(real_cache_path, None) if svn_revision_code != cache_revision_code: print 'Update [' + dep_libname + ' ' + dep_libversion + ']...' SvnLocalOper.update(real_cache_path, ignore_error, trunk_user, trunk_passwd) print 'Update [' + dep_libname + ' ' + dep_libversion + '] OK!' h_child_item.data = svn_revision_code self.update_tree(h_child_item, cmode, ignore_error) h_child_item = self.get_next_sibling_item(h_child_item)
def __copy_dependent(dependence, svn_tree, buildc_rc, build_home, cmode, dirname): if dirname != "include" and dirname != "lib" and dirname != "": print 'dirname args invalid' sys.exit(Errors.args_invalid) (dep_libname, dep_libversion, dep_tagfile) = Glo.get_dependent_name_and_version(dependence) h_child_item = svn_tree.get_root_item() while (h_child_item != None): svn_root_path = svn_tree.get_item_text(h_child_item) full_svn_path = svn_root_path + '|' + dep_libname + '|' + dep_libversion + '|' + Glo.CPU + '_' + cmode[ 0:2] + '_' + Glo.SYSTEM leaf_node = svn_tree.find_item(full_svn_path, '|', False, 1) if leaf_node != None: cache_root_path = Glo.get_local_cache_path( svn_root_path, buildc_rc.external_repositories) if cache_root_path == None: print svn_root_path + ' does not exist in .buildc.rc' sys.exit(Errors.conf_item_not_found) lib_path = cache_root_path + '/' + dep_libname + '/' + dep_libversion + '/' + Glo.CPU + '_' + cmode[ 0:2] + '_' + Glo.SYSTEM + '/' + dirname deps_lib_path = build_home + '/src/deps/' + dep_libname + '/' + dep_libversion + '/' + Glo.CPU + '_' + cmode[ 0:2] + '_' + Glo.SYSTEM + '/' + dirname if dirname == "lib": Pack.__copy_dependent_file(lib_path, deps_lib_path, dep_tagfile) else: Pack.__copy_dependent_file(lib_path, deps_lib_path, None) return h_child_item = svn_tree.get_next_sibling_item(h_child_item) print('Can not found ' + dep_libname + '/' + dep_libversion + '/' + Glo.CPU + '_' + cmode[0:2] + '_' + Glo.SYSTEM + \ ' in external repositories.') sys.exit(Errors.file_or_dir_exists)
def get_cache_libs(self, item, cmode, cache_libs): if (item == None): h_child_item = self.get_root_item() else: h_child_item = self.get_child_item(item) while (h_child_item != None): if (self.get_child_item(h_child_item) == None): item_text = self.get_item_text(h_child_item) if item_text == Glo.CPU + '_' + cmode[0:2] + '_' + Glo.SYSTEM: full_svn_path = self.get_full_path(h_child_item, '|')[0] svn_root_path = full_svn_path[:str(full_svn_path).find('|' )] cache_root_path = Glo.get_local_cache_path( svn_root_path, self.__repositories) if cache_root_path == None: print svn_root_path + ' does not exist in .buildc.rc' sys.exit(Errors.conf_item_not_found) full_cache_path = cache_root_path + '|' + full_svn_path[ str(full_svn_path).find('|') + 1:] real_cache_path = str(full_cache_path).replace('|', '/') real_cache_version_path = real_cache_path[:str( real_cache_path).rfind('/')] real_cache_name_path = real_cache_version_path[:str( real_cache_version_path).rfind('/')] cache_libversion = real_cache_version_path[ str(real_cache_version_path).rfind('/') + 1:] cache_libname = real_cache_name_path[ str(real_cache_name_path).rfind('/') + 1:] cache_libs.append((cache_libname, cache_libversion, os.path.expanduser(cache_root_path))) self.get_cache_libs(h_child_item, cmode, cache_libs) h_child_item = self.get_next_sibling_item(h_child_item)
def build_dependent(self, dep_libname, dep_libversion, cmode, force_update = True): lib_flag = False h_child_item = self.get_root_item() while(h_child_item != None): svn_root_path = self.get_item_text(h_child_item) full_svn_path = svn_root_path + '|' + dep_libname + '|' + dep_libversion + '|' + Glo.CPU + '_' + cmode[0:2] + '_' + Glo.SYSTEM real_svn_path = str(full_svn_path).replace('|', '/') leaf_node = self.find_item(full_svn_path, '|', False, 1) if leaf_node != None: lib_flag = True cache_root_path = Glo.get_local_cache_path(svn_root_path, self.__repositories) if cache_root_path == None: print svn_root_path + ' does not exist in .buildc.rc' sys.exit(Errors.conf_item_not_found) full_cache_path = cache_root_path + '|' + dep_libname + '|' + dep_libversion + '|' + Glo.CPU + '_' + cmode[0:2] + '_' + Glo.SYSTEM real_cache_path = str(full_cache_path).replace('|', '/') (trunk_user, trunk_passwd) = self.__get_user_and_passwd_by_url(svn_root_path) svn_revision_code = SvnLocalOper.get_svn_info_revision_code(real_svn_path, True, trunk_user, trunk_passwd) if svn_revision_code == "": return False if leaf_node.data == 'none': if os.path.exists(real_cache_path): Util.execute_and_return("rm -rf " + real_cache_path) print 'library [' + dep_libname + ' ' + dep_libversion + '] does not exist!' print 'Checkout [' + real_svn_path + ']...' result = SvnLocalOper.checkout(real_svn_path, real_cache_path, True, trunk_user, trunk_passwd) if result == False: return False print 'Checkout [' + real_svn_path + '] OK!' leaf_node.data = svn_revision_code else: if not os.path.exists(real_cache_path): print 'library [' + dep_libname + ' ' + dep_libversion + '] does not exist!' print 'Checkout [' + real_svn_path + ']...' result = SvnLocalOper.checkout(real_svn_path, real_cache_path, True, trunk_user, trunk_passwd) if result == False: return False print 'Checkout [' + real_svn_path + '] OK!' leaf_node.data = svn_revision_code else: if force_update: cache_revision_code = SvnLocalOper.get_svn_info_revision_code(real_cache_path, True) if cache_revision_code == "": return False if svn_revision_code != cache_revision_code: print 'Update [' + dep_libname + ' ' + dep_libversion + ']...' result = SvnLocalOper.update(real_cache_path, True, trunk_user, trunk_passwd) if result == False: return False print 'Update [' + dep_libname + ' ' + dep_libversion + '] OK!' leaf_node.data = svn_revision_code else: print "Do not use force_update, skip the update check!" pass break h_child_item = self.get_next_sibling_item(h_child_item) if lib_flag == True: return True else: return False
def remove_tree(self, item, cmode): if (item == None): h_child_item = self.get_root_item() else: h_child_item = self.get_child_item(item) while (h_child_item != None): if (self.get_child_item(h_child_item) == None): item_text = self.get_item_text(h_child_item) if str(item_text).find("_" + cmode[0:2] + "_") != -1: full_svn_path = self.get_full_path(h_child_item, '|')[0] svn_root_path = full_svn_path[:str(full_svn_path).find('|' )] cache_root_path = Glo.get_local_cache_path( svn_root_path, self.__repositories) if cache_root_path == None: print svn_root_path + ' does not exist in .buildc.rc' sys.exit(Errors.conf_item_not_found) full_cache_path = cache_root_path + '|' + full_svn_path[ str(full_svn_path).find('|') + 1:] real_cache_path = str(full_cache_path).replace('|', '/') real_cache_version_path = real_cache_path[:str( real_cache_path).rfind('/')] real_cache_name_path = real_cache_version_path[:str( real_cache_version_path).rfind('/')] if h_child_item.data == 'none': if os.path.exists(real_cache_path): ret = Util.execute_and_return("rm -rf " + real_cache_path + "/.svn " + real_cache_path) if (ret != 0): print 'Remove [' + real_cache_path + '] Failed!' sys.exit(ret) else: print 'Remove [' + real_cache_path + '] OK!' else: if not os.path.exists(real_cache_path): pass else: ret = Util.execute_and_return("rm -rf " + real_cache_path + "/.svn " + real_cache_path) if (ret != 0): print 'Remove [' + real_cache_path + '] Failed!' sys.exit(ret) else: print 'Remove [' + real_cache_path + '] OK!' if os.path.exists(real_cache_version_path): if len(os.listdir(real_cache_version_path)) == 0: os.rmdir(real_cache_version_path) if os.path.exists(real_cache_name_path): if len(os.listdir(real_cache_name_path)) == 0: os.rmdir(real_cache_name_path) if os.path.exists(cache_root_path): if len(os.listdir(cache_root_path)) == 0: os.rmdir(cache_root_path) h_child_item.data = 'none' self.remove_tree(h_child_item, cmode) h_child_item = self.get_next_sibling_item(h_child_item)
def build_dependent(self, dep_libname, dep_libversion, cmode, force_update=True): lib_flag = False h_child_item = self.get_root_item() while (h_child_item != None): svn_root_path = self.get_item_text(h_child_item) full_svn_path = svn_root_path + '|' + dep_libname + '|' + dep_libversion + '|' + Glo.CPU + '_' + cmode[ 0:2] + '_' + Glo.SYSTEM real_svn_path = str(full_svn_path).replace('|', '/') leaf_node = self.find_item(full_svn_path, '|', False, 1) if leaf_node != None: lib_flag = True cache_root_path = Glo.get_local_cache_path( svn_root_path, self.__repositories) if cache_root_path == None: print svn_root_path + ' does not exist in .buildc.rc' sys.exit(Errors.conf_item_not_found) full_cache_path = cache_root_path + '|' + dep_libname + '|' + dep_libversion + '|' + Glo.CPU + '_' + cmode[ 0:2] + '_' + Glo.SYSTEM real_cache_path = str(full_cache_path).replace('|', '/') (trunk_user, trunk_passwd ) = self.__get_user_and_passwd_by_url(svn_root_path) svn_revision_code = SvnLocalOper.get_svn_info_revision_code( real_svn_path, True, trunk_user, trunk_passwd) if svn_revision_code == "": return False if leaf_node.data == 'none': if os.path.exists(real_cache_path): Util.execute_and_return("rm -rf " + real_cache_path) print 'library [' + dep_libname + ' ' + dep_libversion + '] does not exist!' print 'Checkout [' + real_svn_path + ']...' result = SvnLocalOper.checkout(real_svn_path, real_cache_path, True, trunk_user, trunk_passwd) if result == False: return False print 'Checkout [' + real_svn_path + '] OK!' leaf_node.data = svn_revision_code else: if not os.path.exists(real_cache_path): print 'library [' + dep_libname + ' ' + dep_libversion + '] does not exist!' print 'Checkout [' + real_svn_path + ']...' result = SvnLocalOper.checkout(real_svn_path, real_cache_path, True, trunk_user, trunk_passwd) if result == False: return False print 'Checkout [' + real_svn_path + '] OK!' leaf_node.data = svn_revision_code else: if force_update: cache_revision_code = SvnLocalOper.get_svn_info_revision_code( real_cache_path, True) if cache_revision_code == "": return False if svn_revision_code != cache_revision_code: print 'Update [' + dep_libname + ' ' + dep_libversion + ']...' result = SvnLocalOper.update( real_cache_path, True, trunk_user, trunk_passwd) if result == False: return False print 'Update [' + dep_libname + ' ' + dep_libversion + '] OK!' leaf_node.data = svn_revision_code else: print "Do not use force_update, skip the update check!" pass break h_child_item = self.get_next_sibling_item(h_child_item) if lib_flag == True: return True else: return False
def update_tree(self, item, cmode, ignore_error): if (item == None): h_child_item = self.get_root_item() else: h_child_item = self.get_child_item(item) while (h_child_item != None): if (self.get_child_item(h_child_item) == None): item_text = self.get_item_text(h_child_item) if str(item_text).find("_" + cmode[0:2] + "_") != -1: full_svn_path = self.get_full_path(h_child_item, '|')[0] real_svn_path = str(full_svn_path).replace('|', '/') svn_root_path = full_svn_path[:str(full_svn_path).find('|' )] cache_root_path = Glo.get_local_cache_path( svn_root_path, self.__repositories) if cache_root_path == None: print svn_root_path + ' does not exist in .buildc.rc' sys.exit(Errors.conf_item_not_found) full_cache_path = cache_root_path + '|' + full_svn_path[ str(full_svn_path).find('|') + 1:] real_cache_path = str(full_cache_path).replace('|', '/') real_cache_version_path = real_cache_path[:str( real_cache_path).rfind('/')] real_cache_name_path = real_cache_version_path[:str( real_cache_version_path).rfind('/')] dep_libname = real_cache_name_path[str(real_cache_name_path ).rfind('/') + 1:] dep_libversion = real_cache_version_path[ str(real_cache_version_path).rfind('/') + 1:] (trunk_user, trunk_passwd ) = self.__get_user_and_passwd_by_url(svn_root_path) svn_revision_code = SvnLocalOper.get_svn_info_revision_code( real_svn_path, True, trunk_user, trunk_passwd) if h_child_item.data == 'none': if os.path.exists(real_cache_path): Util.execute_and_return("rm -rf " + real_cache_path) else: if not os.path.exists(real_cache_path): print 'library [' + dep_libname + ' ' + dep_libversion + '] does not exist!' print 'Checkout [' + real_svn_path + ']...' SvnLocalOper.checkout(real_svn_path, real_cache_path, ignore_error, trunk_user, trunk_passwd) print 'Checkout [' + real_svn_path + '] OK!' else: cache_revision_code = SvnLocalOper.get_svn_info_revision_code( real_cache_path, None) if svn_revision_code != cache_revision_code: print 'Update [' + dep_libname + ' ' + dep_libversion + ']...' SvnLocalOper.update(real_cache_path, ignore_error, trunk_user, trunk_passwd) print 'Update [' + dep_libname + ' ' + dep_libversion + '] OK!' h_child_item.data = svn_revision_code self.update_tree(h_child_item, cmode, ignore_error) h_child_item = self.get_next_sibling_item(h_child_item)