From 4b0e7ee7d379caba8593b5d529d093151029643d Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Thu, 20 Sep 2012 12:53:49 +0200 Subject: [PATCH] [entropy.tools] introduce expand_plain_database_mirror() This follows the previously introduced expand_plain_package_mirror() method. Now both methods can expand repository and package mirror URLs read from Entropy repository configuration files adding product, arch and branch information. --- lib/entropy/core/settings/base.py | 11 +++++------ lib/entropy/tools.py | 28 +++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/lib/entropy/core/settings/base.py b/lib/entropy/core/settings/base.py index 79e7bc72c..b265c3d4d 100644 --- a/lib/entropy/core/settings/base.py +++ b/lib/entropy/core/settings/base.py @@ -1373,9 +1373,11 @@ class SystemSettings(Singleton, EntropyPluginStore): raise AttributeError("invalid repository database URL") mydata['plain_database'] = repodatabase - mydata['database'] = repodatabase + os.path.sep + product + \ - os.path.sep + reponame + "/database/" + etpConst['currentarch'] + \ - os.path.sep + branch + database = entropy.tools.expand_plain_database_mirror( + repodatabase, product, reponame, branch) + if database is None: + database = const_convert_to_unicode("") + mydata['database'] = database mydata['notice_board'] = mydata['database'] + os.path.sep + \ etpConst['rss-notice-board'] @@ -1419,9 +1421,6 @@ class SystemSettings(Singleton, EntropyPluginStore): repopackages = [x.strip() for x in repopackages.split() if x.strip()] for repo_package in repopackages: - if not entropy.tools.is_valid_uri(repo_package): - # filter out - continue new_repo_package = entropy.tools.expand_plain_package_mirror( repo_package, product, reponame) if new_repo_package is None: diff --git a/lib/entropy/tools.py b/lib/entropy/tools.py index b9ddfa50a..e5ac96619 100644 --- a/lib/entropy/tools.py +++ b/lib/entropy/tools.py @@ -2490,16 +2490,34 @@ def expand_plain_package_mirror(mirror, product, repository_id): @type product: string @param repository_id: repository identifier @type repository_id: string - @return: expanded URL or None, if mirror url is invalid + @return: expanded URL or None if invalid @rtype: string or None """ if not is_valid_uri(mirror): return None - try: - mirror = str(mirror) - except (UnicodeDecodeError, UnicodeEncodeError,): + sep = const_convert_to_unicode("/") + return mirror + sep + product + sep + repository_id + +def expand_plain_database_mirror(mirror, product, repository_id, branch): + """ + Expand plain database mirror URL adding product, repository identifier + and branch data to it. + + @param mirror: mirror URL + @type mirror: string + @param product: Entropy repository product + @type product: string + @param repository_id: repository identifier + @type repository_id: string + @return: expanded URL or None if invalid + @rtype: string or None + """ + if not is_valid_uri(mirror): return None - return mirror + os.path.sep + product + os.path.sep + repository_id + sep = const_convert_to_unicode("/") + return mirror + sep + product + sep + repository_id + sep + \ + etpConst['databaserelativepath_basedir'] + sep + \ + etpConst['currentarch'] + sep + branch _repo_re = re.compile("^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$", re.IGNORECASE) def validate_repository_id(repository_id):