diff options
author | Christopher Larson <chris_larson@mentor.com> | 2014-08-25 15:57:44 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-08-27 12:12:29 +0100 |
commit | 8491ca52b86f22c0d9ba8e4c927262dab322969c (patch) | |
tree | 8a0f34f34569418120bc4c4121146a0a20be2dff | |
parent | af6d66852f1868f00d24e0ff1d9ac0c9e82434ac (diff) | |
download | ast2050-yocto-poky-8491ca52b86f22c0d9ba8e4c927262dab322969c.zip ast2050-yocto-poky-8491ca52b86f22c0d9ba8e4c927262dab322969c.tar.gz |
sanity: refactor mirrors checks to be more pythonic
- Use clearer variable names
- Use variable unpacking to reference elements by name rather than index
- Sacrifice a small amount of time (iterate over protocols twice per entry
rather than once) for clarity: use readable generator expressions with any()
rather than maintaining state.
(From OE-Core rev: 9d31e1e6ce07991fe360e67295311e62a55603af)
Signed-off-by: Christopher Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/classes/sanity.bbclass | 73 |
1 files changed, 35 insertions, 38 deletions
diff --git a/meta/classes/sanity.bbclass b/meta/classes/sanity.bbclass index f655d8b..5be5efb 100644 --- a/meta/classes/sanity.bbclass +++ b/meta/classes/sanity.bbclass @@ -755,44 +755,41 @@ def check_sanity_everybuild(status, d): # Check the format of MIRRORS, PREMIRRORS and SSTATE_MIRRORS import re - mir_types = ['MIRRORS', 'PREMIRRORS', 'SSTATE_MIRRORS'] - protocols = ['http://', 'ftp://', 'file://', 'https://', \ - 'git://', 'gitsm://', 'hg://', 'osc://', 'p4://', 'svk://', 'svn://', \ - 'bzr://', 'cvs://'] - for mir_type in mir_types: - mirros = (d.getVar(mir_type, True) or '').replace('\\n', '\n').split('\n') - for mir in mirros: - mir_list = mir.split() - # Should be two members. - if len(mir_list) not in [0, 2]: - bb.warn('Invalid %s: %s, should be 2 members, but found %s.' \ - % (mir_type, mir.strip(), len(mir_list))) - elif len(mir_list) == 2: - decoded = bb.fetch2.decodeurl(mir_list[0]) - try: - pattern_scheme = re.compile(decoded[0]) - except re.error as exc: - bb.warn('Invalid scheme regex (%s) in %s: %s' % (decoded[0], mir_type, mir.strip())) - continue - - # Each member should start with protocols - valid_protocol_0 = False - valid_protocol_1 = False - file_absolute = True - for protocol in protocols: - if not valid_protocol_0 and pattern_scheme.match(protocol[:-3]): - valid_protocol_0 = True - if not valid_protocol_1 and mir_list[1].startswith(protocol): - valid_protocol_1 = True - # The file:// must be an absolute path. - if protocol == 'file://' and not mir_list[1].startswith('file:///'): - file_absolute = False - if valid_protocol_0 and valid_protocol_1: - break - if not (valid_protocol_0 and valid_protocol_1): - bb.warn('Invalid protocol in %s: %s' % (mir_type, mir.strip())) - if not file_absolute: - bb.warn('Invalid file url in %s: %s, must be absolute path (file:///)' % (mir_type, mir.strip())) + mirror_vars = ['MIRRORS', 'PREMIRRORS', 'SSTATE_MIRRORS'] + protocols = ['http', 'ftp', 'file', 'https', \ + 'git', 'gitsm', 'hg', 'osc', 'p4', 'svk', 'svn', \ + 'bzr', 'cvs'] + for mirror_var in mirror_vars: + mirrors = (d.getVar(mirror_var, True) or '').replace('\\n', '\n').split('\n') + for mirror_entry in mirrors: + mirror_entry = mirror_entry.strip() + if not mirror_entry: + # ignore blank lines + continue + + try: + pattern, mirror = mirror_entry.split() + except ValueError: + bb.warn('Invalid %s: %s, should be 2 members.' % (mirror_var, mirror_entry.strip())) + continue + + decoded = bb.fetch2.decodeurl(pattern) + try: + pattern_scheme = re.compile(decoded[0]) + except re.error as exc: + bb.warn('Invalid scheme regex (%s) in %s; %s' % (pattern, mirror_var, mirror_entry)) + continue + + if not any(pattern_scheme.match(protocol) for protocol in protocols): + bb.warn('Invalid protocol (%s) in %s: %s' % (decoded[0], mirror_var, mirror_entry)) + continue + + if not any(mirror.startswith(protocol + '://') for protocol in protocols): + bb.warn('Invalid protocol in %s: %s' % (mirror_var, mirror_entry)) + continue + + if mirror.startswith('file://') and not mirror.startswith('file:///'): + bb.warn('Invalid file url in %s: %s, must be absolute path (file:///)' % (mirror_var, mirror_entry)) # Check that TMPDIR hasn't changed location since the last time we were run tmpdir = d.getVar('TMPDIR', True) |