mirror of
https://github.com/google/pebble.git
synced 2025-06-27 11:26:15 +00:00
Import of the watch repository from Pebble
This commit is contained in:
commit
3b92768480
10334 changed files with 2564465 additions and 0 deletions
59
third_party/pbl/pbl/.gitignore
vendored
Normal file
59
third_party/pbl/pbl/.gitignore
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*,cover
|
||||
.hypothesis/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
21
third_party/pbl/pbl/README.md
vendored
Normal file
21
third_party/pbl/pbl/README.md
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
# pbl
|
||||
Like pebble-tool, but for internal things.
|
||||
|
||||
Not to be confused with pebble-tool-dev. This repository is for internal tools
|
||||
that don't make sense to ever be public; pebble-tool-dev is for public tools
|
||||
that can't be public yet.
|
||||
|
||||
Not sure where to put something? Ask Katharine!
|
||||
|
||||
## Installation
|
||||
|
||||
pip install git+ssh://git@github.com/pebble/pbl.git
|
||||
|
||||
## Adding commands
|
||||
|
||||
Create a new file in pbl/commands. Add a class inheriting from `BaseCommand`
|
||||
(or `PebbleCommand` if it connects to a pebble). The docstring will be used as
|
||||
help. Include a `command` field that gives the name of the command. The class's
|
||||
`__call__` method will be called when you run the command.
|
||||
|
||||
Many examples can be found [in pebble-tool](https://github.com/pebble/pebble-tool/tree/master/pebble_tool/commands).
|
37
third_party/pbl/pbl/pbl/__init__.py
vendored
Normal file
37
third_party/pbl/pbl/pbl/__init__.py
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
import logging
|
||||
|
||||
import pebble_tool
|
||||
from libpebble2.communication.transports.pulse import PULSETransport
|
||||
from libpebble2.exceptions import PebbleError
|
||||
from commands import coredump
|
||||
from commands import install_lang
|
||||
from commands import test
|
||||
|
||||
# TODO: unopened logging ports cause super noisy logs, fix this in the
|
||||
# pulse package then remove this
|
||||
logging.getLogger('pebble.pulse2.transports').setLevel(logging.ERROR)
|
||||
|
||||
class PebbleTransportPULSE(pebble_tool.commands.base.PebbleTransportConfiguration):
|
||||
transport_class = PULSETransport
|
||||
name = 'pulse'
|
||||
|
||||
@classmethod
|
||||
def _connect_args(cls, args):
|
||||
try:
|
||||
from pebble import pulse2
|
||||
except ImportError:
|
||||
raise PebbleError('pulse2 package not installed: it is required for PULSE transport')
|
||||
|
||||
url, = super(PebbleTransportPULSE, cls)._connect_args(args)
|
||||
interface = pulse2.Interface.open_dbgserial(url=url)
|
||||
link = interface.get_link()
|
||||
return (link,)
|
||||
|
||||
@classmethod
|
||||
def add_argument_handler(cls, parser):
|
||||
parser.add_argument('--pulse', type=str,
|
||||
help="Use this option to connect to your Pebble via"
|
||||
" the PULSE transport. Equivalent to PEBBLE_PULSE.")
|
||||
|
||||
def run_tool(args=None):
|
||||
pebble_tool.run_tool(args)
|
0
third_party/pbl/pbl/pbl/commands/__init__.py
vendored
Normal file
0
third_party/pbl/pbl/pbl/commands/__init__.py
vendored
Normal file
58
third_party/pbl/pbl/pbl/commands/coredump.py
vendored
Normal file
58
third_party/pbl/pbl/pbl/commands/coredump.py
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
from __future__ import absolute_import, print_function
|
||||
|
||||
import datetime
|
||||
from progressbar import ProgressBar, Bar, FileTransferSpeed, Timer, Percentage
|
||||
|
||||
from libpebble2.protocol.transfers import GetBytesInfoResponse
|
||||
from libpebble2.services.getbytes import GetBytesService
|
||||
from libpebble2.exceptions import GetBytesError
|
||||
|
||||
from pebble_tool.commands.base import PebbleCommand
|
||||
from pebble_tool.exceptions import ToolError
|
||||
|
||||
class CoredumpCommand(PebbleCommand):
|
||||
"""Takes a screenshot from the watch."""
|
||||
command = 'coredump'
|
||||
|
||||
def __init__(self):
|
||||
self.progress_bar = ProgressBar(widgets=[Percentage(), Bar(marker='=', left='[', right=']'), ' ',
|
||||
FileTransferSpeed(), ' ', Timer(format='%s')])
|
||||
self.started = False
|
||||
|
||||
def __call__(self, args):
|
||||
super(CoredumpCommand, self).__call__(args)
|
||||
get_bytes = GetBytesService(self.pebble)
|
||||
get_bytes.register_handler("progress", self._handle_progress)
|
||||
|
||||
self.progress_bar.start()
|
||||
try:
|
||||
core_data = get_bytes.get_coredump(args.fresh)
|
||||
except GetBytesError as ex:
|
||||
if ex.code == GetBytesInfoResponse.ErrorCode.DoesNotExist:
|
||||
raise ToolError('No coredump on device')
|
||||
else:
|
||||
raise
|
||||
|
||||
self.progress_bar.finish()
|
||||
|
||||
filename = self._generate_filename() if args.filename is None else args.filename
|
||||
with open(filename, "w") as core_file:
|
||||
core_file.write(core_data)
|
||||
print("Saved coredump to {}".format(filename))
|
||||
|
||||
def _handle_progress(self, progress, total):
|
||||
if not self.started:
|
||||
self.progress_bar.maxval = total
|
||||
self.started = True
|
||||
self.progress_bar.update(progress)
|
||||
|
||||
@classmethod
|
||||
def _generate_filename(cls):
|
||||
return datetime.datetime.now().strftime("pebble_coredump_%Y-%m-%d_%H-%M-%S.core")
|
||||
|
||||
@classmethod
|
||||
def add_parser(cls, parser):
|
||||
parser = super(CoredumpCommand, cls).add_parser(parser)
|
||||
parser.add_argument('filename', nargs='?', type=str, help="Filename of coredump")
|
||||
parser.add_argument('--fresh', action="store_true", help="Require a fresh coredump")
|
||||
return parser
|
38
third_party/pbl/pbl/pbl/commands/install_lang.py
vendored
Normal file
38
third_party/pbl/pbl/pbl/commands/install_lang.py
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
from __future__ import absolute_import, print_function
|
||||
from pebble_tool.commands.base import PebbleCommand
|
||||
|
||||
from progressbar import ProgressBar, Bar, FileTransferSpeed, Timer, Percentage
|
||||
|
||||
from libpebble2.services.putbytes import PutBytes, PutBytesType
|
||||
|
||||
class InstallLangCcommand(PebbleCommand):
|
||||
"""Install a language pack on a watch"""
|
||||
|
||||
command = 'install-lang'
|
||||
|
||||
def __call__(self, args):
|
||||
super(InstallLangCcommand, self).__call__(args)
|
||||
|
||||
progress_bar = ProgressBar(widgets=[Percentage(), Bar(marker='=', left='[', right=']'),
|
||||
' ', FileTransferSpeed(), ' ', Timer(format='%s')])
|
||||
|
||||
with open(args.lang_file, 'rb') as f:
|
||||
lang_pack = f.read()
|
||||
|
||||
progress_bar.maxval = len(lang_pack)
|
||||
progress_bar.start()
|
||||
|
||||
def _handle_progress(sent, total_sent, total_length):
|
||||
progress_bar.update(total_sent)
|
||||
|
||||
pb = PutBytes(self.pebble, PutBytesType.File, lang_pack, bank=0, filename="lang")
|
||||
pb.register_handler("progress", _handle_progress)
|
||||
pb.send()
|
||||
|
||||
progress_bar.finish()
|
||||
|
||||
@classmethod
|
||||
def add_parser(cls, parser):
|
||||
parser = super(InstallLangCcommand, cls).add_parser(parser)
|
||||
parser.add_argument('lang_file', help="Language file to install")
|
||||
return parser
|
11
third_party/pbl/pbl/pbl/commands/test.py
vendored
Normal file
11
third_party/pbl/pbl/pbl/commands/test.py
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
from __future__ import absolute_import, print_function
|
||||
from pebble_tool.commands.base import BaseCommand
|
||||
|
||||
|
||||
class TestCommand(BaseCommand):
|
||||
"""Testing!"""
|
||||
command = 'test'
|
||||
|
||||
def __call__(self, *args):
|
||||
super(TestCommand, self).__call__(*args)
|
||||
print("Hi there!")
|
1
third_party/pbl/pbl/pbl/version.py
vendored
Normal file
1
third_party/pbl/pbl/pbl/version.py
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
__version__ = "1.0.1"
|
30
third_party/pbl/pbl/setup.py
vendored
Normal file
30
third_party/pbl/pbl/setup.py
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
__author__ = 'katharine'
|
||||
|
||||
import sys
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
requires = [
|
||||
'pebble_tool==4.4-dp2',
|
||||
'libpebble2[pulse]>=0.0.23',
|
||||
]
|
||||
|
||||
if sys.version_info < (3, 4, 0):
|
||||
requires.append('enum34==1.0.4')
|
||||
|
||||
__version__ = None # Overwritten by executing version.py.
|
||||
with open('pbl/version.py') as f:
|
||||
exec(f.read())
|
||||
|
||||
setup(name='pbl-tool',
|
||||
version=__version__,
|
||||
description='Internal tool for interacting with pebbles.',
|
||||
url='https://github.com/pebble/pbl',
|
||||
author='Pebble Technology Corporation',
|
||||
author_email='katharine@pebble.com',
|
||||
license='MIT',
|
||||
packages=find_packages(),
|
||||
install_requires=requires,
|
||||
entry_points={
|
||||
'console_scripts': ['pbl=pbl:run_tool'],
|
||||
},
|
||||
zip_safe=False)
|
Loading…
Add table
Add a link
Reference in a new issue