<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> from ingest_db_wrapper import IngestDBWrapper , TC_PENDING <EOL> from agdc . cube_util import get_file_size_mb <EOL> import re <EOL> import psycopg2 <EOL> LOGGER = logging . getLogger ( __name__ ) <EOL> LOGGER . setLevel ( logging . INFO ) <EOL> class TileRecord ( object ) : <EOL> """<STR_LIT>""" <EOL> TILE_METADATA_FIELDS = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> def __init__ ( self , collection , dataset_record , tile_contents ) : <EOL> self . collection = collection <EOL> self . datacube = collection . datacube <EOL> self . dataset_record = dataset_record <EOL> self . tile_contents = tile_contents <EOL> self . tile_footprint = tile_contents . tile_footprint <EOL> self . tile_type_id = tile_contents . tile_type_id <EOL> self . tile_class_id = TC_PENDING <EOL> self . tile_id = None <EOL> self . db = IngestDBWrapper ( self . datacube . db_connection ) <EOL> tile_dict = { } <EOL> self . tile_dict = tile_dict <EOL> tile_dict [ '<STR_LIT>' ] = self . tile_footprint [ <NUM_LIT:0> ] <EOL> tile_dict [ '<STR_LIT>' ] = self . tile_footprint [ <NUM_LIT:1> ] <EOL> tile_dict [ '<STR_LIT>' ] = self . tile_type_id <EOL> tile_dict [ '<STR_LIT>' ] = self . dataset_record . dataset_id <EOL> tile_dict [ '<STR_LIT>' ] = self . tile_contents . tile_output_path <EOL> tile_dict [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> tile_dict [ '<STR_LIT>' ] = get_file_size_mb ( self . tile_contents <EOL> . temp_tile_output_path ) <EOL> self . update_tile_footprint ( ) <EOL> self . tile_id = self . db . get_tile_id ( tile_dict ) <EOL> if self . tile_id is None : <EOL> self . tile_id = self . db . insert_tile_record ( tile_dict ) <EOL> else : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> tile_dict [ '<STR_LIT>' ] = self . tile_id <EOL> def update_tile_footprint ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . db . tile_footprint_exists ( self . tile_dict ) : <EOL> footprint_dict = { '<STR_LIT>' : self . tile_footprint [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : self . tile_footprint [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : self . tile_type_id , <EOL> '<STR_LIT>' : self . tile_contents . tile_extents [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : self . tile_contents . tile_extents [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : self . tile_contents . tile_extents [ <NUM_LIT:2> ] , <EOL> '<STR_LIT>' : self . tile_contents . tile_extents [ <NUM_LIT:3> ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> my_db = IngestDBWrapper ( self . datacube . create_connection ( ) ) <EOL> try : <EOL> with self . collection . transaction ( my_db ) : <EOL> if not my_db . tile_footprint_exists ( self . tile_dict ) : <EOL> my_db . insert_tile_footprint ( footprint_dict ) <EOL> except psycopg2 . IntegrityError : <EOL> pass <EOL> finally : <EOL> my_db . close ( ) </s>
