def setUp(self): self.c = config.TestConfig() create_database(self.c, 'db_a') self.s = make_session(self.c)
def db_a(self): LOGGER.info('creating db_a') c = config.Config() create_database(c, 'db_a')
def register_extensions(app: Flask): from models import ma from models import db, create_database db.init_app(app) ma.init_app(app) with app.app_context(): create_database() db.create_all()
def __init__(self, filepath, create_database=False): ''' filepath refers to the database file pluricent.db''' import os.path as osp if not osp.isfile(filepath) and not create_database: raise Exception('%s must be an existing file' % filepath) if create_database: models.create_database(filepath, from_existing_repository=True) self.filepath = osp.abspath(filepath) self.session = models.create_session(filepath)
def load_database(self): """ Loads and initializes the database if necessary :return: None """ if not database_exists(): print("[+] No database found, creating database '{}'".format( DATABASE_PATH)) create_database() if self._server_exists(): self._load_server() else: print( "[+] First run detected for server '{}', setting up tracker.". format(self.config.server_name)) print( "[?] Note: No changes will be able to be detected this session" ) self._add_server()
def __init__(self, service, id, conn, host, port): super(MessagingAgent, self).__init__() self.daemon = True self.name = 'messaging-{}'.format(id) self.queue = Queue.Queue() self.socket = conn self.service = service self.host = host self.port = port self.session = {"id": self.name} self.db = models.create_database() conn.settimeout(config.MESSAGING_WAIT_INTERVAL)
def __init__(self, service, id, conn, host, port): super(MessagingAgent, self).__init__() self.daemon = True self.name = 'messaging-{}'.format(id) self.queue = Queue.Queue() self.socket = conn self.service = service self.host = host self.port = port self.session = { "id": self.name } self.db = models.create_database() conn.settimeout(config.MESSAGING_WAIT_INTERVAL)
def setup_testing_db(context): return create_database(':memory:')
def get_menu_dict(menus): return { 'type': 'list', 'message': 'Choice an option: ', 'name': 'option', 'default': '0', 'choices': array_menu(menus) } def ask(menu_dict): reply = prompt(menu_dict)['option'] if reply.has_children(): children = reply.children() md = get_menu_dict(children) ask(md) if __name__ == '__main__': create_database('./settings') load_fixtures() root_menus = get_root_menus() menu_dict = get_menu_dict(root_menus) ask(menu_dict)
import os import models BOT_NAME = os.getenv('BOT_NAME', 'Token Not found') BOT_ADDRESS = os.getenv('BOT_ADDRESS', 'Token Not found') BOT_PRIVATE_KEY = os.getenv('BOT_PRIVATE_KEY', 'Token Not found') BOT_MNEMONIC = os.getenv('BOT_MNEMONIC', 'Token Not found') conn = models.sql_connection() models.create_database(conn) models.insert_user(BOT_NAME,BOT_ADDRESS,BOT_PRIVATE_KEY,BOT_MNEMONIC)
def before_first_request(): global session_fact db = init_connection_engine() session_fact = sessionmaker(bind=db) create_database(db)
def populate_from_directory(self, rootdir, answer_yes=False): '''directory should be the root dir containing multiple studies''' unknown = [] import os import os.path as osp from pluricent import checkbase as cb from pluricent import tests rootdir = osp.abspath(rootdir) dirlist = [ e for e in os.listdir(rootdir) if osp.isdir(osp.join(rootdir, e)) and not e in ['.', '..'] ] filelist = [ e for e in os.listdir(rootdir) if osp.isfile(osp.join(rootdir, e)) ] if not filelist == ['pluricent.db']: raise EXception( '%s should contain only pluricent.db and study folder (contains %s)' % (rootdir, filelist)) actions = [] # Then, go for the browsing for each in dirlist: studydir = osp.join(rootdir, each) print 'processing %s' % studydir assert (tests.test_respect_hierarchy(studydir)) cl = cb.CloudyCheckbase(studydir) # first look for dataset_description.json and add study fp = cb.getfilepath('dataset_description', {'database': studydir}, cl.patterns) if not osp.exists(fp): print fp, 'is missing' import json studyname = json.load(open(fp))['name'] actions.append([ 'add_study', { 'name': studyname, 'directory': studydir[len(rootdir) + 1:], 'description_file': fp[len(osp.dirname(fp)) + 1:] } ]) print 'study %s (%s)' % (studyname, studydir) for s in [ e for e in os.listdir(studydir) if osp.isdir(osp.join(studydir, e)) ]: actions.append( ['add_subject', { 'subjects': [s], 'study': studyname }]) for root, dirs, files in os.walk(studydir): for f in files: fp = osp.join(root, f) res = cb.parsefilepath(fp, cl.patterns) if not res is None: datatype, att = res if datatype == 'raw': actions.append([ 'add_image', { 'path': fp[len(rootdir) + 1:], 'study': studyname, 'subject': att['subject'] } ]) elif datatype in ['left_greywhite', 'right_greywhite', 'nobias', 'spm_nobias', 'split', 'brainmask', \ 'left_white', 'right_white', 'left_hemi', 'right_hemi', 'left_sulci', 'right_sulci', 'spm_nobias',\ 'spm_greymap', 'spm_whitemap', 'spm_csfmap', 'spm_greymap_warped', 'spm_whitemap_warped',\ 'spm_csfmap_warped', 'spm_greymap_modulated', 'spm_whitemap_modulated', 'spm_csfmap_modulated']: t1image = cb.getfilepath('raw', att, cl.patterns) software = 'spm8' if datatype.startswith( 'spm') else 'morphologist' actions.append([ 'add_processing', { 'path': fp[len(rootdir) + 1:], 'inputfp': t1image[len(rootdir) + 1:], 'datatype': datatype, 'software': software } ]) elif datatype == 'measurements': actions.append([ 'add_measurements', { 'csvfile': fp[len(rootdir) + 1:], 'study': studyname } ]) print actions print len(actions), 'actions to make' ans = answer_yes or raw_input('proceed ? y/n') == 'y' if ans: print 'warning: erasing database contents' ans = answer_yes or raw_input('proceed ? y/n') == 'y' if ans: models.create_database(self.filepath, from_existing_repository=True) self.make_actions(actions)
import models if __name__ == '__main__': # getservertaskinfo () # gettaskstatus() models.create_database()