Merge lp:~sergiusens/snapcraft/1507814 into lp:~snappy-dev/snapcraft/core

Proposed by Sergio Schvezov
Status: Merged
Approved by: Sergio Schvezov
Approved revision: 251
Merged at revision: 250
Proposed branch: lp:~sergiusens/snapcraft/1507814
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 79 lines (+21/-13)
3 files modified
integration-tests/data/assemble/snapcraft.yaml (+1/-1)
integration-tests/units/jobs.pxu (+11/-1)
snapcraft/cmds.py (+9/-11)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/1507814
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
Review via email: mp+275021@code.launchpad.net

Commit message

Query the apt cache to verify if a package is installed or not

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Looks good, one (silly) suggestion inline.

review: Needs Fixing
Revision history for this message
Michael Vogt (mvo) wrote :

Uh, sorry I'm an idiot, this should have been an "approve" before already. Using apt-get is fine of course and you can just use "apt-get -o Dpkg::Progress-Fancy=1" to get the same nice progress bar.

review: Approve
lp:~sergiusens/snapcraft/1507814 updated
251. By Sergio Schvezov

Use fancy progress for apt

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'integration-tests/data/assemble/snapcraft.yaml'
2--- integration-tests/data/assemble/snapcraft.yaml 2015-09-30 17:13:13 +0000
3+++ integration-tests/data/assemble/snapcraft.yaml 2015-10-20 13:49:32 +0000
4@@ -16,5 +16,5 @@
5
6 parts:
7 make-project:
8- plugin: make-project
9+ plugin: make
10 source: .
11
12=== modified file 'integration-tests/units/jobs.pxu'
13--- integration-tests/units/jobs.pxu 2015-10-20 01:49:04 +0000
14+++ integration-tests/units/jobs.pxu 2015-10-20 13:49:32 +0000
15@@ -63,11 +63,21 @@
16 test ! -e ./snap/dir
17 flags: simple has-leftovers
18
19+id: snapcraft/normal/assemble-inexistent-build-package
20+command:
21+ set -x
22+ cp -rT $PLAINBOX_PROVIDER_DATA/assemble .
23+ echo "build-packages:" >> snapcraft.yaml
24+ echo " - inexistent-package" >> snapcraft.yaml
25+ OUTPUT=$(${SNAPCRAFT} assemble 2>&1)
26+ echo $OUTPUT | grep "Could not find all the .*build-packages.* required in snapcraft\.yaml"
27+flags: simple has-leftovers
28+
29 id: snapcraft/normal/assemble-no-plugin
30 command:
31 set -x
32 cp -rT $PLAINBOX_PROVIDER_DATA/assemble .
33- sed -e '/.*plugin: make-project$/d' -i snapcraft.yaml
34+ sed -e '/ *plugin: make$/d' -i snapcraft.yaml
35 OUTPUT=$(${SNAPCRAFT} assemble 2>&1)
36 test $? = 1 || exit 1
37 echo $OUTPUT | grep -q 'Issues while validating snapcraft.yaml: the "plugin" keyword is missing for the "make-project" part.'
38
39=== modified file 'snapcraft/cmds.py'
40--- snapcraft/cmds.py 2015-10-19 20:42:36 +0000
41+++ snapcraft/cmds.py 2015-10-20 13:49:32 +0000
42@@ -14,6 +14,7 @@
43 # You should have received a copy of the GNU General Public License
44 # along with this program. If not, see <http://www.gnu.org/licenses/>.
45
46+import apt
47 import filecmp
48 import glob
49 import logging
50@@ -351,21 +352,18 @@
51
52 def _install_build_packages(packages):
53 new_packages = []
54- for check_pkg in packages:
55- if subprocess.call(['dpkg-query', '-s', check_pkg],
56- stdout=subprocess.DEVNULL,
57- stderr=subprocess.DEVNULL) != 0:
58- new_packages.append(check_pkg)
59- if new_packages:
60- logger.info('Installing required packages on the host system')
61+ for pkg in packages:
62 try:
63- _check_call(
64- ['sudo', 'apt-get', '-y', 'install'] + new_packages,
65- stdout=subprocess.DEVNULL)
66- except subprocess.CalledProcessError:
67+ if not apt.Cache()[pkg].installed:
68+ new_packages.append(pkg)
69+ except KeyError:
70 logger.error('Could not find all the "build-packages" required '
71 'in snapcraft.yaml')
72 sys.exit(1)
73+ if new_packages:
74+ logger.info('Installing required packages on the host system')
75+ _check_call(['sudo', 'apt-get', '-o', 'Dpkg::Progress-Fancy=1',
76+ '-y', 'install'] + new_packages)
77
78
79 def _load_config():

Subscribers

People subscribed via source and target branches