Merge lp:~sergiusens/phablet-tools/recovery_from_system_images into lp:phablet-tools

Proposed by Sergio Schvezov
Status: Merged
Approved by: Sergio Schvezov
Approved revision: 178
Merged at revision: 177
Proposed branch: lp:~sergiusens/phablet-tools/recovery_from_system_images
Merge into: lp:phablet-tools
Diff against target: 107 lines (+27/-5)
4 files modified
debian/control (+1/-0)
phabletutils/environment.py (+1/-1)
phabletutils/fileutils.py (+12/-0)
phabletutils/projects.py (+13/-4)
To merge this branch: bzr merge lp:~sergiusens/phablet-tools/recovery_from_system_images
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Stéphane Graber Approve
Review via email: mp+183868@code.launchpad.net

Commit message

Using device file from system image server to extract recovery instead of downloading the latest from cdimage.

Description of the change

Keep in mind that by accepting this, you are marking partitions/recovery.img as a stable interface.

I can add some magic to finding and extracting the right file, but this may as well be stable.

To post a comment you must log in.
Revision history for this message
Stéphane Graber (stgraber) wrote :

Assuming this was tested, the code change looks good.

Note that in python3 python-tarfile supports opening xz-compressed files directly ("r:xz" mode) but I had reliability problems when doing that as part of the server work, so using lzma + uncompressed tarfile is probably safest at this point.

Revision history for this message
Stéphane Graber (stgraber) wrote :

Oh, the above comment was meant to be an ack.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2013-08-20 20:45:44 +0000
3+++ debian/control 2013-09-04 12:58:37 +0000
4@@ -5,6 +5,7 @@
5 Build-Depends: debhelper (>= 9.0.0),
6 python (>= 2.7),
7 python-configobj,
8+ python-lzma,
9 python-mock,
10 python-requests,
11 python-setuptools,
12
13=== modified file 'phabletutils/environment.py'
14--- phabletutils/environment.py 2013-08-28 14:17:46 +0000
15+++ phabletutils/environment.py 2013-09-04 12:58:37 +0000
16@@ -216,7 +216,7 @@
17 return projects.UbuntuTouchSystem(
18 file_list=files,
19 command_part=command_part,
20- recovery=recovery,
21+ device=device,
22 backup=args.backup)
23
24
25
26=== modified file 'phabletutils/fileutils.py'
27--- phabletutils/fileutils.py 2013-08-22 22:25:37 +0000
28+++ phabletutils/fileutils.py 2013-09-04 12:58:37 +0000
29@@ -15,9 +15,12 @@
30 # along with this program. If not, see <http://www.gnu.org/licenses/>.
31
32 import atexit
33+import contextlib
34 import logging
35+import lzma
36 import os.path
37 import shutil
38+import tarfile
39 import tempfile
40
41
42@@ -48,3 +51,12 @@
43 else:
44 raise e
45 return directory
46+
47+
48+def lzma_extract_file(lzma_tarfile, file_name):
49+ log.info('Decompressing %s from %s' % (file_name, lzma_tarfile))
50+ temp_dir = create_temp_dir()
51+ with contextlib.closing(lzma.LZMAFile(lzma_tarfile)) as xz:
52+ with tarfile.open(fileobj=xz) as tar:
53+ tar.extract(member=file_name, path=temp_dir)
54+ return os.path.join(temp_dir, file_name)
55
56=== modified file 'phabletutils/projects.py'
57--- phabletutils/projects.py 2013-08-24 12:18:07 +0000
58+++ phabletutils/projects.py 2013-09-04 12:58:37 +0000
59@@ -26,6 +26,7 @@
60 from phabletutils.resources import (File, SignedFile)
61 from phabletutils import backup
62 from phabletutils import downloads
63+from phabletutils import fileutils
64 from time import sleep
65 from textwrap import dedent
66
67@@ -218,9 +219,9 @@
68 mount system
69 ''')
70
71- def __init__(self, file_list, recovery, command_part, backup):
72+ def __init__(self, file_list, device, command_part, backup):
73 log.debug('UbuntuTouchSystem')
74- super(UbuntuTouchSystem, self).__init__(recovery=recovery, wipe=True)
75+ super(UbuntuTouchSystem, self).__init__(wipe=True)
76 for item in file_list:
77 if item and not isinstance(item, File):
78 raise TypeError('%s is not of type File' % item)
79@@ -229,6 +230,11 @@
80 self._recovery_list = file_list
81 self._command_part = command_part
82 self._backup = backup
83+ self._device = device
84+
85+ def _is_device_file(self, entry):
86+ f = os.path.basename(entry.path)
87+ return f.startswith(self._device) and f.endswith('.xz')
88
89 def install(self, adb, fastboot=None):
90 """
91@@ -250,11 +256,14 @@
92 adb.push(entry.sig_path, '/cache/recovery/')
93 except AttributeError:
94 pass
95+ if self._is_device_file(entry):
96+ recovery_path = fileutils.lzma_extract_file(
97+ entry.path, 'partitions/recovery.img')
98 adb.push(self.create_ubuntu_command_file(),
99 '/cache/recovery/ubuntu_command')
100 adb.reboot(bootloader=True)
101- fastboot.flash('recovery', self._recovery.path)
102- fastboot.boot(self._recovery.path)
103+ fastboot.flash('recovery', recovery_path)
104+ fastboot.boot(recovery_path)
105 self._loop_until_installed(adb)
106 if backup_file:
107 log.warning('Restoring from backup')

Subscribers

People subscribed via source and target branches