[gnome-continuous-yocto/gnomeostree-3.28-rocko: 2506/8267] recipetool: create: fix name/version extraction from filename
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-continuous-yocto/gnomeostree-3.28-rocko: 2506/8267] recipetool: create: fix name/version extraction from filename
- Date: Sat, 16 Dec 2017 23:19:33 +0000 (UTC)
commit e30276cb185b5b4448628b39fbbd533abbb0f94e
Author: Paul Eggleton <paul eggleton linux intel com>
Date: Mon Sep 19 08:08:06 2016 +1200
recipetool: create: fix name/version extraction from filename
I ran into an example where recipetool was getting the name/version
completely wrong:
https://bitbucket.org/sortsmill/libunicodenames/downloads/libunicodenames-1.1.0_beta1.tar.xz
>From this it would create a libunicodenames-1.1.0-beta1_1.1.0-beta1.bb
file (likely because it couldn't split the file name and therefore took
all of it, then got the version from one of the files inside the
tarball). When this happens it's just irritating because you then have
to delete the recipe / run devtool reset and then run recipetool create
/ devtool add again and specify the version manually.
This patch is the result of systematically running the
determine_from_filename() function over the files on the Yocto Project
source mirror and my local downloads directory and fixing as many of the
generic issues as reasonably practical - it now gets the name and
version correct much more often. There are still cases where it won't,
but they are now in the minority.
(From OE-Core rev: 7b018b1d493a8d10fd02b8cc220990b191c87fe5)
Signed-off-by: Paul Eggleton <paul eggleton linux intel com>
Signed-off-by: Richard Purdie <richard purdie linuxfoundation org>
scripts/lib/recipetool/create.py | 50 +++++++++++++++++++++++++++----------
1 files changed, 36 insertions(+), 14 deletions(-)
---
diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py
index cd86747..f7b0676 100644
--- a/scripts/lib/recipetool/create.py
+++ b/scripts/lib/recipetool/create.py
@@ -256,27 +256,49 @@ def validate_pv(pv):
def determine_from_filename(srcfile):
"""Determine name and version from a filename"""
- part = ''
- if '.tar.' in srcfile:
- namepart = srcfile.split('.tar.')[0].lower()
- else:
- namepart = os.path.splitext(srcfile)[0].lower()
if is_package(srcfile):
# Force getting the value from the package metadata
return None, None
+
+ if '.tar.' in srcfile:
+ namepart = srcfile.split('.tar.')[0]
else:
- splitval = namepart.rsplit('_', 1)
+ namepart = os.path.splitext(srcfile)[0]
+ namepart = namepart.lower().replace('_', '-')
+ if namepart.endswith('.src'):
+ namepart = namepart[:-4]
+ if namepart.endswith('.orig'):
+ namepart = namepart[:-5]
+ splitval = namepart.split('-')
+ logger.debug('determine_from_filename: split name %s into: %s' % (srcfile, splitval))
+
+ ver_re = re.compile('^v?[0-9]')
+
+ pv = None
+ pn = None
if len(splitval) == 1:
- splitval = namepart.rsplit('-', 1)
- pn = splitval[0].replace('_', '-')
- if len(splitval) > 1:
- if splitval[1][0] in '0123456789':
- pv = splitval[1]
+ # Try to split the version out if there is no separator (or a .)
+ res = re.match('^([^0-9]+)([0-9.]+.*)$', namepart)
+ if res:
+ if len(res.group(1)) > 1 and len(res.group(2)) > 1:
+ pn = res.group(1).rstrip('.')
+ pv = res.group(2)
else:
- pn = '-'.join(splitval).replace('_', '-')
- pv = None
+ pn = namepart
else:
- pv = None
+ if splitval[-1] in ['source', 'src']:
+ splitval.pop()
+ if len(splitval) > 2 and re.match('^(alpha|beta|stable|release|rc[0-9]|pre[0-9]|p[0-9]|[0-9]{8})',
splitval[-1]) and ver_re.match(splitval[-2]):
+ pv = '-'.join(splitval[-2:])
+ if pv.endswith('-release'):
+ pv = pv[:-8]
+ splitval = splitval[:-2]
+ elif ver_re.match(splitval[-1]):
+ pv = splitval.pop()
+ pn = '-'.join(splitval)
+ if pv and pv.startswith('v'):
+ pv = pv[1:]
+ logger.debug('determine_from_filename: name = "%s" version = "%s"' % (pn, pv))
return (pn, pv)
def determine_from_url(srcuri):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]