28
28
from . import player
29
29
import logging
30
30
31
+ CAN_CHECK_FOR_UPDATES = True
32
+ try :
33
+ from urllib .request import urlopen
34
+ except ImportError :
35
+ try :
36
+ from urllib2 import urlopen
37
+ except ImportError :
38
+ CAN_CHECK_FOR_UPDATES = False
39
+
31
40
logger = logging .getLogger (__name__ )
32
41
33
42
import locale
@@ -89,7 +98,10 @@ class PyRadio(object):
89
98
90
99
_old_config_encoding = ''
91
100
92
- #_recovery_lock = threading.Lock()
101
+
102
+ _update_version = '0.8'
103
+ _update_notify_lock = threading .Lock ()
104
+ _update_version_do_display = ''
93
105
94
106
def __init__ (self , pyradio_config , play = False , req_player = '' , theme = '' ):
95
107
self ._cnf = pyradio_config
@@ -399,6 +411,10 @@ def run(self):
399
411
except KeyboardInterrupt :
400
412
pass
401
413
else :
414
+ # start update thread
415
+ if CAN_CHECK_FOR_UPDATES :
416
+ pass
417
+
402
418
#signal.signal(signal.SIGINT, self.ctrl_c_handler)
403
419
self .log .write ('Selected player: {}' .format (self ._format_player_string ()), help_msg = True )
404
420
#self.log.write_right('Press ? for help')
@@ -1191,6 +1207,23 @@ def _print_config_save_error(self):
1191
1207
prompt = ' Press any key to exit ' ,
1192
1208
is_message = True )
1193
1209
1210
+ def _print_update_notification (self ):
1211
+ txt = '''A new |PyRadio| release (|{0}|) is available!
1212
+
1213
+ You are strongly encouraged to update now, so that
1214
+ you enjoy new features and bug fixes.
1215
+
1216
+ You can get more info at:
1217
+ |https://github.com/coderholic/pyradio#installation|
1218
+ '''
1219
+ self ._show_help (txt .format (self ._update_version_do_display ),
1220
+ mode_to_set = UPDATE_NOTIFICATION_MODE ,
1221
+ caption = ' New Release Available ' ,
1222
+ prompt = ' Press any key to hide ' ,
1223
+ is_message = True )
1224
+ self ._update_version = ''
1225
+
1226
+
1194
1227
def _align_stations_and_refresh (self , cur_mode ):
1195
1228
need_to_scan_playlist = False
1196
1229
""" refresh reference """
@@ -1380,6 +1413,8 @@ def _redisplay_transient_window(self):
1380
1413
self .operation_mode == SELECT_PLAYLIST_HELP_MODE or \
1381
1414
self .operation_mode == SELECT_STATION_HELP_MODE :
1382
1415
self ._print_help ()
1416
+ elif self .operation_mode == UPDATE_NOTIFICATION_MODE :
1417
+ self ._print_update_notification ()
1383
1418
elif self .operation_mode == SELECT_ENCODING_HELP_MODE :
1384
1419
if self .window_mode == NORMAL_MODE :
1385
1420
self ._encoding_select_win .refresh_and_resize (self .bodyMaxY , self .bodyMaxX )
@@ -1827,6 +1862,18 @@ def keypress(self, char):
1827
1862
self .refreshBody ()
1828
1863
return
1829
1864
1865
+ elif self .operation_mode == UPDATE_NOTIFICATION_MODE :
1866
+ self .helpWinContainer = None
1867
+ self .helpWin = None
1868
+ self .operation_mode = NORMAL_MODE
1869
+ self ._update_notify_lock .acquire ()
1870
+ self ._update_version = ''
1871
+ self ._update_notify_lock .release ()
1872
+ if logger .isEnabledFor (logging .DEBUG ):
1873
+ logger .debug ('MODE: UPDATE_NOTIFICATION_MODE => NORMAL_MODE' )
1874
+ self .refreshBody ()
1875
+ return
1876
+
1830
1877
elif self .operation_mode == NO_PLAYER_ERROR_MODE :
1831
1878
""" if no player, don't serve keyboard """
1832
1879
return
@@ -1973,6 +2020,16 @@ def keypress(self, char):
1973
2020
self .stopPlayer ()
1974
2021
return - 1
1975
2022
2023
+ elif self .operation_mode == UPDATE_NOTIFICATION_MODE :
2024
+ self .helpWinContainer = None
2025
+ self .helpWin = None
2026
+ self .operation_mode = self .window_mode = NORMAL_MODE
2027
+ #self.setupAndDrawScreen()
2028
+ self .refreshBody ()
2029
+ if logger .isEnabledFor (logging .DEBUG ):
2030
+ logger .debug ('MODE: UPDATE_NOTIFICATION_MODE -> NORMAL_MODE' )
2031
+ return
2032
+
1976
2033
elif self .operation_mode == PLAYLIST_RECOVERY_ERROR_MODE :
1977
2034
self ._cnf .playlist_recovery_result = 0
1978
2035
self .operation_mode = PLAYLIST_MODE
@@ -2420,7 +2477,11 @@ def keypress(self, char):
2420
2477
if self .number_of_items > 0 :
2421
2478
self .playSelection ()
2422
2479
self .refreshBody ()
2423
- #self.setupAndDrawScreen()
2480
+ self ._update_notify_lock .acquire ()
2481
+ if self ._update_version :
2482
+ self ._update_version_do_display = self ._update_version
2483
+ self ._print_update_notification ()
2484
+ self ._update_notify_lock .release ()
2424
2485
return
2425
2486
2426
2487
elif char in (ord (' ' ), curses .KEY_LEFT , ord ('h' )):
@@ -2432,6 +2493,11 @@ def keypress(self, char):
2432
2493
else :
2433
2494
self .playSelection ()
2434
2495
self .refreshBody ()
2496
+ self ._update_notify_lock .acquire ()
2497
+ if self ._update_version :
2498
+ self ._update_version_do_display = self ._update_version
2499
+ self ._print_update_notification ()
2500
+ self ._update_notify_lock .release ()
2435
2501
return
2436
2502
2437
2503
elif char in (ord ('x' ), curses .KEY_DC ):
@@ -2529,4 +2595,13 @@ def keypress(self, char):
2529
2595
self .selections [self .operation_mode ] = (self .selection , self .startPos , self .playing , self ._cnf .playlists )
2530
2596
self .refreshBody ()
2531
2597
2598
+ def detectUpdateThread (self , * args ):
2599
+ """ a thread to check if an update is available
2600
+
2601
+ arg[0]: config dir
2602
+ arg[1]: lock
2603
+ """
2604
+ while True :
2605
+
2606
+ pass
2532
2607
# pymode:lint_ignore=W901
0 commit comments