Ejemplo n.º 1
0
def make_tasks_from_args(args):
    localtree = args.services['filesystem']('local')
    config = Config(args.services)
    if args.config:
        config.read_file(localtree, args.config)
    else:
        confpaths = localtree.get_config_paths_for('ebakup')
        for path in confpaths:
            config.read_file(localtree, path + ('config',))
    tasks = []
    tasks.append(WebUITask(config, args))
    if args.command == 'backup':
        task = BackupTask(config, args)
        tasks.append(task)
    elif args.command == 'info':
        task = InfoTask(config, args)
        tasks.append(task)
    elif args.command == 'shadowcopy':
        task = MakeShadowTreeTask(config, args)
        tasks.append(task)
    elif args.command == 'webui':
        pass
    elif args.command == 'sync':
        task = SyncTask(config, args)
        tasks.append(task)
    elif args.command == 'verify':
        task = _make_verify_task(config, args)
        tasks.append(task)
    else:
        raise UnknownCommandError('Unknown command: ' + args.command)
    return tasks
Ejemplo n.º 2
0
def __get_config():
    conf = Config(logging.getLogger('django'))
    try:
        conf.read_file(CONFIG_FILE)
        return conf
    except IOError:
        return None
Ejemplo n.º 3
0
def main():
    parser = OptionParser()
    parser.add_option('-o', '--output', dest='output',
                      help='write messages to FILE', metavar='FILE')
    parser.add_option('-c', '--config', dest='config',
                      help='read config from FILE', metavar='FILE')
    parser.add_option('-d', '--debug', dest='debug', action='store_true',
                      help='print debug messages')
    parser.add_option('-v', '--version', dest='version', action='store_true',
                      help='print version number and exit')
    (options, args) = parser.parse_args()

    if options.version:
        print VERSION
        sys.exit(0)

    if not options.config:
        print >> sys.stderr, 'ERROR: Please provide a config file.'
        print parser.print_help()
        sys.exit(1)

    # Logging
    logger = logging.getLogger('Remidomo')
    if options.output:
        handler = logging.FileHandler(options.output)
    else:
        handler = logging.StreamHandler()
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    handler.setFormatter(formatter)
    if options.debug:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)
    logger.addHandler(handler)

    # Main loop
    logger.info('Démarrage')

    config_timestamp = None
    rfx_listener = None
    while 1:
        file_timestamp = os.path.getmtime(options.config)
        if config_timestamp is None or config_timestamp != file_timestamp:
            if rfx_listener is not None:
                rfx_listener.stop()
                time.sleep(15)
            config = Config(logger)
            config.read_file(options.config)
            database = Database(config, logger)
            database.connect()
            executor = Executor(config, logger)
            rfx_listener = RFXListener(config, database, executor, logger)
            rfx_listener.start()
            config_timestamp = file_timestamp
            executor.service_flag(1)

        try:
            executor.blink_activity()
            check_orders(logger, config, executor, database)
            if not rfx_listener.isAlive():
                raise Exception('RFX thread stopped')
            time.sleep(60)
        except KeyboardInterrupt:
            print >> sys.stderr, '\nExiting by user request.\n'
            executor.heating_poweroff()
            executor.service_flag(0)
            rfx_listener.stop()
            database.close()
            sys.exit(0)
        except Exception, e:
            logger.warning('Emergency shutdown ! %s' % e)
            executor.heating_poweroff()
            executor.service_flag(0)
            # If main thread crashes, we must also stop RFX thread !
            rfx_listener.stop()
            database.close()
            raise