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
1=== modified file 'phablet-flash'
2--- phablet-flash 2013-02-26 16:04:10 +0000
3+++ phablet-flash 2013-03-11 20:40:26 +0000
4@@ -49,13 +49,21 @@
5 help='''Device serial. Use when more than
6 one device is connected.''',
7 )
8- parser.add_argument('-b',
9- '--bootstrap',
10- help='''Bootstrap the target device, this only
11- works on Nexus devices or devices that
12- use fastboot and are unlocked.''',
13- action='store_true',
14- )
15+ group = parser.add_mutually_exclusive_group()
16+ group.add_argument('-b',
17+ '--bootstrap',
18+ help='''Bootstrap the target device, this only
19+ works on Nexus devices or devices that
20+ use fastboot and are unlocked.''',
21+ action='store_true',
22+ )
23+ group.add_argument('-D',
24+ '--download-only',
25+ help='''Download image only, but do not flash device.
26+ Use -d to override target device autodetection
27+ if target device is not connected.''',
28+ action='store_true',
29+ )
30 parser.add_argument('-r',
31 '--revision',
32 required=False,
33@@ -266,12 +274,11 @@
34 return jenkins_data
35
36
37-def validate_device(adb, device_param):
38+@adb_errors
39+def validate_device(adb):
40 '''
41 Validates if the image would be installable on the target
42- returns device
43 '''
44- device = detect_device(adb, device_param)
45 df = adb.shell('df').split('\n')
46 try:
47 free_data = map(str.split,
48@@ -284,7 +291,6 @@
49 else:
50 log.error('Not enough space in /data, found %s', free_data)
51 exit(1)
52- return device
53
54
55 def main(args):
56@@ -295,7 +301,7 @@
57 adb = AndroidBridge(args.serial)
58 else:
59 adb = AndroidBridge()
60- device = validate_device(adb, args.device)
61+ device = detect_device(adb, args.device)
62 # Determine uri to download from
63 if not args.uri:
64 args.uri = settings.download_uri
65@@ -333,16 +339,18 @@
66 except subprocess.CalledProcessError:
67 log.error('Error while downloading, ensure connection')
68 exit(1)
69- if args.bootstrap:
70- push_for_autodeploy(adb, download_mgr.files[settings.ubuntu_image])
71- bootstrap(adb, download_mgr.files[recovery_img],
72- download_mgr.files[device_img],
73- download_mgr.files[boot_img],)
74- else:
75- recovery_file = create_recovery_file(adb,
76- download_mgr.files[device_img],
77- download_mgr.files[settings.ubuntu_image])
78- deploy_recovery_image(adb, download_mgr.files, recovery_file)
79+ if not args.download_only:
80+ validate_device(adb)
81+ if args.bootstrap:
82+ push_for_autodeploy(adb, download_mgr.files[settings.ubuntu_image])
83+ bootstrap(adb, download_mgr.files[recovery_img],
84+ download_mgr.files[device_img],
85+ download_mgr.files[boot_img],)
86+ else:
87+ recovery_file = create_recovery_file(adb,
88+ download_mgr.files[device_img],
89+ download_mgr.files[settings.ubuntu_image])
90+ deploy_recovery_image(adb, download_mgr.files, recovery_file)
91
92
93 if __name__ == "__main__":

Subscribers

People subscribed via source and target branches