示例#1
0
def main(args=sys.argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('-f', dest='conffile', default='caliopen.yaml')
    kwargs = parser.parse_args(args[1:])
    kwargs = vars(kwargs)

    config_uri = kwargs.pop('conffile')
    Configuration.load(config_uri, 'global')
    connect_storage()
    shell(**kwargs)
示例#2
0
def main(global_config, **settings):
    """Caliopen entry point for WSGI application.

    Load Caliopen configuration and setup a WSGI application
    with loaded API services.
    """
    # XXX ugly way to init caliopen configuration before pyramid
    caliopen_config = settings['caliopen.config'].split(':')[1]
    Configuration.load(caliopen_config, 'global')

    settings['pyramid_swagger.exclude_paths'] = [r'^/api-ui/?', r'^/doc/api/?', r'^/defs/?']
    settings['pyramid_swagger.enable_response_validation'] = True
    config = Configurator(settings=settings)
    services = config.registry.settings. \
        get('caliopen_api.services', []). \
        split('\n')
    route_prefix = settings.get('caliopen_api.route_prefix')
    for service in services:
        log.info('Loading %s service' % service)
        config.include(service, route_prefix=route_prefix)
    config.end()
    return config.make_wsgi_app()
示例#3
0
def main(global_config, **settings):
    """Caliopen entry point for WSGI application.

    Load Caliopen configuration and setup a WSGI application
    with loaded API services.
    """
    # XXX ugly way to init caliopen configuration before pyramid
    caliopen_config = settings['caliopen.config'].split(':')[1]
    Configuration.load(caliopen_config, 'global')

    settings['pyramid_swagger.exclude_paths'] = [
        r'^/api-ui/?', r'^/doc/api/?', r'^/defs/?'
    ]
    settings['pyramid_swagger.enable_response_validation'] = True
    config = Configurator(settings=settings)
    services = config.registry.settings. \
        get('caliopen_api.services', []). \
        split('\n')
    route_prefix = settings.get('caliopen_api.route_prefix')
    for service in services:
        log.info('Loading %s service' % service)
        config.include(service, route_prefix=route_prefix)
    config.end()
    return config.make_wsgi_app()
from caliopen_storage.config import Configuration
from caliopen_storage.helpers.connection import connect_storage
from caliopen_main.common.errors import PatchConflict
from caliopen_storage.exception import NotFound

log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-f', dest='conffile')
    parser.add_argument('-t', dest='test', action='store_true', default=False)

    args = parser.parse_args()
    Configuration.load(args.conffile, 'global')
    connect_storage()
    from caliopen_main.user.core.user import LocalIdentity
    from caliopen_main.message.store.message import Message
    from caliopen_main.message.objects.message import Message as ObjMessage

    identities = [x.identifier for x in LocalIdentity._model_class.all()]
    cpt = {'received': 0, 'sent': 0}
    for message in Message.all():
        if message.is_received is None:
            from_participant = [x for x in message.participants
                                if x['type'] == 'From']
            if not from_participant:
                log.error('No from participant found for message {} : {}'.
                          format(message.message_id, message.participants))
            else:
示例#5
0
文件: cli.py 项目: hsabouri/Caliopen
def main(args=sys.argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('-f', dest='conffile', default='development.ini')
    subparsers = parser.add_subparsers(title="action")

    sp_import = subparsers.add_parser('import', help='import existing mailbox')
    sp_import.set_defaults(func=import_email)
    sp_import.add_argument('-f',
                           dest='format',
                           choices=['mbox', 'maildir'],
                           default='mbox')
    sp_import.add_argument('-p', dest='import_path')
    sp_import.add_argument('-e', dest='email')
    sp_import.add_argument('--contact-probability',
                           dest='contact_probability',
                           default=1.0)

    sp_import_vcard = subparsers.add_parser('import_vcard',
                                            help='import vcard')
    sp_import_vcard.set_defaults(func=import_vcard)
    sp_import_vcard.add_argument('-u', dest='username', help='username')
    sp_import_vcard.add_argument('-d', dest='directory', help='directory')
    sp_import_vcard.add_argument('-f', dest='file_vcard', help='file')

    sp_setup_storage = subparsers.add_parser(
        'setup', help='initialize the storage engine')
    sp_setup_storage.set_defaults(func=setup_storage)

    sp_create_user = subparsers.add_parser('create_user',
                                           help='Create a new user')
    sp_create_user.set_defaults(func=create_user)
    sp_create_user.add_argument('-e', dest='email', help='user email')
    sp_create_user.add_argument('-p', dest='password', help='password')
    sp_create_user.add_argument('-g',
                                dest='given_name',
                                help='user given name')
    sp_create_user.add_argument('-f',
                                dest='family_name',
                                help='user family name')

    sp_shell = subparsers.add_parser('shell')
    sp_shell.set_defaults(func=shell)

    sp_dump = subparsers.add_parser('dump')
    sp_dump.set_defaults(func=dump_model)
    sp_dump.add_argument('-m', dest='model', help='model to dump')
    sp_dump.add_argument('-o', dest='output_path', help='output path')

    sp_dump_index = subparsers.add_parser('dump_index')
    sp_dump_index.set_defaults(func=dump_indexes)
    sp_dump_index.add_argument('-o', dest='output_path', help='output path')

    sp_migrate_index = subparsers.add_parser('migrate_index')
    sp_migrate_index.set_defaults(func=migrate_index)
    sp_migrate_index.add_argument(
        '-s',
        dest='input_script',
        help='python script to execute against index')

    sp_inject = subparsers.add_parser('inject')
    sp_inject.set_defaults(func=inject_email)
    sp_inject.add_argument('-f',
                           dest='format',
                           choices=['mbox', 'maildir'],
                           default='mbox')
    sp_inject.add_argument('-p', dest='import_path')
    sp_inject.add_argument('-e', dest='email')
    sp_inject.add_argument('--host',
                           dest='host',
                           help='host to send mail to',
                           default='localhost:25')

    sp_compute = subparsers.add_parser('compute', help='Launch basic compute')
    sp_compute.set_defaults(func=basic_compute)
    sp_compute.add_argument('-u', dest='username', help='username')
    sp_compute.add_argument('-j', dest='job', help='job name')

    sp_reserved = subparsers.add_parser('reserved_names',
                                        help='Import reserved names list')
    sp_reserved.set_defaults(func=import_reserved_names)
    sp_reserved.add_argument('-i', dest='input_file', help='csv file')

    kwargs = parser.parse_args(args[1:])
    kwargs = vars(kwargs)

    config_uri = kwargs.pop('conffile')
    func = kwargs.pop('func')

    Configuration.load(config_uri, 'global')
    connect_storage()

    func(**kwargs)
示例#6
0
    servers = [server]

    opts = {"servers": servers}
    yield client.connect(**opts)

    # create and register subscriber(s)
    key_subscriber = subscribers.DiscoverKeyAction(client)
    future = client.subscribe("discoverKeyAction", "discoverKeyQueue",
                              key_subscriber.handler)
    log.info("nats subscription started for discoverKeyAction")
    future.result()


if __name__ == '__main__':
    # load Caliopen config
    args = sys.argv
    parser = argparse.ArgumentParser()
    parser.add_argument('-f', dest='conffile')
    kwargs = parser.parse_args(args[1:])
    kwargs = vars(kwargs)
    Configuration.load(kwargs['conffile'], 'global')
    # need to load config before importing subscribers
    import subscribers

    connect_storage()
    inbound_handler(Configuration('global').get('message_queue'))
    contact_update_handler(Configuration('global').get('message_queue'))
    discovey_key_handler(Configuration('global').get('message_queue'))
    loop_instance = tornado.ioloop.IOLoop.instance()
    loop_instance.start()
示例#7
0
def main(args=sys.argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('-f', dest='conffile', default='development.ini')
    subparsers = parser.add_subparsers(title="action")

    sp_import = subparsers.add_parser('import', help='import existing mailbox')
    sp_import.set_defaults(func=import_email)
    sp_import.add_argument('-f', dest='format', choices=['mbox', 'maildir'],
                           default='mbox')
    sp_import.add_argument('-p', dest='import_path')
    sp_import.add_argument('-e', dest='email')
    sp_import.add_argument('--contact-probability', dest='contact_probability',
                           default=0.8)
    sp_import.add_argument('-t', dest='to')

    sp_import_vcard = subparsers.add_parser('import_vcard',
                                            help='import vcard')
    sp_import_vcard.set_defaults(func=import_vcard)
    sp_import_vcard.add_argument('-u', dest='username', help='username')
    sp_import_vcard.add_argument('-d', dest='directory', help='directory')
    sp_import_vcard.add_argument('-f', dest='file_vcard', help='file')

    sp_setup = subparsers.add_parser('setup',
                                     help='initialize the storage engine')
    sp_setup.set_defaults(func=setup)

    sp_create_user = subparsers.add_parser('create_user',
                                           help='Create a new user')
    sp_create_user.set_defaults(func=create_user)
    sp_create_user.add_argument('-e', dest='email', help='user email')
    sp_create_user.add_argument('-p', dest='password', help='password')
    sp_create_user.add_argument('-g', dest='given_name',
                                help='user given name')
    sp_create_user.add_argument('-f', dest='family_name',
                                help='user family name')

    sp_shell = subparsers.add_parser('shell')
    sp_shell.set_defaults(func=shell)

    sp_dump = subparsers.add_parser('dump')
    sp_dump.set_defaults(func=dump_model)
    sp_dump.add_argument('-m', dest='model', help='model to dump')
    sp_dump.add_argument('-o', dest='output_path', help='output path')

    sp_copy = subparsers.add_parser('copy')
    sp_copy.set_defaults(func=copy_model)
    sp_copy.add_argument('-m', dest='model', help='model to dump')
    sp_copy.add_argument('--where', dest='where', help='where condition')
    sp_copy.add_argument('--fetch-size', dest='fetch_size', default=100)

    sp_dump_index = subparsers.add_parser('dump_index')
    sp_dump_index.set_defaults(func=dump_indexes)
    sp_dump_index.add_argument('-o', dest='output_path', help='output path')

    sp_migrate_index = subparsers.add_parser('migrate_index')
    sp_migrate_index.set_defaults(func=migrate_index)
    sp_migrate_index.add_argument('-s', dest='input_script',
                                  help='python script to execute on index')

    sp_inject = subparsers.add_parser('inject')
    sp_inject.set_defaults(func=inject_email)
    sp_inject.add_argument('-e', dest='email')
    sp_inject.add_argument('-r', dest='recipient')

    sp_compute = subparsers.add_parser('compute', help='Launch basic compute')
    sp_compute.set_defaults(func=basic_compute)
    sp_compute.add_argument('-u', dest='username', help='username')
    sp_compute.add_argument('-j', dest='job', help='job name')

    sp_reserved = subparsers.add_parser('reserved_names',
                                        help='Import reserved names list')
    sp_reserved.set_defaults(func=import_reserved_names)
    sp_reserved.add_argument('-i', dest='input_file', help='csv file')

    sp_resync = subparsers.add_parser('resync_index',
                                      help='Resync index for an user')
    sp_resync.set_defaults(func=resync_index)
    sp_resync.add_argument('-u', dest='user_name', help='User name')
    sp_resync.add_argument('-i', dest='user_id', help='User uuid')
    sp_resync.add_argument('--delete', dest='delete', action='store_true')

    sp_resync = subparsers.add_parser('resync_shard',
                                      help='Resync shard index')
    sp_resync.set_defaults(func=resync_shard_index)
    sp_resync.add_argument('-s', dest='shard_id', help='Shard id')
    sp_resync.add_argument('-o', dest='old_shard_id', help='Old shard id')
    kwargs = parser.parse_args(args[1:])
    kwargs = vars(kwargs)

    config_uri = kwargs.pop('conffile')
    func = kwargs.pop('func')

    Configuration.load(config_uri, 'global')
    connect_storage()

    func(**kwargs)
"""Test importance level compute."""

import unittest
import os

from caliopen_storage.config import Configuration

if 'CALIOPEN_BASEDIR' in os.environ:
    conf_file = '{}/src/backend/configs/caliopen.yaml.template'. \
                format(os.environ['CALIOPEN_BASEDIR'])
else:
    conf_file = '../../../../../configs/caliopen.yaml.template'

Configuration.load(conf_file, 'global')

from caliopen_pi.features.helpers.importance_level import compute_importance


class MockPI(object):

    def __init__(self, technic, context, comportment):
        self.technic = technic
        self.context = context
        self.comportment = comportment


class MockMessage(object):

    def __init__(self, pi, tags=None, refs=None):
        self.pi = pi
        self.tags = tags if tags else []
示例#9
0
import os

from datetime import datetime
from zope.interface.verify import verifyObject

from caliopen_storage.config import Configuration

import vobject

if 'CALIOPEN_BASEDIR' in os.environ:
    conf_file = '{}/src/backend/configs/caliopen.yaml.template'. \
                format(os.environ['CALIOPEN_BASEDIR'])
else:
    conf_file = '../../../../../configs/caliopen.yaml.template'

Configuration.load(conf_file, 'global')

#from caliopen_main.interfaces import IMessageParser
from caliopen_main.contact.parameters import NewContact
from caliopen_main.contact.parsers import parse_vcard


def load_vcard(filename):

    dir_path = os.path.dirname(os.path.realpath(__file__))
    path = '{}/../fixtures/vcard'.format(dir_path)
    with open('{}/{}'.format(path, filename)) as f:
        data = f.read()
    return data

示例#10
0
        else:
            indices = self._get_indices()
        with open(output, 'w') as output:
            for index in indices:
                cpt = 0
                log.info('Processing index %s' % index)
                search = IndexedMessage.search()
                self.provider.prepare(search,
                                      index=index,
                                      doc_type='indexed_message')
                for records in self.provider.next():
                    for record in records:
                        output.write('{0}\n'.format(';'.join(record)))
                        cpt += 1
                log.info('%d records processed' % cpt)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-f', dest='conffile')
    parser.add_argument('-o', dest='output')
    parser.add_argument('-i', dest='index')
    args = parser.parse_args()

    Configuration.load(args.conffile, 'global')
    from caliopen_main.message.store.message_index import IndexedMessage

    config = Configuration('global').configuration
    extractor = Extractor(config)
    extractor.process(args.output, args.index)
示例#11
0
文件: cli.py 项目: CaliOpen/Caliopen
def main(args=sys.argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('-f', dest='conffile', default='development.ini')
    subparsers = parser.add_subparsers(title="action")

    sp_import = subparsers.add_parser('import', help='import existing mailbox')
    sp_import.set_defaults(func=import_email)
    sp_import.add_argument('-f', dest='format', choices=['mbox', 'maildir'],
                           default='mbox')
    sp_import.add_argument('-p', dest='import_path')
    sp_import.add_argument('-e', dest='email')
    sp_import.add_argument('--contact-probability', dest='contact_probability',
                           default=1.0)
    sp_import.add_argument('-t', dest='to')

    sp_import_vcard = subparsers.add_parser('import_vcard',
                                            help='import vcard')
    sp_import_vcard.set_defaults(func=import_vcard)
    sp_import_vcard.add_argument('-u', dest='username', help='username')
    sp_import_vcard.add_argument('-d', dest='directory', help='directory')
    sp_import_vcard.add_argument('-f', dest='file_vcard', help='file')

    sp_setup = subparsers.add_parser('setup',
                                     help='initialize the storage engine')
    sp_setup.set_defaults(func=setup)

    sp_create_user = subparsers.add_parser('create_user',
                                           help='Create a new user')
    sp_create_user.set_defaults(func=create_user)
    sp_create_user.add_argument('-e', dest='email', help='user email')
    sp_create_user.add_argument('-p', dest='password', help='password')
    sp_create_user.add_argument('-g', dest='given_name',
                                help='user given name')
    sp_create_user.add_argument('-f', dest='family_name',
                                help='user family name')

    sp_shell = subparsers.add_parser('shell')
    sp_shell.set_defaults(func=shell)

    sp_dump = subparsers.add_parser('dump')
    sp_dump.set_defaults(func=dump_model)
    sp_dump.add_argument('-m', dest='model', help='model to dump')
    sp_dump.add_argument('-o', dest='output_path', help='output path')

    sp_copy = subparsers.add_parser('copy')
    sp_copy.set_defaults(func=copy_model)
    sp_copy.add_argument('-m', dest='model', help='model to dump')
    sp_copy.add_argument('--where', dest='where', help='where condition')
    sp_copy.add_argument('--fetch-size', dest='fetch_size', default=100)

    sp_dump_index = subparsers.add_parser('dump_index')
    sp_dump_index.set_defaults(func=dump_indexes)
    sp_dump_index.add_argument('-o', dest='output_path', help='output path')

    sp_migrate_index = subparsers.add_parser('migrate_index')
    sp_migrate_index.set_defaults(func=migrate_index)
    sp_migrate_index.add_argument('-s', dest='input_script',
                                  help='python script to execute on index')

    sp_inject = subparsers.add_parser('inject')
    sp_inject.set_defaults(func=inject_email)
    sp_inject.add_argument('-e', dest='email')
    sp_inject.add_argument('-r', dest='recipient')

    sp_compute = subparsers.add_parser('compute', help='Launch basic compute')
    sp_compute.set_defaults(func=basic_compute)
    sp_compute.add_argument('-u', dest='username', help='username')
    sp_compute.add_argument('-j', dest='job', help='job name')

    sp_reserved = subparsers.add_parser('reserved_names',
                                        help='Import reserved names list')
    sp_reserved.set_defaults(func=import_reserved_names)
    sp_reserved.add_argument('-i', dest='input_file', help='csv file')

    sp_resync = subparsers.add_parser('resync_index',
                                      help='Resync index for an user')
    sp_resync.set_defaults(func=resync_index)
    sp_resync.add_argument('-u', dest='user_name', help='User name')
    sp_resync.add_argument('-i', dest='user_id', help='User uuid')
    sp_resync.add_argument('--delete', dest='delete', action='store_true')

    sp_resync = subparsers.add_parser('resync_shard',
                                      help='Resync shard index')
    sp_resync.set_defaults(func=resync_shard_index)
    sp_resync.add_argument('-s', dest='shard_id', help='Shard id')
    sp_resync.add_argument('-o', dest='old_shard_id', help='Old shard id')
    kwargs = parser.parse_args(args[1:])
    kwargs = vars(kwargs)

    config_uri = kwargs.pop('conffile')
    func = kwargs.pop('func')

    Configuration.load(config_uri, 'global')
    connect_storage()

    func(**kwargs)
示例#12
0
文件: cli.py 项目: CaliOpen/Caliopen
 def __init__(self, filename):
     from caliopen_storage.config import Configuration
     from caliopen_storage.helpers.connection import connect_storage
     self.conf = Configuration.load(filename, 'global').configuration
     connect_storage()