Skip to content

Commit 702ded8

Browse files
committed
update/uninstall for windows and ficing install for linux
1 parent dbb5214 commit 702ded8

File tree

11 files changed

+173
-310
lines changed

11 files changed

+173
-310
lines changed

README.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ <h2 id="command-line-options">Command line options <span style="padding-left: 10
117117
(refer to the output of the -lp option)
118118
-lp, --list-player-parameters
119119
List extra players parameters.
120+
-U, --update Update PyRadio.
121+
-R, --uninstall Uninstall PyRadio.
120122
--unlock Remove sessions&#39; lock file.
121123
-d, --debug Start pyradio in debug mode.
122124
</pre>
@@ -560,8 +562,8 @@ <h2 id="todo">TODO <span style="padding-left: 10px;"><sup style="font-size: 50%"
560562
New player selection configuration window (<a target="_blank" href="https://github.com/coderholic/pyradio/issues/118">#118</a>) - v. 0.8.8.3</li>
561563
<li><input type="checkbox" disabled="" />
562564
Notify the user that the package’s stations.csv has changed</li>
563-
<li><input type="checkbox" disabled="" />
564-
Update / uninstall using command line parameters (-U / -R)</li>
565+
<li><input type="checkbox" disabled="" checked="" />
566+
Update / uninstall using command line parameters (-U / -R) - v. 0.9.0</li>
565567
<li><input type="checkbox" disabled="" />
566568
Use Radio Browser service (<a target="_blank" href="https://github.com/coderholic/pyradio/issues/80">#80</a> <a target="_blank" href="https://github.com/coderholic/pyradio/issues/93">#93</a> <a target="_blank" href="https://github.com/coderholic/pyradio/issues/112">#112</a>)</li>
567569
</ul>

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ optional arguments:
9292
(refer to the output of the -lp option)
9393
-lp, --list-player-parameters
9494
List extra players parameters.
95+
-U, --update Update PyRadio.
96+
-R, --uninstall Uninstall PyRadio.
9597
--unlock Remove sessions' lock file.
9698
-d, --debug Start pyradio in debug mode.
9799
@@ -747,7 +749,7 @@ Finally, include the file produced in your report.
747749
- [x] Players extra parameters ([#118](https://github.com/coderholic/pyradio/issues/118)) - v. 0.8.8.3
748750
- [x] New player selection configuration window ([#118](https://github.com/coderholic/pyradio/issues/118)) - v. 0.8.8.3
749751
- [ ] Notify the user that the package's stations.csv has changed
750-
- [ ] Update / uninstall using command line parameters (-U / -R)
752+
- [x] Update / uninstall using command line parameters (-U / -R) - v. 0.9.0
751753
- [ ] Use Radio Browser service ([#80](https://github.com/coderholic/pyradio/issues/80) [#93](https://github.com/coderholic/pyradio/issues/93) [#112](https://github.com/coderholic/pyradio/issues/112))
752754

753755
## Acknowledgment

devel/build_install_pyradio

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ rm -f /tmp/pyradio-uninstall.$$ /tmp/pyradio-delete.$$ 2>/dev/null
6060

6161
function uninstall(){
6262
local user
63-
user=$(which pyradio 2>/dev/null) || {
64-
echo "PyRadio is not installed..."
65-
exit
63+
[ -z "$1" ] && {
64+
user=$(which pyradio 2>/dev/null) || {
65+
echo "PyRadio is not installed..."
66+
exit
67+
}
6668
}
67-
echo 'Uninstalling PyRadio'
69+
# keep this sudo as to not break lines
70+
sudo echo 'Uninstalling PyRadio'
6871
user=$(which pyradio | grep '\.local')
6972
[ -z "$user" ] && {
7073
echo -n '** Removing executable ... '
@@ -233,7 +236,7 @@ for prog in git sed ;do
233236
done
234237

235238
# uninstall previous versions
236-
uninstall
239+
uninstall 1
237240

238241
# delete any files that were left from previous attempt
239242
[ -z "$TO_USER" ] && {
@@ -288,7 +291,7 @@ python"${TO_PYTHON}" setup.py build && {
288291
}
289292
} || {
290293
echo "***** installing for user..."
291-
python"${TO_PYTHON}" setup.py install --user | tee installed && {
294+
python"${TO_PYTHON}" setup.py install --user && {
292295
gzip -k pyradio.1
293296
mkdir -p ~/.local/share/man/man1 2>/dev/null
294297
mv -f pyradio.1.gz ~/.local/share/man/man1 2>/dev/null || mv -f pyradio.1.gz ~/.local/local/share/man/man1
@@ -323,6 +326,4 @@ python"${TO_PYTHON}" setup.py build && {
323326
#git checkout pyradio/radio.py
324327
}
325328
rm sed.$$ 2>/dev/null
326-
[ -z "$REMOVE_DIR" ] || {
327-
(sleep 5; sudo rm -r "$REMOVE_DIR") &
328-
}
329+
[ -z "$REMOVE_DIR" ] || [[ $REMOVE_DIR == *pyradio ]] && sudo rm -fr "$REMOVE_DIR"

pyradio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" pyradio -- Console radio player. "
22

3-
version_info = (0, 8, 8, 5)
3+
version_info = (0, 9, 0)
44

55
# Application state:
66
# New stable version: ''

pyradio/update.py renamed to pyradio/install.py

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ class PyRadioUpdate(object):
5555

5656
ZIP_DIR = ('pyradio-master', 'pyradio-master', 'pyradio-devel')
5757

58+
install = False
5859

5960
def __init__(self, package=0):
60-
package = 2
6161
if platform.system().lower().startswith('win'):
6262
raise RuntimeError('This is a linux only class...')
6363
self._dir = self._install_dir = ''
@@ -72,11 +72,18 @@ def update_pyradio(self, win_open_dir=False):
7272
self.update_or_uninstall_on_windows('update')
7373
else:
7474
''' update PyRadio under Linux and MacOS '''
75-
print('Updating PyRadio...')
75+
if self.install:
76+
print('Installing PyRadio...')
77+
else:
78+
print('Updating PyRadio...')
7679
if self._do_it():
77-
print('\n\nPyRadio updated to the latest release!')
78-
print('Thank you for your continuous support to this project!')
79-
print('Enjoy!\n')
80+
if self.install:
81+
print('\n\nPyRadio succesfully installed!')
82+
print('Hope you have a lot of fun using it!')
83+
else:
84+
print('\n\nPyRadio updated to the latest release!')
85+
print('Thank you for your continuous support to this project!')
86+
print('Cheers!\n')
8087
sys.exit()
8188
else:
8289
print('\n\nAn error occured during the installation!')
@@ -109,7 +116,7 @@ def remove_pyradio(self, win_open_dir=False):
109116
def update_or_uninstall_on_windows(self, mode='update'):
110117
isRunning()
111118
''' Creates BAT file to update or unisntall PyRadio on Windows'''
112-
self._dir = os.path.join(os.path.expanduser('~'), 'tmp_pyradio')
119+
self._dir = os.path.join(os.path.expanduser('~'), 'tmp-pyradio')
113120
shutil.rmtree(self._dir, ignore_errors=True)
114121
os.makedirs(self._dir, exist_ok=True)
115122
if mode.startswith('update'):
@@ -125,12 +132,12 @@ def update_or_uninstall_on_windows(self, mode='update'):
125132
b.write('CLS\n')
126133
b.write('pip install requests --upgrade 1>NUL 2>NUL\n')
127134
if mode.startswith('update'):
128-
b.write('COPY "{}" . 1>NUL\n'.format(__file__))
129-
b.write('python update.py --do-update\n')
135+
b.write('COPY "{}" . 1>NUL\n'.format(os.path.abspath(__file__)))
136+
b.write('python install.py --do-update\n')
130137
b.write('cd "' + os.path.join(self._dir, self.ZIP_DIR[self._package]) + '"\n')
131138
b.write('devel\\build_install_pyradio.bat -U\n')
132139
else:
133-
b.write('COPY "{}" uninstall.py 1>NUL\n'.format(__file__))
140+
b.write('COPY "{}" uninstall.py 1>NUL\n'.format(os.path.abspath(__file__)))
134141
b.write('python uninstall.py --do-uninstall\n')
135142
b.write('cd "' + os.path.join(self._dir, self.ZIP_DIR[self._package]) + '"\n')
136143
b.write('devel\\build_install_pyradio.bat -u\n')
@@ -165,9 +172,9 @@ def _do_it(self, mode='update'):
165172

166173
'''' get tmp dir '''
167174
if os.path.isdir('/tmp'):
168-
self._dir = os.path.join('/tmp', 'tmp_pyradio')
175+
self._dir = os.path.join('/tmp', 'tmp-pyradio')
169176
else:
170-
self._dir = os.path.join(os.path.expanduser('~'), 'tmp_pyradio')
177+
self._dir = os.path.join(os.path.expanduser('~'), 'tmp-pyradio')
171178
print('Using directory: "{}"'.format(self._dir))
172179

173180
''' create tmp directory '''
@@ -188,8 +195,10 @@ def _do_it(self, mode='update'):
188195
print('Error: Failed to download PyRadio source code...\n')
189196
sys.exit(1)
190197

191-
''' PROGRAM DEBUG: uncomment this to use the latest changes '''
192-
shutil.copyfile('/home/spiros/projects/my-gits/pyradio/devel/build_install_pyradio', '/tmp/tmp_pyradio/pyradio-devel/devel/build_install_pyradio')
198+
''' PROGRAM DEBUG: uncomment this to use the latest
199+
build_install_pyradio changes.
200+
'''
201+
# shutil.copyfile('/home/spiros/projects/my-gits/pyradio/devel/build_install_pyradio', '/tmp/tmp-pyradio/pyradio/devel/build_install_pyradio')
193202
if mode == 'update':
194203
''' install pyradio '''
195204
try:
@@ -306,10 +315,9 @@ def _download_file(self, url, filename):
306315
class PyRadioUpdateOnWindows(PyRadioUpdate):
307316

308317
def __init__(self, fromTUI=False, package=0):
309-
package = 2
310318
if not platform.system().lower().startswith('win'):
311319
raise RuntimeError('This is a windows only class...')
312-
self._dir = os.path.join(os.path.expanduser('~'), 'tmp_pyradio')
320+
self._dir = os.path.join(os.path.expanduser('~'), 'tmp-pyradio')
313321
self._package = package
314322
self._fromTUI = fromTUI
315323

@@ -318,14 +326,14 @@ def print_update_bat_created(cls):
318326
print('To complete the process you will have to execute a batch file.')
319327
print('Windows Explorer will open the location of the batch file to run.\n')
320328
print('Please double click\n\n update.bat\n\nto get PyRadio\'s latest version.\n')
321-
print('After you are done, you can delete the folder named "tmp-pyradio"')
329+
print('After you are done, you can delete the folder:\n\n "{}"'.format(os.path.join(os.path.expanduser("~"), 'tmp-pyradio')))
322330

323331
@classmethod
324332
def print_uninstall_bat_created(cls):
325333
print('To complete the process you will have to execute a batch file.')
326334
print('Windows Explorer will open the location of the batch file to run.\n')
327335
print('Please double click\n\n uninstall.bat\n\nto remove PyRadio from your system.\n')
328-
print('After you are done, you can delete the folder named "tmp-pyradio"')
336+
print('After you are done, you can delete the folder:\n\n "{}"'.format(os.path.join(os.path.expanduser("~"), 'tmp-pyradio')))
329337

330338
def update_pyradio(self):
331339
self._do_it()
@@ -353,34 +361,6 @@ def _do_it(self, mode='update'):
353361
sys.exit(1)
354362

355363
os.chdir(self._dir)
356-
cur_dir = os.path.join(self._dir, self.ZIP_DIR[self._package])
357-
358-
359-
shutil.copyfile('C:\\Users\\Spiros\\pyradio\\devel\\build_install_pyradio.bat',
360-
'C:\\Users\\Spiros\\tmp_pyradio\\pyradio-devel\\devel\\build_install_pyradio.bat')
361-
sys.exit()
362-
# input('File copyied... Press ENTER to continue ')
363-
if mode == 'update':
364-
''' install pyradio '''
365-
try:
366-
subprocess.call(os.path.join(cur_dir, 'devel\\build_install_pyradio.bat'), shell=True)
367-
ret = True
368-
except:
369-
ret = False
370-
self._clean_up()
371-
return ret
372-
else:
373-
''' uninstall pyradio '''
374-
try:
375-
# path = os.path.join(cur_dir, 'devel\\build_install_pyradio.bat')
376-
# print('Running BAT file... "{}"'.format(path))
377-
subprocess.call(os.path.join(cur_dir, 'devel\\build_install_pyradio.bat') + ' -u', shell=True)
378-
ret = True
379-
except:
380-
ret = False
381-
print('Error running BAT file!!!')
382-
self._clean_up()
383-
return ret
384364

385365
if __name__ == '__main__':
386366
from argparse import ArgumentParser, SUPPRESS as SUPPRESS
@@ -395,7 +375,7 @@ def _do_it(self, mode='update'):
395375
''' extra downloads
396376
only use them after the developer says so,
397377
for debug purposes only
398-
--sng download developer release
378+
--sng download developer release (master)
399379
--sng-devel download developer devel branch
400380
'''
401381
parser.add_argument('--sng', action='store_true', help=SUPPRESS)
@@ -438,8 +418,27 @@ def _do_it(self, mode='update'):
438418
sys.exit()
439419
elif args.do_update:
440420
''' coming from update BAT file on Windows'''
441-
print('do_update')
442421
upd = PyRadioUpdateOnWindows(package=package)
443422
upd.update_pyradio()
444423
sys.exit()
445424

425+
''' Installation!!! '''
426+
if platform.system().lower().startswith('win'):
427+
subprocess.call('pip install windows-curses --upgrade')
428+
subprocess.call('pip install pywin32 --upgrade')
429+
subprocess.call('pip install requests --upgrade')
430+
uni = PyRadioUpdateOnWindows()
431+
uni.update_or_uninstall_on_windows(mode='update-open')
432+
while not os.path.isfile(os.path.join(uni._dir, 'update.bat')):
433+
pass
434+
os.chdir(uni._dir)
435+
subprocess.call('update.bat')
436+
print('\n\nNow you can delete the folder:')
437+
print(' "{}"'.format(uni._dir))
438+
print('and the file:')
439+
print(' "{}"'.format(__file__))
440+
else:
441+
uni = PyRadioUpdate()
442+
uni.install = True
443+
uni.update_pyradio()
444+

pyradio/log.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ def write(self,
119119
d_msg = self.msg.encode('utf-8', 'replace').strip()[0: self.width].replace('\r', '').replace('\n', '')
120120
self.cursesScreen.addstr(0, 1, d_msg)
121121
except:
122-
if logger.isEnabledFor(logging.ERROR):
123-
logger.error('Error updating the Status Bar')
122+
pass
123+
# if logger.isEnabledFor(logging.ERROR):
124+
# logger.error('Error updating the Status Bar')
124125
if self._show_status_updates:
125126
if logger.isEnabledFor(logging.DEBUG):
126127
try:

pyradio/main.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import sys
33
import curses
44
import logging
5-
from argparse import ArgumentParser
5+
from argparse import ArgumentParser, SUPPRESS as SUPPRESS
66
from os import path, getenv, environ
77
from sys import platform, version_info
88
from contextlib import contextmanager
99

1010
from .radio import PyRadio
1111
from .config import PyRadioConfig, SUPPORTED_PLAYERS
12-
from .update import PyRadioUpdate, PyRadioUpdateOnWindows
12+
from .install import PyRadioUpdate, PyRadioUpdateOnWindows
1313

1414
PATTERN = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
1515

@@ -95,21 +95,37 @@ def shell():
9595
help="Remove sessions' lock file.")
9696
parser.add_argument('-d', '--debug', action='store_true',
9797
help='Start pyradio in debug mode.')
98+
''' extra downloads
99+
only use them after the developer says so,
100+
for debug purposes only
101+
--sng download developer release (master)
102+
--sng-devel download developer devel branch
103+
--force-update give a versio > than current,
104+
to check update notification functionality
105+
'''
106+
parser.add_argument('--sng-master', action='store_true', help=SUPPRESS)
107+
parser.add_argument('--sng-devel', action='store_true', help=SUPPRESS)
108+
parser.add_argument('--force-update', default='', help=SUPPRESS)
98109
args = parser.parse_args()
99110
sys.stdout.flush()
100111

101112
with pyradio_config_file() as pyradio_config:
102113

103-
if args.update:
114+
if args.update or args.sng_master or args.sng_devel:
104115
if pyradio_config.distro != 'None' and \
105116
not platform.startswith('win'):
106117
no_update()
107118

119+
package = 0
120+
if args.sng_master:
121+
package = 1
122+
elif args.sng_devel:
123+
package = 2
108124
try:
109-
upd = PyRadioUpdate(package=2)
125+
upd = PyRadioUpdate(package=package)
110126
upd.update_pyradio()
111127
except RuntimeError:
112-
upd = PyRadioUpdateOnWindows(package=2)
128+
upd = PyRadioUpdateOnWindows(package=package)
113129
upd.update_or_uninstall_on_windows(mode='update-open')
114130
sys.exit()
115131

@@ -119,10 +135,10 @@ def shell():
119135
no_update(action='uninstall')
120136

121137
try:
122-
upd = PyRadioUpdate(package=2)
138+
upd = PyRadioUpdate()
123139
upd.remove_pyradio()
124140
except RuntimeError:
125-
upd = PyRadioUpdateOnWindows(package=2)
141+
upd = PyRadioUpdateOnWindows()
126142
upd.update_or_uninstall_on_windows(mode='uninstall-open')
127143
sys.exit()
128144

@@ -294,7 +310,8 @@ def shell():
294310
pyradio_config,
295311
play=args.play,
296312
req_player=requested_player,
297-
theme=theme_to_use
313+
theme=theme_to_use,
314+
force_update=args.force_update
298315
)
299316
''' Setting ESCAPE key delay to 25ms
300317
Refer to: https://stackoverflow.com/questions/27372068/why-does-the-escape-key-have-a-delay-in-python-curses
@@ -320,18 +337,19 @@ def shell():
320337
sys.stdout.write('\x1b]2;PyRadio: Your Internet Radio Player\x07')
321338
except:
322339
pass
323-
324340
sys.stdout.flush()
325341

326-
342+
''' curses wrapper '''
327343
curses.wrapper(pyradio.setup)
344+
345+
''' curses is off '''
328346
if pyradio.setup_return_status:
329347
if pyradio_config.PROGRAM_UPDATE:
330348
if platform.startswith('win'):
331-
upd = PyRadioUpdateOnWindows(package=2)
349+
upd = PyRadioUpdateOnWindows()
332350
upd.update_or_uninstall_on_windows(mode='update-open')
333351
else:
334-
upd = PyRadioUpdate(package=2)
352+
upd = PyRadioUpdate()
335353
upd.update_pyradio()
336354
else:
337355
print('\nThank you for using PyRadio. Cheers!')

0 commit comments

Comments
 (0)