26 lines
936 B
Python
26 lines
936 B
Python
"""Run via SSH: manage_devices.py pair | list | revoke DEVICE_ID.
|
|
|
|
Pairing codes expire in ten minutes and must be entered in Android Settings.
|
|
"""
|
|
import argparse
|
|
import os
|
|
from pathlib import Path
|
|
from device_auth import DeviceStore
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('action', choices=['pair', 'list', 'revoke'])
|
|
parser.add_argument('device_id', nargs='?')
|
|
args = parser.parse_args()
|
|
root = Path(os.environ.get('AUDIOBOOK_SERVICE_ROOT', '/home/sevenhill/apps/aletheia-audiobook'))
|
|
store = DeviceStore(root / 'audiobook-jobs/jobs.db3')
|
|
if args.action == 'pair':
|
|
print(store.create_code())
|
|
elif args.action == 'revoke':
|
|
if not args.device_id:
|
|
parser.error('device_id is required')
|
|
store.revoke(args.device_id)
|
|
else:
|
|
with store.connect() as db:
|
|
for row in db.execute('SELECT id,label,revoked,created_at FROM devices ORDER BY created_at'):
|
|
print('\t'.join(map(str, row)))
|