1 new commit in galaxy-central: 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.