3 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/a0db2788e912/ Changeset: a0db2788e912 User: iracooke Date: 2014-08-01 03:31:51 Summary: Added sqlite metadata detection (from JJ) Affected #: 1 file diff -r 19859e3e4b1c58217c31d2f3c472359c667c2a7f -r a0db2788e9125270aec5391e676d8a0b36691233 lib/galaxy/datatypes/binary.py --- a/lib/galaxy/datatypes/binary.py +++ b/lib/galaxy/datatypes/binary.py @@ -20,7 +20,7 @@ from bx.seq.twobit import TWOBIT_MAGIC_NUMBER, TWOBIT_MAGIC_NUMBER_SWAP, TWOBIT_MAGIC_SIZE -from galaxy.datatypes.metadata import MetadataElement +from galaxy.datatypes.metadata import MetadataElement,ListParameter,DictParameter from galaxy.datatypes import metadata from galaxy.datatypes.sniff import * import dataproviders @@ -550,8 +550,36 @@ @dataproviders.decorators.has_dataproviders class SQlite ( Binary ): + """Class describing a Sqlite database """ + MetadataElement( name="tables", default=[], param=ListParameter, desc="Database Tables", readonly=True, visible=True, no_value=[] ) + MetadataElement( name="table_columns", default={}, param=DictParameter, desc="Database Table Columns", readonly=True, visible=True, no_value={} ) + MetadataElement( name="table_row_count", default={}, param=DictParameter, desc="Database Table Row Count", readonly=True, visible=True, no_value={} ) file_ext = "sqlite" + def init_meta( self, dataset, copy_from=None ): + Binary.init_meta( self, dataset, copy_from=copy_from ) + + def set_meta( self, dataset, overwrite = True, **kwd ): + try: + tables = [] + columns = dict() + rowcounts = dict() + conn = sqlite3.connect(dataset.file_name) + c = conn.cursor() + tables_query = "SELECT name,sql FROM sqlite_master WHERE type='table' ORDER BY name" + rslt = c.execute(tables_query).fetchall() + for table,sql in rslt: + tables.append(table) + columns[table] = re.sub('^.*\((.*)\)$','\\1',sql).split(',') + for table in tables: + row_query = "SELECT count(*) FROM %s" % table + rowcounts[table] = c.execute(row_query).fetchone()[0] + dataset.metadata.tables = tables + dataset.metadata.table_columns = columns + dataset.metadata.table_row_count = rowcounts + except Exception, exc: + pass + # Connects and runs a query that should work on any real database # If the file is not sqlite, an exception will be thrown and the sniffer will return false def sniff( self, filename ): @@ -568,6 +596,14 @@ def set_peek( self, dataset, is_multi_byte=False ): if not dataset.dataset.purged: dataset.peek = "SQLite Database" + lines = ['SQLite Database'] + if dataset.metadata.tables: + for table in dataset.metadata.tables: + try: + lines.append('%s [%s]' % (table,dataset.metadata.table_row_count[table])) + except: + continue + dataset.peek = '\n'.join(lines) dataset.blurb = data.nice_size( dataset.get_size() ) else: dataset.peek = 'file does not exist' https://bitbucket.org/galaxy/galaxy-central/commits/7dd390cfd674/ Changeset: 7dd390cfd674 User: iracooke Date: 2014-08-01 03:33:22 Summary: Merged galaxy/galaxy-central into default Affected #: 50 files diff -r a0db2788e9125270aec5391e676d8a0b36691233 -r 7dd390cfd674cae4c2833fb36f9b4875576cb1c0 .hgtags --- a/.hgtags +++ b/.hgtags @@ -7,6 +7,13 @@ 26f58e05aa1068761660681583821e21e6cbf7ab release_2013.11.04 5e605ed6069fe4c5ca9875e95e91b2713499e8ca release_2014.02.10 9e53251b0b7e93b9563008a2b112f2e815a04bbc release_2014.04.14 -68a8b0397947c732b28207d465d3f3c4e2a7a8a0 latest_2014.04.14 7e257c7b10badb65772b1528cb61d58175a42e47 release_2014.06.02 -8a863a311a6c9f14b302799bffcf94df9186fef7 latest_2014.06.02 +8c30e91bc9ae19ee4dc7ec2c22fa825979497108 latest_2014.06.02 +9661b9d5d5b330483ae3ad2236410e0efaa7c500 latest_2014.04.14 +6b0bd93038a843b1585155f0d63f0eea2459c70b latest_2013.01.13 +3e62060b14b9afc46f8e0ec02e1a4500d77db9e1 latest_2013.02.08 +425009b3ff4d8b67d2812253b221f3c4f4a8d1e3 latest_2013.04.01 +9713d86392ef985ffcdc39ff0c8ddf51a1f9ce47 latest_2013.06.03 +9ed84cd208e07e8985ec917cb025fcbbb09edcfb latest_2013.08.12 +81fbe25bd02edcd53065e8e4476dd1dfb5a72cf2 latest_2013.11.04 +2a756ca2cb1826db7796018e77d12e2dd7b67603 latest_2014.02.10 diff -r a0db2788e9125270aec5391e676d8a0b36691233 -r 7dd390cfd674cae4c2833fb36f9b4875576cb1c0 lib/galaxy/util/__init__.py --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -714,11 +714,11 @@ def object_to_string( obj ): - return binascii.hexlify( pickle.dumps( obj, 2 ) ) + return binascii.hexlify( obj ) def string_to_object( s ): - return pickle.loads( binascii.unhexlify( s ) ) + return binascii.unhexlify( s ) class ParamsWithSpecs( collections.defaultdict ): diff -r a0db2788e9125270aec5391e676d8a0b36691233 -r 7dd390cfd674cae4c2833fb36f9b4875576cb1c0 lib/galaxy/webapps/galaxy/controllers/ucsc_proxy.py --- a/lib/galaxy/webapps/galaxy/controllers/ucsc_proxy.py +++ b/lib/galaxy/webapps/galaxy/controllers/ucsc_proxy.py @@ -5,6 +5,7 @@ from galaxy.web.base.controller import * import sys +import json from galaxy import web, util import re, urllib, logging @@ -33,7 +34,7 @@ try: store = params.get("__GALAXY__", None) if store: - store = util.string_to_object(store) + store = json.loads(util.string_to_object(store)) else: store = {} UCSC_URL = 'UCSC_URL' @@ -86,7 +87,7 @@ # Serialize store into a form element store_text = "<INPUT TYPE=\"HIDDEN\" NAME=\"__GALAXY__\" ID=\"__GALAXY__\" VALUE=\"" \ - + util.object_to_string(store) + "\" \>" + + json.dumps(util.object_to_string(store)) + "\" \>" # Remove text regions that should not be exposed for key,value in altered_regions.items(): diff -r a0db2788e9125270aec5391e676d8a0b36691233 -r 7dd390cfd674cae4c2833fb36f9b4875576cb1c0 lib/galaxy/webapps/tool_shed/controllers/repository.py --- a/lib/galaxy/webapps/tool_shed/controllers/repository.py +++ b/lib/galaxy/webapps/tool_shed/controllers/repository.py @@ -20,13 +20,13 @@ from tool_shed.galaxy_install import dependency_display from tool_shed.metadata import repository_metadata_manager +from tool_shed.utility_containers import ToolShedUtilityContainerManager from tool_shed.tools import tool_validator from tool_shed.tools import tool_version_manager from tool_shed.util import basic_util from tool_shed.util import common_util -from tool_shed.util import container_util from tool_shed.util import encoding_util from tool_shed.util import hg_util from tool_shed.util import metadata_util @@ -1273,12 +1273,12 @@ # Only display repository dependencies if they exist. exclude = [ 'datatypes', 'invalid_repository_dependencies', 'invalid_tool_dependencies', 'invalid_tools', 'readme_files', 'tool_dependencies', 'tools', 'tool_test_results', 'workflows', 'data_manager' ] - containers_dict = container_util.build_repository_containers_for_tool_shed( trans.app, - repository, - changeset_revision, - repository_dependencies, - repository_metadata, - exclude=exclude ) + tsucm = ToolShedUtilityContainerManager( trans.app ) + containers_dict = tsucm.build_repository_containers( repository, + changeset_revision, + repository_dependencies, + repository_metadata, + exclude=exclude ) export_repository_dependencies_check_box = CheckboxField( 'export_repository_dependencies', checked=True ) else: containers_dict = None @@ -2458,11 +2458,11 @@ skip_tool_tests_check_box = CheckboxField( 'skip_tool_tests', checked=skip_tool_tests_checked ) categories = suc.get_categories( trans.app ) selected_categories = [ rca.category_id for rca in repository.categories ] - containers_dict = container_util.build_repository_containers_for_tool_shed( trans.app, - repository, - changeset_revision, - repository_dependencies, - repository_metadata ) + tsucm = ToolShedUtilityContainerManager( trans.app ) + containers_dict = tsucm.build_repository_containers( repository, + changeset_revision, + repository_dependencies, + repository_metadata ) heads = hg_util.get_repository_heads( repo ) deprecated_repository_dependency_tups = \ metadata_util.get_repository_dependency_tups_from_repository_metadata( trans.app, @@ -2653,11 +2653,11 @@ selected_value=changeset_revision, add_id_to_name=False, downloadable=False ) - containers_dict = container_util.build_repository_containers_for_tool_shed( trans.app, - repository, - changeset_revision, - repository_dependencies, - repository_metadata ) + tsucm = ToolShedUtilityContainerManager( trans.app ) + containers_dict = tsucm.build_repository_containers( repository, + changeset_revision, + repository_dependencies, + repository_metadata ) return trans.fill_template( '/webapps/tool_shed/repository/preview_tools_in_changeset.mako', repository=repository, containers_dict=containers_dict, @@ -3360,11 +3360,11 @@ else: message += malicious_error status = 'error' - containers_dict = container_util.build_repository_containers_for_tool_shed( trans.app, - repository, - changeset_revision, - repository_dependencies, - repository_metadata ) + tsucm = ToolShedUtilityContainerManager( trans.app ) + containers_dict = tsucm.build_repository_containers( repository, + changeset_revision, + repository_dependencies, + repository_metadata ) repository_type_select_field = rt_util.build_repository_type_select_field( trans, repository=repository ) heads = hg_util.get_repository_heads( repo ) return trans.fill_template( '/webapps/tool_shed/repository/view_repository.mako', diff -r a0db2788e9125270aec5391e676d8a0b36691233 -r 7dd390cfd674cae4c2833fb36f9b4875576cb1c0 lib/galaxy/webapps/tool_shed/controllers/repository_review.py --- a/lib/galaxy/webapps/tool_shed/controllers/repository_review.py +++ b/lib/galaxy/webapps/tool_shed/controllers/repository_review.py @@ -1,17 +1,26 @@ -import os, logging -from galaxy import web, util +import logging +import os + +from sqlalchemy.sql.expression import func + +from galaxy import util +from galaxy import web + +from galaxy.model.orm import and_ +from galaxy.util.odict import odict from galaxy.web.base.controller import BaseUIController -from galaxy.web.form_builder import SelectField, CheckboxField -from sqlalchemy.sql.expression import func -from galaxy.model.orm import and_ +from galaxy.web.form_builder import CheckboxField +from galaxy.web.form_builder import SelectField + from galaxy.webapps.tool_shed.util import ratings_util + +import tool_shed.grids.repository_review_grids as repository_review_grids +import tool_shed.grids.util as grids_util + from tool_shed.util.container_util import STRSEP -import tool_shed.util.shed_util_common as suc from tool_shed.util import hg_util from tool_shed.util import review_util -from galaxy.util.odict import odict -import tool_shed.grids.repository_review_grids as repository_review_grids -import tool_shed.grids.util as grids_util +from tool_shed.util import shed_util_common as suc log = logging.getLogger( __name__ ) diff -r a0db2788e9125270aec5391e676d8a0b36691233 -r 7dd390cfd674cae4c2833fb36f9b4875576cb1c0 lib/tool_shed/dependencies/repository/relation_builder.py --- a/lib/tool_shed/dependencies/repository/relation_builder.py +++ b/lib/tool_shed/dependencies/repository/relation_builder.py @@ -3,6 +3,7 @@ from galaxy.util import asbool from galaxy.util import listify + from tool_shed.util import common_util from tool_shed.util import container_util from tool_shed.util import hg_util diff -r a0db2788e9125270aec5391e676d8a0b36691233 -r 7dd390cfd674cae4c2833fb36f9b4875576cb1c0 lib/tool_shed/galaxy_install/dependency_display.py --- a/lib/tool_shed/galaxy_install/dependency_display.py +++ b/lib/tool_shed/galaxy_install/dependency_display.py @@ -5,6 +5,9 @@ from galaxy import util +from tool_shed.galaxy_install.utility_containers import GalaxyUtilityContainerManager +from tool_shed.utility_containers import utility_container_manager + from tool_shed.util import common_util from tool_shed.util import container_util from tool_shed.util import readme_util @@ -276,22 +279,23 @@ old_container_repository_dependencies_root = old_container_dict[ 'repository_dependencies' ] if old_container_repository_dependencies_root: if repository_dependencies_root_folder is None: - repository_dependencies_root_folder = container_util.Folder( id=folder_id, - key='root', - label='root', - parent=None ) + repository_dependencies_root_folder = utility_container_manager.Folder( id=folder_id, + key='root', + label='root', + parent=None ) folder_id += 1 - repository_dependencies_folder = container_util.Folder( id=folder_id, - key='merged', - label='Repository dependencies', - parent=repository_dependencies_root_folder ) + repository_dependencies_folder = utility_container_manager.Folder( id=folder_id, + key='merged', + label='Repository dependencies', + parent=repository_dependencies_root_folder ) folder_id += 1 # The old_container_repository_dependencies_root will be a root folder containing a single sub_folder. old_container_repository_dependencies_folder = old_container_repository_dependencies_root.folders[ 0 ] # Change the folder id so it won't confict with others being merged. old_container_repository_dependencies_folder.id = folder_id folder_id += 1 - repository_components_tuple = container_util.get_components_from_key( old_container_repository_dependencies_folder.key ) + repository_components_tuple = \ + container_util.get_components_from_key( old_container_repository_dependencies_folder.key ) components_list = suc.extract_components_from_tuple( repository_components_tuple ) name = components_list[ 1 ] # Generate the label by retrieving the repository name. @@ -301,15 +305,15 @@ old_container_tool_dependencies_root = old_container_dict[ 'tool_dependencies' ] if old_container_tool_dependencies_root: if tool_dependencies_root_folder is None: - tool_dependencies_root_folder = container_util.Folder( id=folder_id, - key='root', - label='root', - parent=None ) + tool_dependencies_root_folder = utility_container_manager.Folder( id=folder_id, + key='root', + label='root', + parent=None ) folder_id += 1 - tool_dependencies_folder = container_util.Folder( id=folder_id, - key='merged', - label='Tool dependencies', - parent=tool_dependencies_root_folder ) + tool_dependencies_folder = utility_container_manager.Folder( id=folder_id, + key='merged', + label='Tool dependencies', + parent=tool_dependencies_root_folder ) folder_id += 1 else: td_list = [ td.listify for td in tool_dependencies_folder.tool_dependencies ] @@ -410,23 +414,22 @@ repository_missing_tool_dependencies=missing_tool_dependencies, required_repo_info_dicts=None ) # Most of the repository contents are set to None since we don't yet know what they are. - containers_dict = \ - container_util.build_repository_containers_for_galaxy( app=self.app, - repository=None, - datatypes=None, - invalid_tools=None, - missing_repository_dependencies=missing_repository_dependencies, - missing_tool_dependencies=missing_tool_dependencies, - readme_files_dict=readme_files_dict, - repository_dependencies=installed_repository_dependencies, - tool_dependencies=installed_tool_dependencies, - valid_tools=None, - workflows=None, - valid_data_managers=None, - invalid_data_managers=None, - data_managers_errors=None, - new_install=True, - reinstalling=False ) + gucm = GalaxyUtilityContainerManager( self.app ) + containers_dict = gucm.build_repository_containers( repository=None, + datatypes=None, + invalid_tools=None, + missing_repository_dependencies=missing_repository_dependencies, + missing_tool_dependencies=missing_tool_dependencies, + readme_files_dict=readme_files_dict, + repository_dependencies=installed_repository_dependencies, + tool_dependencies=installed_tool_dependencies, + valid_tools=None, + workflows=None, + valid_data_managers=None, + invalid_data_managers=None, + data_managers_errors=None, + new_install=True, + reinstalling=False ) if not updating: # If we installing a new repository and not updaing an installed repository, we can merge # the missing_repository_dependencies container contents to the installed_repository_dependencies @@ -508,23 +511,22 @@ valid_data_managers = metadata['data_manager'].get( 'data_managers', None ) invalid_data_managers = metadata['data_manager'].get( 'invalid_data_managers', None ) data_managers_errors = metadata['data_manager'].get( 'messages', None ) - containers_dict = \ - container_util.build_repository_containers_for_galaxy( app=self.app, - repository=repository, - datatypes=datatypes, - invalid_tools=invalid_tools, - missing_repository_dependencies=missing_repository_dependencies, - missing_tool_dependencies=missing_tool_dependencies, - readme_files_dict=readme_files_dict, - repository_dependencies=installed_repository_dependencies, - tool_dependencies=installed_tool_dependencies, - valid_tools=valid_tools, - workflows=workflows, - valid_data_managers=valid_data_managers, - invalid_data_managers=invalid_data_managers, - data_managers_errors=data_managers_errors, - new_install=False, - reinstalling=reinstalling ) + gucm = GalaxyUtilityContainerManager( self.app ) + containers_dict = gucm.build_repository_containers( repository=repository, + datatypes=datatypes, + invalid_tools=invalid_tools, + missing_repository_dependencies=missing_repository_dependencies, + missing_tool_dependencies=missing_tool_dependencies, + readme_files_dict=readme_files_dict, + repository_dependencies=installed_repository_dependencies, + tool_dependencies=installed_tool_dependencies, + valid_tools=valid_tools, + workflows=workflows, + valid_data_managers=valid_data_managers, + invalid_data_managers=invalid_data_managers, + data_managers_errors=data_managers_errors, + new_install=False, + reinstalling=reinstalling ) else: containers_dict = dict( datatypes=None, invalid_tools=None, diff -r a0db2788e9125270aec5391e676d8a0b36691233 -r 7dd390cfd674cae4c2833fb36f9b4875576cb1c0 lib/tool_shed/galaxy_install/utility_containers/__init__.py --- /dev/null +++ b/lib/tool_shed/galaxy_install/utility_containers/__init__.py @@ -0,0 +1,145 @@ +import logging +import os +import threading + +from tool_shed.utility_containers import utility_container_manager + +log = logging.getLogger( __name__ ) + + +class GalaxyUtilityContainerManager( utility_container_manager.UtilityContainerManager ): + + def __init__( self, app ): + self.app = app + + def build_repository_containers( self, repository, datatypes, invalid_tools, missing_repository_dependencies, + missing_tool_dependencies, readme_files_dict, repository_dependencies, + tool_dependencies, valid_tools, workflows, valid_data_managers, + invalid_data_managers, data_managers_errors, new_install=False, + reinstalling=False ): + """ + Return a dictionary of containers for the received repository's dependencies and readme files for + display during installation to Galaxy. + """ + containers_dict = dict( datatypes=None, + invalid_tools=None, + missing_tool_dependencies=None, + readme_files=None, + repository_dependencies=None, + missing_repository_dependencies=None, + tool_dependencies=None, + valid_tools=None, + workflows=None, + valid_data_managers=None, + invalid_data_managers=None ) + # Some of the tool dependency folders will include links to display tool dependency information, and + # some of these links require the repository id. However we need to be careful because sometimes the + # repository object is None. + if repository: + repository_id = repository.id + changeset_revision = repository.changeset_revision + else: + repository_id = None + changeset_revision = None + lock = threading.Lock() + lock.acquire( True ) + try: + folder_id = 0 + # Datatypes container. + if datatypes: + folder_id, datatypes_root_folder = self.build_datatypes_folder( folder_id, datatypes ) + containers_dict[ 'datatypes' ] = datatypes_root_folder + # Invalid tools container. + if invalid_tools: + folder_id, invalid_tools_root_folder = \ + self.build_invalid_tools_folder( folder_id, + invalid_tools, + changeset_revision, + repository=repository, + label='Invalid tools' ) + containers_dict[ 'invalid_tools' ] = invalid_tools_root_folder + # Readme files container. + if readme_files_dict: + folder_id, readme_files_root_folder = self.build_readme_files_folder( folder_id, readme_files_dict ) + containers_dict[ 'readme_files' ] = readme_files_root_folder + # Installed repository dependencies container. + if repository_dependencies: + if new_install: + label = 'Repository dependencies' + else: + label = 'Installed repository dependencies' + folder_id, repository_dependencies_root_folder = \ + self.build_repository_dependencies_folder( folder_id=folder_id, + repository_dependencies=repository_dependencies, + label=label, + installed=True ) + containers_dict[ 'repository_dependencies' ] = repository_dependencies_root_folder + # Missing repository dependencies container. + if missing_repository_dependencies: + folder_id, missing_repository_dependencies_root_folder = \ + self.build_repository_dependencies_folder( folder_id=folder_id, + repository_dependencies=missing_repository_dependencies, + label='Missing repository dependencies', + installed=False ) + containers_dict[ 'missing_repository_dependencies' ] = missing_repository_dependencies_root_folder + # Installed tool dependencies container. + if tool_dependencies: + if new_install: + label = 'Tool dependencies' + else: + label = 'Installed tool dependencies' + # We only want to display the Status column if the tool_dependency is missing. + folder_id, tool_dependencies_root_folder = \ + self.build_tool_dependencies_folder( folder_id, + tool_dependencies, + label=label, + missing=False, + new_install=new_install, + reinstalling=reinstalling ) + containers_dict[ 'tool_dependencies' ] = tool_dependencies_root_folder + # Missing tool dependencies container. + if missing_tool_dependencies: + # We only want to display the Status column if the tool_dependency is missing. + folder_id, missing_tool_dependencies_root_folder = \ + self.build_tool_dependencies_folder( folder_id, + missing_tool_dependencies, + label='Missing tool dependencies', + missing=True, + new_install=new_install, + reinstalling=reinstalling ) + containers_dict[ 'missing_tool_dependencies' ] = missing_tool_dependencies_root_folder + # Valid tools container. + if valid_tools: + folder_id, valid_tools_root_folder = self.build_tools_folder( folder_id, + valid_tools, + repository, + changeset_revision, + label='Valid tools' ) + containers_dict[ 'valid_tools' ] = valid_tools_root_folder + # Workflows container. + if workflows: + folder_id, workflows_root_folder = \ + self.build_workflows_folder( folder_id=folder_id, + workflows=workflows, + repository_metadata_id=None, + repository_id=repository_id, + label='Workflows' ) + containers_dict[ 'workflows' ] = workflows_root_folder + if valid_data_managers: + folder_id, valid_data_managers_root_folder = \ + self.build_data_managers_folder( folder_id=folder_id, + data_managers=valid_data_managers, + label='Valid Data Managers' ) + containers_dict[ 'valid_data_managers' ] = valid_data_managers_root_folder + if invalid_data_managers or data_managers_errors: + folder_id, invalid_data_managers_root_folder = \ + self.build_invalid_data_managers_folder( folder_id=folder_id, + data_managers=invalid_data_managers, + error_messages=data_managers_errors, + label='Invalid Data Managers' ) + containers_dict[ 'invalid_data_managers' ] = invalid_data_managers_root_folder + except Exception, e: + log.debug( "Exception in build_repository_containers: %s" % str( e ) ) + finally: + lock.release() + return containers_dict diff -r a0db2788e9125270aec5391e676d8a0b36691233 -r 7dd390cfd674cae4c2833fb36f9b4875576cb1c0 lib/tool_shed/grids/repository_grid_filter_manager.py --- a/lib/tool_shed/grids/repository_grid_filter_manager.py +++ b/lib/tool_shed/grids/repository_grid_filter_manager.py @@ -27,7 +27,7 @@ return "Certified 2 Repository Suites %s" % trailing_string if filter == self.filters.SUITES: return "Repository Suites %s" % trailing_string - return "%s" % default + return "%s %s" % ( default, trailing_string ) def get_filter( self, trans ): filter = trans.get_cookie( name='toolshedrepogridfilter' ) This diff is so big that we needed to truncate the remainder. https://bitbucket.org/galaxy/galaxy-central/commits/213a23e98fec/ Changeset: 213a23e98fec User: dannon Date: 2014-08-05 16:00:07 Summary: Merged in iracooke/galaxy-central (pull request #446) Metadata detection for sqlite datatype Affected #: 1 file diff -r a714f168aa7ddb1dfd3142f49869992cd325456c -r 213a23e98fec2ad620483e36286ce4a35b3f7c1f lib/galaxy/datatypes/binary.py --- a/lib/galaxy/datatypes/binary.py +++ b/lib/galaxy/datatypes/binary.py @@ -20,7 +20,7 @@ from bx.seq.twobit import TWOBIT_MAGIC_NUMBER, TWOBIT_MAGIC_NUMBER_SWAP, TWOBIT_MAGIC_SIZE -from galaxy.datatypes.metadata import MetadataElement +from galaxy.datatypes.metadata import MetadataElement,ListParameter,DictParameter from galaxy.datatypes import metadata from galaxy.datatypes.sniff import * import dataproviders @@ -550,8 +550,36 @@ @dataproviders.decorators.has_dataproviders class SQlite ( Binary ): + """Class describing a Sqlite database """ + MetadataElement( name="tables", default=[], param=ListParameter, desc="Database Tables", readonly=True, visible=True, no_value=[] ) + MetadataElement( name="table_columns", default={}, param=DictParameter, desc="Database Table Columns", readonly=True, visible=True, no_value={} ) + MetadataElement( name="table_row_count", default={}, param=DictParameter, desc="Database Table Row Count", readonly=True, visible=True, no_value={} ) file_ext = "sqlite" + def init_meta( self, dataset, copy_from=None ): + Binary.init_meta( self, dataset, copy_from=copy_from ) + + def set_meta( self, dataset, overwrite = True, **kwd ): + try: + tables = [] + columns = dict() + rowcounts = dict() + conn = sqlite3.connect(dataset.file_name) + c = conn.cursor() + tables_query = "SELECT name,sql FROM sqlite_master WHERE type='table' ORDER BY name" + rslt = c.execute(tables_query).fetchall() + for table,sql in rslt: + tables.append(table) + columns[table] = re.sub('^.*\((.*)\)$','\\1',sql).split(',') + for table in tables: + row_query = "SELECT count(*) FROM %s" % table + rowcounts[table] = c.execute(row_query).fetchone()[0] + dataset.metadata.tables = tables + dataset.metadata.table_columns = columns + dataset.metadata.table_row_count = rowcounts + except Exception, exc: + pass + # Connects and runs a query that should work on any real database # If the file is not sqlite, an exception will be thrown and the sniffer will return false def sniff( self, filename ): @@ -568,6 +596,14 @@ def set_peek( self, dataset, is_multi_byte=False ): if not dataset.dataset.purged: dataset.peek = "SQLite Database" + lines = ['SQLite Database'] + if dataset.metadata.tables: + for table in dataset.metadata.tables: + try: + lines.append('%s [%s]' % (table,dataset.metadata.table_row_count[table])) + except: + continue + dataset.peek = '\n'.join(lines) dataset.blurb = data.nice_size( dataset.get_size() ) else: dataset.peek = 'file does not exist' Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.