Ejemplo n.º 1
0
 def __init__(self, log=None, show=False):
     self.cpi = ConsolePi()
     self.debug = config.cfg.get('debug', False)
     self.show = show
     self.stop = False
     self.discovered = [
     ]  # for display when running interactively, resets @ every restart
     self.d_discovered = []  # used when running as daemon (doesn't reset)
     self.startup_logged = False
     self.zc = None
Ejemplo n.º 2
0
 def __init__(self, show=False):
     config.cloud = False  # mdns doesn't need to sync w cloud
     self.cpi = ConsolePi(bypass_outlets=True)
     self.debug = config.cfg.get('debug', False)
     self.show = show
     self.stop = False
     self.discovered = []    # for display when running interactively, resets @ every restart
     self.d_discovered = []  # used when running as daemon (doesn't reset)
     self.no_adapters = []  # If both mdns and API report no adapters for remote add to list to prevent subsequent API calls
     self.startup_logged = False
     self.zc = Zeroconf()
Ejemplo n.º 3
0
 def __init__(self, log=None, show=False):
     self.cpi = ConsolePi()
     self.debug = config.cfg.get('debug', False)
     self.show = show
     self.stop = False
     self.discovered = [
     ]  # for display when running interactively, resets @ every restart
     self.d_discovered = []  # used when running as daemon (doesn't reset)
     self.no_adapters = [
     ]  # If both mdns and API report no adapters for remote add to list to prevent subsequent API calls
     self.startup_logged = False
     self.zc = None
Ejemplo n.º 4
0
def main():
    cpi = ConsolePi()
    cloud_svc = config.cfg.get("cloud_svc", "error")
    local = cpi.local
    remotes = cpi.remotes
    cpiexec = cpi.cpiexec
    log.info('[CLOUD TRIGGER (IP)]: Cloud Update triggered by IP Update')
    CLOUD_CREDS_FILE = config.static.get(
        "CLOUD_CREDS_FILE",
        '/etc/ConsolePi/cloud/gdrive/.credentials/credentials.json')
    if not utils.is_reachable("www.googleapis.com", 443):
        log.error(f"Not Updating {cloud_svc} due to connection failure")
        sys.exit(1)
        if not utils.valid_file(CLOUD_CREDS_FILE):
            log.error('Credentials file not found or invalid')
            sys.exit(1)

    # -- // Get details from Google Drive - once populated will skip \\ --
    if cloud_svc == "gdrive" and remotes.cloud is None:
        remotes.cloud = GoogleDrive(hostname=local.hostname)

    if cpiexec.wait_for_threads(thread_type="remotes") and (
            config.power and cpiexec.wait_for_threads(name="_toggle_refresh")):
        log.error(
            'IP Change Cloud Update Trigger: TimeOut Waiting for Threads to Complete'
        )

    remote_consoles = remotes.cloud.update_files(local.data)
    if remote_consoles and "Gdrive-Error:" in remote_consoles:
        log.error(remote_consoles)
    else:
        for r in remote_consoles:
            # -- Convert Any Remotes with old API schema to new API schema --
            if isinstance(remote_consoles[r].get("adapters", {}), list):
                remote_consoles[r]["adapters"] = remotes.convert_adapters(
                    remote_consoles[r]["adapters"])
                log.warning(
                    f"Adapter data for {r} retrieved from cloud in old API format... Converted"
                )
        if len(remote_consoles) > 0:
            remotes.update_local_cloud_file(remote_consoles)
Ejemplo n.º 5
0
attached to the remotes).

mdns and gdrive provide discovery/sync mechanisms, the API is used
to ensure the remote is reachable and that the data is current.
'''
import sys
sys.path.insert(0, '/etc/ConsolePi/src/pypkg')
from consolepi import config, log  # NoQA
from consolepi.consolepi import ConsolePi  # NoQA
from fastapi import FastAPI  # NoQA
from pydantic import BaseModel  # NoQA
from time import time  # NoQA
from starlette.requests import Request  # NoQA
import uvicorn  # NoQA

cpi = ConsolePi()
cpiexec = cpi.cpiexec
local = cpi.local
if config.power:
    if not cpiexec.wait_for_threads():
        OUTLETS = cpi.pwr.data if cpi.pwr.data else None
else:
    OUTLETS = None
user = local.user
last_update = int(time())
udev_last_update = int(time())

# class Adapters(BaseModel):
#     adapters: dict

#     class Config:
Ejemplo n.º 6
0
#!/etc/ConsolePi/venv/bin/python3

'''
argv1 is the process menu currently uses picocom
argv2 is the device
'''
# imports in try/except in case user aborts after ssh session established
try:
    import psutil
    import sys
    import subprocess
    from time import sleep
    sys.path.insert(0, '/etc/ConsolePi/src/pypkg')
    from consolepi import config, utils  # type: ignore # NoQA
    from consolepi.consolepi import ConsolePi  # type: ignore # NoQA
    cpi = ConsolePi(bypass_remotes=True)
except (KeyboardInterrupt, EOFError):
    print("Operation Aborted")
    exit(0)


def find_procs_by_name(name, dev):
    "Return a list of processes matching 'name'."
    ppid = None
    for p in psutil.process_iter(attrs=["name", "cmdline"]):
        if name == p.info['name'] and dev in p.info['cmdline']:
            ppid = p.pid if p.ppid() == 1 else p.ppid()
    return ppid


def terminate_process(pid):
Ejemplo n.º 7
0
 def __init__(self):
     self.zeroconf = Zeroconf()
     self.context = pyudev.Context()
     self.cpi = ConsolePi()