Пример #1
0
def initialize(url, username=None, password=None):

    if GLOBAL_DEBUG:
        debug('initialize')

    global GLOBAL_CLIENT

    global GLOBAL_CORPUS

    global GLOBAL_USERS
    global GLOBAL_GROUPS

    global GLOBAL_ME
    global GLOBAL_TEAM

    global GLOBAL_SUBMISSION_QUEUE

    # -------------------------------------------------------------------------
    # connect to Camomile server
    # -------------------------------------------------------------------------

    GLOBAL_CLIENT = Camomile(url)
    if username is None:
        username = raw_input('Login: '******'Unable to connect to %s with login %s' % (url, username))

    # -------------------------------------------------------------------------
    # find corpus identifier (development or test set)
    # -------------------------------------------------------------------------

    try:
        name = (CORPUS_NAME_DEV
                if GLOBAL_DEV_OR_TEST == "dev"
                else CORPUS_NAME_TEST)
        corpora = GLOBAL_CLIENT.getCorpora(name=name)
        GLOBAL_CORPUS = corpora[0]._id
    except Exception:
        reportErrorAndExit(
            'Unable to identify %s corpus.' % GLOBAL_DEV_OR_TEST)

    # -------------------------------------------------------------------------
    # get list of users and groups
    # -------------------------------------------------------------------------

    try:
        GLOBAL_GROUPS = GLOBAL_CLIENT.getGroups()
        GLOBAL_USERS = GLOBAL_CLIENT.getUsers()
    except Exception:
        reportErrorAndExit('Unable to obtain list of users and groups.')

    # -------------------------------------------------------------------------
    # get (supposedly unique) team of current user
    # -------------------------------------------------------------------------

    try:
        GLOBAL_TEAM = None
        userGroups = GLOBAL_CLIENT.getMyGroups()
        for group in GLOBAL_GROUPS:
            if group._id in userGroups and group.name.startswith('team_'):
                GLOBAL_TEAM = group
                break
    except Exception:
        pass

    if GLOBAL_TEAM is None:
        reportErrorAndExit('Unable to identify your team.')

    # -------------------------------------------------------------------------
    # identify submission queue
    # -------------------------------------------------------------------------

    if GLOBAL_DEBUG:
        debug('locate submission queue.')

    try:
        queues = [queue._id
                  for queue in GLOBAL_CLIENT.getQueues()
                  if queue.name == QUEUE_SUBMISSION]
        GLOBAL_SUBMISSION_QUEUE = queues[0]

    except Exception:
        reportErrorAndExit('Unable to locate submission queue.')
Пример #2
0
if __name__ == '__main__':
	# read config
    Config = ConfigParser.ConfigParser()
    Config.read("config.ini")

    server = Config.get('mainSection', 'url')+":"+Config.get('mainSection', 'port')
    corpusName = Config.get('ressourceSection', 'corpusName')

    userAdmin = sys.argv[1]
    pwdAdmin = sys.argv[2]

    client = Camomile(server)
    client.login(userAdmin, pwdAdmin)

    id_corpus = client.getCorpora(name=corpusName, returns_id=True)
    if id_corpus == []:
        print corpusName, 'is not found in the database'
        sys.exit(0)
    id_corpus = id_corpus[0]


    users = client.getUsers()
    layers = client.getLayers()
    
	for u in users:
		if u.role == 'user':
			for l in layers:
				client.setLayerPermissions(layer=l._id, permission=client.WRITE, user=u._id)