summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Larson <chris_larson@mentor.com>2014-08-25 15:57:44 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-08-27 12:12:29 +0100
commit8491ca52b86f22c0d9ba8e4c927262dab322969c (patch)
tree8a0f34f34569418120bc4c4121146a0a20be2dff
parentaf6d66852f1868f00d24e0ff1d9ac0c9e82434ac (diff)
downloadpoky-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.bbclass73
1 files changed, 35 insertions, 38 deletions
diff --git a/meta/classes/sanity.bbclass b/meta/classes/sanity.bbclass
index f655d8bf61..5be5efb8a4 100644
--- a/meta/classes/sanity.bbclass
+++ b/meta/classes/sanity.bbclass
@@ -755,44 +755,41 @@ def check_sanity_everybuild(status, d):
755 755
756 # Check the format of MIRRORS, PREMIRRORS and SSTATE_MIRRORS 756 # Check the format of MIRRORS, PREMIRRORS and SSTATE_MIRRORS
757 import re 757 import re
758 mir_types = ['MIRRORS', 'PREMIRRORS', 'SSTATE_MIRRORS'] 758 mirror_vars = ['MIRRORS', 'PREMIRRORS', 'SSTATE_MIRRORS']
759 protocols = ['http://', 'ftp://', 'file://', 'https://', \ 759 protocols = ['http', 'ftp', 'file', 'https', \
760 'git://', 'gitsm://', 'hg://', 'osc://', 'p4://', 'svk://', 'svn://', \ 760 'git', 'gitsm', 'hg', 'osc', 'p4', 'svk', 'svn', \
761 'bzr://', 'cvs://'] 761 'bzr', 'cvs']
762 for mir_type in mir_types: 762 for mirror_var in mirror_vars:
763 mirros = (d.getVar(mir_type, True) or '').replace('\\n', '\n').split('\n') 763 mirrors = (d.getVar(mirror_var, True) or '').replace('\\n', '\n').split('\n')
764 for mir in mirros: 764 for mirror_entry in mirrors:
765 mir_list = mir.split() 765 mirror_entry = mirror_entry.strip()
766 # Should be two members. 766 if not mirror_entry:
767 if len(mir_list) not in [0, 2]: 767 # ignore blank lines
768 bb.warn('Invalid %s: %s, should be 2 members, but found %s.' \ 768 continue
769 % (mir_type, mir.strip(), len(mir_list))) 769
770 elif len(mir_list) == 2: 770 try:
771 decoded = bb.fetch2.decodeurl(mir_list[0]) 771 pattern, mirror = mirror_entry.split()
772 try: 772 except ValueError:
773 pattern_scheme = re.compile(decoded[0]) 773 bb.warn('Invalid %s: %s, should be 2 members.' % (mirror_var, mirror_entry.strip()))
774 except re.error as exc: 774 continue
775 bb.warn('Invalid scheme regex (%s) in %s: %s' % (decoded[0], mir_type, mir.strip())) 775
776 continue 776 decoded = bb.fetch2.decodeurl(pattern)
777 777 try:
778 # Each member should start with protocols 778 pattern_scheme = re.compile(decoded[0])
779 valid_protocol_0 = False 779 except re.error as exc:
780 valid_protocol_1 = False 780 bb.warn('Invalid scheme regex (%s) in %s; %s' % (pattern, mirror_var, mirror_entry))
781 file_absolute = True 781 continue
782 for protocol in protocols: 782
783 if not valid_protocol_0 and pattern_scheme.match(protocol[:-3]): 783 if not any(pattern_scheme.match(protocol) for protocol in protocols):
784 valid_protocol_0 = True 784 bb.warn('Invalid protocol (%s) in %s: %s' % (decoded[0], mirror_var, mirror_entry))
785 if not valid_protocol_1 and mir_list[1].startswith(protocol): 785 continue
786 valid_protocol_1 = True 786
787 # The file:// must be an absolute path. 787 if not any(mirror.startswith(protocol + '://') for protocol in protocols):
788 if protocol == 'file://' and not mir_list[1].startswith('file:///'): 788 bb.warn('Invalid protocol in %s: %s' % (mirror_var, mirror_entry))
789 file_absolute = False 789 continue
790 if valid_protocol_0 and valid_protocol_1: 790
791 break 791 if mirror.startswith('file://') and not mirror.startswith('file:///'):
792 if not (valid_protocol_0 and valid_protocol_1): 792 bb.warn('Invalid file url in %s: %s, must be absolute path (file:///)' % (mirror_var, mirror_entry))
793 bb.warn('Invalid protocol in %s: %s' % (mir_type, mir.strip()))
794 if not file_absolute:
795 bb.warn('Invalid file url in %s: %s, must be absolute path (file:///)' % (mir_type, mir.strip()))
796 793
797 # Check that TMPDIR hasn't changed location since the last time we were run 794 # Check that TMPDIR hasn't changed location since the last time we were run
798 tmpdir = d.getVar('TMPDIR', True) 795 tmpdir = d.getVar('TMPDIR', True)