Add partial path macro for vcs URL fields

Add a %pathelement[]% macro that lets you extract just the nth element
or a slice and substitute it into the URL. This will be used so we can
treat multiple repos that appear under the same base URL as belonging to
the same comparison layer, e.g.
https://github.com/somedistro/<packagename>/... would be handled
using the file URL
https://github.com/somedistro/%pathelement[0]%/blob/master/%pathelement[1:]%
so that the path /abc/fix.patch would generate the URL
https://github.com/somedistro/abc/blob/master/fix.patch

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2017-12-18 22:57:16 +13:00
parent 7b9cea66a4
commit 8ab9c15085

View File

@ -236,12 +236,28 @@ class LayerBranch(models.Model):
else:
branchname = self.branch.name
url = base_url.replace('%branch%', branchname)
if path:
splitpath = path.split('/')
for match in re.findall('(%pathelement\[([0-9]*)(:[0-9]*)?\]%)', url):
if match[1] == '':
start = None
else:
start = int(match[1])
if ':' in match[2]:
stopstr = match[2][1:]
if stopstr == '':
stop = None
else:
stop = int(stopstr)
url = url.replace(match[0], '/'.join(splitpath[start:stop]))
else:
url = url.replace(match[0], splitpath[start])
# If there's a % in the path (e.g. a wildcard bbappend) we need to encode it
if extra_path:
extra_path = extra_path.replace('%', '%25')
if '%path%' in base_url:
if '%path%' in base_url or '%pathelement[' in base_url:
if extra_path:
url = re.sub(r'\[([^\]]*%path%[^\]]*)\]', '\\1', url)
else: