Mercurial > repos > cropgeeks > flapjack
comparison flapjack.py @ 40:4a0f069c98e0 draft
Uploaded
author | cropgeeks |
---|---|
date | Thu, 02 Mar 2017 08:25:37 -0500 |
parents | c8c40cbe2945 |
children | 1de63acd6b12 |
comparison
equal
deleted
inserted
replaced
39:c8c40cbe2945 | 40:4a0f069c98e0 |
---|---|
3 from galaxy.datatypes.binary import Binary | 3 from galaxy.datatypes.binary import Binary |
4 | 4 |
5 class FlapjackFormat(Binary): | 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 # The first 16 bytes of any SQLite3 database file is 'SQLite format 3\0', and the file is binary. For details | 9 # The first 16 bytes of any SQLite3 database file is 'SQLite format 3\0', and the file is binary. For details |
10 # about the format, see http://www.sqlite.org/fileformat.html | 10 # about the format, see http://www.sqlite.org/fileformat.html |
11 try: | 11 # try: |
12 header = open(filename, 'rb').read(16) | 12 # header = open(filename, 'rb').read(16) |
13 if header == b'SQLite format 3\0': | 13 # if header == b'SQLite format 3\0': |
14 fj_table_names = ["objects", "project"] | 14 # fj_table_names = ["objects", "project"] |
15 conn = sqlite.connect(filename) | 15 # conn = sqlite.connect(filename) |
16 c = conn.cursor() | 16 # c = conn.cursor() |
17 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" |
18 result = c.execute(tables_query).fetchall() | 18 # result = c.execute(tables_query).fetchall() |
19 result = [_[0] for _ in result] | 19 # result = [_[0] for _ in result] |
20 for table_name in fj_table_names: | 20 # for table_name in fj_table_names: |
21 if table_name not in result: | 21 # if table_name not in result: |
22 return False | 22 # return False |
23 return True | 23 # return True |
24 return False | 24 # return False |
25 except: | 25 # except: |
26 return False | 26 # return False |
27 | |
28 Binary.register_sniffable_binary_format( "flapjack", "flapjack", FlapjackFormat) | |
29 | 27 |
30 class FlapjackMapFormat(Tabular): | 28 class FlapjackMapFormat(Tabular): |
31 file_ext = "fjmap" | 29 file_ext = "fjmap" |
32 | 30 |
33 def sniff( self, filename ): | 31 def sniff( self, filename ): |