-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
14 changed files
with
256 additions
and
143 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
File renamed without changes.
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,11 @@ | ||
transilien: | ||
stations: | ||
test: '00000000' | ||
credentials: | ||
username: 898323 | ||
refresh_time: 10 | ||
display: | ||
type: 'oled' | ||
lcd: | ||
columns: 'hello' | ||
rows: 2 |
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
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
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
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 |
---|---|---|
@@ -1,3 +1,16 @@ | ||
from pathlib import Path | ||
|
||
from transilienwatcher.app import TransilienWatcher | ||
from transilienwatcher.configuration import ConfigManager | ||
|
||
WORKSPACE = f"{Path.home()}/transilenwatcher" | ||
CONFIG_FILE = f"{WORKSPACE}/config.yml" | ||
LOG_FILE = f"{WORKSPACE}/transilenwatcher.log" | ||
|
||
__all__ = ["TransilienWatcher"] | ||
__all__ = [ | ||
"TransilienWatcher", | ||
"ConfigManager", | ||
"WORKSPACE", | ||
"CONFIG_FILE", | ||
"LOG_FILE", | ||
] |
This file was deleted.
Oops, something went wrong.
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
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,80 @@ | ||
#!/usr/bin/env python3 | ||
import argparse | ||
import sys | ||
from enum import Enum, auto | ||
from pathlib import Path | ||
|
||
from loguru import logger | ||
|
||
from transilienwatcher import ConfigManager, LOG_FILE, CONFIG_FILE, WORKSPACE | ||
from transilienwatcher import TransilienWatcher | ||
|
||
|
||
def _app_already_init(): | ||
return Path(WORKSPACE).is_dir() and Path(CONFIG_FILE).is_file() | ||
|
||
|
||
def run(): | ||
if not _app_already_init(): | ||
print( | ||
"It appears that it may be the first time you run TransilienWatcher." | ||
"\nYou need to run 'transilienwatcher-init' first." | ||
) | ||
sys.exit() | ||
|
||
parser = argparse.ArgumentParser(description="TransilienWatcher") | ||
parser.add_argument( | ||
dest="operation", | ||
type=str, | ||
choices=["start", "stop", "status"], | ||
help="TransilienWatcher commands.", | ||
) | ||
args = parser.parse_args() | ||
|
||
logger.remove() # Reset default loguru logger. | ||
logger.add(LOG_FILE, rotation="00:00", retention="2 days", level="DEBUG") | ||
config = ConfigManager.load(file=CONFIG_FILE) | ||
|
||
daemon = TransilienWatcher(log_file=LOG_FILE, config=config) | ||
operation = getattr(daemon, args.operation) | ||
operation() | ||
|
||
|
||
def init(): | ||
if _app_already_init(): | ||
print(f"TranslienWatcher config already exists in '{WORKSPACE}'.") | ||
return | ||
|
||
class Status(Enum): | ||
ASK_SETUP = auto() | ||
ASK_QUIT = auto() | ||
SETUP = auto() | ||
QUIT = auto() | ||
|
||
setup_status = Status.ASK_SETUP | ||
while setup_status != Status.QUIT: | ||
if setup_status == Status.ASK_SETUP: | ||
resp = input("Setup TransilienWatcher configuration file? [Y/n]: ") or "y" | ||
if resp.lower() in ["y", "yes"]: | ||
setup_status = Status.SETUP | ||
if resp.lower() in ["n", "no"]: | ||
setup_status = Status.ASK_QUIT | ||
if setup_status == Status.ASK_QUIT: | ||
resp = ( | ||
input("Setup is mandatory to run the app, are you sure? [Y/n]: ") or "y" | ||
) | ||
if resp.lower() in ["y", "yes"]: | ||
setup_status = Status.QUIT | ||
if resp.lower() in ["n", "no"]: | ||
setup_status = Status.ASK_SETUP | ||
if setup_status == Status.SETUP: | ||
print("Setting up TransilienWatcher...") | ||
Path(WORKSPACE).mkdir(exist_ok=True) | ||
print("Creating TransilienWatcher config...") | ||
ConfigManager.create(CONFIG_FILE) | ||
print( | ||
f"All done!\n\nYou can now edit TransilienWatcher config in " | ||
f"'{CONFIG_FILE}' and then start the app." | ||
) | ||
setup_status = Status.QUIT | ||
sys.exit() |
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
Oops, something went wrong.