Created
February 19, 2015 20:41
-
-
Save godber/618cb56bb73a89d7adfa to your computer and use it in GitHub Desktop.
This takes a file the Mastcam PDS Index Label file and generates CREATE TABLE command for PostgreSQL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Being lazy here, everything is hardcoded. | |
# This takes a file like the following and generates CREATE TABLE command for | |
# PostgreSQL: | |
# http://pds-imaging.jpl.nasa.gov/data/msl/MSLMST_0007/INDEX/EDRINDEX.LBL | |
# Load it with this: | |
# psql -U postgres -h localhost -p 5432 -d mslpdsindex -f mcam-pds-index.sql | |
def main(): | |
"""Generates SQL to create PostrgreSQL Table from EDR_CMDX.LBL""" | |
type_map = { | |
'CHARACTER': 'text', | |
'INTEGER': 'int', | |
'ASCII_REAL': 'float', | |
} | |
with open('EDR_CMDX.LBL', 'r') as f: | |
for line in f: | |
if ' NAME' in line: | |
name_line = line | |
name = name_line.split('=')[1].strip() | |
next_line = f.next() | |
if 'DATA_TYPE' in next_line: | |
type_line = next_line | |
else: | |
name = next_line.strip() | |
type_line = f.next() | |
data_type = type_line.split('=')[1].strip() | |
print " %s %s," % ( | |
name.replace(':', '_').lower(), type_map[data_type]) | |
if __name__ == '__main__': | |
print "CREATE TABLE mcampds (" | |
main() | |
print " PRIMARY KEY (volume_id, file_name)" | |
print ");" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment