Skip to content

Commit 336101c

Browse files
committed
fixing windows lnk installation
1 parent a72f250 commit 336101c

14 files changed

+145
-23
lines changed

devel/build_install_pyradio.bat

+11-5
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,17 @@ CD ..
119119

120120
:: Install lnk file
121121
ECHO *** Installing Dekstop Shortcut
122-
COPY /Y %APPDATA%\pyradio\help\*.lnk %DESKTOP% >NUL
123-
IF EXIST "%APPDATA%\Microsoft\Windows\Start Menu\Programs" (
124-
ECHO *** Installing Start Menu Shortcut
125-
COPY /Y %APPDATA%\pyradio\help\*.lnk "%APPDATA%\Microsoft\Windows\Start Menu\Programs" >NUL
126-
)
122+
REM DEL %USERPROFILE%\desktop\PyRadio.lnk >NUL
123+
REM DEL "%APPDATA%\Microsoft\Windows\Start Menu\Programs\PyRadio.lnk" >NUL
124+
REM REM COPY /Y %APPDATA%\pyradio\help\PyRadio.lnk %DESKTOP% >NUL
125+
REM COPY /Y %APPDATA%\pyradio\help\PyRadio.lnk %USERPROFILE%\desktop >NUL
126+
REM IF EXIST "%APPDATA%\Microsoft\Windows\Start Menu\Programs" (
127+
REM ECHO *** Installing Start Menu Shortcut
128+
REM COPY /Y %APPDATA%\pyradio\help\PyRadio.lnk "%APPDATA%\Microsoft\Windows\Start Menu\Programs" >NUL
129+
REM )
130+
CD pyradio
131+
%PROGRAM% -c "from win import install_pyradio_link; install_pyradio_link()"
132+
CD ..
127133

128134
:: Clean up
129135
CD pyradio

pyradio/cjkwrap.py

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
import unicodedata
3030
import sys
3131

32+
import locale
33+
locale.setlocale(locale.LC_ALL, "")
34+
3235
PY3 = sys.version[0] == '3'
3336

3437
if PY3:

pyradio/compare_files.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import hashlib
22

3+
import locale
4+
locale.setlocale(locale.LC_ALL, "")
5+
36
class CompareFiles(object):
47
''' Class to compare two files by content '''
58

pyradio/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
SUPPORTED_PLAYERS = ('mpv', 'mplayer', 'vlc')
4343

44+
import locale
45+
locale.setlocale(locale.LC_ALL, "")
4446

4547
class PyRadioStations(object):
4648
''' PyRadio stations file management '''

pyradio/del_vlc_log.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
from sys import platform
33

4+
import locale
5+
locale.setlocale(locale.LC_ALL, "")
46

57
def RemoveWinVlcLogFiles(*args):
68
''' Removes all VLC log files within pyradio config

pyradio/install.py

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import json
88
from time import sleep
99
import site
10+
11+
import locale
12+
locale.setlocale(locale.LC_ALL, "")
13+
1014
try:
1115
from os.path import curdir, exists
1216
import ctypes

pyradio/log.py

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from .common import player_start_stop_token
1414
from .cjkwrap import cjklen, PY3
1515

16+
import locale
17+
locale.setlocale(locale.LC_ALL, "")
18+
1619
HAS_WIN10TOAST = True
1720
try:
1821
from win10toast import ToastNotifier

pyradio/main.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
from .cjkwrap import cjklen, cjkslices, fill
1616
from .log import Log
1717

18+
import locale
19+
locale.setlocale(locale.LC_ALL, "")
20+
1821
PATTERN = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
1922
PATTERN_TITLE = '%(asctime)s | %(message)s'
2023

@@ -400,7 +403,6 @@ def shell():
400403
ret = pyradio_config.read_playlist_file(
401404
stationFile=args.stations,
402405
is_last_playlist=is_last_playlist)
403-
print('ret = {}'.format(ret))
404406
if ret < 0:
405407
print_playlist_selection_error(args.stations, pyradio_config, ret)
406408

pyradio/ping.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import subprocess
22
from sys import platform, version_info
33

4+
import locale
5+
locale.setlocale(locale.LC_ALL, "")
6+
47
def ping(server, count=10, timeout_in_seconds=1):
58
''' ping a server on any platform
69
Returns:

pyradio/player.py

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
import collections
1212
import json
1313
import socket
14+
15+
import locale
16+
locale.setlocale(locale.LC_ALL, "")
17+
1418
try:
1519
import psutil
1620
except:

pyradio/themes.py

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
logger = logging.getLogger(__name__)
1616

17+
import locale
18+
locale.setlocale(locale.LC_ALL, "")
19+
1720
def isLightOrDark(rgbColor=[0,128,255]):
1821
[r,g,b]=rgbColor
1922
'''

pyradio/win.py

+98-17
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import subprocess
1313
from urllib.request import urlretrieve
1414

15+
import locale
16+
locale.setlocale(locale.LC_ALL, "")
17+
1518
HAVE_PYUNPACK = True
1619
try:
1720
from pyunpack import Archive
@@ -454,28 +457,106 @@ def clean_up(print_msg=True):
454457
stdout=subprocess.DEVNULL,
455458
stderr=subprocess.DEVNULL)
456459

460+
def get_path(exe):
461+
out_exe = ''
462+
chk = []
463+
464+
for n in site.getsitepackages():
465+
# print('adding: "{}"'.format(join(n, exe)))
466+
# print('adding: "{}"'.format(join(n, 'Scripts', exe)))
467+
chk.append(join(n, exe))
468+
chk.append(join(n, 'Scripts', exe))
469+
# print('------------------------')
470+
x = site.getusersitepackages()
471+
if isinstance(x, str):
472+
# print('adding: "{}"'.format(join(x, exe)))
473+
# print('adding: "{}"'.format(join(x, 'Scripts', exe)))
474+
chk.append(join(x, exe))
475+
chk.append(join(x, 'Scripts', exe))
476+
# print('adding: "{}"'.format(join(x, exe)).replace('\site-packages', ''))
477+
# print('adding: "{}"'.format(join(x, 'Scripts', exe)).replace('\site-packages', ''))
478+
chk.append(join(x, exe).replace('\site-packages', ''))
479+
chk.append(join(x, 'Scripts', exe).replace('\site-packages', ''))
480+
else:
481+
for n in site.getusersitepackages():
482+
# print('adding: "{}"'.format(join(n, exe)))
483+
# print('adding: "{}"'.format(join(n, 'Scripts', exe)))
484+
chk.append(join(n, exe))
485+
chk.append(join(n, 'Scripts', exe))
486+
# print('------------------------')
487+
for n in site.PREFIXES:
488+
# print('adding: "{}"'.format(join(n, exe)))
489+
# print('adding: "{}"'.format(join(n, 'Scripts', exe)))
490+
chk.append(join(n, exe))
491+
chk.append(join(n, 'Scripts', exe))
492+
# for n in range(0,4):
493+
# print('')
494+
# for n in chk:
495+
# print(n)
496+
# print('------------------------')
497+
for n in chk:
498+
# print('checking: "{}'.format(n))
499+
if exists(n):
500+
return n
501+
return ''
502+
503+
def get_pyradio():
504+
return get_path('pyradio.exe')
505+
506+
def get_pylnk():
507+
return get_path('pylnk3.exe')
508+
457509
def create_pyradio_link():
458-
sp = site.USER_SITE.split(sep)
459-
sp[-1] = 'Scripts'
460-
scripts_path = sep.join(sp)
461-
pyradio_exe = join(scripts_path, 'pyradio.exe')
462-
pylnk_exe = join(scripts_path, 'pylnk3.exe')
510+
pyradio_exe = 'pyradio'
511+
pyradio_exe = get_pyradio()
512+
pylnk_exe = get_pylnk()
513+
# print('pyradio_exe = "{}"'.format(pyradio_exe))
514+
# print('pylnk_exe = "{}"'.format(pylnk_exe))
463515
icon = join(environ['APPDATA'], 'pyradio', 'help', 'pyradio.ico')
516+
# print('icon = "{}"'.format(icon))
464517
link_path = join(environ['APPDATA'], 'pyradio', 'help', 'PyRadio.lnk')
518+
# print('link_path = "{}"'.format(link_path))
465519
workdir = join(environ['APPDATA'], 'pyradio')
466-
if exists(pyradio_exe):
467-
print('*** Updating Dekstop Shortcut')
520+
# print('workdir = "{}"'.format(workdir))
521+
# print('*** Updating Dekstop Shortcut')
522+
if not exists(workdir):
523+
makedirs(workdir, exist_ok=True)
468524
if not exists(workdir):
469-
makedirs(workdir, exist_ok=True)
470-
if not exists(workdir):
471-
print('Cannot create "' + workdir + '"')
472-
sys.exit(1)
473-
if not exists(pylnk_exe):
474-
install_pylnk(workdir)
475-
cmd = pylnk_exe + ' c --icon ' + icon + ' --workdir ' + workdir \
476-
+ ' ' + pyradio_exe + ' ' + link_path
477-
#print(cmd)
478-
subprocess.call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
525+
print('Cannot create "' + workdir + '"')
526+
sys.exit(1)
527+
if not exists(pylnk_exe):
528+
install_pylnk(workdir)
529+
pylnk_exe = get_pylnk()
530+
# print('pylnk_exe = "{}"'.format(pylnk_exe))
531+
cmd = pylnk_exe + ' c --icon ' + icon + ' --workdir ' + workdir \
532+
+ ' ' + pyradio_exe + ' ' + link_path
533+
# print('cmd = "{}"'.format(cmd))
534+
subprocess.Popen(
535+
[pylnk_exe, 'c', '--icon', icon, '--workdir', workdir, pyradio_exe, link_path],
536+
shell=True,
537+
stdout=subprocess.DEVNULL,
538+
stderr=subprocess.DEVNULL
539+
)
540+
541+
def install_pyradio_link():
542+
from shutil import copy
543+
desktop = getenv('DESKTOP')
544+
user_profile = getenv('USERPROFILE')
545+
appdata = getenv('APPDATA')
546+
to_desktop = desktop if desktop is not None else join(user_profile, 'desktop')
547+
to_start_menu = join(appdata, 'Microsoft', 'Windows', 'Start Menu', 'Programs')
548+
549+
if exists(to_desktop):
550+
copy(
551+
join(appdata, 'pyradio', 'help', 'PyRadio.lnk'),
552+
join(to_desktop, 'PyRadio.lnk')
553+
)
554+
555+
if exists(to_start_menu):
556+
copy(
557+
join(appdata, 'pyradio', 'help', 'PyRadio.lnk'),
558+
join(to_start_menu, 'PyRadio.lnk')
559+
)
479560

480561
if __name__ == '__main__':
481562
# _post_download(1, "C:\\Users\\spiros\\AppData\\Roaming\\pyradio")

pyradio/win_del_old_inst.py

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import os
33
from sys import platform
44

5+
import locale
6+
locale.setlocale(locale.LC_ALL, "")
7+
58
def win_del_old_inst():
69
if not platform.startswith('win'):
710
return False

pyradio/window_stack.py

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
locale.setlocale(locale.LC_ALL, "")
66
logger = logging.getLogger(__name__)
77

8+
import locale
9+
locale.setlocale(locale.LC_ALL, "")
10+
811

912
class Window_Stack_Constants(object):
1013
''' Modes of Operation '''

0 commit comments

Comments
 (0)