#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2013 eNovance SAS # # Author: Chmouel Boudjnah # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import sys import logging import optparse import swsync.accounts from swsync.utils import parse_ini, ConfigurationError class Main(object): def __init__(self): self.options = {} def set_logging(self): logger = logging.getLogger() logger.setLevel({ 'debug': logging.DEBUG, 'info': logging.INFO, 'warning': logging.WARNING, 'error': logging.ERROR, 'critical': logging.CRITICAL}.get( self.options.log_level.lower() )) loghandler = logging.StreamHandler() logger.addHandler(loghandler) logger = logging.LoggerAdapter(logger, 'swsync') logformat = logging.Formatter('%(asctime)s %(levelname)s %(message)s') loghandler.setFormatter(logformat) def main(self): usage = "usage: %prog [OPTIONS] [CONF_FILE]" parser = optparse.OptionParser(usage=usage) parser.add_option( '-l', '--log-level', dest='log_level', default='info', help='Number of containers to distribute objects among') self.options, args = parser.parse_args() if args: conf = parse_ini(args[0]) else: try: conf = parse_ini() except(ConfigurationError): parser.print_help() sys.exit(1) self.set_logging() #beurk swsync.utils.CONFIG = conf swsync.accounts.main() if __name__ == '__main__': m = Main() m.main()