Exemplo n.º 1
0
def fullAccessIPs():
    if not options.isFlag(FLAG_FULL_IP): return

    serviceGateway = entityFor(IGatewayService)
    assert isinstance(serviceGateway, IGatewayService)

    if options.addIPs:
        for ip in options.addIPs:
            gateway = Custom()
            gateway.Name = 'full_access_%s' % ip
            gateway.Clients = [
                '\.'.join(mark.replace('*', '\d+') for mark in ip.split('.'))
            ]
            try:
                serviceGateway.insert(gateway)
            except:
                log.info('IP \'%s\' already present', ip)
            else:
                log.info('IP \'%s\' added', ip)

    if options.remIPs:
        for ip in options.remIPs:
            if serviceGateway.delete('full_access_%s' % ip):
                log.info('IP \'%s\' removed', ip)
            else:
                log.info('IP \'%s\' is not present', ip)
Exemplo n.º 2
0
def dump():
    if not options.isFlag(FLAG_DUMP): return
    if not __debug__:
        log.error('Cannot dump configuration file if python is run with "-O" or "-OO" option')
        sys.exit(1)
    # Forcing the processing of all configurations
    saveConfigurations(context.configurationsExtract())
Exemplo n.º 3
0
def start():
    if not options.isFlag(FLAG_START): return
    if not os.path.isfile(options.configuration):
        log.warn(
            'The configuration file "%s" doesn\'t exist, create one by running the the application '
            'with "-dump" option', options.configuration)
    context.processStart()
Exemplo n.º 4
0
def dump():
    if not options.isFlag(FLAG_DUMP): return
    if not __debug__:
        log.error(
            'Cannot dump configuration file if python is run with "-O" or "-OO" option'
        )
        sys.exit(1)
    # Forcing the processing of all configurations
    saveConfigurations(context.configurationsExtract())
Exemplo n.º 5
0
def test():
    if not options.isFlag(FLAG_TEST): return
    classes = aop.classesIn('__unit_test__.**.*').asList()
    classes = [clazz for clazz in classes if issubclass(clazz, unittest.TestCase)]
    if not classes:
        log.info('-' * 71)
        log.info('No unit test available')
        sys.exit(1)
    testLoader, runner, tests = unittest.TestLoader(), unittest.TextTestRunner(stream=sys.stdout), unittest.TestSuite()
    for clazz in classes: tests.addTest(testLoader.loadTestsFromTestCase(clazz))
    runner.run(tests)
Exemplo n.º 6
0
def test():
    if not options.isFlag(FLAG_TEST): return
    classes = aop.classesIn('__unit_test__.**.*').asList()
    classes = [
        clazz for clazz in classes if issubclass(clazz, unittest.TestCase)
    ]
    if not classes:
        log.info('-' * 71)
        log.info('No unit test available')
        sys.exit(1)
    testLoader, runner, tests = unittest.TestLoader(), unittest.TextTestRunner(
        stream=sys.stdout), unittest.TestSuite()
    for clazz in classes:
        tests.addTest(testLoader.loadTestsFromTestCase(clazz))
    runner.run(tests)
Exemplo n.º 7
0
def fullAccessIPs():
    if not options.isFlag(FLAG_FULL_IP): return
    
    serviceGateway = entityFor(IGatewayService)
    assert isinstance(serviceGateway, IGatewayService)
    
    if options.addIPs:
        for ip in options.addIPs:
            gateway = Custom()
            gateway.Name = 'full_access_%s' % ip
            gateway.Clients = ['\.'.join(mark.replace('*', '\d+') for mark in ip.split('.'))]
            try: serviceGateway.insert(gateway)
            except: log.info('IP \'%s\' already present', ip)
            else: log.info('IP \'%s\' added', ip)
            
    if options.remIPs:
        for ip in options.remIPs:
            if serviceGateway.delete('full_access_%s' % ip): log.info('IP \'%s\' removed', ip)
            else: log.info('IP \'%s\' is not present', ip)
Exemplo n.º 8
0
def configureMongrel2():
    if not options.isFlag(FLAG_CONFIG_MONGREL2): return
    folders = [path.join('mongrel2', name) for name in ('logs', 'run', 'tmp')]
    folders.append(path.join('shared', 'upload'))

    folder = options.mongrel2Folder or 'workspace'

    for name in folders:
        folder = path.join(folder, name)
        if not path.isdir(folder): makedirs(folder)

    updateConfig = False
    if server_type() != 'mongrel2':
        updateConfig = True
        support.persist(server_type, 'mongrel2')

    sendIdent = send_ident()
    if sendIdent is None:
        updateConfig = True
        sendIdent = str(uuid4())
        support.persist(send_ident, sendIdent)

    replace = {}
    replace['${send_spec}'] = send_spec()
    replace['${send_ident}'] = sendIdent
    replace['${recv_spec}'] = recv_spec()
    replace['${recv_ident}'] = recv_ident()
    replace['${server_port}'] = str(server_port())

    if updateConfig: saveConfigurations(context.configurationsExtract())

    conf = openURI(path.join(pythonPath(), 'resources', 'ally.conf'))
    conf = codecs.getreader('utf8')(conf)
    conf = ReplaceInStream(conf, replace)
    with open(path.join(folder, 'ally.conf'), 'w') as f:
        pipe(conf, f)
    with open(path.join(folder, 'README-Mongrel2.txt'), 'wb') as f:
        pipe(
            openURI(path.join(pythonPath(), 'resources',
                              'README-Mongrel2.txt')), f)

    log.info('Configured \'%s\' mongrel2 workspace' % folder)
Exemplo n.º 9
0
def configureMongrel2():
    if not options.isFlag(FLAG_CONFIG_MONGREL2): return
    folders = [path.join('mongrel2', name) for name in ('logs', 'run', 'tmp')]
    folders.append(path.join('shared', 'upload'))

    folder = options.mongrel2Folder or 'workspace'
    
    for name in folders:
        folder = path.join(folder, name)
        if not path.isdir(folder): makedirs(folder)
    
    updateConfig = False
    if server_type() != 'mongrel2':
        updateConfig = True
        support.persist(server_type, 'mongrel2')
    
    sendIdent = send_ident()
    if sendIdent is None:
        updateConfig = True
        sendIdent = str(uuid4())
        support.persist(send_ident, sendIdent)
    
    replace = {}
    replace['${send_spec}'] = send_spec()
    replace['${send_ident}'] = sendIdent
    replace['${recv_spec}'] = recv_spec()
    replace['${recv_ident}'] = recv_ident()
    replace['${server_port}'] = str(server_port())

    if updateConfig: saveConfigurations(context.configurationsExtract())
        
    conf = openURI(path.join(pythonPath(), 'resources', 'ally.conf'))
    conf = codecs.getreader('utf8')(conf)
    conf = ReplaceInStream(conf, replace)
    with open(path.join(folder, 'ally.conf'), 'w') as f: pipe(conf, f)
    with open(path.join(folder, 'README-Mongrel2.txt'), 'wb') as f:
        pipe(openURI(path.join(pythonPath(), 'resources', 'README-Mongrel2.txt')), f)
    
    log.info('Configured \'%s\' mongrel2 workspace' % folder)
Exemplo n.º 10
0
def document():
    if not options.isFlag(FLAG_DOCUMENT): return
    with activate(plugins(), 'document'):
        context.processStart()
        createDocumentation()
Exemplo n.º 11
0
def document():
    if not options.isFlag(FLAG_DOCUMENT): return
    with activate(plugins(), 'document'):
        context.processStart()
        createDocumentation()
Exemplo n.º 12
0
def repair():
    if not options.isFlag(FLAG_REPAIR): return
    support.performEventsFor(event.REPAIR)
Exemplo n.º 13
0
def repair():
    if not options.isFlag(FLAG_REPAIR): return
    support.performEventsFor(event.REPAIR)
Exemplo n.º 14
0
def configureApplication():
    if not options.isFlag(FLAG_CONFIGURE): return
    context.configurationsLoad(configurations())
Exemplo n.º 15
0
def start():
    if not options.isFlag(FLAG_START): return
    if not os.path.isfile(options.configuration):
        log.warn('The configuration file "%s" doesn\'t exist, create one by running the the application '
                 'with "-dump" option', options.configuration)
    context.processStart()
Exemplo n.º 16
0
def dumpPlugins():
    if not options.isFlag(FLAG_DUMP): return
    with activate(plugins(), 'events'):
        context.configurationsLoad(configurations())
        support.performEventsFor(app.DUMP)
        saveConfigurations(context.configurationsExtract())
Exemplo n.º 17
0
def configureApplication():
    if not options.isFlag(FLAG_CONFIGURE): return
    context.configurationsLoad(configurations())
Exemplo n.º 18
0
def dumpPlugins():
    if not options.isFlag(FLAG_DUMP): return
    with activate(plugins(), 'events'):
        context.configurationsLoad(configurations())
        support.performEventsFor(app.DUMP)
        saveConfigurations(context.configurationsExtract())