Skip to content

Commit aff1d70

Browse files
committed
fixing MacOS layout breakage on RadioBrowser
1 parent cd6eaaa commit aff1d70

File tree

5 files changed

+140
-4
lines changed

5 files changed

+140
-4
lines changed

Changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
2022-03-10 s-n-g
22
* Windows installation method updated to pip
33
* adding F7, F8, F9, F10 functionality for Windows
4+
* fixing MacOS layout breakage on RadioBrowser
45
* updating docs
56

67
2022-02-14 s-n-g

README.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ <h2 id="changelog">Changelog <span style="padding-left: 10px;"><sup style="font-
146146
2022-03-10 s-n-g
147147
* Windows installation method updated to pip
148148
* adding F7, F8, F9, F10 functionality for Windows
149+
* fixing MacOS layout breakage on RadioBrowser
149150
* updating docs
150151

151152
2022-02-14 s-n-g

pyradio/ping.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ def linux_ping(server, count=1, timeout_in_seconds=1):
3434
0: server is not alive (False)
3535
-1: error
3636
'''
37+
timeout_token = '-w' if platform == 'linux' else '-t'
3738
try:
38-
r=subprocess.Popen(['ping', '-c', str(count), '-w', str(timeout_in_seconds), server ], stdout=subprocess.PIPE).stdout.read()
39+
r=subprocess.Popen(['ping', '-c', str(count), timeout_token, str(timeout_in_seconds), server ], stdout=subprocess.PIPE).stdout.read()
3940
# print(r)
4041
return 0 if '100%' in str(r) else 1
4142
except:

pyradio/radio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,9 +2666,9 @@ def _print_py2_editor_error(self):
26662666
txt = '''
26672667
Non-ASCII characters editing is |not supported!|
26682668
2669-
You running |PyRadio| on |Python 2|. As a result, the
2670-
station editor only supports |ASCII characters|, but
2671-
the station name you are trying to edit contains
2669+
You are running |PyRadio| on |Python 2|. As a result,
2670+
the station editor only supports |ASCII characters|,
2671+
but the station name you are trying to edit contains
26722672
|non-ASCII| characters.
26732673
26742674
To edit this station, either run |PyRadio| on |Python 3|,

pyradio/win_del_old_inst.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import glob
2+
import os
3+
from sys import platform
4+
5+
def win_del_old_inst():
6+
if not platform.startswith('win'):
7+
return False
8+
9+
path = os.getenv('PROGRAMFILES')
10+
11+
out = []
12+
pdirs = [f for f in glob.glob(path + "**/Python*", recursive=False)]
13+
14+
for f in pdirs:
15+
# print('Searching in "' + f + '"')
16+
exe = os.path.join(f, 'Scripts', 'pyradio.exe')
17+
# # print(" EXE: {0} - {1}".format(exe, 'exists' if os.path.exists(exe) else 'not found'))
18+
if os.path.exists(exe):
19+
# print(' Found "' + exe + '"')
20+
out.append('DEL "' + exe + '"\n')
21+
site_packages = os.path.join(f, 'Lib', 'site-packages')
22+
if os.path.exists(site_packages):
23+
# # print('site-packages: "{}"'.format(site_packages))
24+
pydir = [f for f in glob.glob(site_packages + "**/pyradio*.egg", recursive=False)]
25+
for n in pydir:
26+
# print(' Found "' + n + '"')
27+
out.append('RD /Q /S "' + n + '"\n')
28+
# print(pydir)
29+
# print('')
30+
if out:
31+
TARGET = os.path.join(os.getenv('USERPROFILE'), 'tmp-pyradio')
32+
if not os.path.exists(TARGET):
33+
os.makedirs(TARGET)
34+
35+
msg = '''@ECHO OFF
36+
SETLOCAL EnableDelayedExpansion
37+
38+
IF EXIST DEV (SET NO_DEV=0) ELSE (SET NO_DEV=1)
39+
40+
::net file to test privileges, 1>NUL redirects output, 2>NUL redirects errors
41+
:: https://gist.github.com/neremin/3a4020c172053d837ab37945d81986f6
42+
:: https://stackoverflow.com/questions/13212033/get-windows-version-in-a-batch-file
43+
net session >nul 2>&1
44+
IF "%errorlevel%" == "0" ( GOTO START ) ELSE (
45+
FOR /f "tokens=4-5 delims=. " %%i in ('ver') do SET VERSION=%%i.%%j
46+
IF "%version%" == "6.1" ( GOTO win7exit )
47+
IF "%version%" == "6.0" ( GOTO win7exit )
48+
GOTO getPrivileges
49+
)
50+
51+
:win7exit
52+
ECHO.
53+
ECHO Error: You must have Administrative permissions to run this script.
54+
ECHO Please start cmd "As Administrator".
55+
ECHO.
56+
ECHO If that does not work, ask the system administrator to
57+
ECHO install PyRadio for you.
58+
ECHO.
59+
GOTO endnopause
60+
61+
:getPrivileges
62+
IF "%version%" == "6.1" ( GOTO win7exit )
63+
IF "%version%" == "6.0" ( GOTO win7exit )
64+
65+
IF '%1'=='ELEV' ( GOTO START ) ELSE ( ECHO Running elevated in a different window)
66+
67+
SET "batchPath=%~f0"
68+
SET "batchArgs=ELEV"
69+
70+
::Add quotes to the batch path, IF needed
71+
SET "script=%0"
72+
SET script=%script:"=%
73+
IF '%0'=='!script!' ( GOTO PathQuotesDone )
74+
SET "batchPath=""%batchPath%"""
75+
:PathQuotesDone
76+
77+
::Add quotes to the arguments, IF needed.
78+
:ArgLoop
79+
IF '%1'=='' ( GOTO EndArgLoop ) ELSE ( GOTO AddArg )
80+
:AddArg
81+
SET "arg=%1"
82+
SET arg=%arg:"=%
83+
IF '%1'=='!arg!' ( GOTO NoQuotes )
84+
SET "batchArgs=%batchArgs% "%1""
85+
GOTO QuotesDone
86+
:NoQuotes
87+
SET "batchArgs=%batchArgs% %1"
88+
:QuotesDone
89+
SHIFT
90+
GOTO ArgLoop
91+
:EndArgLoop
92+
93+
::Create and run the vb script to elevate the batch file
94+
ECHO SET UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
95+
ECHO UAC.ShellExecute "cmd", "/c ""!batchPath! !batchArgs!""", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
96+
"%temp%\OEgetPrivileges.vbs"
97+
EXIT /B
98+
99+
:START
100+
::Remove the elevation tag and SET the correct working directory
101+
IF '%1'=='ELEV' ( SHIFT /1 )
102+
CD /d %~dp0
103+
104+
::Do your adminy thing here...
105+
106+
:: RD /Q /S %USERPROFILE%\tmp-pyradio
107+
:: MKDIR %USERPROFILE%\tmp-pyradio
108+
:: START %USERPROFILE%\tmp-pyradio
109+
110+
111+
'''
112+
TARGET_FILE = os.path.join(TARGET, 'RunMe.bat')
113+
with open(TARGET_FILE, 'w') as ofile:
114+
ofile.write(msg)
115+
ofile.write('\nECHO Looking for old style installation files\n')
116+
for n in out:
117+
ofile.write('ECHO found ' + n.replace('RD /Q /S ', '').replace('DEL ', '').replace('\n', '') + ' - removing it...\n')
118+
# enable this one to not delete any files
119+
# ofile.write(':: ' + n)
120+
# enable this one to actually delete files
121+
ofile.write(n)
122+
ofile.write('ECHO.\n')
123+
ofile.write('ECHO Old style installation files removed...\n')
124+
ofile.write('ECHO.\n')
125+
ofile.write('PAUSE\n')
126+
127+
os.startfile(TARGET_FILE)
128+
return True
129+
130+
if __name__ == '__main__':
131+
if not win_del_old_inst():
132+
print('This is a Windows only program!')
133+

0 commit comments

Comments
 (0)