@@ -55,9 +55,9 @@ class PyRadioUpdate(object):
55
55
56
56
ZIP_DIR = ('pyradio-master' , 'pyradio-master' , 'pyradio-devel' )
57
57
58
+ install = False
58
59
59
60
def __init__ (self , package = 0 ):
60
- package = 2
61
61
if platform .system ().lower ().startswith ('win' ):
62
62
raise RuntimeError ('This is a linux only class...' )
63
63
self ._dir = self ._install_dir = ''
@@ -72,11 +72,18 @@ def update_pyradio(self, win_open_dir=False):
72
72
self .update_or_uninstall_on_windows ('update' )
73
73
else :
74
74
''' update PyRadio under Linux and MacOS '''
75
- print ('Updating PyRadio...' )
75
+ if self .install :
76
+ print ('Installing PyRadio...' )
77
+ else :
78
+ print ('Updating PyRadio...' )
76
79
if self ._do_it ():
77
- print ('\n \n PyRadio 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 \n PyRadio succesfully installed!' )
82
+ print ('Hope you have a lot of fun using it!' )
83
+ else :
84
+ print ('\n \n PyRadio updated to the latest release!' )
85
+ print ('Thank you for your continuous support to this project!' )
86
+ print ('Cheers!\n ' )
80
87
sys .exit ()
81
88
else :
82
89
print ('\n \n An error occured during the installation!' )
@@ -109,7 +116,7 @@ def remove_pyradio(self, win_open_dir=False):
109
116
def update_or_uninstall_on_windows (self , mode = 'update' ):
110
117
isRunning ()
111
118
''' 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 ' )
113
120
shutil .rmtree (self ._dir , ignore_errors = True )
114
121
os .makedirs (self ._dir , exist_ok = True )
115
122
if mode .startswith ('update' ):
@@ -125,12 +132,12 @@ def update_or_uninstall_on_windows(self, mode='update'):
125
132
b .write ('CLS\n ' )
126
133
b .write ('pip install requests --upgrade 1>NUL 2>NUL\n ' )
127
134
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 ' )
130
137
b .write ('cd "' + os .path .join (self ._dir , self .ZIP_DIR [self ._package ]) + '"\n ' )
131
138
b .write ('devel\\ build_install_pyradio.bat -U\n ' )
132
139
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__ ) ))
134
141
b .write ('python uninstall.py --do-uninstall\n ' )
135
142
b .write ('cd "' + os .path .join (self ._dir , self .ZIP_DIR [self ._package ]) + '"\n ' )
136
143
b .write ('devel\\ build_install_pyradio.bat -u\n ' )
@@ -165,9 +172,9 @@ def _do_it(self, mode='update'):
165
172
166
173
'''' get tmp dir '''
167
174
if os .path .isdir ('/tmp' ):
168
- self ._dir = os .path .join ('/tmp' , 'tmp_pyradio ' )
175
+ self ._dir = os .path .join ('/tmp' , 'tmp-pyradio ' )
169
176
else :
170
- self ._dir = os .path .join (os .path .expanduser ('~' ), 'tmp_pyradio ' )
177
+ self ._dir = os .path .join (os .path .expanduser ('~' ), 'tmp-pyradio ' )
171
178
print ('Using directory: "{}"' .format (self ._dir ))
172
179
173
180
''' create tmp directory '''
@@ -188,8 +195,10 @@ def _do_it(self, mode='update'):
188
195
print ('Error: Failed to download PyRadio source code...\n ' )
189
196
sys .exit (1 )
190
197
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')
193
202
if mode == 'update' :
194
203
''' install pyradio '''
195
204
try :
@@ -306,10 +315,9 @@ def _download_file(self, url, filename):
306
315
class PyRadioUpdateOnWindows (PyRadioUpdate ):
307
316
308
317
def __init__ (self , fromTUI = False , package = 0 ):
309
- package = 2
310
318
if not platform .system ().lower ().startswith ('win' ):
311
319
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 ' )
313
321
self ._package = package
314
322
self ._fromTUI = fromTUI
315
323
@@ -318,14 +326,14 @@ def print_update_bat_created(cls):
318
326
print ('To complete the process you will have to execute a batch file.' )
319
327
print ('Windows Explorer will open the location of the batch file to run.\n ' )
320
328
print ('Please double click\n \n update.bat\n \n to 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' )) )
322
330
323
331
@classmethod
324
332
def print_uninstall_bat_created (cls ):
325
333
print ('To complete the process you will have to execute a batch file.' )
326
334
print ('Windows Explorer will open the location of the batch file to run.\n ' )
327
335
print ('Please double click\n \n uninstall.bat\n \n to 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' )) )
329
337
330
338
def update_pyradio (self ):
331
339
self ._do_it ()
@@ -353,34 +361,6 @@ def _do_it(self, mode='update'):
353
361
sys .exit (1 )
354
362
355
363
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
384
364
385
365
if __name__ == '__main__' :
386
366
from argparse import ArgumentParser , SUPPRESS as SUPPRESS
@@ -395,7 +375,7 @@ def _do_it(self, mode='update'):
395
375
''' extra downloads
396
376
only use them after the developer says so,
397
377
for debug purposes only
398
- --sng download developer release
378
+ --sng download developer release (master)
399
379
--sng-devel download developer devel branch
400
380
'''
401
381
parser .add_argument ('--sng' , action = 'store_true' , help = SUPPRESS )
@@ -438,8 +418,27 @@ def _do_it(self, mode='update'):
438
418
sys .exit ()
439
419
elif args .do_update :
440
420
''' coming from update BAT file on Windows'''
441
- print ('do_update' )
442
421
upd = PyRadioUpdateOnWindows (package = package )
443
422
upd .update_pyradio ()
444
423
sys .exit ()
445
424
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 \n Now 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
+
0 commit comments