diff --git a/docs/TODO b/docs/TODO index aa0befc6d..e4c2a0d3b 100644 --- a/docs/TODO +++ b/docs/TODO @@ -5,10 +5,10 @@ - entropy.server API rework - move sensible pkgs to alt dir - UGC: pkg icon support + - equo repo enable/disable/add/remove 0.99.40: - - "#" tag mark, move to entropy.const - move all the portage related stuff in entropy.tools to entropy.spm.metaphor - sulfur: code refactoring - PackageKit integration diff --git a/libraries/entropy/client/interfaces/dep.py b/libraries/entropy/client/interfaces/dep.py index bdf110bc7..4f94449f9 100644 --- a/libraries/entropy/client/interfaces/dep.py +++ b/libraries/entropy/client/interfaces/dep.py @@ -1816,7 +1816,7 @@ class CalculatorsMixin: myrev = self.clientDbconn.retrieveRevision(match[0]) pkg_match = "="+myatom+"~"+str(myrev) if mytag is not None: - pkg_match += "#%s" % (mytag,) + pkg_match += "%s%s" % (etpConst['entropytagprefix'], mytag,) pkg_unsatisfied = self._get_unsatisfied_dependencies([pkg_match], deep_deps = deep) if pkg_unsatisfied: diff --git a/libraries/entropy/client/interfaces/methods.py b/libraries/entropy/client/interfaces/methods.py index 68ad12ecf..e886c2594 100644 --- a/libraries/entropy/client/interfaces/methods.py +++ b/libraries/entropy/client/interfaces/methods.py @@ -265,7 +265,7 @@ class RepositoryMixin: else: - entropy.tools.save_repository_settings(repodata) + self.__save_repository_settings(repodata) self.SystemSettings._clear_repository_cache(repoid = repoid) self.close_all_repositories() self.clear_cache() @@ -306,9 +306,9 @@ class RepositoryMixin: repodata = {} repodata['repoid'] = repoid if disable: - entropy.tools.save_repository_settings(repodata, disable = True) + self.__save_repository_settings(repodata, disable = True) else: - entropy.tools.save_repository_settings(repodata, remove = True) + self.__save_repository_settings(repodata, remove = True) self.SystemSettings.clear() repo_mem_key = self.__get_repository_cache_key(repoid) @@ -320,11 +320,128 @@ class RepositoryMixin: self.close_all_repositories() self.validate_repositories() + def __save_repository_settings(self, repodata, remove = False, + disable = False, enable = False): + + if repodata['repoid'].endswith(etpConst['packagesext']): + return + + content = [] + if os.path.isfile(etpConst['repositoriesconf']): + f = open(etpConst['repositoriesconf']) + content = [x.strip() for x in f.readlines()] + f.close() + + if not disable and not enable: + content = [x for x in content if not \ + x.startswith("repository|"+repodata['repoid'])] + if remove: + # also remove possible disable repo + content = [x for x in content if not (x.startswith("#") and \ + not x.startswith("##") and \ + (x.find("repository|"+repodata['repoid']) != -1))] + if not remove: + + repolines = [x for x in content if x.startswith("repository|") or \ + (x.startswith("#") and not x.startswith("##") and \ + (x.find("repository|") != -1))] + # exclude lines from repolines + content = [x for x in content if x not in repolines] + # filter sane repolines lines + repolines = [x for x in repolines if (len(x.split("|")) == 5)] + repolines_data = {} + repocount = 0 + for x in repolines: + repolines_data[repocount] = {} + repolines_data[repocount]['repoid'] = x.split("|")[1] + repolines_data[repocount]['line'] = x + if disable and x.split("|")[1] == repodata['repoid']: + if not x.startswith("#"): + x = "#"+x + repolines_data[repocount]['line'] = x + elif enable and x.split("|")[1] == repodata['repoid'] \ + and x.startswith("#"): + repolines_data[repocount]['line'] = x[1:] + repocount += 1 + + if not disable and not enable: # so it's a add + + line = "repository|%s|%s|%s|%s#%s#%s,%s" % ( + repodata['repoid'], + repodata['description'], + ' '.join(repodata['plain_packages']), + repodata['plain_database'], + repodata['dbcformat'], + repodata['service_port'], + repodata['ssl_service_port'], + ) + + # seek in repolines_data for a disabled entry and remove + to_remove = set() + for cc in repolines_data: + cc_line = repolines_data[cc]['line'] + if cc_line.startswith("#") and \ + (cc_line.find("repository|"+repodata['repoid']) != -1): + # then remove + to_remove.add(cc) + for x in to_remove: + del repolines_data[x] + + repolines_data[repocount] = {} + repolines_data[repocount]['repoid'] = repodata['repoid'] + repolines_data[repocount]['line'] = line + + # inject new repodata + keys = sorted(repolines_data.keys()) + for cc in keys: + #repoid = repolines_data[cc]['repoid'] + # write the first + line = repolines_data[cc]['line'] + content.append(line) + + try: + repo_conf = etpConst['repositoriesconf'] + tmp_repo_conf = repo_conf + ".cfg_save_set" + with open(tmp_repo_conf, "w") as tmp_f: + for line in content: + tmp_f.write(line + "\n") + tmp_f.flush() + os.rename(tmp_repo_conf, repo_conf) + except (OSError, IOError,): # permission denied? + return False + return True + + + def __write_ordered_repositories_entries(self, ordered_repository_list): + content = [] + if os.path.isfile(etpConst['repositoriesconf']): + f = open(etpConst['repositoriesconf']) + content = [x.strip() for x in f.readlines()] + f.close() + + repolines = [x for x in content if x.startswith("repository|") and \ + (len(x.split("|")) == 5)] + content = [x for x in content if x not in repolines] + for repoid in ordered_repository_list: + # get repoid from repolines + for x in repolines: + repoidline = x.split("|")[1] + if repoid == repoidline: + content.append(x) + + repo_conf = etpConst['repositoriesconf'] + tmp_repo_conf = repo_conf + ".cfg_save" + with open(tmp_repo_conf, "w") as tmp_f: + for line in content: + tmp_f.write(line + "\n") + tmp_f.flush() + os.rename(tmp_repo_conf, repo_conf) + def shift_repository(self, repoid, toidx): # update self.SystemSettings['repositories']['order'] self.SystemSettings['repositories']['order'].remove(repoid) self.SystemSettings['repositories']['order'].insert(toidx, repoid) - entropy.tools.write_ordered_repositories_entries( + self.__write_ordered_repositories_entries( self.SystemSettings['repositories']['order']) self.SystemSettings.clear() self.close_all_repositories() @@ -336,7 +453,7 @@ class RepositoryMixin: # save new self.SystemSettings['repositories']['available'] to file repodata = {} repodata['repoid'] = repoid - entropy.tools.save_repository_settings(repodata, enable = True) + self.__save_repository_settings(repodata, enable = True) self.SystemSettings.clear() self.close_all_repositories() self.validate_repositories() @@ -362,7 +479,7 @@ class RepositoryMixin: # save new self.SystemSettings['repositories']['available'] to file repodata = {} repodata['repoid'] = repoid - entropy.tools.save_repository_settings(repodata, disable = True) + self.__save_repository_settings(repodata, disable = True) self.SystemSettings.clear() self.close_all_repositories() diff --git a/libraries/entropy/tools.py b/libraries/entropy/tools.py index e9bf1cd0a..f14ae9389 100644 --- a/libraries/entropy/tools.py +++ b/libraries/entropy/tools.py @@ -1869,7 +1869,7 @@ def remove_tag(mydep): @return: @rtype: """ - colon = mydep.rfind("#") + colon = mydep.rfind(etpConst['entropytagprefix']) if colon == -1: return mydep return mydep[:colon] @@ -1960,7 +1960,7 @@ def dep_gettag(mydep): """ dep = mydep[:] dep = remove_entropy_revision(dep) - colon = dep.rfind("#") + colon = dep.rfind(etpConst['entropytagprefix']) if colon != -1: mydep = dep[colon+1:] rslt = remove_slot(mydep) @@ -2587,147 +2587,6 @@ def convert_seconds_to_fancy_output(seconds): output.reverse() return ':'.join(output) -def read_repositories_conf(): - """ - docstring_title - - @return: - @rtype: - """ - content = [] - if os.path.isfile(etpConst['repositoriesconf']): - f = open(etpConst['repositoriesconf']) - content = f.readlines() - f.close() - return content - -def write_ordered_repositories_entries(ordered_repository_list): - """ - docstring_title - - @param ordered_repository_list: - @type ordered_repository_list: - @return: - @rtype: - """ - content = read_repositories_conf() - content = [x.strip() for x in content] - repolines = [x for x in content if x.startswith("repository|") and \ - (len(x.split("|")) == 5)] - content = [x for x in content if x not in repolines] - for repoid in ordered_repository_list: - # get repoid from repolines - for x in repolines: - repoidline = x.split("|")[1] - if repoid == repoidline: - content.append(x) - _save_repositories_content(content) - -def save_repository_settings(repodata, remove = False, disable = False, - enable = False): - """ - docstring_title - - @param repodata: - @type repodata: - @keyword remove: - @type remove: - @keyword disable: - @type disable: - @keyword enable: - @type enable: - @return: - @rtype: - """ - - if repodata['repoid'].endswith(etpConst['packagesext']): - return - - content = read_repositories_conf() - content = [x.strip() for x in content] - if not disable and not enable: - content = [x for x in content if not x.startswith("repository|"+repodata['repoid'])] - if remove: - # also remove possible disable repo - content = [x for x in content if not (x.startswith("#") and not x.startswith("##") and (x.find("repository|"+repodata['repoid']) != -1))] - if not remove: - - repolines = [x for x in content if x.startswith("repository|") or (x.startswith("#") and not x.startswith("##") and (x.find("repository|") != -1))] - content = [x for x in content if x not in repolines] # exclude lines from repolines - # filter sane repolines lines - repolines = [x for x in repolines if (len(x.split("|")) == 5)] - repolines_data = {} - repocount = 0 - for x in repolines: - repolines_data[repocount] = {} - repolines_data[repocount]['repoid'] = x.split("|")[1] - repolines_data[repocount]['line'] = x - if disable and x.split("|")[1] == repodata['repoid']: - if not x.startswith("#"): - x = "#"+x - repolines_data[repocount]['line'] = x - elif enable and x.split("|")[1] == repodata['repoid'] and x.startswith("#"): - repolines_data[repocount]['line'] = x[1:] - repocount += 1 - - if not disable and not enable: # so it's a add - - line = "repository|%s|%s|%s|%s#%s#%s,%s" % ( repodata['repoid'], - repodata['description'], - ' '.join(repodata['plain_packages']), - repodata['plain_database'], - repodata['dbcformat'], - repodata['service_port'], - repodata['ssl_service_port'], - ) - - # seek in repolines_data for a disabled entry and remove - to_remove = set() - for cc in repolines_data: - if repolines_data[cc]['line'].startswith("#") and \ - (repolines_data[cc]['line'].find("repository|"+repodata['repoid']) != -1): - # then remove - to_remove.add(cc) - for x in to_remove: - del repolines_data[x] - - repolines_data[repocount] = {} - repolines_data[repocount]['repoid'] = repodata['repoid'] - repolines_data[repocount]['line'] = line - - # inject new repodata - keys = sorted(repolines_data.keys()) - for cc in keys: - #repoid = repolines_data[cc]['repoid'] - # write the first - line = repolines_data[cc]['line'] - content.append(line) - - try: - _save_repositories_content(content) - except OSError: # permission denied? - return False - return True - -def _save_repositories_content(content): - """ - docstring_title - - @param content: - @type content: - @return: - @rtype: - """ - if os.path.isfile(etpConst['repositoriesconf']): - if os.path.isfile(etpConst['repositoriesconf']+".old"): - os.remove(etpConst['repositoriesconf']+".old") - shutil.copy2(etpConst['repositoriesconf'], etpConst['repositoriesconf']+".old") - f = open(etpConst['repositoriesconf'], "w") - for x in content: - f.write(x+"\n") - f.flush() - f.close() - def write_parameter_to_file(config_file, name, data): """ docstring_title @@ -2857,19 +2716,6 @@ def is_valid_md5(myhash): return True return False -def open_buffer(): - """ - docstring_title - - @return: - @rtype: - """ - try: - import io as stringio - except ImportError: - import io as stringio - return stringio.StringIO() - def seek_till_newline(f): """ docstring_title @@ -3219,7 +3065,7 @@ def create_package_filename(category, name, version, package_tag): @rtype: """ if package_tag: - package_tag = "#%s" % (package_tag,) + package_tag = "%s%s" % (etpConst['entropytagprefix'], package_tag,) else: package_tag = '' @@ -3244,7 +3090,7 @@ def create_package_atom_string(category, name, version, package_tag): @rtype: """ if package_tag: - package_tag = "#%s" % (package_tag,) + package_tag = "%s%s" % (etpConst['entropytagprefix'], package_tag,) else: package_tag = '' package_name = "%s/%s-%s" % (category, name, version,)