def test_install_with_problem(self): "bauble.pluginmgr.init() using plugin which can't install" db.open(uri, verify=False) db.create(False) bauble.pluginmgr.plugins[FailingInstallPlugin.__name__] = FailingInstallPlugin() bauble.pluginmgr.plugins[DependsOnFailingInstallPlugin.__name__] = DependsOnFailingInstallPlugin() self.assertRaises(BaubleError, bauble.pluginmgr.init, force=True)
def test_install_with_problem(self): "bauble.pluginmgr.init() using plugin which can't install" db.open(uri, verify=False) db.create(False) bauble.pluginmgr.plugins[ FailingInstallPlugin.__name__] = FailingInstallPlugin() bauble.pluginmgr.plugins[DependsOnFailingInstallPlugin. __name__] = DependsOnFailingInstallPlugin() self.assertRaises(BaubleError, bauble.pluginmgr.init, force=True)
def test_init(self): """ Test bauble.pluginmgr.init() """ db.open(uri, verify=False) db.create(False) bauble.pluginmgr.plugins[C.__name__] = C bauble.pluginmgr.plugins[B.__name__] = B bauble.pluginmgr.plugins[A.__name__] = A bauble.pluginmgr.init(force=True) self.assert_(A.initialized and B.initialized and C.initialized)
def test_successfulinit(self): "bauble.pluginmgr.init() should be successful" db.open(uri, verify=False) db.create(False) bauble.pluginmgr.plugins[C.__name__] = C() bauble.pluginmgr.plugins[B.__name__] = B() bauble.pluginmgr.plugins[A.__name__] = A() bauble.pluginmgr.init(force=True) self.assertTrue(A.initialized) self.assertTrue(B.initialized) self.assertTrue(C.initialized)
def test_dependencies_CA(self): "test that loading C will also load A" pA = A() pB = B() pC = C() bauble.pluginmgr.plugins[B.__name__] = pB bauble.pluginmgr.plugins[A.__name__] = pA bauble.pluginmgr.plugins[C.__name__] = pC db.open(uri, verify=False) db.create(False) ## should try to load the A plugin self.assertRaises(KeyError, bauble.pluginmgr.install, (pC, ), force=True)
def test_install(self): """ Test bauble.pluginmgr.install() """ pA = A() pB = B() pC = C() bauble.pluginmgr.plugins[C.__name__] = pC bauble.pluginmgr.plugins[B.__name__] = pB bauble.pluginmgr.plugins[A.__name__] = pA db.open(uri, verify=False) db.create(False) bauble.pluginmgr.install((pA, pB, pC), force=True) self.assert_(A.installed and B.installed and C.installed)
def test_init_with_problem(self): "bauble.pluginmgr.init() using plugin which can't initialize" old_dialog = utils.message_details_dialog self.invoked = False def fake_dialog(a,b,c): "trap dialog box invocation" self.invoked = True utils.message_details_dialog = fake_dialog db.open(uri, verify=False) db.create(False) bauble.pluginmgr.plugins[FailingInitPlugin.__name__] = FailingInitPlugin() bauble.pluginmgr.plugins[DependsOnFailingInitPlugin.__name__] = DependsOnFailingInitPlugin() bauble.pluginmgr.init(force=True) self.assertTrue(self.invoked) # self.assertFalse(FailingInitPlugin.initialized) # irrelevant self.assertFalse(DependsOnFailingInitPlugin.initialized) utils.message_details_dialog = old_dialog
def test_init_with_problem(self): "bauble.pluginmgr.init() using plugin which can't initialize" old_dialog = utils.message_details_dialog self.invoked = False def fake_dialog(a, b, c): "trap dialog box invocation" self.invoked = True utils.message_details_dialog = fake_dialog db.open(uri, verify=False) db.create(False) bauble.pluginmgr.plugins[ FailingInitPlugin.__name__] = FailingInitPlugin() bauble.pluginmgr.plugins[DependsOnFailingInitPlugin. __name__] = DependsOnFailingInitPlugin() bauble.pluginmgr.init(force=True) self.assertTrue(self.invoked) # self.assertFalse(FailingInitPlugin.initialized) # irrelevant self.assertFalse(DependsOnFailingInitPlugin.initialized) utils.message_details_dialog = old_dialog
def on_file_menu_open(self, widget, data=None): """ Open the connection manager. """ from connmgr import ConnMgrPresenter default_conn = prefs[bauble.conn_default_pref] cm = ConnMgrPresenter(default=default_conn) name, uri = cm.start() if name is None: return engine = None try: engine = db.open(uri, True, True) except Exception, e: # we don't do anything to handle the exception since db.open() # should have shown an error dialog if there was a problem # opening the database as long as the show_error_dialogs # parameter is True logger.warning(e)
def init_bauble(uri, create=False): try: db.open(uri, verify=False) except Exception, e: print >>sys.stderr, e
def species_to_fix(s, create=False): gen_epithet, sp_epithet = s.split(' ') return plants.Species.retrieve_or_create( ssn, {'object': 'taxon', 'rank': 'species', 'ht-epithet': gen_epithet, 'epithet': sp_epithet, 'ht-rank': 'genus'}, create=create) def species_to_add(s): return species_to_fix(s, create=True) db.open("sqlite:////home/mario/.bauble/jbdm.db") ssn = db.Session() import codecs with codecs.open("/tmp/complete.csv", 'r', 'utf16') as f: keys = f.readline().strip().split('\t') for l in f.readlines(): l = l.strip() values = [i.strip() for i in l.split("\t")] fields = dict(zip(keys, values)) if float(fields['Overall_score']) <= 0.9: print fields['Name_submitted'] continue obj = species_to_fix(fields['Name_submitted'])
def species_to_fix(s, create=False): gen_epithet, sp_epithet = s.split(' ', 1) return plants.Species.retrieve_or_create( ssn, {'object': 'taxon', 'rank': 'species', 'ht-epithet': gen_epithet, 'epithet': sp_epithet, 'ht-rank': 'genus'}, create=create) def species_to_add(s): return species_to_fix(s, create=True) db.open("sqlite:////home/mario/.bauble/cuchubo-corrected.db") ssn = db.Session() import codecs with codecs.open("/tmp/complete.csv", 'r', 'utf16') as f: keys = f.readline().strip().split('\t') for l in f.readlines(): l = l.strip() values = [i.strip() for i in l.split("\t")] fields = dict(zip(keys, values)) print fields['Name_submitted'], fields['Name_matched'] obj = species_to_fix(fields['Name_submitted']) if obj is None: print fields['Name_submitted'] continue
def init_bauble(uri, create=False): try: db.open(uri, verify=False) except Exception, e: print >> sys.stderr, e
import os, sys import xml.sax.saxutils as saxutils sys.path.append('.') import sqlalchemy as sa from sqlalchemy.orm import * from sqlalchemy.orm.mapper import _mapper_registry from sqlalchemy.orm.properties import * import bauble import bauble.db as db import bauble.pluginmgr as pluginmgr from bauble.prefs import prefs import bauble.view as view uri = 'sqlite:///:memory:' db.open(uri, verify=False) prefs.init() pluginmgr.load() db.create(False) pluginmgr.init(True) def column_type_str(col): print type(col) if isinstance(col, sa.String): return 'string' elif isinstance(col, sa.Unicode): return 'unicode' elif isinstance(col, sa.Integer): return 'integer' elif isinstance(col, sa.ForeignKey): return 'foreign key(int)'
# intialize the user preferences prefs.init() open_exc = None # open default database if uri is None: from bauble.connmgr import ConnectionManager default_conn = prefs[conn_default_pref] while True: if not uri or not conn_name: cm = ConnectionManager(default_conn) conn_name, uri = cm.start() if conn_name is None: quit() try: if db.open(uri, True, True): prefs[conn_default_pref] = conn_name break else: uri = conn_name = None except err.VersionError, e: warning(e) db.open(uri, False) break except (err.EmptyDatabaseError, err.MetaTableError, err.VersionError, err.TimestampError, err.RegistryError), e: warning(e) open_exc = e # reopen without verification so that db.Session and # db.engine, db.metadata will be bound to an engine
gen_epithet, sp_epithet = s.split(' ', 1) return plants.Species.retrieve_or_create(ssn, { 'object': 'taxon', 'rank': 'species', 'ht-epithet': gen_epithet, 'epithet': sp_epithet, 'ht-rank': 'genus' }, create=create) def species_to_add(s): return species_to_fix(s, create=True) db.open("sqlite:////home/mario/.bauble/cuchubo-corrected.db") ssn = db.Session() import codecs with codecs.open("/tmp/complete.csv", 'r', 'utf16') as f: keys = f.readline().strip().split('\t') for l in f.readlines(): l = l.strip() values = [i.strip() for i in l.split("\t")] fields = dict(zip(keys, values)) print fields['Name_submitted'], fields['Name_matched'] obj = species_to_fix(fields['Name_submitted']) if obj is None: print fields['Name_submitted'] continue
import os, sys import xml.sax.saxutils as saxutils sys.path.append('.') import sqlalchemy as sa from sqlalchemy.orm import * from sqlalchemy.orm.mapper import _mapper_registry from sqlalchemy.orm.properties import * import bauble import bauble.db as db import bauble.pluginmgr as pluginmgr from bauble.prefs import prefs import bauble.view as view uri = 'sqlite:///:memory:' db.open(uri, verify=False) prefs.init() pluginmgr.load() db.create(False) pluginmgr.init(True) def column_type_str(col): print type(col) if isinstance(col, sa.String): return 'string' elif isinstance(col, sa.Unicode): return 'unicode' elif isinstance(col, sa.Integer): return 'integer' elif isinstance(col, sa.ForeignKey):
# declare module level variables global gui, default_icon, conn_name default_icon = os.path.join(paths.lib_dir(), "images", "icon.svg") open_exc = None # open default database if uri is None: from bauble.connmgr import start_connection_manager while True: if not uri or not conn_name: conn_name, uri = start_connection_manager() if conn_name is None: quit() try: if db.open(uri, True, True): prefs[conn_default_pref] = conn_name break else: uri = conn_name = None except err.VersionError, e: logger.warning("%s(%s)" % (type(e), e)) db.open(uri, False) break except (err.EmptyDatabaseError, err.MetaTableError, err.VersionError, err.TimestampError, err.RegistryError), e: logger.info("%s(%s)" % (type(e), e)) open_exc = e # reopen without verification so that db.Session and # db.engine, db.metadata will be bound to an engine