Skip to content

Commit 76f5ba2

Browse files
committed
fixing issues reported by pylint
1 parent d50a883 commit 76f5ba2

14 files changed

+139
-95
lines changed

pyradio/browser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ def keypress(self, char):
23742374

23752375
elif char in (
23762376
curses.KEY_EXIT, 27, kbkey['q']
2377-
) or check_localized(char, (kbkey['q],'])):
2377+
) or check_localized(char, (kbkey['q'], )):
23782378
return -1
23792379

23802380
elif (char in (kbkey['pause'], curses.KEY_ENTER, ord('\n'), ord('\r')) or \

pyradio/config.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ class PyRadioStations():
104104
previous_station_path = ''
105105

106106
''' this is always on users config dir '''
107-
stations_dir = ''
108-
registers_dir = ''
107+
# stations_dir = ''
108+
# registers_dir = ''
109109

110110
''' True if playlist not in config dir '''
111111
foreign_file = False
@@ -2089,7 +2089,7 @@ def _check_config_file(self, usr):
20892089
if path.exists(user_config_file + '.restore'):
20902090
try:
20912091
copyfile(user_config_file + '.restore', user_config_file)
2092-
remove(self.user_config_file + '.restore')
2092+
remove(user_config_file + '.restore')
20932093
except:
20942094
pass
20952095

pyradio/config_window.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ def set_global_functions(global_functions):
3838

3939

4040
class PyRadioConfigWindow():
41-
42-
parent = None
4341
_win = None
4442

4543
_title = 'PyRadio Configuration'
4644

47-
selection = __selection = 1
45+
__selection = 1
4846

4947
''' Keep a copy of saved values for theme and transparency
5048
Work-around for 'T' auto save (trasnsparency), and
@@ -3612,7 +3610,7 @@ def item(self, an_item_id=None):
36123610
return self._list[self._selection]
36133611
return self._list[an_item_id]
36143612

3615-
def _rename_keyboard_json_file(file_path):
3613+
def _rename_keyboard_json_file(self, file_path):
36163614
# Check if the file path ends with "keyboard.json"
36173615
if not file_path.endswith("keyboard.json"):
36183616
raise ValueError("The file path must end with 'keyboard.json'")

pyradio/install.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,12 @@ def find_pyradio_win_exe():
138138
an_exe = os.path.join(a_path, 'Scripts' , 'pyradio.exe')
139139
if os.path.exists(an_exe):
140140
exe[0] = an_exe
141-
an_exe = os.path.join(site.getuserbase(), py_with_ver, 'Scripts' , 'pyradio.exe')
142-
# print('an_exe: {}'.format(an_exe))
143-
if os.path.exists(an_exe):
144-
exe[1] = an_exe
145-
# print('exe: {}'.format(exe))
141+
if py_with_ver:
142+
an_exe = os.path.join(site.getuserbase(), py_with_ver, 'Scripts' , 'pyradio.exe')
143+
# print('an_exe: {}'.format(an_exe))
144+
if os.path.exists(an_exe):
145+
exe[1] = an_exe
146+
# print('exe: {}'.format(exe))
146147
return exe
147148

148149
def fix_pyradio_win_exe():

pyradio/keyboard.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -974,10 +974,11 @@ def _clear_parent(self, col):
974974
self._parent.clear()
975975
self._parent.refresh()
976976

977-
def _create_win(self, parent):
977+
def _create_win(self, parent=None):
978978
if self._win is not None:
979979
self._win.clear()
980-
self._parent = parent
980+
if parent is not None:
981+
self._parent = parent
981982
# self._clear_parent(2)
982983
self.calculate_window_size()
983984
self._win = self._parent.subwin(self._height, self._width, self._start_line, 1)

pyradio/log.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def _show_time(self, old_time=None):
204204
if old_time:
205205
if self.current_time == old_time:
206206
# do not update the display
207-
return
207+
return old_time
208208

209209
# Call _update_functions in a new thread without blocking
210210
with self.function_lock:
@@ -213,8 +213,9 @@ def _show_time(self, old_time=None):
213213
if self._exit():
214214
if logger.isEnabledFor(logging.DEBUG):
215215
logger.debug('Timer threat asked to stop. Stopping...')
216-
return
216+
return old_time
217217
threading.Thread(target=an_update_function, args=(self.current_time,)).start()
218+
return self.current_time
218219

219220
def get_current_time(self):
220221
""" Safely return the current time. Returns an empty string if the timer is not running. """

pyradio/player.py

+56-25
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ class Player():
310310
GET_AUDIO_FORMAT = b'{ "command": ["get_property", "audio-out-params"], "request_id": 200 }\n'
311311
GET_AUDIO_CODEC = b'{ "command": ["get_property", "audio-codec"], "request_id": 300 }\n'
312312
GET_AUDIO_CODEC_NAME = b'{ "command": ["get_property", "audio-codec-name"], "request_id": 400 }\n'
313+
GET_ERROR = b'{"command": ["get_property", "error"]}\n'
314+
GET_ERROR = b'{"command": ["get_property", "http-header-fields"], "request_id": 500 }\n'
315+
INPUT_COMMANDS = b'{"command": ["get_property", "user-data/mpv/ytdl/json-subprocess-result"], "request_id": 600 }\n'
313316

314317
all_config_files = {}
315318

@@ -696,9 +699,12 @@ def get_info_string(self, a_station, max_width, win_width):
696699
ret = '|' + '\n'.join(a_list).replace('Encoding: |', 'Encoding: ').replace('URL: |', 'URL: ').replace('\n', '\n|')
697700
tail = ''
698701
if 'icy-name' in self._icy_data:
699-
if a_station[0] != self._icy_data['icy-name'] and \
700-
self._icy_data['icy-name'] and \
701-
self._icy_data['icy-name'] != '(null)':
702+
if self._cnf._online_browser is None and \
703+
(
704+
a_station[0] != self._icy_data['icy-name'] and \
705+
self._icy_data['icy-name'] and \
706+
self._icy_data['icy-name'] != '(null)'
707+
):
702708
tail = '\n\nPress |r| to rename station to |Reported Name|, or'
703709
return ret + '\n\n|Highlighted values| are user specified.\nOther values are station provided (live) data.', tail
704710

@@ -1319,11 +1325,12 @@ def updateMPVStatus(self, *args):
13191325
if stop():
13201326
break
13211327
elif b'"file_error":"loading failed"' in a_data:
1322-
got_404 = True
1323-
logger.error('\n\ngot_404 = {}\n\n'.format(got_404))
1324-
if logger.isEnabledFor(logging.INFO):
1325-
logger.info('----==== playbak stopped, reason: {} ====----'.format(a_data))
1326-
break
1328+
self._request_mpv_error(sock)
1329+
# got_404 = True
1330+
# logger.error('\n\ngot_404 = {}\n\n'.format(got_404))
1331+
# if logger.isEnabledFor(logging.INFO):
1332+
# logger.info('----==== playbak stopped, reason: {} ====----'.format(a_data))
1333+
# break
13271334
elif a_data == b'':
13281335
if logger.isEnabledFor(logging.INFO):
13291336
logger.info('----==== MPV crashed ====----')
@@ -1646,6 +1653,16 @@ def do_crash_detection(detect_if_player_exited, stop):
16461653
pass
16471654
self._clear_empty_mkv()
16481655

1656+
def _request_mpv_error(self, sock):
1657+
try:
1658+
if platform.startswith('win'):
1659+
win32file.WriteFile(sock, self.GET_ERROR)
1660+
else:
1661+
# sock.sendall(self.GET_ERROR)
1662+
sock.sendall(self.INPUT_COMMANDS)
1663+
except BrokenPipeError:
1664+
pass
1665+
16491666
def _request_mpv_info_data(self, sock):
16501667
with self.status_update_lock:
16511668
ret = len(self._icy_data) == 0
@@ -1656,27 +1673,41 @@ def _request_mpv_info_data(self, sock):
16561673
# if ret == 0 or force:
16571674
if ret:
16581675
# logger.error('\n\nIn _request_mpv_info_data')
1676+
no_get_title_exception = True
16591677
if platform.startswith('win'):
16601678
if self._request_mpv_info_data_counter == 4:
1661-
win32file.WriteFile(sock, self.GET_TITLE)
1662-
if 'audio_format' not in self._icy_data:
1663-
win32file.WriteFile(sock, self.GET_AUDIO_FORMAT)
1664-
if 'codec' not in self._icy_data:
1665-
win32file.WriteFile(sock, self.GET_AUDIO_CODEC)
1666-
if 'codec-name' not in self._icy_data:
1667-
win32file.WriteFile(sock, self.GET_AUDIO_CODEC_NAME)
1679+
try:
1680+
win32file.WriteFile(sock, self.GET_TITLE)
1681+
except BrokenPipeError:
1682+
no_get_title_exception = False
1683+
try:
1684+
if 'audio_format' not in self._icy_data:
1685+
win32file.WriteFile(sock, self.GET_AUDIO_FORMAT)
1686+
if 'codec' not in self._icy_data:
1687+
win32file.WriteFile(sock, self.GET_AUDIO_CODEC)
1688+
if 'codec-name' not in self._icy_data:
1689+
win32file.WriteFile(sock, self.GET_AUDIO_CODEC_NAME)
1690+
except BrokenPipeError:
1691+
pass
16681692
else:
16691693
if self._request_mpv_info_data_counter == 4:
1670-
sock.sendall(self.GET_TITLE)
1671-
if 'audio_format' not in self._icy_data:
1672-
sock.sendall(self.GET_AUDIO_FORMAT)
1673-
if 'codec' not in self._icy_data:
1674-
sock.sendall(self.GET_AUDIO_CODEC)
1675-
if 'codec-name' not in self._icy_data:
1676-
sock.sendall(self.GET_AUDIO_CODEC_NAME)
1694+
try:
1695+
sock.sendall(self.GET_TITLE)
1696+
except BrokenPipeError:
1697+
no_get_title_exception = False
1698+
try:
1699+
if 'audio_format' not in self._icy_data:
1700+
sock.sendall(self.GET_AUDIO_FORMAT)
1701+
if 'codec' not in self._icy_data:
1702+
sock.sendall(self.GET_AUDIO_CODEC)
1703+
if 'codec-name' not in self._icy_data:
1704+
sock.sendall(self.GET_AUDIO_CODEC_NAME)
1705+
except BrokenPipeError:
1706+
pass
1707+
if no_get_title_exception:
16771708
self._request_mpv_info_data_counter += 1
1678-
if self._request_mpv_info_data_counter >= 4:
1679-
self._request_mpv_info_data_counter = 0
1709+
if self._request_mpv_info_data_counter >= 4:
1710+
self._request_mpv_info_data_counter = 0
16801711

16811712
def _get_mpv_metadata(self, *args):
16821713
''' Get MPV metadata
@@ -2701,7 +2732,7 @@ def _stop(self):
27012732
self.stop_mpv_status_update_thread = True
27022733
self._send_mpv_command('quit')
27032734
if not platform.startswith('win'):
2704-
os.system('rm ' + self.mpvsocket + ' 2>/dev/null');
2735+
os.system('rm ' + self.mpvsocket + ' 2>/dev/null')
27052736
self._icy_data = {}
27062737
self.monitor = self.monitor_process = self.monitor_opts = None
27072738
if self._chapters:

pyradio/radio.py

+19-20
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,12 @@ class PyRadio():
446446

447447
_keyboard_config_win = None
448448

449+
handled_signals = {
450+
'SIGHUP': signal.SIGHUP,
451+
'SIGTERM': signal.SIGTERM,
452+
'SIGKIL': signal.SIGKILL,
453+
}
454+
449455
def ll(self, msg):
450456
logger.error('DE ==========')
451457
logger.error('DE ===> {}'.format(msg))
@@ -1165,6 +1171,7 @@ def setup(self, stdscr):
11651171
self.run()
11661172

11671173
def change_player(self, a_player):
1174+
new_player = None
11681175
if a_player == self.player.PLAYER_NAME:
11691176
pass
11701177
else:
@@ -4524,16 +4531,12 @@ def _show_station_info(self):
45244531
#logger.error('msg\n{}'.format(msg))
45254532
if tail and not self._cnf.browsing_station_service:
45264533
self._station_rename_from_info = True
4527-
self._messaging_win.set_a_message(
4528-
'M_STATION_INFO',
4529-
('Station Info', msg)
4530-
)
45314534
else:
45324535
self._station_rename_from_info = False
4533-
self._messaging_win.set_a_message(
4534-
'M_STATION_INFO',
4535-
('Station Info', msg)
4536-
)
4536+
self._messaging_win.set_a_message(
4537+
'M_STATION_INFO',
4538+
('Station Info', msg)
4539+
)
45374540
self._open_simple_message_by_key_and_mode(
45384541
self.ws.STATION_INFO_MODE,
45394542
'M_STATION_INFO'
@@ -7435,8 +7438,9 @@ def keypress(self, char):
74357438

74367439
elif ret == self.ws.LOCALIZED_CONFIG_MODE:
74377440
''' keyboard localized window '''
7438-
self.ws.operation_mode = self.ws.LOCALIZED_CONFIG_MODE
7439-
self._localized_init_config()
7441+
self._print_not_implemented_yet()
7442+
# self.ws.operation_mode = self.ws.LOCALIZED_CONFIG_MODE
7443+
# self._localized_init_config()
74407444
return
74417445

74427446
else:
@@ -9772,7 +9776,7 @@ def _stop_player(self, got_404=False):
97729776
else:
97739777
self.detect_if_player_exited = True
97749778
logger.error('20 self.detect_if_player_exited = {}'.format(self.detect_if_player_exited))
9775-
self.playSelection(got_404=got_404)
9779+
self.playSelection()
97769780
self.refreshBody()
97779781
self.player.recording_filename = ''
97789782
self.player.muted = self.player.paused = False
@@ -10740,16 +10744,11 @@ def _register_signals_handlers(self):
1074010744
# logger.debug('SetConsoleCtrlHandler: Signal SIGINT failed to register (with Exception)!!!')
1074110745

1074210746
else:
10743-
handled_signals = {
10744-
'SIGHUP': signal.SIGHUP,
10745-
'SIGTERM': signal.SIGTERM,
10746-
'SIGKIL': signal.SIGKILL,
10747-
}
1074810747
self.def_signal_handlers = {}
1074910748
try:
10750-
for a_sig in handled_signals:
10749+
for a_sig in self.handled_signals:
1075110750
self.def_signal_handlers[a_sig] = signal.signal(
10752-
handled_signals[a_sig],
10751+
self.handled_signals[a_sig],
1075310752
self._linux_signal_handler
1075410753
)
1075510754
if logger.isEnabledFor(logging.DEBUG):
@@ -10803,10 +10802,10 @@ def _linux_signal_handler(self, a_signal, a_frame):
1080310802
self.player.close()
1080410803
self._cnf.save_config()
1080510804
self._cnf.remove_session_lock_file()
10806-
for a_sig in handled_signals:
10805+
for a_sig in self.handled_signals:
1080710806
try:
1080810807
signal.signal(
10809-
handled_signals[a_sig],
10808+
self.handled_signals[a_sig],
1081010809
self.def_signal_handlers[a_sig]
1081110810
)
1081210811
except:

pyradio/schedule.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,13 @@ def item(self):
501501

502502
@item.setter
503503
def item(self, val):
504-
if isinstance(item, str):
504+
if isinstance(val, str):
505505
try:
506-
self._item = json.loads(item)
506+
self._item = json.loads(val)
507507
except:
508508
raise ValueError('JSON string not supported')
509-
elif isinstance(item, dict):
510-
self._item = item
509+
elif isinstance(val, dict):
510+
self._item = val
511511

512512
for n in self.default_item:
513513
if n not in self._item:
@@ -858,6 +858,9 @@ def set_time(self, a_time_string):
858858
except ValueError:
859859
valid = False
860860

861+
hour = 0
862+
minute = 0
863+
seconds = 0
861864
if valid:
862865
if is_12_format == self.PM_FORMAT:
863866
''' pm '''
@@ -927,6 +930,9 @@ def string_to_pyradio_time(cls, a_string):
927930
except ValueError:
928931
valid = False
929932

933+
hour = 0
934+
minute = 0
935+
seconds = 0
930936
if valid:
931937
if is_12_format == PyRadioTime.PM_FORMAT:
932938
''' pm '''
@@ -969,9 +975,9 @@ def pyradio_time_to_string(cls, a_time):
969975

970976
@classmethod
971977
def to_24_format(cls, a_time):
972-
if a_time[-1] == self.NO_AM_PM_FORMAT:
978+
if a_time[-1] == PyRadioTime.NO_AM_PM_FORMAT:
973979
return a_time
974-
elif a_time[-1] == self.PM_FORMAT:
980+
elif a_time[-1] == PyRadioTime.PM_FORMAT:
975981
''' PM '''
976982
out = list(a_time)
977983
out[-1] = 0
@@ -1019,7 +1025,7 @@ def pyradio_time_to_datetime(self, t_date=None, t_time=None):
10191025
if t_date is None:
10201026
a_date = datetime.now()
10211027
else:
1022-
a_date = t_data
1028+
a_date = t_date
10231029
b_date= a_date.replace(
10241030
hour = a_time[0],
10251031
minute = a_time[1],

pyradio/schedule_win.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ def show(self, parent=None):
546546
self._get_parent(parent)
547547
if self._showed:
548548
self._move_widgets()
549-
if self._widgets == None:
549+
if self._widgets is None:
550550
self._add_widgets()
551551
with self.lock:
552552
try:

0 commit comments

Comments
 (0)