<s> from __future__ import print_function , unicode_literals <EOL> from abc import ABCMeta , abstractmethod <EOL> from voodoo . sessions . session_id import SessionId <EOL> import weblab . core . coordinator . status as WSS <EOL> from weblab . core . exc import InvalidReservationStatusError <EOL> NULL_POSITION = <NUM_LIT> <EOL> class Reservation ( object ) : <EOL> __metaclass__ = ABCMeta <EOL> WAITING = "<STR_LIT>" <EOL> WAITING_CONFIRMATION = "<STR_LIT>" <EOL> WAITING_INSTANCES = "<STR_LIT>" <EOL> CONFIRMED = "<STR_LIT>" <EOL> POST_RESERVATION = "<STR_LIT>" <EOL> POLLING_STATUS = ( WAITING , WAITING_CONFIRMATION , WAITING_INSTANCES , CONFIRMED ) <EOL> def __init__ ( self , status , reservation_id ) : <EOL> """<STR_LIT>""" <EOL> super ( Reservation , self ) . __init__ ( ) <EOL> self . status = status <EOL> self . reservation_id = SessionId ( reservation_id ) <EOL> def __repr__ ( self ) : <EOL> return self . status <EOL> @ staticmethod <EOL> def translate_reservation ( status ) : <EOL> if status . status == WSS . WebLabSchedulingStatus . WAITING : <EOL> reservation = WaitingReservation ( status . reservation_id , status . position ) <EOL> elif status . status == WSS . WebLabSchedulingStatus . WAITING_CONFIRMATION : <EOL> reservation = WaitingConfirmationReservation ( status . reservation_id , status . url ) <EOL> elif status . status == WSS . WebLabSchedulingStatus . RESERVED_REMOTE : <EOL> reservation = ConfirmedReservation ( status . reservation_id , status . remaining_time , status . initial_configuration , status . url , status . remote_reservation_id ) <EOL> elif status . status == WSS . WebLabSchedulingStatus . RESERVED_LOCAL : <EOL> reservation = ConfirmedReservation ( status . reservation_id , status . remaining_time , status . initial_configuration , status . url , "<STR_LIT>" ) <EOL> elif status . status == WSS . WebLabSchedulingStatus . WAITING_INSTANCES : <EOL> reservation = WaitingInstances ( status . reservation_id , status . position ) <EOL> elif status . status == WSS . WebLabSchedulingStatus . POST_RESERVATION : <EOL> reservation = PostReservationReservation ( status . reservation_id , status . finished , status . initial_data , status . end_data ) <EOL> else : <EOL> raise InvalidReservationStatusError ( "<STR_LIT>" % status . status ) <EOL> return reservation <EOL> @ staticmethod <EOL> def translate_reservation_from_data ( status_text , reservation_id , position , time , initial_configuration , end_data , url , finished , initial_data , remote_reservation_id ) : <EOL> if status_text == Reservation . WAITING : <EOL> reservation = WaitingReservation ( reservation_id , position ) <EOL> elif status_text == Reservation . WAITING_CONFIRMATION : <EOL> reservation = WaitingConfirmationReservation ( reservation_id , url ) <EOL> elif status_text == Reservation . WAITING_INSTANCES : <EOL> reservation = WaitingInstances ( reservation_id , position ) <EOL> elif status_text == Reservation . CONFIRMED : <EOL> reservation = ConfirmedReservation ( reservation_id , time , initial_configuration , url , remote_reservation_id ) <EOL> elif status_text == Reservation . POST_RESERVATION : <EOL> reservation = PostReservationReservation ( reservation_id , finished , initial_data , end_data ) <EOL> else : <EOL> raise InvalidReservationStatusError ( "<STR_LIT>" % ( status_text ) ) <EOL> return reservation <EOL> def is_null ( self ) : <EOL> return isinstance ( self , WaitingInstances ) and self . position == NULL_POSITION <EOL> @ abstractmethod <EOL> def to_status ( self ) : <EOL> """<STR_LIT>""" <EOL> class WaitingReservation ( Reservation ) : <EOL> def __init__ ( self , reservation_id , position ) : <EOL> super ( WaitingReservation , self ) . __init__ ( Reservation . WAITING , reservation_id ) <EOL> self . position = position <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . reservation_id . id , self . position ) <EOL> def to_status ( self ) : <EOL> return WSS . WaitingQueueStatus ( self . reservation_id , self . position ) <EOL> class ConfirmedReservation ( Reservation ) : <EOL> def __init__ ( self , reservation_id , time , initial_configuration , url , remote_reservation_id ) : <EOL> super ( ConfirmedReservation , self ) . __init__ ( Reservation . CONFIRMED , reservation_id ) <EOL> self . time = time <EOL> self . initial_configuration = initial_configuration <EOL> self . url = url <EOL> self . remote_reservation_id = SessionId ( remote_reservation_id ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . reservation_id . id , self . time , self . initial_configuration , self . url , self . remote_reservation_id . id ) <EOL> def to_status ( self ) : <EOL> return WSS . RemoteReservedStatus ( self . reservation_id , self . time , self . initial_configuration , self . url , self . remote_reservation_id . id ) <EOL> class WaitingConfirmationReservation ( Reservation ) : <EOL> def __init__ ( self , reservation_id , url ) : <EOL> super ( WaitingConfirmationReservation , self ) . __init__ ( Reservation . WAITING_CONFIRMATION , reservation_id ) <EOL> self . url = url <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . reservation_id . id , self . url ) <EOL> def to_status ( self ) : <EOL> return WSS . WaitingConfirmationQueueStatus ( self . reservation_id , self . url ) <EOL> class WaitingInstances ( Reservation ) : <EOL> def __init__ ( self , reservation_id , position ) : <EOL> super ( WaitingInstances , self ) . __init__ ( Reservation . WAITING_INSTANCES , reservation_id ) <EOL> self . position = position <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . reservation_id . id , self . position ) <EOL> def to_status ( self ) : <EOL> return WSS . WaitingInstancesQueueStatus ( self . reservation_id , self . position ) <EOL> class NullReservation ( WaitingInstances ) : <EOL> def __init__ ( self ) : <EOL> super ( NullReservation , self ) . __init__ ( '<STR_LIT>' , NULL_POSITION ) <EOL> class PostReservationReservation ( Reservation ) : <EOL> def __init__ ( self , reservation_id , finished , initial_data , end_data ) : <EOL> super ( PostReservationReservation , self ) . __init__ ( Reservation . POST_RESERVATION , reservation_id ) <EOL> self . finished = finished <EOL> self . initial_data = initial_data <EOL> self . end_data = end_data <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . reservation_id . id , self . finished , self . initial_data , self . end_data ) <EOL> def to_status ( self ) : <EOL> return WSS . PostReservationStatus ( self . reservation_id , self . finished , self . initial_data , self . end_data ) </s>
