From a96902b13e48c4c3d8badf9c02d19c0694a95685 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Thu, 8 Mar 2018 09:58:30 +0200 Subject: Use mount() in mount_and_install --- machammer/functions.py | 6 ++++-- tests.py | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/machammer/functions.py b/machammer/functions.py index 01e49bb..fa4fc63 100644 --- a/machammer/functions.py +++ b/machammer/functions.py @@ -145,7 +145,6 @@ def is_laptop(): def is_desktop(): return not is_laptop() - def mount_image(path, mp=None, *args): """Mount disk image and return path to mountpoint.""" logging.debug('Mounting image %s' % path) @@ -160,6 +159,7 @@ def mount_image(path, mp=None, *args): stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) + # work around EULA prompt out, err = p.communicate(input=b'Q\nY\n') logging.debug('mount_image got %s' % out) @@ -172,7 +172,7 @@ def mount_image(path, mp=None, *args): def mount_and_install(dmg, pkg): """Mounts the DMG and installs the PKG.""" - with mount_image(dmg) as p: + with mount(dmg) as p: install_pkg(os.path.join(p, pkg)) @@ -241,7 +241,9 @@ def mount(what, where=None): raise Exception('Invalid path: %s' % what) where = mount_image(what, where) + yield where + eject(where) diff --git a/tests.py b/tests.py index e860cfc..95288b7 100755 --- a/tests.py +++ b/tests.py @@ -144,6 +144,15 @@ class AppsTestCase(TestCase): self.assertTrue(len(results) > 10) +class InstallerTestCase(TestCase): + def setUp(self): + self.pkg = os.getenv('MH_PKG') + self.image = os.getenv('MH_IMAGE') + + def test_mount_and_install(self): + functions.mount_and_install(self.image, self.pkg) + + class MountTestCase(TestCase): def setUp(self): self.mp = None -- cgit v1.2.3