From 076bf3106fcfe884d29be3ec16dcd8d7cef44fd0 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Wed, 11 Mar 2015 11:56:49 +0000 Subject: Allow glob patterns in the 'ignore' field for upstream Troves The documentation on wiki.baserock.org described the 'ignore' field as "glob patterns on repository pathnames which to not mirror (trove only)" but it was actually being treated as a simple list of repos to ignore. Globs are much more useful. --- README | 5 +++-- lorrycontroller/lstroves.py | 14 +++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README b/README index 31ad55e..d5e9d8a 100644 --- a/README +++ b/README @@ -126,8 +126,9 @@ Additionally, the following optional keys are allowed in Trove specifications: * `ignore` -- a list of git repositories from the other Trove that - should NOT be mirrored. Each list element is a path to the git - repository (not including leading slash). + should NOT be mirrored. Each list element is a glob pattern which + is matched against the path to the git repository (not including leading + slash). * `auth` -- specify how to authenticate to the remote Trove over https (only). It should be a dictionary with the fields `username` and diff --git a/lorrycontroller/lstroves.py b/lorrycontroller/lstroves.py index e69dce2..72515f5 100644 --- a/lorrycontroller/lstroves.py +++ b/lorrycontroller/lstroves.py @@ -1,4 +1,4 @@ -# Copyright (C) 2014 Codethink Limited +# Copyright (C) 2014-2015 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -14,12 +14,11 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import fnmatch import json import logging -import time import bottle -import cliapp import lorrycontroller @@ -83,8 +82,13 @@ class TroveRepositoryLister(object): return repo_paths def skip_ignored_repos(self, trovehost, repo_paths): - ignored_paths = json.loads(trovehost['ignore']) - return [x for x in repo_paths if x not in ignored_paths] + ignored_patterns = json.loads(trovehost['ignore']) + + ignored_paths = set() + for pattern in ignored_patterns: + ignored_paths.update(fnmatch.filter(repo_paths, pattern)) + + return set(repo_paths).difference(ignored_paths) def map_remote_repos_to_local_ones(self, trove_info, remote_paths): '''Return a dict that maps each remote repo path to a local one.''' -- cgit v1.2.1