Skip to content

Commit

Permalink
Merge pull request devstructure#137 from cpbills/master
Browse files Browse the repository at this point in the history
Debian multi-arch support fix
  • Loading branch information
rcrowley committed Jun 22, 2013
2 parents ee70d9d + 91c389d commit 7eb16b0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions blueprint/backend/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Search for `apt` packages to include in the blueprint.
"""

import os
import logging
import subprocess

Expand All @@ -11,13 +12,22 @@
def apt(b, r):
logging.info('searching for APT packages')

# define a default output format string for dpkg-query
output_format = '${Status}\x1E${binary:Package}\x1E${Version}\n'

# try running dpkg --print-foreign-architectures to see if dpkg is
# multi-arch aware. if not, revert to old style output_format
with open(os.devnull, 'w') as fnull:
rv = subprocess.call(['dpkg', '--print-foreign-architectures'],
stdout = fnull, stderr = fnull)
if rv != 0:
output_format = '${Status}\x1E${Package}\x1E${Version}\n'

# Try for the full list of packages. If this fails, don't even
# bother with the rest because this is probably a Yum/RPM-based
# system.
try:
p = subprocess.Popen(['dpkg-query',
'-f=${Status}\x1E${Package}\x1E${Version}\n',
'-W'],
p = subprocess.Popen(['dpkg-query','-Wf', output_format],
close_fds=True, stdout=subprocess.PIPE)
except OSError:
return
Expand Down

0 comments on commit 7eb16b0

Please sign in to comment.