From bae7254ff3214305a1d6d352bfd389f195986546 Mon Sep 17 00:00:00 2001 From: Michael DM Dryden <mdryden@chem.utoronto.ca> Date: Tue, 14 Mar 2017 19:20:19 -0400 Subject: [PATCH] Remove ZODB support until newest version can be integrated properly. Fixes #24 --- .gitmodules | 9 - dstat_interface/db.py | 194 ---------------- dstat_interface/interface/db.glade | 219 ------------------ .../interface/dstatinterface.glade | 27 --- dstat_interface/main.py | 52 +---- dstat_interface/params.py | 4 +- pavement.py | 3 +- 7 files changed, 4 insertions(+), 504 deletions(-) delete mode 100644 dstat_interface/db.py delete mode 100644 dstat_interface/interface/db.glade diff --git a/.gitmodules b/.gitmodules index a95ffcb..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +0,0 @@ -[submodule "mr_db"] - path = mr_db - url = /Users/mdryden/src/mr_db -[submodule "dstat-interface/mr_db"] - path = dstat-interface/mr_db - url = http://microfluidics.utoronto.ca/gitlab/mdryden/mr-db.git -[submodule "dstat_interface/mr_db"] - path = dstat_interface/mr_db - url = http://microfluidics.utoronto.ca/gitlab/mdryden/mr-db.git diff --git a/dstat_interface/db.py b/dstat_interface/db.py deleted file mode 100644 index 3e1fda8..0000000 --- a/dstat_interface/db.py +++ /dev/null @@ -1,194 +0,0 @@ -import logging -from time import sleep, time -from os.path import expanduser -from uuid import uuid4 - -from BTrees.OOBTree import OOBTree - -import mr_db.mr_db as db - -logger = logging.getLogger("dstat.db") - -current_db = None - -def start_db(path=None): - global current_db - current_db = Database(data_dir=path) - -def restart_db(object, path): - logger.info("Restarting database") - global current_db - if current_db is None: - logger.info("No database running") - start_db(path=path) - else: - stop_db() - start_db(path=path) - -def stop_db(): - global current_db - if not current_db is None: - logger.info("Stopping ZEO") - current_db.disconnect() - current_db = None - db.stop_server() - else: - logger.warning("Tried to disconnect ZEO when not connected") - -class Database(object): - def __init__(self, name='dstat', data_dir=None): - if data_dir is None: - data_dir = expanduser('~/.mr_db') - self.connected = False - self.name = name - - self.db_connect(data_dir) - - self.db = self.connection.databases - - # Make sure database exists - if not self.db.has_key(name): - self.db[name] = OOBTree() - db.transaction.commit() - - def disconnect(self): - if self.connected is True: - self.connection.db.close() - else: - logger.war("Tried to disconnect ZEO when not connected") - - def db_connect(self, root_dir): - """Connects to ZEO process. Starts ZEO if not running. Returns - connection object. - """ - if root_dir == '': - root_dir = None - - while self.connected is False: - try: - self.connection = db.DbConnection(root_dir=root_dir) - self.connected = True - logger.info("Connected to ZEO server") - except db.ClientStorage.ClientDisconnected: - db.stop_server() - logger.info("Starting ZEO server -- root_dir = %s", root_dir) - db_proc = db.start_server(root_dir=root_dir) - sleep(3) - - def add_results(self, measurement_uuid=None, measurement_name=None, - experiment_uuid=None, experiment_metadata=None, - patient_id=None, - timestamp=None, - data=None): - - """Add a measurement""" - - if experiment_metadata is None: - experiment_metadata = {} - - try: - logger.info("Starting DB transaction") - db.transaction.begin() - - logger.info("Creating Experiment with id: %s", experiment_uuid) - exp_db, exp_id = self.add_experiment( - experiment_uuid=experiment_uuid, - timestamp=timestamp, - **experiment_metadata) - - logger.info("Adding Measurement with id: %s", measurement_uuid) - name = self.add_dstat_measurement(experiment=exp_db[exp_id], - measurement_uuid=measurement_uuid, - name=measurement_name, - timestamp=timestamp, - data=data) - - if patient_id is not None: - if not patient_id in self.db['patients']: - logger.info("Creating patient with id: %s", patient_id) - patient = db.Patient(pid=patient_id) - self.db['patients'][patient_id] = patient - - if not exp_id in self.db['patients'][patient_id].experiments: - logger.info("Linking experiment into patient with id: %s", - patient_id) - self.db['patients'][patient_id].link_experiment(exp_db, - exp_id) - - logger.info("Committing DB transaction") - db.transaction.commit() - - return name - - except: - logger.error("Aborting DB transaction") - db.transaction.abort() - raise - - def add_experiment(self, experiment_uuid=None, timestamp=None, **kwargs): - """Add a new experiment. Will raise KeyExistsError if id is already - in db to avoid unintended collisions. - ---- - Arguments: - id: experiment id---UUID will be generated if not supplied - timestamp: current time---Will be generated if not supplied - kwargs: additional keyword arguments that will be saved in experiment. - """ - - if experiment_uuid is None: - experiment_uuid = uuid4().hex - if timestamp is None: - timestamp = time() - - kwargs.update({'id':experiment_uuid, 'timestamp':timestamp}) - - if not experiment_uuid in self.db[self.name]: - self.db[self.name][experiment_uuid] = db.PersistentMapping() - else: - logger.info("Experiment already exists, appending") - - self.db[self.name][experiment_uuid].update(kwargs) - - return (self.db[self.name], experiment_uuid) - - def add_dstat_measurement(self, experiment, measurement_uuid=None, - data=None, timestamp=None, name=None): - - if measurement_uuid is None: - measurement_uuid = uuid4().hex - if timestamp is None: - timestamp = time() - if data is None: - data = {} - - if not 'measurements' in experiment: - experiment['measurements'] = db.PersistentMapping() - if not 'measurements_by_name' in experiment: - experiment['measurements_by_name'] = db.PersistentMapping() - - if measurement_uuid in experiment['measurements']: - raise db.KeyExistsError(measurement_uuid, - "Measurement ID already exists. Access directly to update") - - data['timestamp'] = timestamp - data['id'] = measurement_uuid - - if name is not None: - data['name'] = name - - experiment['measurements'][measurement_uuid] = data - - if name is not None: - while name in experiment['measurements_by_name']: - first, sep, last = name.rpartition('-') - - if last.isdigit(): - index = int(last) - index += 1 - name = sep.join((first,str(index))) - else: - name += '-1' - - experiment['measurements_by_name'][name] = data - - return name \ No newline at end of file diff --git a/dstat_interface/interface/db.glade b/dstat_interface/interface/db.glade deleted file mode 100644 index 20a833a..0000000 --- a/dstat_interface/interface/db.glade +++ /dev/null @@ -1,219 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<interface> - <requires lib="gtk+" version="2.24"/> - <!-- interface-naming-policy project-wide --> - <object class="GtkWindow" id="db_window"> - <property name="can_focus">False</property> - <property name="title" translatable="yes">Database</property> - <property name="window_position">center-on-parent</property> - <property name="destroy_with_parent">True</property> - <child> - <object class="GtkVBox" id="vbox1"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <child> - <object class="GtkCheckButton" id="db_enable_checkbutton"> - <property name="label" translatable="yes">Enable Database saving</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="active">True</property> - <property name="draw_indicator">True</property> - <signal name="toggled" handler="on_db_enable_checkbutton_toggled" swapped="no"/> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkTable" id="db_control_table"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="n_rows">5</property> - <property name="n_columns">3</property> - <child> - <placeholder/> - </child> - <child> - <placeholder/> - </child> - <child> - <object class="GtkLabel" id="label3"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">Measurement ID</property> - </object> - <packing> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label1"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">Experiment ID</property> - </object> - </child> - <child> - <object class="GtkEntry" id="exp_id_entry"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">â—</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> - <property name="primary_icon_sensitive">True</property> - <property name="secondary_icon_sensitive">True</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - </packing> - </child> - <child> - <object class="GtkEntry" id="measure_id_entry"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">False</property> - <property name="invisible_char">â—</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> - <property name="primary_icon_sensitive">True</property> - <property name="secondary_icon_sensitive">True</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - </packing> - </child> - <child> - <object class="GtkEntry" id="patient_id_entry"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">False</property> - <property name="invisible_char">â—</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> - <property name="primary_icon_sensitive">True</property> - <property name="secondary_icon_sensitive">True</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label2"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">Patient ID</property> - </object> - <packing> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> - </packing> - </child> - <child> - <object class="GtkButton" id="exp_id_autogen_button"> - <property name="label" translatable="yes">Generate New</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <signal name="clicked" handler="on_exp_id_autogen_button_clicked" swapped="no"/> - </object> - <packing> - <property name="left_attach">2</property> - <property name="right_attach">3</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label4"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">DB Path</property> - </object> - <packing> - <property name="top_attach">4</property> - <property name="bottom_attach">5</property> - </packing> - </child> - <child> - <object class="GtkEntry" id="db_path_entry"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">â—</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> - <property name="primary_icon_sensitive">True</property> - <property name="secondary_icon_sensitive">True</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">4</property> - <property name="bottom_attach">5</property> - </packing> - </child> - <child> - <object class="GtkButton" id="db_apply_button"> - <property name="label" translatable="yes">Apply</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <signal name="clicked" handler="on_db_apply_button_clicked" swapped="no"/> - </object> - <packing> - <property name="left_attach">2</property> - <property name="right_attach">3</property> - <property name="top_attach">4</property> - <property name="bottom_attach">5</property> - </packing> - </child> - <child> - <placeholder/> - </child> - <child> - <object class="GtkLabel" id="label5"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">Measurement Name</property> - </object> - <packing> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - </packing> - </child> - <child> - <object class="GtkEntry" id="measure_name_entry"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">â—</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> - <property name="primary_icon_sensitive">True</property> - <property name="secondary_icon_sensitive">True</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - </packing> - </child> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - </object> -</interface> diff --git a/dstat_interface/interface/dstatinterface.glade b/dstat_interface/interface/dstatinterface.glade index 6503660..8ae7a00 100644 --- a/dstat_interface/interface/dstatinterface.glade +++ b/dstat_interface/interface/dstatinterface.glade @@ -749,11 +749,6 @@ Thanks to Christian Fobel for help with Dropbot Plugin</property> <property name="can_focus">False</property> <property name="stock">gtk-preferences</property> </object> - <object class="GtkImage" id="image7"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="stock">gtk-info</property> - </object> <object class="GtkListStore" id="serial_liststore"> <columns> <!-- column-name serial --> @@ -897,28 +892,6 @@ Thanks to Christian Fobel for help with Dropbot Plugin</property> </child> </object> </child> - <child> - <object class="GtkMenuItem" id="menu_database"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">Database</property> - <child type="submenu"> - <object class="GtkMenu" id="menu5"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <child> - <object class="GtkImageMenuItem" id="menu_database_options"> - <property name="label">View…</property> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="image">image7</property> - <property name="use_stock">False</property> - </object> - </child> - </object> - </child> - </object> - </child> <child> <object class="GtkMenuItem" id="menuitem4"> <property name="visible">True</property> diff --git a/dstat_interface/main.py b/dstat_interface/main.py index a7e05d1..6b72172 100755 --- a/dstat_interface/main.py +++ b/dstat_interface/main.py @@ -50,7 +50,6 @@ os.chdir(os.path.dirname(os.path.abspath(sys.argv[0]))) from version import getVersion import interface.save as save -from interface.db import DB_Window import dstat_comm as comm import interface.exp_window as exp_window import interface.adc_pot as adc_pot @@ -59,7 +58,6 @@ import params import parameter_test import analysis import zmq -import db from errors import InputError from plugin import DstatPlugin, get_hub_uri @@ -105,12 +103,6 @@ class Main(object): self.exp_window = exp_window.Experiments(self.builder) self.analysis_opt_window = analysis.AnalysisOptions(self.builder) - - self.db_window = DB_Window() - self.builder.get_object('menu_database_options').connect_object( - 'activate', DB_Window.show, self.db_window - ) - self.db_window.connect('db_reset', db.restart_db) # Setup Autosave self.autosave_checkbox = self.builder.get_object('autosave_checkbutton') @@ -209,7 +201,6 @@ class Main(object): params.save_params(self, 'last_params.yml') self.on_serial_disconnect_clicked() - db.stop_db() gtk.main_quit() def on_gtk_about_activate(self, menuitem, data=None): @@ -438,13 +429,7 @@ class Main(object): self.metadata = metadata if self.metadata is not None: - logger.info("Loading external metadata") - self.db_window.update_from_metadata(self.metadata) - elif self.db_window.params['exp_id_entry'] is None: - logger.info("DB exp_id field blank, autogenerating") - self.db_window.on_exp_id_autogen_button_clicked() - - self.db_window.params = {'measure_id_entry':experiment_id.hex} + logger.info("Loading external metadata") def exceptions(): """ Cleans up after errors """ @@ -470,13 +455,7 @@ class Main(object): else: nb.get_nth_page(nb.page_num(self.ft_window)).hide() # nb.get_nth_page(nb.page_num(self.period_window)).hide() - - if parameters['db_enable_checkbutton']: - if db.current_db is None: - db.start_db() - elif not db.current_db.connected: - db.restart_db() - + comm.serial_instance.proc_pipe_p.send(self.current_exp) # Flush data pipe @@ -811,33 +790,6 @@ class Main(object): self.autosavedir_button.get_filename(), self.autosavename.get_text() ) - # Database output - if self.current_exp.parameters['db_enable_checkbutton']: - meta = {} - - if self.current_exp.parameters['metadata'] is not None: - metadata = self.current_exp.parameters['metadata'] - exp_metakeys = ['experiment_uuid', 'patient_id', 'name'] - meta.update( - {k: metadata[k] - for k in metadata - if k not in exp_metakeys - } - ) - - name = self.current_exp.parameters['measure_name_entry'] - - newname = db.current_db.add_results( - measurement_uuid=self.active_experiment_id.hex, - measurement_name=name, - experiment_uuid=self.current_exp.parameters['exp_id_entry'], - experiment_metadata=meta, - patient_id=self.current_exp.parameters['patient_id_entry'], - timestamp=None, - data=self.current_exp.export() - ) - - self.db_window.params = {'measure_name_entry':newname} # uDrop # UI stuff diff --git a/dstat_interface/params.py b/dstat_interface/params.py index 6dbc720..048d1f4 100755 --- a/dstat_interface/params.py +++ b/dstat_interface/params.py @@ -44,8 +44,7 @@ def get_params(window): logger.info("No gain selected.") parameters.update(window.exp_window.get_params(selection)) parameters.update(window.analysis_opt_window.params) - parameters.update(window.db_window.persistent_params) - + return parameters def save_params(window, path): @@ -77,6 +76,5 @@ def set_params(window, params): window.exp_window.set_params(params['experiment_index'], params) window.analysis_opt_window.params = params - window.db_window.params = params window.params_loaded = True diff --git a/pavement.py b/pavement.py index bf1f907..0aea7f5 100644 --- a/pavement.py +++ b/pavement.py @@ -18,8 +18,7 @@ setup(name='dstat_interface', license='GPLv3', packages=['dstat_interface', ], install_requires=['matplotlib', 'numpy', 'pyserial', 'pyzmq', - 'pyyaml','seaborn', 'zmq-plugin>=0.2.post2', 'zodb', - 'zeo', 'psutil'], + 'pyyaml','seaborn', 'zmq-plugin>=0.2.post2'], # Install data listed in `MANIFEST.in` include_package_data=True) -- GitLab