Mercurial > repos > cropgeeks > flapjack
comparison flapjack.py @ 39:c8c40cbe2945 draft
Uploaded
| author | cropgeeks |
|---|---|
| date | Thu, 02 Mar 2017 08:16:25 -0500 |
| parents | 7ae1bb322c6f |
| children | 4a0f069c98e0 |
comparison
equal
deleted
inserted
replaced
| 38:7ae1bb322c6f | 39:c8c40cbe2945 |
|---|---|
| 1 from galaxy.datatypes.data import Text | 1 from galaxy.datatypes.data import Text |
| 2 from galaxy.datatypes.tabular import Tabular | 2 from galaxy.datatypes.tabular import Tabular |
| 3 from galaxy.datatypes.binary import SQlite | 3 from galaxy.datatypes.binary import Binary |
| 4 | 4 |
| 5 class FlapjackFormat(SQlite): | 5 class FlapjackFormat(Binary): |
| 6 file_ext = "flapjack" | 6 file_ext = "flapjack" |
| 7 | 7 |
| 8 def sniff(self, filename): | 8 def sniff(self, filename): |
| 9 if super(FlapjackFormat, self).sniff(filename): | 9 # The first 16 bytes of any SQLite3 database file is 'SQLite format 3\0', and the file is binary. For details |
| 10 fj_table_names = ["objects", "project"] | 10 # about the format, see http://www.sqlite.org/fileformat.html |
| 11 try: | 11 try: |
| 12 header = open(filename, 'rb').read(16) | |
| 13 if header == b'SQLite format 3\0': | |
| 14 fj_table_names = ["objects", "project"] | |
| 12 conn = sqlite.connect(filename) | 15 conn = sqlite.connect(filename) |
| 13 c = conn.cursor() | 16 c = conn.cursor() |
| 14 tables_query = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name" | 17 tables_query = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name" |
| 15 result = c.execute(tables_query).fetchall() | 18 result = c.execute(tables_query).fetchall() |
| 16 result = [_[0] for _ in result] | 19 result = [_[0] for _ in result] |
| 17 for table_name in fj_table_names: | 20 for table_name in fj_table_names: |
| 18 if table_name not in result: | 21 if table_name not in result: |
| 19 return False | 22 return False |
| 20 return True | 23 return True |
| 21 except Exception as e: | 24 return False |
| 22 log.warning('%s, sniff Exception: %s', self, e) | 25 except: |
| 23 return False | 26 return False |
| 24 | 27 |
| 25 Binary.register_sniffable_binary_format( "flapjack", "flapjack", FlapjackFormat) | 28 Binary.register_sniffable_binary_format( "flapjack", "flapjack", FlapjackFormat) |
| 26 | 29 |
| 27 class FlapjackMapFormat(Tabular): | 30 class FlapjackMapFormat(Tabular): |
| 28 file_ext = "fjmap" | 31 file_ext = "fjmap" |
