diff --git a/__init__.py b/__init__.py index 4c919609..de5968fc 100644 --- a/__init__.py +++ b/__init__.py @@ -19,110 +19,97 @@ from __future__ import absolute_import, division, print_function -try: - import time -except: - print("Couldn't import time") +def boot_supercollider(): + """ Uses subprocesses to boot supercollider from the cli """ -try: + import time import platform -except: - print("Couldn't import platform library") - -import os - -import subprocess - -try: - import psutil -except: - os.system("pip install psutil") - -try: + import os + import subprocess import getpass -except: - print("Couldn't import getpass library") - -sclangpath = "" #find path to sclang + try: + import psutil + except ImportError: + os.system("pip install psutil") + import sys + sys.exit("Installed psutil, please start FoxDot again.") -thispath = "" #find this path + """ + def is_proc_running(name): + for p in psutil.process_iter(attrs=["name", "exe", "cmdline"]): + #print(p); + procname = p.info['name'] or \ + p.info['exe'] and os.path.basename(p.info['exe']) == name or \ + p.info['cmdline'] and p.info['cmdline'][0] == name + if(name in str(procname)): + return True + return False + """ -""" + def is_proc_running(ourcwd): + return False -Sclang path and supercollider path are the same but need to go to the actual file for sclang + + sclangpath = "" #find path to sclang -For CWR (current working directory) need to go to the folder that contains sclang (also contains supercollider (scide.exe)) + thispath = "" #find this path -""" + thisdir = os.getcwd() -thisdir = os.getcwd() + OS = platform.system() -OS = platform.system() + username = getpass.getuser() -username = getpass.getuser() + if(OS == "Windows"): -if(OS == "Windows"): + sclangloc = os.popen('where /R "C:\\Program Files" sclang.exe').read() - print("OS: Windows") + thiscwd = str(sclangloc) - sclangloc = os.popen('where /R "C:\Program Files" sclang.exe').read() + ourcwd = thiscwd.replace('\\sclang.exe\n', '') - thiscwd = str(sclangloc) + final = ourcwd + "\sclang.exe" - ourcwd = thiscwd.replace('\\sclang.exe\n', '') + print(final) - def is_proc_running(name): - for p in psutil.process_iter(attrs=["name", "exe", "cmdline"]): - #print(p); - procname = p.info['name'] or \ - p.info['exe'] and os.path.basename(p.info['exe']) == name or \ - p.info['cmdline'] and p.info['cmdline'][0] == name - if(procname.startswith(name)): - return True - return False + running = (is_proc_running(final)) + if(running == False): + print("Booting supercollider background process...") + startup = thisdir+"/FoxDot/startup.scd" + #os.system("sclang"+startup+" &") + subprocess.Popen([sclangloc, startup], cwd=ourcwd, shell=True) - running = (is_proc_running("sclang")) - if(running == False): - startup = thisdir+"/FoxDot/startup.scd" - #os.system("sclang"+startup+" &") - subprocess.Popen([sclangloc, startup], cwd=ourcwd, shell=True) + elif(OS == "Linux"): -elif(OS == "Linux"): + running = (is_proc_running("sclang")) - print("OS: Linux") + if(running == False): + startup = thisdir+"/FoxDot/startup.scd" + #os.system('sclang "/home/foxdot/Desktop/FoxDot-Cross-Platform/FoxDot/startup.scd" &') #fuctional + os.system("sclang "+startup+" &") - def is_proc_running(name): - for p in psutil.process_iter(attrs=["name","cmdline"]): - #print(p); - procname = p.info['name'] or \ - p.info['cmdline'] and p.info['cmdline'][0] == name - if(procname.startswith(name)): - return True - return False + else: + print("Operating system unrecognised") + #Potentially get the user to choose their OS from a list? + #Then run the corresponding functions - running = (is_proc_running("sclang")) +import sys - if(running == False): - startup = thisdir+"/FoxDot/startup.scd" - #os.system('sclang "/home/foxdot/Desktop/FoxDot-Cross-Platform/FoxDot/startup.scd" &') #fuctional - os.system("sclang "+startup+" &") +if "--boot" in sys.argv: + boot_supercollider() -else: - print("Operating system unrecognised") - #Potentially get the user to choose their OS from a list? - #Then run the corresponding functions + sys.argv.remove("--boot") from .lib import * - def main(): """ Function for starting the GUI when importing the library """ - FoxDot = Workspace.workspace(FoxDotCode).run() + FoxDot = Workspace.Editor.workspace(FoxDotCode).run() def Go(): """ Function to be called at the end of Python files with FoxDot code in to keep