-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 362fd90
Showing
34 changed files
with
2,802 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
setup.py | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
venv/ | ||
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 | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Intellij (PyCharm, etc) project files | ||
.idea | ||
.iml | ||
|
||
# vscode | ||
.vscode | ||
|
||
# sonarlint | ||
.sonarlint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Charles TISSIER | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
clean-pyc: | ||
find . -name '*.pyc' -exec rm --force {} + | ||
find . -name '*.pyo' -exec rm --force {} + | ||
find . -name '*~' -exec rm --force {} | ||
|
||
clean-build: | ||
rm --force --recursive build/ | ||
rm --force --recursive dist/ | ||
rm --force --recursive __pycache__/ | ||
rm --force --recursive *.egg-info | ||
|
||
build: clean-build | ||
pyi-makespec --onefile lastseen.py | ||
pyinstaller -F --onefile --clean -y --dist ./dist/linux --workpath /tmp lastseen.spec | ||
|
||
lint: | ||
# autopep8 -i *.py | ||
autopep8 -i *.py | ||
flake8 | ||
#for when I'm a masochist | ||
#pylint *.py | ||
|
||
test: clean-pyc | ||
py.test --verbose --color=yes $(TEST_PATH) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Tut - Tablo User Tools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
import sys | ||
import os | ||
from glob import glob | ||
import pickle | ||
import configparser | ||
import logging | ||
import logging.config | ||
|
||
from util import print_dict | ||
from tablo.api import Api | ||
|
||
# For batch Api call | ||
MAX_BATCH = 50 | ||
|
||
config = configparser.ConfigParser() | ||
# TODO: see about using this for cleaner variable interpolation | ||
# config = configparser.ConfigParser( | ||
# interpolation=configparser.ExtendedInterpolation | ||
# ) | ||
# prevent lowercasing options | ||
config.optionxform = lambda option: option | ||
orig_config = configparser.ConfigParser() | ||
|
||
# built in shared options that we aren't allowing to be user-configurable | ||
built_ins = {} | ||
|
||
|
||
def view(): | ||
print(f"Settings from: {built_ins['config_file']}") | ||
print("-" * 50) | ||
|
||
# for display purposes... | ||
orig_config['DEFAULT']['base_path'] = built_ins['base_path'] | ||
|
||
for sect in config.sections(): | ||
print(f'[{sect}]') | ||
for item, val in config.items(sect): | ||
ipol_disp = None | ||
if item == 'base_path': | ||
continue | ||
else: | ||
|
||
test = orig_config.get(sect, item) | ||
def_val = f'{val} (default)' | ||
|
||
if not test and not val: | ||
val_disp = def_val | ||
elif test and not val: | ||
val_disp = f'{test} (default) ' | ||
elif val == test: | ||
val = config.get(sect, item) | ||
raw_val = config.get(sect, item, raw=True) | ||
if raw_val != val: | ||
val_disp = f'{val} (set to default) ' | ||
ipol_disp = raw_val | ||
else: | ||
val_disp = f'{val} (set to default) ' | ||
|
||
else: | ||
# print(f'{item} = {val}') | ||
val_disp = val | ||
pass | ||
|
||
print('{:10}'.format(item) + " = " + val_disp) | ||
if ipol_disp: | ||
print('{:>10}'.format('real') + " = " + ipol_disp) | ||
|
||
print() | ||
|
||
print() | ||
print("Built-in settings") | ||
print("-" * 50) | ||
print_dict(built_ins, '') | ||
print() | ||
print("Cached Devices") | ||
print("-" * 50) | ||
|
||
for name in glob(built_ins['db']['path']+"device_*"): | ||
with open(name, 'rb') as file: | ||
device = pickle.load(file) | ||
device.dump_info() | ||
print() | ||
print("Devices pre-loaded in Api") | ||
print("-" * 50) | ||
for device in Api.getTablos(): | ||
print(f"{device.ID} - {device.IP} - {device.modified}") | ||
if Api.selectDevice(device.ID): | ||
print("\tSuccessfully connected to Tablo!") | ||
else: | ||
print("\tUnable to connect to Tablo!") | ||
print() | ||
|
||
|
||
def discover(display=True): | ||
Api.discover() | ||
devices = Api.getTablos() | ||
if not devices: | ||
if display: | ||
print("Unable to locate any Tablo devices!") | ||
else: | ||
for device in devices: | ||
device.dump_info() | ||
Api.selectDevice(device.ID) | ||
if display: | ||
print(f'timezone: {Api.timezone}') | ||
print('srvInfo: ') | ||
print_dict(Api.serverInfo) | ||
print('subscription:') | ||
print_dict(Api.subscription) | ||
|
||
# cache the devices for later | ||
# TODO: maybe save serverinfo and subscription if find a need | ||
name = "device_" + device.ID | ||
with open(built_ins['db']['path'] + name, 'wb') as file: | ||
pickle.dump(device, file) | ||
|
||
|
||
def setup(): | ||
# create/find what should our config file | ||
if sys.platform == 'win32': # pragma: no cover | ||
path = os.path.expanduser(r'~\Tablo') | ||
else: | ||
path = os.path.expanduser('~/Tablo') | ||
|
||
built_ins['base_path'] = path | ||
|
||
built_ins['config_file'] = built_ins['base_path'] + "/tablo.ini" | ||
# this is here primarily for display order... :/ | ||
built_ins['dry_run'] = False | ||
|
||
db_path = built_ins['base_path'] + "/db/" | ||
built_ins['db'] = { | ||
'path': db_path, | ||
'guide': db_path + "guide.json", | ||
'recordings': db_path + "recordings.json", | ||
'recording_shows': db_path + "recording_shows.json" | ||
} | ||
|
||
os.makedirs(db_path, exist_ok=True) | ||
|
||
if os.path.exists(built_ins['config_file']): | ||
|
||
config.read(built_ins['config_file']) | ||
else: | ||
# write out a default config file | ||
config.read_string(DEFAULT_CONFIG_FILE) | ||
|
||
with open(built_ins['config_file'], 'w') as configfile: | ||
config.write(configfile) | ||
|
||
orig_config.read_string(DEFAULT_CONFIG_FILE) | ||
# Setup config defaults we're not configuring yet, but need | ||
config['DEFAULT']['base_path'] = built_ins['base_path'] | ||
|
||
# Load cached devices so we don't *have* to discover | ||
for name in glob(built_ins['db']['path'] + "device_*"): | ||
with open(name, 'rb') as file: | ||
device = pickle.load(file) | ||
Api.add_device(device) | ||
# if we cn, go ahead and select a default device | ||
# TODO: try to use the config ip/id here too | ||
if Api.devices and len(Api.devices.tablos) == 1: | ||
Api.device = Api.devices.tablos[0] | ||
|
||
|
||
def setup_logger(level=logging.CRITICAL): | ||
logging.config.dictConfig({ | ||
'version': 1, | ||
'disable_existing_loggers': False, | ||
'formatters': { | ||
'default': { | ||
'format': | ||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s' | ||
} | ||
}, | ||
'handlers': { | ||
'console': { | ||
'class': 'logging.StreamHandler', | ||
'level': level, | ||
'formatter': 'default', | ||
'stream': 'ext://sys.stdout' | ||
}, | ||
|
||
}, | ||
'root': { | ||
'level': 'DEBUG', | ||
'handlers': ['console'] | ||
}, | ||
'loggers': { | ||
'default': { | ||
'level': 'DEBUG', | ||
'handlers': ['console'] | ||
} | ||
}, | ||
|
||
}) | ||
""" | ||
'file': { | ||
'level': 'DEBUG', | ||
'class': 'logging.handlers.RotatingFileHandler', | ||
'formatter': 'default', | ||
'filename': log_path, | ||
'maxBytes': 1024, | ||
'backupCount': 3 | ||
} | ||
""" | ||
|
||
|
||
DEFAULT_CONFIG_FILE = """ | ||
[Tablo] | ||
# Define settings for the Tablo device you want to use. Usually only one Tablo | ||
# exists and will be found/used by default, so there's really no need to set | ||
# these. | ||
# | ||
# Theses values can be found by running './tablo.py config --discover' | ||
# | ||
# IMPORTANT: If these are set and wrong, you'll need to remove or manually | ||
# change them before things work. | ||
ID = | ||
# ID: the device ID (see above) selects a specific Tablo regardless of IP | ||
# (great for non-reserved DHCP addresses) | ||
IP = | ||
# IP: the device IP address. | ||
Timezone = | ||
# Timezone: defaults to America/New_York | ||
[Output Locations] | ||
# The locations/paths recordings will be output to | ||
# These will default to HOME_DIR-Tablo | ||
TV = %(base_path)s/TV | ||
Movies = %(base_path)s/Movies | ||
""" |
Oops, something went wrong.