예제 #1
0
def main():
    global options
    options = docopt.docopt(__doc__, version = __version__)
    filepath_configuration =     options["--configuration"]
    alarms                 =     options["--alarms"].lower() == "true"
    interval               = int(options["--interval"])
    verbose                =     options["--verbose"].lower() == "true"
    global log
    log = logging.getLogger(name)
    log.addHandler(technicolor.ColorisingStreamHandler())
    if verbose:
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)
    if not exist_filepaths(filepaths = [filepath_configuration]):
        sys.exit()
    while True:
        configuration = lock.load_JSON(filepath_configuration)
        log.info("\n" + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S Z"))
        for stream, characteristics in (configuration["streams"].items()):
            if exist_filepaths(filepaths = [stream]):
                characteristics["last_modification_time"] = os.stat(os.path.expanduser(stream)).st_mtime
                current_time = (datetime.datetime.utcnow() - datetime.datetime.utcfromtimestamp(0)).total_seconds()
                if verbose:
                    log.info("{stream} last modification time: {last_modification_time}".format(
                        stream                 = stream.ljust(40),
                        last_modification_time = datetime.datetime.fromtimestamp(int(characteristics["last_modification_time"])).strftime("%Y-%m-%d %H:%M:%S")
                    ))
                if current_time - characteristics["last_modification_time"] > characteristics["update_time"]:
                    alert(text = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H%M%SZ") + " {stream} has not updated within its expected update time of {update_time} s".format(
                        stream      = stream,
                        update_time = characteristics["update_time"]
                    ))
                    if alarms: play_alarm()
        time.sleep(interval)
예제 #2
0
    def __init__(self,
                 parent=None,
                 options=None,
                 name=None,
                 version=None,
                 logo=None,
                 engage_log=True,
                 filename_log=None,
                 instance=None):

        global clock
        clock = shijian.Clock(name="program run time")

        if options is None:
            options = dict()

        self.options = options
        self.username = self.options["--username"]
        self.verbose = self.options["--verbose"]
        self.silent = self.options["--silent"]

        self.name = name
        self.version = version
        self.logo = logo
        self.engage_log = engage_log
        self.filename_log = filename_log
        self.instance = instance

        if self.username is None:
            self.username = os.getenv("USER")
        if self.logo is not None:
            self.display_logo = True
        elif self.logo is None and self.name is not None:
            self.logo = pyprel.render_banner(text=self.name.upper())
            self.display_logo = True
        else:
            self.display_logo = False
        if self.instance is None:
            self.instance = str(uuid.uuid4())

        # logging
        if engage_log:
            global log
            log = logging.getLogger(__name__)
            logging.root.addHandler(technicolor.ColorisingStreamHandler())

            # logging level
            if self.verbose:
                logging.root.setLevel(logging.DEBUG)
            else:
                logging.root.setLevel(logging.INFO)

            if self.filename_log:
                logging.root.addHandler(logging.FileHandler(self.filename_log))

        self.engage()
예제 #3
0
    def __init__(self, parent=None, options=None):

        # internal options
        self.display_logo = True

        # clock
        global clock
        clock = shijian.Clock(name="program run time")

        # name, version, logo
        if "name" in globals():
            self.name = name
        else:
            self.name = None
        if "version" in globals():
            self.version = version
        else:
            self.version = None
        if "logo" in globals():
            self.logo = logo
        elif "logo" not in globals() and hasattr(self, "name"):
            self.logo = pyprel.render_banner(text=self.name.upper())
        else:
            self.display_logo = False
            self.logo = None

        # options
        self.options = options
        self.username = self.options["--username"]
        self.verbose = self.options["--verbose"]
        self.files = self.options["--files"]
        self.configuration_filename = self.options["--configuration"]

        # default values
        if self.username is None:
            self.username = os.getenv("USER")
        if self.files is not None:
            self.files = self.files.split(",")

        # logging
        global log
        log = logging.getLogger(__name__)
        logging.root.addHandler(technicolor.ColorisingStreamHandler())

        # logging level
        if self.verbose:
            logging.root.setLevel(logging.DEBUG)
        else:
            logging.root.setLevel(logging.INFO)

        self.engage()

        # configuration
        self.configuration = pyrecon.open_configuration(
            self.configuration_filename)
예제 #4
0
import getpass
import logging
if sys.version_info[0] <= 2:
    from pathlib2 import Path
else:
    from pathlib import Path
import yaml

from cryptography.fernet import Fernet
import technicolor

name = "william_blake_crypto"
__version__ = "2019-04-03T0616Z"

log = logging.getLogger(name)
log.addHandler(technicolor.ColorisingStreamHandler())
log.setLevel(logging.INFO)
log.debug(name + " " + __version__)

global _key
_key = None


def generate_key():
    return Fernet.generate_key()


def input_key(prompt="enter key: "):
    global _key
    _key = getpass.getpass(prompt=prompt).encode("utf8")