""" Aug 26th 2010, Dale Hamel, University of Manitoba Description: Determines whether the system is OS X or linux, and creates a symbolic link to the appropriate launcher Note: this script is partnered with creatlauncher.py createlauncher.py makes the launchers at installtime, and linklauncher.py creates the links whenever newuser is run. Synopsis: python linklauncher.py @modified: March 31, 2020 @author: Dale Hamel @contact: umhameld@cc.umanitoba.ca """ import os import sys blib = os.environ.get("BIRCHLIB") sys.path.append(blib) from birchlib import Birchmod PROGRAM = "linklauncher.py: " USAGE = "\n\tUSAGE: linklauncher.py" BM = Birchmod(PROGRAM, USAGE) def get_desktop(): """ Returns the location of the current user's desktop directory by reading the environment variable "HOME", and assuming that there is a "HOME/Desktop" directory """ home_dir = os.environ.get("HOME") if (os.path.exists(home_dir)): desktop_dir = home_dir + "/Desktop" if (os.path.exists(desktop_dir)): print(PROGRAM + "Found desktop at: " + desktop_dir) else: desktop_dir = None return desktop_dir def link_gnome_launcher(birch_dir, desktop_dir): """ Creates a launcher of the form biolegato.desktop for use on linux desktops such as GNOME (v2+) and KDE (v3.5+). May also work on other desktops such as qt, etc, but not yet tested @desktop_dir: the location of the user's desktop directory, where the launcher will be placed """ file_name = birch_dir + "/admin/launchers/birch.desktop" if (birch_dir != None): os.chdir(desktop_dir) os.system("ln -s "+file_name+" .") print("Made symbolic link to launcher on desktop") def link_apple_launcher(birch_dir, desktop_dir): """ Makes a launcher application for OS X (tested on 10.5.8) of the format biolegato.app. The launcher is just a wrapper for an apple script that calls the system biolegato, and should use system paths. The this method copies a template launcher called "biolegato.app" to the desktop that is assumed to be in the current working directory in adirectory called "osx_launcher", if this changes then this method will need to be updated. Once the launcher is copied, all the contents of the BIRCH directory specified by the environment variable $BIRCH will be symbolically linked into the applications resource directory under: ~/biolegato.app/Contents/Resources" @desktop_dir: the location of the user's desktop directory, where the launcher will be placed """ if (birch_dir != None): os.chdir(desktop_dir) #os.system("ln -s "+birch_dir+"/admin/launchers/biolegato.app .") os.system("ln -s "+birch_dir+"/admin/launchers/birch.app .") print(PROGRAM + "Made symbolic link to launcher on desktop") def link_win_launcher(birch_dir): """ Creates a shortcut to the windows launcher script to run biolegato (birch) """ windir=os.environ.get("HOMEDRIVE")+os.environ.get("HOMEPATH") os.chdir(windir+"/Desktop") print(os.getcwd()) #Note: there is a hardcoded link to biolegato here, this should be fixed! biolegato=birch_dir+"/java/bioLegato/biolegato.bat" birch_icon=birch_dir+"/public_html/birch_black_ico.icns" cygwin_bat="/cygwin.bat" os.system("mkshortcut -n bioLegato -i "+birch_icon+" "+biolegato) os.system("mkshortcut -n birchTerm "+cygwin_bat) def main(BIRCH, PLATFORM): desktop_dir = get_desktop() print("PLATFORM: " + PLATFORM) if (desktop_dir != None): #This assumes either OSX or using gnome/kde, if this changes #this switch will need to be updated if "linux" in PLATFORM or "Linux" in PLATFORM : link_gnome_launcher(BIRCH, desktop_dir) elif "osx" in PLATFORM or "Darwin" in PLATFORM : link_apple_launcher(BIRCH, desktop_dir) elif(PLATFORM=="winxp-32"): link_win_launcher(BIRCH) else: exit() print(PROGRAM + "completed execution normally.") if __name__=="__main__": if (BM.documentor() or "-test" in sys.argv): pass else: #PLATFORM = os.environ.get("BIRCH_PLATFORM") #BIRCH = os.environ.get("BIRCH") main(BIRCH, PLATFORM)