<s> from meocloud . client . linux . protocol . daemon_ui . ttypes import InitResult , StatusResult , RemoteDirectoryListingResult , SyncStatus <EOL> from meocloud . client . linux . protocol . daemon_core . ttypes import State <EOL> from meocloud . client . linux . protocol . daemon_ui import UI <EOL> from meocloud . client . linux . thrift_utils import ThriftListener <EOL> from meocloud . client . linux . settings import LOGGER_NAME , VERSION <EOL> from meocloud . client . linux . timeouts import CONNECTION_REQUIRED_TIMEOUT , USER_ACTION_REQUIRED_TIMEOUT <EOL> from meocloud . client . linux . daemon . communication import Events , AsyncResults , DaemonState <EOL> from meocloud . client . linux . daemon import api <EOL> from meocloud . client . linux . utils import get_sync_code , dict_from_slots_obj <EOL> import logging <EOL> log = logging . getLogger ( LOGGER_NAME ) <EOL> class UIListener ( ThriftListener ) : <EOL> def __init__ ( self , socket , core_client , ui_config , notifs_handler ) : <EOL> handler = UIListenerHandler ( core_client , ui_config , notifs_handler ) <EOL> processor = UI . Processor ( handler ) <EOL> super ( UIListener , self ) . __init__ ( '<STR_LIT>' , socket , processor ) <EOL> class UIListenerHandler ( UI . Iface ) : <EOL> def __init__ ( self , core_client , ui_config , notifs_handler ) : <EOL> super ( UIListenerHandler , self ) . __init__ ( ) <EOL> self . core_client = core_client <EOL> self . ui_config = ui_config <EOL> self . notifs_handler = notifs_handler <EOL> def waitForAuthorization ( self ) : <EOL> return self . init ( timeout = USER_ACTION_REQUIRED_TIMEOUT ) <EOL> def init ( self , timeout = CONNECTION_REQUIRED_TIMEOUT ) : <EOL> log . debug ( '<STR_LIT>' ) <EOL> Events . state_changed . wait ( timeout = timeout ) <EOL> if Events . state_changed . is_set ( ) : <EOL> Events . state_changed . clear ( ) <EOL> log . debug ( '<STR_LIT>' . format ( DaemonState . current ) ) <EOL> if DaemonState . current == DaemonState . AUTHORIZATION_REQUIRED : <EOL> return InitResult . AUTHORIZATION_REQUIRED <EOL> elif DaemonState . current == DaemonState . OFFLINE : <EOL> return InitResult . OFFLINE <EOL> elif DaemonState . current == DaemonState . AUTHORIZATION_OK : <EOL> return InitResult . AUTHORIZATION_OK <EOL> elif DaemonState . current == DaemonState . ROOT_FOLDER_MISSING : <EOL> return InitResult . ROOT_FOLDER_MISSING <EOL> assert False <EOL> else : <EOL> log . warning ( '<STR_LIT>' ) <EOL> Events . shutdown_required . set ( ) <EOL> return InitResult . TIMEDOUT <EOL> def startCore ( self ) : <EOL> log . info ( '<STR_LIT>' ) <EOL> Events . core_start_ready . set ( ) <EOL> def authorizeWithDeviceName ( self , device_name ) : <EOL> log . debug ( '<STR_LIT>' . format ( device_name ) ) <EOL> url = self . core_client . authorizeWithDeviceName ( device_name ) <EOL> return url <EOL> def status ( self ) : <EOL> log . debug ( '<STR_LIT>' ) <EOL> status_result = StatusResult ( ) <EOL> status = self . core_client . currentStatus ( ) <EOL> if status . state == State . SYNCING : <EOL> sync_status = self . core_client . currentSyncStatus ( ) <EOL> sync_status_dict = dict_from_slots_obj ( sync_status ) <EOL> sync_status_dict [ '<STR_LIT>' ] = get_sync_code ( status . statusCode ) <EOL> status_result . syncStatus = SyncStatus ( ** sync_status_dict ) <EOL> status_result . status = status <EOL> status_result . persistentNotifs = self . notifs_handler . get_persistent_notifs ( ) <EOL> return status_result <EOL> def recentlyChangedFilePaths ( self ) : <EOL> log . debug ( '<STR_LIT>' ) <EOL> pass <EOL> def pause ( self ) : <EOL> log . debug ( '<STR_LIT>' ) <EOL> self . core_client . pause ( ) <EOL> def unpause ( self ) : <EOL> log . debug ( '<STR_LIT>' ) <EOL> self . core_client . unpause ( ) <EOL> def shutdown ( self ) : <EOL> log . debug ( '<STR_LIT>' ) <EOL> Events . shutdown_required . set ( ) <EOL> def unlink ( self ) : <EOL> log . debug ( '<STR_LIT>' ) <EOL> return api . unlink ( self . core_client , self . ui_config ) <EOL> def networkSettingsChanged ( self ) : <EOL> log . debug ( '<STR_LIT>' ) <EOL> self . core_client . networkSettingsChanged ( api . get_network_settings ( self . ui_config ) ) <EOL> def remoteDirectoryListing ( self , path ) : <EOL> log . debug ( '<STR_LIT>' . format ( path ) ) <EOL> AsyncResults . remote_directory_listing . create ( ) <EOL> self . core_client . requestRemoteDirectoryListing ( path ) <EOL> args = AsyncResults . remote_directory_listing . get ( timeout = CONNECTION_REQUIRED_TIMEOUT ) <EOL> if args is None : <EOL> return RemoteDirectoryListingResult ( ) <EOL> result = RemoteDirectoryListingResult ( ) <EOL> result . statusCode = args [ '<STR_LIT>' ] <EOL> result . path = args [ '<STR_LIT:path>' ] <EOL> result . listing = args [ '<STR_LIT>' ] <EOL> return result <EOL> def ignoredDirectories ( self ) : <EOL> log . debug ( '<STR_LIT>' ) <EOL> return self . core_client . ignoredDirectories ( ) <EOL> def setIgnoredDirectories ( self , paths ) : <EOL> log . debug ( '<STR_LIT>' . format ( paths ) ) <EOL> self . core_client . setIgnoredDirectories ( paths ) <EOL> def webLoginURL ( self ) : <EOL> log . debug ( '<STR_LIT>' ) <EOL> pass <EOL> def ping ( self ) : <EOL> log . debug ( '<STR_LIT>' ) <EOL> return True <EOL> def version ( self ) : <EOL> log . debug ( '<STR_LIT>' ) <EOL> return VERSION <EOL> def coreVersion ( self ) : <EOL> log . debug ( '<STR_LIT>' ) <EOL> return self . core_client . version ( ) </s>
