<s> from debile . utils . commands import run_command <EOL> def arch_matches ( arch , alias ) : <EOL> """<STR_LIT>""" <EOL> if arch == alias : <EOL> return True <EOL> if arch == '<STR_LIT:all>' or arch == '<STR_LIT:source>' : <EOL> return False <EOL> if alias == '<STR_LIT>' : <EOL> return True <EOL> if alias == '<STR_LIT>' : <EOL> return '<STR_LIT:->' not in arch or '<STR_LIT>' in arch . split ( '<STR_LIT:->' ) <EOL> if alias . endswith ( '<STR_LIT>' ) : <EOL> osname , _ = alias . split ( '<STR_LIT:->' , <NUM_LIT:1> ) <EOL> return osname in arch . split ( '<STR_LIT:->' ) <EOL> if "<STR_LIT:->" not in arch and "<STR_LIT:->" not in alias : <EOL> return False <EOL> out , err , ret = run_command ( [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" % ( arch ) , <EOL> "<STR_LIT>" % ( alias ) <EOL> ] ) <EOL> return ret == <NUM_LIT:0> <EOL> def get_preferred_affinity ( <EOL> affinity_preference , valid_affinities , valid_arches <EOL> ) : <EOL> """<STR_LIT>""" <EOL> for affinity in affinity_preference : <EOL> arch = None <EOL> for x in valid_arches : <EOL> if x . name == affinity : <EOL> arch = x <EOL> break <EOL> if arch is None : <EOL> continue <EOL> for alias in valid_affinities : <EOL> if arch_matches ( affinity , alias ) : <EOL> return arch <EOL> raise ValueError ( <EOL> "<STR_LIT>" % ( <EOL> "<STR_LIT:U+002CU+0020>" . join ( affinity_preference ) , <EOL> "<STR_LIT:U+002CU+0020>" . join ( valid_affinities ) , <EOL> "<STR_LIT:U+002CU+0020>" . join ( [ x . name for x in valid_arches ] ) , ) ) <EOL> def get_source_arches ( dsc_arches , valid_arches ) : <EOL> """<STR_LIT>""" <EOL> ret = [ ] <EOL> for arch in valid_arches : <EOL> for alias in dsc_arches : <EOL> if arch_matches ( arch . name , alias ) : <EOL> ret . append ( arch ) <EOL> break <EOL> return ret </s>
