コード例 #1
0
def refresh(input_file_path, output_file_path, day, joiner, attribute, full_val):
	food = foody.get_food(day)
	inj = inject.Injector(input_file_path, output_file_path)
	for i in range(len(food)):
		inj.replace({"attrs" : {attribute : str(i)}}, html.escape(food[i]))
	food = joiner.join(food)
	inj.replace({"attrs" : {attribute : full_val}}, html.escape(food))
	inj.apply()
コード例 #2
0
def init():
    """
    """

    parser = OptionParser()
    parser.add_option(
        "-c",
        "--config",
        dest="configfile",
        help="Read configuration from FILE. (Overrides default config file.)",
        metavar="FILE")
    parser.add_option("-a",
                      "--host",
                      dest="broker_host",
                      help="Listen on specified address for broker.",
                      metavar="ADDR")
    parser.add_option("-p",
                      "--port",
                      dest="broker_port",
                      help="Listen on specified port for broker.",
                      type="int",
                      metavar="PORT")
    parser.add_option("-l",
                      "--logfile",
                      dest="logfile",
                      help="Log to specified file.",
                      metavar="FILE")
    parser.add_option(
        "--debug",
        action="store_true",
        dest="debug",
        default=False,
        help="Sets logging to debug (unless logging configured in config file)."
    )

    (options, args) = parser.parse_args()

    config = init_config()
    injector = inject.Injector()
    inject.register(injector)

    injector.bind('config', to=config)
    injector.bind('words', to=VMWords.getWords, scope=inject.appscope)
    injector.bind('stompProtocol', to=StompProtocol, scope=inject.appscope)
    injector.bind('stompEngine', to=VMStompEngine, scope=inject.appscope)
    injector.bind('subject', to=VMStompEngine, scope=inject.appscope)

    if options.broker_host is not None:
        config.set('broker', 'host', options.broker_host)

    if options.broker_port is not None:
        config.set('broker', 'port', str(options.broker_port))

    level = logging.DEBUG if options.debug else logging.INFO
    init_logging(logfile=options.logfile, loglevel=level)
    debug_config(config)
コード例 #3
0
def Inject():
    """ Setup default injections """
    import inject
    from pylons import config

    i = inject.Injector()
    # The examples show passing an instance to but it seems to want a
    # callable so fake one.
    i.bind('config', to=lambda: config)

    # XXX: Ideally this would come from the ini file.  I think you have
    # to use paste to load it.
    config['converter.job_log_dir'] = '/tmp/test-job-logs'

    inject.register(i)
コード例 #4
0
ファイル: config.py プロジェクト: khoanx/vmcontroller
def configure():
    injector = inject.Injector()
    inject.register(injector)

    injector.bind('config', to=getConfig)
    injector.bind('stompEngine', to=FakeEngine)
    injector.bind('stompProtocol', to=StompProtocol)
    injector.bind(
        'subject', to=FakeSubject('FakeSubject')
    )  #injected into BaseWord. It's either Host or VM in practice
    injector.bind('words', to=dict(
        (('AWord', AWord), )))  #gets injected into MsgInterpreter
    injector.bind('hvController', to=HyperVisorController)

    return injector
def config(settings):
    """Initialize Dependency Injection

    :param settings: Application settings
    :type settings: Settings
    """
    injector = inject.Injector()

    injector.bind('service_user', to=service_user, scope=inject.appscope)
    injector.bind('repository_user', to=repository_user, scope=inject.appscope)

    injector.bind('service_document',
                  to=service_document,
                  scope=inject.appscope)
    injector.bind('repository_document',
                  to=repository_document,
                  scope=inject.appscope)

    injector.bind('settings', to=settings, scope=inject.noscope)
    inject.register(injector)
コード例 #6
0
def init():
    """
    Initializes VMController Host package.
    First parses command line options. Then, creates config object from default cfg file.
    Re-initializes config object if a config file is supplied and sets logger configuration.
    Finally, uses dependency injection to bind objects to names.
    """

    parser = OptionParser()
    parser.add_option(
        "-c",
        "--config",
        dest="configfile",
        help="Read configuration from FILE. (Overrides default config file.)",
        metavar="FILE")
    parser.add_option(
        "-a",
        "--host",
        dest="xmlrpc_host",
        help=
        "Listen on specified address for XMLRPC interface (default 127.0.0.1)",
        metavar="ADDR")
    parser.add_option(
        "-p",
        "--port",
        dest="xmlrpc_port",
        help="Listen on specified port for XMLRPC interface (default 50505)",
        type="int",
        metavar="PORT")
    parser.add_option("-l",
                      "--logfile",
                      dest="logfile",
                      help="Log to specified file.",
                      metavar="FILE")
    parser.add_option(
        "--debug",
        action="store_true",
        dest="debug",
        default=False,
        help="Sets logging to debug (unless logging configured in config file)."
    )

    (options, args) = parser.parse_args()

    config = init_config()
    injector = inject.Injector()
    inject.register(injector)

    injector.bind('config', to=config)
    injector.bind('stompEngine', to=HostStompEngine, scope=inject.appscope)
    injector.bind('words', to=HostWords.getWords)
    injector.bind('stompProtocol', to=StompProtocol, scope=inject.appscope)
    injector.bind('subject', to=Host)
    injector.bind('hvController', to=HyperVisorController)

    init_config_file(options.configfile)

    if options.xmlrpc_host is not None:
        config.set('xmlrpc', 'host', options.xmlrpc_host)

    if options.xmlrpc_port is not None:
        config.set('xmlrpc', 'port', str(options.xmlrpc_port))

    level = logging.DEBUG if options.debug else logging.INFO
    init_logging(logfile=options.logfile, loglevel=level)
コード例 #7
0
#  from sys import argv
#  if len(argv) < 2:
#    print "Usage: %s <config-file>" % argv[0]
#    exit(-1)
#  else:
#    configFile = argv[1]
#
#    config = SafeConfigParser()
#    config.read(configFile)

application = service.Application("boinc-vm-controller")

configFile = '/etc/boinc-vm-controller/VMConfig.cfg'  #FIXME: HARDCODED
if not os.path.isfile(configFile):
    configFile = os.path.basename(configFile)

config = SafeConfigParser()
config.read(configFile)

injector = inject.Injector()
inject.register(injector)

injector.bind('config', to=config)
injector.bind('words', to=VMWords.getWords, scope=inject.appscope)
injector.bind('stompProtocol', to=StompProtocol, scope=inject.appscope)
injector.bind('stompEngine', to=VMStompEngine, scope=inject.appscope)
injector.bind('subject', to=VMStompEngine, scope=inject.appscope)

service = start(config)
service.setServiceParent(application)