/scripts/pycam_win32_postinstall.py

https://github.com/SebKuzminsky/pycam · Python · 90 lines · 48 code · 14 blank · 28 comment · 11 complexity · 27f94aa706b7ecec5bbc409777ce716f MD5 · raw file

  1. """
  2. Copyright 2010 Lars Kruse <devel@sumpfralle.de>
  3. This file is part of PyCAM.
  4. PyCAM is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. PyCAM is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
  14. """
  15. import distutils.sysconfig
  16. import os
  17. import sys
  18. try:
  19. logfile = os.path.join(distutils.sysconfig.PREFIX, "pycam-wininst-postinstall.log", "a")
  20. except OSError:
  21. logfile = None
  22. if logfile:
  23. sys.stdout = logfile
  24. sys.stderr = logfile
  25. # There are some additional builtin functions available in the context of this script:
  26. # https://docs.python.org/3/distutils/builtdist.html#the-postinstallation-script
  27. # We use the following functions:
  28. # create_shortcut
  29. # directory_created
  30. # file_created
  31. # get_special_folder_path
  32. LINK_EXTENSION = ".lnk"
  33. try:
  34. START_MENU_BASEDIR = get_special_folder_path("CSIDL_COMMON_PROGRAMS")
  35. except OSError:
  36. START_MENU_BASEDIR = get_special_folder_path("CSIDL_PROGRAMS") # noqa: F821
  37. except NameError:
  38. START_MENU_BASEDIR = "C:\\"
  39. START_MENU_SUBDIR = os.path.join(START_MENU_BASEDIR, "PyCAM")
  40. # create a start menu item for pycam
  41. PYTHON_EXE = os.path.join(distutils.sysconfig.EXEC_PREFIX, "pythonw.exe")
  42. # surround the start script with quotes to avoid space-issues
  43. START_SCRIPT = '"%s"' % os.path.join(distutils.sysconfig.EXEC_PREFIX, "Scripts", "pycam-loader.py")
  44. SHARE_DIR = os.path.join(distutils.sysconfig.PREFIX, "share", "pycam")
  45. PYTHON_DOC_DIR = os.path.join(SHARE_DIR, "doc")
  46. ICON_FILE = os.path.join(SHARE_DIR, "pycam.ico")
  47. # add some more doc files
  48. DOC_FILES = [("LICENSE.TXT", "License")]
  49. WEB_LINKS = [
  50. (r"http://pycam.sourceforge.net/", "Project's Website"),
  51. (r"http://sourceforge.net/tracker/?group_id=237831&atid=1104176", "Report a Bug"),
  52. (r"http://sourceforge.net/projects/pycam/forums", "Forum Discussions"),
  53. (r"http://sourceforge.net/apps/mediawiki/pycam/index.php?title=User_Manual", "User Manual")]
  54. MENU_ITEMS = map(lambda v: (os.path.join(PYTHON_DOC_DIR, v[0]), v[1]), DOC_FILES)
  55. MENU_ITEMS.extend(WEB_LINKS)
  56. action = sys.argv[1]
  57. if action == "-install":
  58. if not os.path.exists(START_MENU_SUBDIR):
  59. os.mkdir(START_MENU_SUBDIR)
  60. directory_created(START_MENU_SUBDIR) # noqa: F821
  61. for menu_item in MENU_ITEMS:
  62. target, description = menu_item
  63. filename = os.path.join(START_MENU_SUBDIR, description) + LINK_EXTENSION
  64. create_shortcut(target, description, filename) # noqa: F821
  65. file_created(filename) # noqa: F821
  66. filename = os.path.join(START_MENU_SUBDIR, "Run PyCAM") + LINK_EXTENSION
  67. create_shortcut(PYTHON_EXE, "Run PyCAM", filename, START_SCRIPT, "", ICON_FILE) # noqa: F821
  68. file_created(filename) # noqa: F821
  69. elif action == "-remove":
  70. pass
  71. else:
  72. pass