~vila/ubuntu-test-cases/retry-apt-get-update

« back to all changes in this revision

Viewing changes to scripts/get-device-info

  • Committer: Leo Arias
  • Date: 2014-11-10 19:28:56 UTC
  • mfrom: (345 touch)
  • mto: This revision was merged to the branch mainline in revision 352.
  • Revision ID: leo.arias@canonical.com-20141110192856-rgpksx9n9j0b39yl
Merged with the touch branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import argparse
 
4
import device_info
 
5
 
 
6
 
 
7
def _get_state(args):
 
8
    device = device_info.get_device(args.name)
 
9
    print(device.get_state())
 
10
 
 
11
 
 
12
def _get_serial(args):
 
13
    device = device_info.get_device(args.name)
 
14
    print(device.get_serial())
 
15
 
 
16
 
 
17
def _get_parser():
 
18
    parser = argparse.ArgumentParser(
 
19
        description='Get information about a device')
 
20
    sub = parser.add_subparsers(title='Commands', metavar='')
 
21
    serial = sub.add_parser('serial', help='Get serial for a device name')
 
22
    serial.set_defaults(func=_get_serial)
 
23
    serial.add_argument('name', help='Device name')
 
24
    state = sub.add_parser('state', help='Get device state for a device')
 
25
    state.set_defaults(func=_get_state)
 
26
    state.add_argument('name', help='Device name')
 
27
    return parser
 
28
 
 
29
 
 
30
if __name__ == '__main__':
 
31
    args = _get_parser().parse_args()
 
32
    exit(args.func(args))