forked from Hexxeh/libpebble
-
Notifications
You must be signed in to change notification settings - Fork 13
/
pebble.py
executable file
·159 lines (134 loc) · 6.02 KB
/
pebble.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python
import argparse
import logging
import sys
from pebble.analytics import PebbleAnalytics, post_event
# Catch any missing python dependencies so we can send an event to analytics
try:
# NOTE: Even though we don't use websocket in this module, keep this
# import here for the unit tests so that they can trigger a missing
# python dependency event.
import websocket
import pebble as libpebble
from pebble.PblProject import InvalidProjectException, OutdatedProjectException
from pebble.PblProjectCreator import PblProjectCreator
from pebble.PblProjectConverter import PblProjectConverter
from pebble.PblBuildCommand import PblBuildCommand, PblCleanCommand, PblAnalyzeSizeCommand
from pebble.LibPebblesCommand import *
except Exception as e:
logging.basicConfig(format='[%(levelname)-8s] %(message)s',
level = logging.DEBUG)
try:
post_event('sdk_missing_dependency', exception=str(e))
except Exception as e:
pass
raise
class PbSDKShell:
commands = []
def __init__(self):
self.commands.append(PblProjectCreator())
self.commands.append(PblProjectConverter())
self.commands.append(PblBuildCommand())
self.commands.append(PblCleanCommand())
self.commands.append(PblAnalyzeSizeCommand())
self.commands.append(PblInstallCommand())
self.commands.append(PblPingCommand())
self.commands.append(PblListCommand())
self.commands.append(PblRemoveCommand())
self.commands.append(PblCurrentAppCommand())
self.commands.append(PblListUuidCommand())
self.commands.append(PblLogsCommand())
self.commands.append(PblReplCommand())
self.commands.append(PblScreenshotCommand())
self.commands.append(PblCoreDumpCommand())
self.commands.append(PblEmuTapCommand())
self.commands.append(PblEmuBluetoothConnectionCommand())
self.commands.append(PblEmuCompassCommand())
self.commands.append(PblEmuBatteryCommand())
self.commands.append(PblEmuAccelCommand())
self.commands.append(PblKillCommand())
self.commands.append(PblWipeCommand())
self.commands.append(PblInsertPinCommand())
self.commands.append(PblDeletePinCommand())
self.commands.append(PblLoginCommand())
def _get_version(self):
try:
from pebble.VersionGenerated import SDK_VERSION
return SDK_VERSION
except:
return "Development"
def main(self):
parser = argparse.ArgumentParser(description = 'Pebble SDK Shell',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--debug', action="store_true",
help="Enable debugging output")
parser.add_argument('--version', action='version',
version='PebbleSDK %s' % self._get_version())
subparsers = parser.add_subparsers(dest="command", title="Command",
description="Action to perform")
for command in self.commands:
subparser = subparsers.add_parser(command.name, help = command.help)
command.configure_subparser(subparser)
args = parser.parse_args()
log_level = logging.INFO
if args.debug:
log_level = logging.DEBUG
logging.basicConfig(format='[%(levelname)-8s] %(message)s',
level = log_level)
if log_level != logging.DEBUG:
logging.getLogger("requests").setLevel(logging.WARNING)
# Just in case logging was already setup, basicConfig would not
# do anything, so set the level on the root logger
logging.getLogger().setLevel(log_level)
return self.run_action(args.command, args)
def run_action(self, action, args):
# Find the extension that was called
command = [x for x in self.commands if x.name == args.command][0]
start_time = time.time()
try:
retval = command.run(args)
return retval
except libpebble.PebbleError as e:
post_event('sdk_libpebble_failed', exception=str(e))
if args.debug:
raise e
else:
logging.error(e)
return 1
except InvalidProjectException as e:
post_event('sdk_run_without_project')
logging.error("This command must be run from a Pebble project directory")
return 1
except OutdatedProjectException as e:
post_event('sdk_building_outdated_project')
logging.error("The Pebble project directory is using an outdated version of the SDK!")
logging.error("Try running `pebble convert-project` to update the project")
return 1
except NoCompilerException as e:
post_event('sdk_missing_tools')
logging.error("The compiler/linker tools could not be found. "
"Ensure that the arm-cs-tools directory is present in the Pebble SDK directory (%s)" %
PblCommand().sdk_path(args))
return 1
except BuildErrorException as e:
post_event('app_build_failed', build_time=(time.time() - start_time), type="compilation_error")
logging.error("A compilation error occurred")
return 1
except AppTooBigException as e:
post_event('app_build_failed', build_time=(time.time() - start_time), type="app_too_large")
logging.error("The built application is too big")
return 1
except Exception as e:
post_event('sdk_unhandled_exception', exception=str(e))
logging.error(str(e))
# Print out stack trace if in debug mode to aid in bug reporting
if args.debug:
raise
return 1
def main():
retval = PbSDKShell().main()
if retval is None:
retval = 0
return retval
if __name__ == '__main__':
sys.exit(main())