Merge lp:~a-j-buxton/phablet-tools/download-only into lp:phablet-tools

Proposed by Alistair Buxton
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 68
Merged at revision: 64
Proposed branch: lp:~a-j-buxton/phablet-tools/download-only
Merge into: lp:phablet-tools
Diff against target: 93 lines (+30/-22)
1 file modified
phablet-flash (+30/-22)
To merge this branch: bzr merge lp:~a-j-buxton/phablet-tools/download-only
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ricardo Salveti (community) Approve
Review via email: mp+152599@code.launchpad.net

Commit message

Adds an option to only download image files and skip device flashing.

Description of the change

Adds an option to only download image files and skip device flashing. If device is connected it will be autodetected as normal, but free space check is not done. If no device is connected, -d can be used to select a target device as normal.

To post a comment you must log in.
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

24 + '--download',

Would you mind using --download-only instead? This is just to make it easier for people when only reading the arg list.

37 - device = validate_device(adb, args.device)
38 + if args.download:
39 + device = detect_device(adb, args.device)
40 + else:
41 + device = validate_device(adb, args.device)

I'd suggest to always call detect_device and remove it from validate_device. Also move validate_device a bit bellow in the code, to call it only in case we're actually flashing the device (bellow line 59, for example).

review: Needs Fixing
Revision history for this message
Alistair Buxton (a-j-buxton) wrote :

I would agree with all of that. I also don't like how detect and validate exit(-1). They should raise an exception or something instead, then the caller can provide context sensitive help.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

> I would agree with all of that. I also don't like how detect and validate
> exit(-1). They should raise an exception or something instead, then the caller
> can provide context sensitive help.

+1, we can improve that at another MR if you prefer.

65. By Alistair Buxton

Download only v2:
 * Rename option to '--download-only'.
 * Remove some unneccessary logic.
 * Split detection and validation.
 * Add missing decorator to validate_device.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

71 + device = validate_device(adb, device)

We already know the device as we're calling detect_device for all use cases, so just call validate_device without checking for the returned value.

Also, please remove the "return device" from the validate_device function.

review: Needs Fixing
66. By Alistair Buxton

Don't return device from validate_device as it cannot modify it.

67. By Alistair Buxton

Really get rid of device parameter this time.

68. By Alistair Buxton

Remove it from the method call too.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Looks good, thanks!

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

FAILED: Continuous integration, rev:68
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~a-j-buxton/phablet-tools/download-only/+merge/152599/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/phablet-tools-ci/14/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/phablet-tools-ci/./build=pbuilder,distribution=quantal,flavor=i386/14/console

Click here to trigger a rebuild:
http://jenkins.qa.ubuntu.com/job/phablet-tools-ci/14//rebuild/?

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'phablet-flash'
--- phablet-flash 2013-02-26 16:04:10 +0000
+++ phablet-flash 2013-03-11 20:40:26 +0000
@@ -49,13 +49,21 @@
49 help='''Device serial. Use when more than49 help='''Device serial. Use when more than
50 one device is connected.''',50 one device is connected.''',
51 )51 )
52 parser.add_argument('-b',52 group = parser.add_mutually_exclusive_group()
53 '--bootstrap',53 group.add_argument('-b',
54 help='''Bootstrap the target device, this only54 '--bootstrap',
55 works on Nexus devices or devices that55 help='''Bootstrap the target device, this only
56 use fastboot and are unlocked.''',56 works on Nexus devices or devices that
57 action='store_true',57 use fastboot and are unlocked.''',
58 )58 action='store_true',
59 )
60 group.add_argument('-D',
61 '--download-only',
62 help='''Download image only, but do not flash device.
63 Use -d to override target device autodetection
64 if target device is not connected.''',
65 action='store_true',
66 )
59 parser.add_argument('-r',67 parser.add_argument('-r',
60 '--revision',68 '--revision',
61 required=False,69 required=False,
@@ -266,12 +274,11 @@
266 return jenkins_data274 return jenkins_data
267275
268276
269def validate_device(adb, device_param):277@adb_errors
278def validate_device(adb):
270 '''279 '''
271 Validates if the image would be installable on the target280 Validates if the image would be installable on the target
272 returns device
273 '''281 '''
274 device = detect_device(adb, device_param)
275 df = adb.shell('df').split('\n')282 df = adb.shell('df').split('\n')
276 try:283 try:
277 free_data = map(str.split, 284 free_data = map(str.split,
@@ -284,7 +291,6 @@
284 else:291 else:
285 log.error('Not enough space in /data, found %s', free_data)292 log.error('Not enough space in /data, found %s', free_data)
286 exit(1)293 exit(1)
287 return device
288294
289295
290def main(args):296def main(args):
@@ -295,7 +301,7 @@
295 adb = AndroidBridge(args.serial)301 adb = AndroidBridge(args.serial)
296 else:302 else:
297 adb = AndroidBridge()303 adb = AndroidBridge()
298 device = validate_device(adb, args.device)304 device = detect_device(adb, args.device)
299 # Determine uri to download from305 # Determine uri to download from
300 if not args.uri:306 if not args.uri:
301 args.uri = settings.download_uri307 args.uri = settings.download_uri
@@ -333,16 +339,18 @@
333 except subprocess.CalledProcessError:339 except subprocess.CalledProcessError:
334 log.error('Error while downloading, ensure connection')340 log.error('Error while downloading, ensure connection')
335 exit(1)341 exit(1)
336 if args.bootstrap:342 if not args.download_only:
337 push_for_autodeploy(adb, download_mgr.files[settings.ubuntu_image])343 validate_device(adb)
338 bootstrap(adb, download_mgr.files[recovery_img],344 if args.bootstrap:
339 download_mgr.files[device_img],345 push_for_autodeploy(adb, download_mgr.files[settings.ubuntu_image])
340 download_mgr.files[boot_img],)346 bootstrap(adb, download_mgr.files[recovery_img],
341 else:347 download_mgr.files[device_img],
342 recovery_file = create_recovery_file(adb,348 download_mgr.files[boot_img],)
343 download_mgr.files[device_img],349 else:
344 download_mgr.files[settings.ubuntu_image])350 recovery_file = create_recovery_file(adb,
345 deploy_recovery_image(adb, download_mgr.files, recovery_file)351 download_mgr.files[device_img],
352 download_mgr.files[settings.ubuntu_image])
353 deploy_recovery_image(adb, download_mgr.files, recovery_file)
346354
347355
348if __name__ == "__main__":356if __name__ == "__main__":

Subscribers

People subscribed via source and target branches