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 export(svn_path, download_path=None, ignore_error=None, trunk_user=None, trunk_pass=None, ignore_hint=True): if download_path != None: Util.execute_and_output("rm -rf " + download_path) cmd_str = "svn export " + "\"" + svn_path + "\"" if download_path != None: cmd_str += " " + "\"" + download_path + "\"" if trunk_user != None and trunk_pass != None and \ trunk_user != "" and trunk_pass != "": cmd_str += " " + "--username " + trunk_user cmd_str += " " + "--password " + trunk_pass cmd_str += " --no-auth-cache" if not ignore_hint: print "command: " + cmd_str err = Util.execute_and_return(cmd_str) if err != 0: print "Failed to execute cmd [%s], errno = [%d]" % (cmd_str, err) if (ignore_error == None): sys.exit(err) return False return True
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 __make(cmode): cmd_str = 'make CMODE=' + cmode + ' > make.log 2>&1' err = Util.execute_and_return(cmd_str) f = open('make.log', 'r') print f.read() f.close() if err != 0: print "Failed to execute cmd [%s], errno = [%d]" % (cmd_str, err) sys.exit(err)
def update(download_path, ignore_error = None, trunk_user = None, trunk_pass = None): cmd_str = "svn update " + "\"" + download_path +"\"" if trunk_user != None and trunk_pass != None and \ trunk_user != "" and trunk_pass != "": cmd_str += " " + "--username " + trunk_user cmd_str += " " + "--password " + trunk_pass cmd_str += " --no-auth-cache" err = Util.execute_and_return(cmd_str) if err != 0: print "Failed to execute cmd [%s], errno = [%d]" % (cmd_str, err) if (ignore_error == None): sys.exit(err) return False return True
def update(download_path, ignore_error=None, trunk_user=None, trunk_pass=None): cmd_str = "svn update " + "\"" + download_path + "\"" if trunk_user != None and trunk_pass != None and \ trunk_user != "" and trunk_pass != "": cmd_str += " " + "--username " + trunk_user cmd_str += " " + "--password " + trunk_pass cmd_str += " --no-auth-cache" err = Util.execute_and_return(cmd_str) if err != 0: print "Failed to execute cmd [%s], errno = [%d]" % (cmd_str, err) if (ignore_error == None): sys.exit(err) return False return True
def export(svn_path, download_path = None, ignore_error = None, trunk_user = None, trunk_pass = None, ignore_hint = True): if download_path != None: Util.execute_and_output("rm -rf " + download_path) cmd_str = "svn export " + "\"" + svn_path +"\"" if download_path != None: cmd_str += " " + "\"" + download_path +"\"" if trunk_user != None and trunk_pass != None and \ trunk_user != "" and trunk_pass != "": cmd_str += " " + "--username " + trunk_user cmd_str += " " + "--password " + trunk_pass cmd_str += " --no-auth-cache" if not ignore_hint: print "command: " + cmd_str err = Util.execute_and_return(cmd_str) if err != 0: print "Failed to execute cmd [%s], errno = [%d]" % (cmd_str, err) if (ignore_error == None): sys.exit(err) return False return True
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)