<s> """<STR_LIT>""" <EOL> import collections <EOL> import wal_e . exception <EOL> from urlparse import urlparse <EOL> CURRENT_VERSION = '<STR_LIT>' <EOL> SEGMENT_REGEXP = ( r'<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> SEGMENT_READY_REGEXP = SEGMENT_REGEXP + r'<STR_LIT>' <EOL> BASE_BACKUP_REGEXP = ( r'<STR_LIT>' + SEGMENT_REGEXP + r'<STR_LIT>' ) <EOL> COMPLETE_BASE_BACKUP_REGEXP = ( <EOL> r'<STR_LIT>' + SEGMENT_REGEXP + <EOL> r'<STR_LIT>' ) <EOL> VOLUME_REGEXP = ( r'<STR_LIT>' ) <EOL> class SegmentNumber ( collections . namedtuple ( '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) ) : <EOL> @ property <EOL> def as_an_integer ( self ) : <EOL> assert len ( self . log ) == <NUM_LIT:8> <EOL> assert len ( self . seg ) == <NUM_LIT:8> <EOL> return int ( self . log + self . seg , <NUM_LIT:16> ) <EOL> @ staticmethod <EOL> def _integer_to_name ( integral ) : <EOL> h = hex ( integral ) <EOL> assert h . startswith ( '<STR_LIT>' ) <EOL> assert len ( h ) <= <NUM_LIT:10> <EOL> name = hex ( integral ) [ <NUM_LIT:2> : ] . upper ( ) . zfill ( <NUM_LIT:8> ) <EOL> assert len ( name ) == <NUM_LIT:8> <EOL> return name <EOL> def next_smaller ( self ) : <EOL> int_seg = int ( self . seg , <NUM_LIT:16> ) <EOL> assert int_seg <= <NUM_LIT> <EOL> if int_seg == <NUM_LIT:0> : <EOL> int_log = int ( self . log , <NUM_LIT:16> ) <EOL> assert int_log <= <NUM_LIT> <EOL> assert int_seg == <NUM_LIT:0> and int_log > <NUM_LIT:0> <EOL> s_log = SegmentNumber . _integer_to_name ( int_log - <NUM_LIT:1> ) <EOL> s_seg = SegmentNumber . _integer_to_name ( <NUM_LIT> ) <EOL> return self . __class__ ( log = s_log , seg = s_seg ) <EOL> else : <EOL> assert int_seg > <NUM_LIT:0> <EOL> s_log = self . log <EOL> s_seg = SegmentNumber . _integer_to_name ( int_seg - <NUM_LIT:1> ) <EOL> return self . __class__ ( log = s_log , seg = s_seg ) <EOL> assert False <EOL> def next_larger ( self ) : <EOL> int_seg = int ( self . seg , <NUM_LIT:16> ) <EOL> assert int_seg <= <NUM_LIT> <EOL> if int_seg == <NUM_LIT> : <EOL> int_log = int ( self . log , <NUM_LIT:16> ) <EOL> assert int_log < <NUM_LIT> <EOL> l_log = SegmentNumber . _integer_to_name ( int_log + <NUM_LIT:1> ) <EOL> l_seg = SegmentNumber . _integer_to_name ( <NUM_LIT:0> ) <EOL> return self . __class__ ( l_log , l_seg ) <EOL> else : <EOL> l_log = self . log <EOL> l_seg = SegmentNumber . _integer_to_name ( int_seg + <NUM_LIT:1> ) <EOL> return self . __class__ ( l_log , l_seg ) <EOL> assert False <EOL> OBSOLETE_VERSIONS = frozenset ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> SUPPORTED_STORE_SCHEMES = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> class BackupInfo ( object ) : <EOL> _fields = [ '<STR_LIT:name>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> def __init__ ( self , ** kwargs ) : <EOL> for field in self . _fields : <EOL> setattr ( self , field , kwargs . get ( field , None ) ) <EOL> self . layout = kwargs [ '<STR_LIT>' ] <EOL> self . spec = kwargs . get ( '<STR_LIT>' , { } ) <EOL> self . _details_loaded = False <EOL> def load_detail ( self , conn ) : <EOL> raise NotImplementedError ( ) <EOL> class StorageLayout ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , prefix , version = CURRENT_VERSION ) : <EOL> self . VERSION = version <EOL> url_tup = urlparse ( prefix ) <EOL> if url_tup . scheme not in SUPPORTED_STORE_SCHEMES : <EOL> raise wal_e . exception . UserException ( <EOL> msg = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> detail = ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( url_tup . scheme ) ) ) <EOL> for scheme in SUPPORTED_STORE_SCHEMES : <EOL> setattr ( self , '<STR_LIT>' % scheme , scheme == url_tup . scheme ) <EOL> self . _url_tup = url_tup <EOL> api_path_prefix = url_tup . path . lstrip ( '<STR_LIT:/>' ) <EOL> if api_path_prefix and api_path_prefix [ - <NUM_LIT:1> ] != '<STR_LIT:/>' : <EOL> self . _api_path_prefix = api_path_prefix + '<STR_LIT:/>' <EOL> self . _api_prefix = prefix + '<STR_LIT:/>' <EOL> else : <EOL> self . _api_path_prefix = api_path_prefix <EOL> self . _api_prefix = prefix <EOL> @ property <EOL> def scheme ( self ) : <EOL> return self . _url_tup . scheme <EOL> @ property <EOL> def prefix ( self ) : <EOL> return self . _api_prefix <EOL> @ property <EOL> def path_prefix ( self ) : <EOL> return self . _api_path_prefix <EOL> def _error_on_unexpected_version ( self ) : <EOL> if self . VERSION != CURRENT_VERSION : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def basebackups ( self ) : <EOL> return self . _api_path_prefix + '<STR_LIT>' + self . VERSION + '<STR_LIT:/>' <EOL> def basebackup_directory ( self , backup_info ) : <EOL> self . _error_on_unexpected_version ( ) <EOL> return ( self . basebackups ( ) + <EOL> '<STR_LIT>' . format ( <EOL> backup_info . wal_segment_backup_start , <EOL> backup_info . wal_segment_offset_backup_start ) ) <EOL> def basebackup_sentinel ( self , backup_info ) : <EOL> self . _error_on_unexpected_version ( ) <EOL> basebackup = self . basebackup_directory ( backup_info ) <EOL> return ( basebackup . rstrip ( '<STR_LIT:/>' ) + '<STR_LIT>' ) <EOL> def basebackup_tar_partition_directory ( self , backup_info ) : <EOL> self . _error_on_unexpected_version ( ) <EOL> return ( self . basebackup_directory ( backup_info ) + <EOL> '<STR_LIT>' ) <EOL> def basebackup_tar_partition ( self , backup_info , part_name ) : <EOL> self . _error_on_unexpected_version ( ) <EOL> return ( self . basebackup_tar_partition_directory ( backup_info ) + <EOL> part_name ) <EOL> def wal_directory ( self ) : <EOL> return self . _api_path_prefix + '<STR_LIT>' + self . VERSION + '<STR_LIT:/>' <EOL> def wal_path ( self , wal_file_name ) : <EOL> self . _error_on_unexpected_version ( ) <EOL> return self . wal_directory ( ) + wal_file_name + '<STR_LIT>' <EOL> def store_name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _url_tup . netloc <EOL> def key_name ( self , key ) : <EOL> return key . name . lstrip ( '<STR_LIT:/>' ) <EOL> def key_last_modified ( self , key ) : <EOL> if hasattr ( key , '<STR_LIT>' ) : <EOL> return key . last_modified <EOL> return key . properties . last_modified <EOL> def get_backup_info ( layout , ** kwargs ) : <EOL> kwargs [ '<STR_LIT>' ] = layout <EOL> if layout . is_s3 : <EOL> from wal_e . storage . s3_storage import S3BackupInfo <EOL> bi = S3BackupInfo ( ** kwargs ) <EOL> elif layout . is_wabs : <EOL> from wal_e . storage . wabs_storage import WABSBackupInfo <EOL> bi = WABSBackupInfo ( ** kwargs ) <EOL> elif layout . is_swift : <EOL> from wal_e . storage . swift_storage import SwiftBackupInfo <EOL> bi = SwiftBackupInfo ( ** kwargs ) <EOL> return bi </s>
