Пример #1
0
def init_mongo(server):
    '''Reset connection to mongodb using MongoKit. Register objects for MongoKit

    :param server: URL to mongo server
    :type server: str

    '''
    global session
    session = Connection(server)
    session.register([User, Project, MobyleConfig, Job, Program])
Пример #2
0
# -*- coding: utf-8 -*-

from mobyle.common import session
from mobyle.common.config import Config

from mongokit import Document

import bcrypt


class User(Document):

    __collection__ = 'users'
    __database__ = Config.config().get('app:main','db_name')

    structure = { 'first_name' : basestring, 'last_name' : basestring, 'email' : basestring, 'hashed_password' : basestring, 'type' : basestring, 'admin': bool, 'groups' : [ basestring ] }

    default_values = { 'hashed_password' : '', 'admin': False }

    required_fields = [ 'email' ]    
    
    def set_password(self, clear_password):
        self['hashed_password'] = bcrypt.hashpw(clear_password, bcrypt.gensalt())
    
    def check_password(self, password):
        hashed = bcrypt.hashpw(password, self['hashed_password'])
        return hashed == self['hashed_password']
    
    
session.register([User])
Пример #3
0
# -*- coding: utf-8 -*-

import abc
from abc import ABCMeta
from abc import abstractmethod
from mobyleError import MobyleError

from mongokit import Document

from mobyle.common import session
from mobyle.common.config import Config

class Program(Document):
    """
    Empty class for the moment, only used as reference
    """

    __collection__ = 'programs'
    __database__ = Config.config().get('app:main','db_name')

    structure = { 'name' : basestring, 'public' : bool }

    default_values = { 'public': True }

    required_fields = [ 'name' ]


session.register([Program])

Пример #4
0
    It contains configuration that can be updated by administrators
    """

    __collection__ = 'config'
    __database__ = Config.config().get('app:main','db_name')

    structure = { 'auth_mod' : basestring , 'mail' : { 'gateway' : basestring, 'user' : basestring, 'password' : basestring, 'origin' : basestring },
                  'url' : basestring, 'datadir' : basestring, 'rootdir' : basestring, 'options' :  { 'apikey' : bool }
    }

    default_values = {
        'options.apikey': False,
        'url': 'http://localhost',
        'datadir' : '/var/lib/mobyle',
        'rootdir' : '/usr/share/mobyle'
    }


    def to_json(self):
        """"
        Return JSON representation of the object

        :return: JSON representation of the config
        :rtype: str
        """
        return json.dumps(self, default=json_util.default)



session.register([MobyleConfig])
Пример #5
0
        """
	add_job is a method defined to attach a new job_id into the project. 
        :param job: job to be associated to the project.
        :type job: :class:`Job` object.
        """
	self['job_ids'].append(job)
	
	
    def get_creation_time(self):
	"""
	get_creation_time returns the project creation date time according to the _id
	:return: the project creation datetime.
	:rtype: string.
	"""
	return self['creation_time']
	

    def add_user(self,user,role):
	"""
	add_user is a method defined to attach a new user and its role into the project.
	:param user: user to be associated to the project.
        :type user: :class:`User` object.
	:param role: user's role in the project.
        :type role: string.
	"""
	self['users'].append({ 'user' : user, 'role' : role})



session.register([Project])
Пример #6
0
# -*- coding: utf-8 -*-

import abc
from abc import ABCMeta
from abc import abstractmethod
from mobyleError import MobyleError

from mongokit import Document

from mobyle.common import session
from mobyle.common.config import Config

class Job(Document):
    """
    Empty class for the moment, only used as reference
    """

    __collection__ = 'jobs'
    __database__ = Config.config().get('app:main','db_name')

    structure = { 'name' : basestring }

session.register([Job])