<s> from lbrynet . lbrynet_console . ControlHandlers import CommandHandler , CommandHandlerFactory <EOL> from lbrynet . lbrynet_console . ControlHandlers import RecursiveCommandHandler , ModifyPaymentRate <EOL> from twisted . internet import defer <EOL> class StartRepeater ( CommandHandler ) : <EOL> prompt_description = "<STR_LIT>" <EOL> def __init__ ( self , console , repeater , settings ) : <EOL> CommandHandler . __init__ ( self , console ) <EOL> self . repeater = repeater <EOL> self . settings = settings <EOL> def start ( self ) : <EOL> d = self . settings . save_repeater_status ( running = True ) <EOL> d . addCallback ( lambda _ : self . repeater . start ( ) ) <EOL> d . addCallback ( lambda _ : self . console . sendLine ( "<STR_LIT>" ) ) <EOL> d . chainDeferred ( self . finished_deferred ) <EOL> class StartRepeaterFactory ( CommandHandlerFactory ) : <EOL> control_handler_class = StartRepeater <EOL> class StopRepeater ( CommandHandler ) : <EOL> prompt_description = "<STR_LIT>" <EOL> def __init__ ( self , console , repeater , settings ) : <EOL> CommandHandler . __init__ ( self , console ) <EOL> self . repeater = repeater <EOL> self . settings = settings <EOL> def start ( self ) : <EOL> d = self . settings . save_repeater_status ( running = False ) <EOL> d . addCallback ( lambda _ : self . repeater . stop ( ) ) <EOL> d . addCallback ( lambda _ : self . console . sendLine ( "<STR_LIT>" ) ) <EOL> d . chainDeferred ( self . finished_deferred ) <EOL> class StopRepeaterFactory ( CommandHandlerFactory ) : <EOL> control_handler_class = StopRepeater <EOL> class UpdateMaxSpace ( CommandHandler ) : <EOL> prompt_description = "<STR_LIT>" <EOL> line_prompt = "<STR_LIT>" <EOL> def __init__ ( self , console , repeater , settings ) : <EOL> CommandHandler . __init__ ( self , console ) <EOL> self . repeater = repeater <EOL> self . settings = settings <EOL> def start ( self ) : <EOL> self . console . sendLine ( self . line_prompt ) <EOL> def handle_line ( self , line ) : <EOL> d = self . _set_max_space ( line ) <EOL> d . chainDeferred ( self . finished_deferred ) <EOL> def _set_max_space ( self , line ) : <EOL> max_space = int ( line ) <EOL> d = self . settings . save_max_space ( max_space ) <EOL> d . addCallback ( lambda _ : self . repeater . set_max_space ( max_space ) ) <EOL> d . addCallback ( lambda _ : self . console . sendLine ( "<STR_LIT>" + str ( max_space ) + "<STR_LIT>" ) ) <EOL> return d <EOL> class UpdateMaxSpaceFactory ( CommandHandlerFactory ) : <EOL> control_handler_class = UpdateMaxSpace <EOL> class AddApprovedPeer ( CommandHandler ) : <EOL> prompt_description = "<STR_LIT>" <EOL> host_prompt = "<STR_LIT>" <EOL> port_prompt = "<STR_LIT>" <EOL> def __init__ ( self , console , repeater , peer_manager , settings ) : <EOL> CommandHandler . __init__ ( self , console ) <EOL> self . repeater = repeater <EOL> self . peer_manager = peer_manager <EOL> self . settings = settings <EOL> self . host_to_add = None <EOL> def start ( self ) : <EOL> self . console . sendLine ( self . host_prompt ) <EOL> def handle_line ( self , line ) : <EOL> if self . host_to_add is None : <EOL> self . host_to_add = line <EOL> self . console . sendLine ( self . port_prompt ) <EOL> else : <EOL> self . host_to_add , host = None , self . host_to_add <EOL> d = self . _add_peer ( host , line ) <EOL> d . chainDeferred ( self . finished_deferred ) <EOL> def _add_peer ( self , host , port ) : <EOL> peer = self . peer_manager . get_peer ( host , int ( port ) ) <EOL> d = self . settings . save_approved_peer ( host , int ( port ) ) <EOL> d . addCallback ( lambda _ : self . repeater . add_approved_peer ( peer ) ) <EOL> d . addCallback ( lambda _ : self . console . sendLine ( "<STR_LIT>" ) ) <EOL> return d <EOL> class AddApprovedPeerFactory ( CommandHandlerFactory ) : <EOL> control_handler_class = AddApprovedPeer <EOL> class ApprovedPeerChooser ( RecursiveCommandHandler ) : <EOL> def __init__ ( self , console , repeater , factory_class , * args , ** kwargs ) : <EOL> self . repeater = repeater <EOL> self . factory_class = factory_class <EOL> self . args = args <EOL> RecursiveCommandHandler . __init__ ( self , console , ** kwargs ) <EOL> def _get_control_handler_factories ( self ) : <EOL> control_handler_factories = [ ] <EOL> for peer in self . repeater . approved_peers : <EOL> control_handler_factories . append ( self . factory_class ( peer , * self . args ) ) <EOL> return control_handler_factories <EOL> class ApprovedPeerChooserFactory ( CommandHandlerFactory ) : <EOL> def get_prompt_description ( self ) : <EOL> peer = self . args [ <NUM_LIT:0> ] <EOL> return str ( peer ) <EOL> class DeleteApprovedPeerChooser ( ApprovedPeerChooser ) : <EOL> prompt_description = "<STR_LIT>" <EOL> def __init__ ( self , console , repeater , settings ) : <EOL> ApprovedPeerChooser . __init__ ( self , console , repeater , DeleteApprovedPeerFactory , repeater , <EOL> settings , exit_after_one_done = True ) <EOL> class DeleteApprovedPeerChooserFactory ( CommandHandlerFactory ) : <EOL> control_handler_class = DeleteApprovedPeerChooser <EOL> class DeleteApprovedPeer ( CommandHandler ) : <EOL> prompt_description = "<STR_LIT>" <EOL> def __init__ ( self , console , peer , repeater , settings ) : <EOL> CommandHandler . __init__ ( self , console ) <EOL> self . repeater = repeater <EOL> self . settings = settings <EOL> self . peer_to_remove = peer <EOL> def start ( self ) : <EOL> d = self . _remove_peer ( ) <EOL> d . chainDeferred ( self . finished_deferred ) <EOL> def _remove_peer ( self ) : <EOL> d = self . settings . remove_approved_peer ( self . peer_to_remove . host , int ( self . peer_to_remove . port ) ) <EOL> d . addCallback ( lambda _ : self . repeater . remove_approved_peer ( self . peer_to_remove ) ) <EOL> d . addCallback ( lambda _ : self . console . sendLine ( "<STR_LIT>" ) ) <EOL> return d <EOL> class DeleteApprovedPeerFactory ( ApprovedPeerChooserFactory ) : <EOL> control_handler_class = DeleteApprovedPeer <EOL> class ShowApprovedPeers ( CommandHandler ) : <EOL> prompt_description = "<STR_LIT>" <EOL> def __init__ ( self , console , repeater ) : <EOL> CommandHandler . __init__ ( self , console ) <EOL> self . repeater = repeater <EOL> def start ( self ) : <EOL> d = self . _show_peers ( ) <EOL> d . chainDeferred ( self . finished_deferred ) <EOL> def _show_peers ( self ) : <EOL> peer_string = "<STR_LIT>" <EOL> for peer in self . repeater . approved_peers : <EOL> peer_string += str ( peer ) + "<STR_LIT:\n>" <EOL> self . console . sendLine ( peer_string ) <EOL> return defer . succeed ( None ) <EOL> class ShowApprovedPeersFactory ( CommandHandlerFactory ) : <EOL> control_handler_class = ShowApprovedPeers <EOL> class RepeaterStatus ( CommandHandler ) : <EOL> prompt_description = "<STR_LIT>" <EOL> def __init__ ( self , console , repeater ) : <EOL> CommandHandler . __init__ ( self , console ) <EOL> self . repeater = repeater <EOL> def start ( self ) : <EOL> self . _show_status ( ) <EOL> self . finished_deferred . callback ( None ) <EOL> def _show_status ( self ) : <EOL> status_string = "<STR_LIT>" + self . repeater . status ( ) + "<STR_LIT:\n>" <EOL> if self . repeater . stopped is False : <EOL> max_space = self . repeater . progress_manager . max_space <EOL> space_used = <NUM_LIT:0> <EOL> for blob in self . repeater . download_manager . blobs : <EOL> if blob . is_validated ( ) : <EOL> space_used += blob . get_length ( ) <EOL> status_string += "<STR_LIT>" + str ( max_space ) + "<STR_LIT>" <EOL> status_string += "<STR_LIT>" + str ( space_used ) + "<STR_LIT>" <EOL> self . console . sendLine ( status_string ) <EOL> class RepeaterStatusFactory ( CommandHandlerFactory ) : <EOL> control_handler_class = RepeaterStatus <EOL> class ModifyDataPaymentRate ( ModifyPaymentRate ) : <EOL> prompt_description = "<STR_LIT>" <EOL> def __init__ ( self , console , repeater , settings ) : <EOL> ModifyPaymentRate . __init__ ( self , console ) <EOL> self . _prompt_choices [ '<STR_LIT>' ] = ( self . _unset , "<STR_LIT>" ) <EOL> self . payment_rate_manager = repeater . payment_rate_manager <EOL> self . settings = settings <EOL> def _unset ( self ) : <EOL> self . _set_rate ( None ) <EOL> return defer . succeed ( "<STR_LIT>" ) <EOL> def _set_rate ( self , rate ) : <EOL> def set_data_payment_rate ( rate ) : <EOL> self . payment_rate_manager . min_blob_data_payment_rate = rate <EOL> d = self . settings . save_data_payment_rate ( rate ) <EOL> d . addCallback ( lambda _ : set_data_payment_rate ( rate ) ) <EOL> return d <EOL> def _get_current_status ( self ) : <EOL> effective_rate = self . payment_rate_manager . get_effective_min_blob_data_payment_rate ( ) <EOL> if self . payment_rate_manager . min_blob_data_payment_rate is None : <EOL> status = "<STR_LIT>" <EOL> status += str ( effective_rate ) <EOL> else : <EOL> status = "<STR_LIT>" <EOL> status += str ( effective_rate ) <EOL> return status <EOL> class ModifyDataPaymentRateFactory ( CommandHandlerFactory ) : <EOL> control_handler_class = ModifyDataPaymentRate <EOL> class ModifyInfoPaymentRate ( ModifyPaymentRate ) : <EOL> prompt_description = "<STR_LIT>" <EOL> def __init__ ( self , console , repeater , settings ) : <EOL> ModifyPaymentRate . __init__ ( self , console ) <EOL> self . payment_rate_manager = repeater . payment_rate_manager <EOL> self . settings = settings <EOL> def _set_rate ( self , rate ) : <EOL> def set_info_payment_rate ( rate ) : <EOL> self . payment_rate_manager . min_valuable_blob_info_payment_rate = rate <EOL> d = self . settings . save_valuable_info_payment_rate ( rate ) <EOL> d . addCallback ( lambda _ : set_info_payment_rate ( rate ) ) <EOL> return d <EOL> def _get_current_status ( self ) : <EOL> status = "<STR_LIT>" <EOL> status += str ( self . payment_rate_manager . min_valuable_blob_info_payment_rate ) <EOL> return status <EOL> class ModifyInfoPaymentRateFactory ( CommandHandlerFactory ) : <EOL> control_handler_class = ModifyInfoPaymentRate <EOL> class ModifyHashPaymentRate ( ModifyPaymentRate ) : <EOL> prompt_description = "<STR_LIT>" <EOL> def __init__ ( self , console , repeater , settings ) : <EOL> ModifyPaymentRate . __init__ ( self , console ) <EOL> self . payment_rate_manager = repeater . payment_rate_manager <EOL> self . settings = settings <EOL> def _set_rate ( self , rate ) : <EOL> def set_hash_payment_rate ( rate ) : <EOL> self . payment_rate_manager . min_valuable_blob_hash_payment_rate = rate <EOL> d = self . settings . save_valuable_hash_payment_rate ( rate ) <EOL> d . addCallback ( lambda _ : set_hash_payment_rate ( rate ) ) <EOL> return d <EOL> def _get_current_status ( self ) : <EOL> status = "<STR_LIT>" <EOL> status += str ( self . payment_rate_manager . min_valuable_blob_hash_payment_rate ) <EOL> return status <EOL> class ModifyHashPaymentRateFactory ( CommandHandlerFactory ) : <EOL> control_handler_class = ModifyHashPaymentRate <EOL> class ModifyRepeaterOptions ( RecursiveCommandHandler ) : <EOL> prompt_description = "<STR_LIT>" <EOL> def __init__ ( self , console , repeater , lbry_session , settings ) : <EOL> self . repeater = repeater <EOL> self . lbry_session = lbry_session <EOL> self . settings = settings <EOL> RecursiveCommandHandler . __init__ ( self , console ) <EOL> def _get_control_handler_factories ( self ) : <EOL> return [ ModifyDataPaymentRateFactory ( self . repeater , self . settings ) , <EOL> ModifyInfoPaymentRateFactory ( self . repeater , self . settings ) , <EOL> ModifyHashPaymentRateFactory ( self . repeater , self . settings ) , <EOL> UpdateMaxSpaceFactory ( self . repeater , self . settings ) , <EOL> AddApprovedPeerFactory ( self . repeater , self . lbry_session . peer_manager , self . settings ) , <EOL> DeleteApprovedPeerChooserFactory ( self . repeater , self . settings ) , <EOL> ] <EOL> class ModifyRepeaterOptionsFactory ( CommandHandlerFactory ) : <EOL> control_handler_class = ModifyRepeaterOptions </s>
