Exemplo n.º 1
0
def thread_google_monitor():
    global manager

    logger.info("Starting Google Drive monitoring in 30 seconds...")
    time.sleep(30)

    # initialize crypt_decoder to None
    crypt_decoder = None

    # load rclone client if crypt being used
    if conf.configs['RCLONE']['CRYPT_MAPPINGS'] != {}:
        logger.info(
            "Crypt mappings have been defined. Initializing Rclone Crypt Decoder..."
        )
        crypt_decoder = rclone.RcloneDecoder(
            conf.configs['RCLONE']['BINARY'],
            conf.configs['RCLONE']['CRYPT_MAPPINGS'],
            conf.configs['RCLONE']['CONFIG'])

    # load google drive manager
    manager = GoogleDriveManager(
        conf.configs['GOOGLE']['CLIENT_ID'],
        conf.configs['GOOGLE']['CLIENT_SECRET'],
        conf.settings['cachefile'],
        allowed_config=conf.configs['GOOGLE']['ALLOWED'],
        show_cache_logs=conf.configs['GOOGLE']['SHOW_CACHE_LOGS'],
        crypt_decoder=crypt_decoder,
        allowed_teamdrives=conf.configs['GOOGLE']['TEAMDRIVES'])

    if not manager.is_authorized():
        logger.error("Failed to validate Google Drive Access Token.")
        exit(1)
    else:
        logger.info("Google Drive access token was successfully validated.")

    # load teamdrives (if enabled)
    if conf.configs['GOOGLE']['TEAMDRIVE'] and not manager.load_teamdrives():
        logger.error("Failed to load Google Teamdrives.")
        exit(1)

    # set callbacks
    manager.set_callbacks({'items_added': process_google_changes})

    try:
        logger.info("Google Drive changes monitor started.")
        while True:
            # poll for changes
            manager.get_changes()
            # sleep before polling for changes again
            time.sleep(conf.configs['GOOGLE']['POLL_INTERVAL'])

    except Exception:
        logger.exception(
            "Fatal Exception occurred while monitoring Google Drive for changes: "
        )
Exemplo n.º 2
0
def thread_google_monitor():
    global manager

    logger.info("Starting Google Drive changes monitor in 30 seconds...")
    time.sleep(30)

    # load google drive manager
    manager = GoogleDriveManager(
        conf.configs['GOOGLE']['CLIENT_ID'],
        conf.configs['GOOGLE']['CLIENT_SECRET'],
        conf.settings['cachefile'],
        allowed_config=conf.configs['GOOGLE']['ALLOWED'],
        allowed_teamdrives=conf.configs['GOOGLE']['TEAMDRIVES'],
        show_cache_logs=conf.configs['GOOGLE']['SHOW_CACHE_LOGS'])

    if not manager.is_authorized():
        logger.error("Failed to validate Google Drive access token...")
        exit(1)
    else:
        logger.info("Google Drive access token was successfully validated")

    # load teamdrives (if enabled)
    if conf.configs['GOOGLE']['TEAMDRIVE'] and not manager.load_teamdrives():
        logger.error("Failed to load teamdrives....?")
        exit(1)

    # set callbacks
    manager.set_callbacks({'items_added': process_google_changes})

    try:
        logger.info("Google Drive changes monitor started")
        while True:
            # poll for changes
            manager.get_changes()
            # sleep before polling for changes again
            time.sleep(conf.configs['GOOGLE']['POLL_INTERVAL'])

    except Exception:
        logger.exception(
            "Fatal Exception occurred while monitoring Google Drive for changes: "
        )
Exemplo n.º 3
0
def click_app(verbose, config_path, log_path, vault_path):
    global cfg, manager, poller, strm

    # Load config
    from utils.config import Config
    cfg = Config(config_path=config_path).cfg

    # Load logger
    log_levels = {0: 'INFO', 1: 'DEBUG', 2: 'TRACE'}
    log_level = log_levels[verbose] if verbose in log_levels else 'TRACE'
    config_logger = {
        'handlers': [
            {'sink': sys.stdout, 'backtrace': True if verbose >= 2 else False, 'level': log_level},
            {'sink': log_path,
             'rotation': '30 days',
             'retention': '7 days',
             'enqueue': True,
             'backtrace': True if verbose >= 2 else False,
             'level': log_level}
        ]
    }
    logger.configure(**config_logger)

    # Load database
    db.init_db(vault_path)
    create_all_tables()

    # Load google drive
    manager = GoogleDriveManager(client_id=cfg.google.client_id, client_secret=cfg.google.client_secret,
                                 allowed_teamdrives=cfg.google.teamdrives, cfg=cfg)

    poller = GooglePoller(manager, cfg)

    # Load strm
    from utils import strm as strm_module
    strm = strm_module

    # Display params
    logger.debug("%s = %r" % ("CONFIG_PATH".ljust(12), config_path))
    logger.debug("%s = %r" % ("LOG_PATH".ljust(12), log_path))
    logger.debug("%s = %r" % ("VAULT_PATH".ljust(12), vault_path))
    logger.debug("")
Exemplo n.º 4
0
        logger.info("Starting server: http://%s:%d/%s",
                    conf.configs['SERVER_IP'], conf.configs['SERVER_PORT'],
                    conf.configs['SERVER_PASS'])
        app.run(host=conf.configs['SERVER_IP'],
                port=conf.configs['SERVER_PORT'],
                debug=False,
                use_reloader=False)
        logger.info("Server stopped")
        exit(0)
    elif conf.args['cmd'] == 'build_caches':
        logger.info("Building caches")
        # load google drive manager
        manager = GoogleDriveManager(
            conf.configs['GOOGLE']['CLIENT_ID'],
            conf.configs['GOOGLE']['CLIENT_SECRET'],
            conf.settings['cachefile'],
            allowed_config=conf.configs['GOOGLE']['ALLOWED'],
            allowed_teamdrives=conf.configs['GOOGLE']['TEAMDRIVES'])

        if not manager.is_authorized():
            logger.error("Failed to validate Google Drive access token...")
            exit(1)
        else:
            logger.info("Google Drive access token was successfully validated")

        # load teamdrives (if enabled)
        if conf.configs['GOOGLE']['TEAMDRIVE'] and not manager.load_teamdrives(
        ):
            logger.error("Failed to load teamdrives....?")
            exit(1)