@@ -66,8 +66,6 @@ class PyRadioStations(object):
6666
6767 playlist_recovery_result = 0
6868
69- locked = False
70-
7169 _open_string = [ "open(stationFile, 'r')" , "open(stationFile, 'r', encoding='utf-8')" ]
7270 _open_string_id = 0
7371
@@ -101,15 +99,6 @@ def __init__(self, stationFile=''):
10199 sys .exit (1 )
102100 self .root_path = path .join (path .dirname (__file__ ), 'stations.csv' )
103101
104- if path .exists (self ._session_lock_file ):
105- self .locked = True
106- else :
107- try :
108- with open (self ._session_lock_file , 'w' ) as f :
109- pass
110- except :
111- pass
112-
113102 self ._ps = PyRadioPlaylistStack ()
114103
115104 if not self .locked :
@@ -371,7 +360,7 @@ def _get_playlist_abspath_from_data(self, stationFile=''):
371360 else :
372361 n , f = self .read_playlists ()
373362 if sel <= n - 1 :
374- stationFile = self .playlists [sel ][- 1 ]
363+ stationFile = self .playlists [sel ][- 1 ]
375364 return stationFile , 0
376365 else :
377366 """ playlist number sel does not exit """
@@ -921,6 +910,9 @@ class PyRadioConfig(PyRadioStations):
921910 theme_has_error = False
922911 theme_not_supported_notification_shown = False
923912
913+ # True if lock file exists
914+ locked = False
915+
924916 opts = collections .OrderedDict ()
925917 opts [ 'general_title' ] = [ 'General Options' , '' ]
926918 opts [ 'player' ] = [ 'Player: ' , '' ]
@@ -964,6 +956,7 @@ def __init__(self):
964956
965957 self ._check_config_file (self .stations_dir )
966958 self .config_file = path .join (self .stations_dir , 'config' )
959+ self .force_to_remove_lock_file = False
967960
968961 @property
969962 def requested_player (self ):
@@ -1083,9 +1076,13 @@ def session_lock_file(self, val):
10831076 return
10841077
10851078 def _get_lock_file (self ):
1079+ ''' Populate self._session_lock_file
1080+ If it exists, locked becomes True
1081+ Otherwise, the file is created
1082+ '''
10861083 if path .exists ('/run/user' ):
10871084 from os import geteuid
1088- self ._session_lock_file = path .join ('/run/user' , str (geteuid ()), 'pyradio.lock' )
1085+ self ._session_lock_file = path .join ('/run/user' , str (geteuid ()), 'pyradio.lock' )
10891086 # remove old style session lock file (if it exists)
10901087 if path .exists (path .join (self .stations_dir , '.lock' )):
10911088 try :
@@ -1095,22 +1092,35 @@ def _get_lock_file(self):
10951092 else :
10961093 self ._session_lock_file = path .join (self .stations_dir , 'pyradio.lock' )
10971094
1098- def remove_session_lock_file (self ):
1099- #print(self._session_lock_file)
11001095 if path .exists (self ._session_lock_file ):
1096+ self .locked = True
1097+ else :
11011098 try :
1102- remove (self ._session_lock_file )
1103- if logger .isEnabledFor (logging .INFO ):
1104- logger .info ('Lock file removed...' )
1105- return 0 , self ._session_lock_file
1099+ with open (self ._session_lock_file , 'w' ) as f :
1100+ pass
11061101 except :
1107- if logger .isEnabledFor (logging .INFO ):
1108- logger .info ('Failed to remove Lock file...' )
1109- return 1 , self ._session_lock_file
1110- else :
1102+ pass
1103+
1104+ def remove_session_lock_file (self ):
1105+ ''' remove session lock file, if session is not locked '''
1106+ if self .locked :
11111107 if logger .isEnabledFor (logging .INFO ):
1112- logger .info ('Lock file not found...' )
1113- return - 1 , self ._session_lock_file
1108+ logger .info ('Not removing lock file; session is locked...' )
1109+ else :
1110+ if path .exists (self ._session_lock_file ):
1111+ try :
1112+ remove (self ._session_lock_file )
1113+ if logger .isEnabledFor (logging .INFO ):
1114+ logger .info ('Lock file removed...' )
1115+ return 0 , self ._session_lock_file
1116+ except :
1117+ if logger .isEnabledFor (logging .INFO ):
1118+ logger .info ('Failed to remove Lock file...' )
1119+ return 1 , self ._session_lock_file
1120+ else :
1121+ if logger .isEnabledFor (logging .INFO ):
1122+ logger .info ('Lock file not found...' )
1123+ return - 1 , self ._session_lock_file
11141124
11151125 def _check_config_file (self , usr ):
11161126 ''' Make sure a config file exists in the config dir '''
0 commit comments