|
12 | 12 | import subprocess
|
13 | 13 | from urllib.request import urlretrieve
|
14 | 14 |
|
| 15 | +import locale |
| 16 | +locale.setlocale(locale.LC_ALL, "") |
| 17 | + |
15 | 18 | HAVE_PYUNPACK = True
|
16 | 19 | try:
|
17 | 20 | from pyunpack import Archive
|
@@ -454,28 +457,106 @@ def clean_up(print_msg=True):
|
454 | 457 | stdout=subprocess.DEVNULL,
|
455 | 458 | stderr=subprocess.DEVNULL)
|
456 | 459 |
|
| 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 | + |
457 | 509 | 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)) |
463 | 515 | icon = join(environ['APPDATA'], 'pyradio', 'help', 'pyradio.ico')
|
| 516 | + # print('icon = "{}"'.format(icon)) |
464 | 517 | link_path = join(environ['APPDATA'], 'pyradio', 'help', 'PyRadio.lnk')
|
| 518 | + # print('link_path = "{}"'.format(link_path)) |
465 | 519 | 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) |
468 | 524 | 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 | + ) |
479 | 560 |
|
480 | 561 | if __name__ == '__main__':
|
481 | 562 | # _post_download(1, "C:\\Users\\spiros\\AppData\\Roaming\\pyradio")
|
|
0 commit comments