Skip to content

Commit 94ef237

Browse files
committed
- Install script will not run if PyRadaio already installed.
- Update / Uiinstall will not run if PyRadio installed from distro or pip
1 parent 702ded8 commit 94ef237

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

pyradio/install.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def _no_download_method(self):
160160

161161
def _do_it(self, mode='update'):
162162
''' do I have git installed? '''
163-
if subprocess.call('git --version 2>/dev/null 1>&2' ,shell=True) == 0:
163+
if subprocess.call('git --version 2>/dev/null 1>&2', shell=True) == 0:
164164
self.git_found = True
165165
else:
166166
self.git_found = False
@@ -424,6 +424,10 @@ def _do_it(self, mode='update'):
424424

425425
''' Installation!!! '''
426426
if platform.system().lower().startswith('win'):
427+
ret = subprocess.call('pyradio -h 1>NUL 2>NUL', shell=True)
428+
if ret == 0:
429+
print('PyRadio is already installed.\n')
430+
sys.exit(1)
427431
subprocess.call('pip install windows-curses --upgrade')
428432
subprocess.call('pip install pywin32 --upgrade')
429433
subprocess.call('pip install requests --upgrade')
@@ -438,6 +442,10 @@ def _do_it(self, mode='update'):
438442
print('and the file:')
439443
print(' "{}"'.format(__file__))
440444
else:
445+
ret = subprocess.call('pyradio -h 1>/dev/null 2>&1', shell=True)
446+
if ret == 0:
447+
print('PyRadio is already installed.\n')
448+
sys.exit(1)
441449
uni = PyRadioUpdate()
442450
uni.install = True
443451
uni.update_pyradio()

pyradio/main.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,21 @@ def shell():
109109
args = parser.parse_args()
110110
sys.stdout.flush()
111111

112+
config_already_read = False
113+
112114
with pyradio_config_file() as pyradio_config:
113115

114-
if args.update or args.sng_master or args.sng_devel:
116+
if args.uninstall or args.update or \
117+
args.sng_master or args.sng_devel:
118+
if not config_already_read:
119+
read_config(pyradio_config)
120+
config_already_read = True
115121
if pyradio_config.distro != 'None' and \
116122
not platform.startswith('win'):
117-
no_update()
123+
no_update(args.uninstall)
124+
sys.exit()
118125

126+
if args.update or args.sng_master or args.sng_devel:
119127
package = 0
120128
if args.sng_master:
121129
package = 1
@@ -227,13 +235,9 @@ def shell():
227235

228236
if args.list is False and args.add is False:
229237
print('Reading config...')
230-
ret = pyradio_config.read_config()
231-
if ret == -1:
232-
print('Error opening config: "{}"'.format(pyradio_config.config_file))
233-
sys.exit(1)
234-
elif ret == -2:
235-
print('Config file is malformed: "{}"'.format(pyradio_config.config_file))
236-
sys.exit(1)
238+
if not config_already_read:
239+
read_config(pyradio_config)
240+
config_already_read = True
237241

238242
if args.use_player != '':
239243
requested_player = args.use_player
@@ -356,8 +360,18 @@ def shell():
356360
else:
357361
print('\nThis terminal can not display colors.\nPyRadio cannot function in such a terminal.\n')
358362

359-
def no_update(action='update'):
360-
print('PyRadio has been installed using your distribution\'s package manager.\nPlease use that to {} it.\n'.format(action))
363+
def read_config(pyradio_config):
364+
ret = pyradio_config.read_config()
365+
if ret == -1:
366+
print('Error opening config: "{}"'.format(pyradio_config.config_file))
367+
sys.exit(1)
368+
elif ret == -2:
369+
print('Config file is malformed: "{}"'.format(pyradio_config.config_file))
370+
sys.exit(1)
371+
372+
def no_update(uninstall):
373+
action = 'uninstall' if uninstall else 'update'
374+
print('PyRadio has been installed using either pip or your distribution\'s\npackage manager. Please use that to {} it.\n'.format(action))
361375
sys.exit(1)
362376

363377
def print_playlist_selection_error(a_selection, cnf, ret, exit_if_malformed=True):

0 commit comments

Comments
 (0)