#NEWLINE# def apt( s ) : #NEWLINE# #INDENT# '\n    Walk the dependency tree of all the packages in set s all the way to\n    the leaves.  Return the set of s plus all their dependencies.\n    ' #NEWLINE# logging . debug ( 'searching for APT dependencies' ) #NEWLINE# if ( not isinstance ( s , set ) ) : #NEWLINE# #INDENT# s = set ( [ s ] ) #NEWLINE# #UNINDENT# tmp_s = s #NEWLINE# pattern_sub = re . compile ( '\\([^)]+\\)' ) #NEWLINE# pattern_split = re . compile ( '[,\\|]' ) #NEWLINE# while 1 : #NEWLINE# #INDENT# new_s = set ( ) #NEWLINE# for package in tmp_s : #NEWLINE# #INDENT# p = subprocess . Popen ( [ 'dpkg-query' , '-f' , '${Pre-Depends}\n${Depends}\n${Recommends}\n' , '-W' , package ] , close_fds = True , stdout = subprocess . PIPE ) #NEWLINE# for line in p . stdout : #NEWLINE# #INDENT# line = line . strip ( ) #NEWLINE# if ( '' == line ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# for part in pattern_split . split ( pattern_sub . sub ( '' , part ) ) : #NEWLINE# #INDENT# new_s . add ( part . strip ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# tmp_s = ( new_s - s ) #NEWLINE# if ( 0 == len ( tmp_s ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# s |= new_s #NEWLINE# #UNINDENT# return s