Skip to content
Snippets Groups Projects
Commit 2b9b9efa authored by Lucio Zambon's avatar Lucio Zambon
Browse files

Update launcher.py

parent cfab1a4f
No related branches found
No related tags found
No related merge requests found
'''
cd ~/.local/share/applications/
cat puma.desktop
[Desktop Entry]
Name=Puma
NoDisplay=true
Exec=/usr/bin/python3 /home/elettra/tmp/lz/launcher.py %u
Type=Application
xdg-mime default puma.desktop x-scheme-handler/puma
'''
import subprocess
import sys
import psutil
import socket
import time
host = socket.gethostname()
import urllib.request
if len(sys.argv)<2:
sys.exit('Error: missing executable name')
sys.argv[1] = sys.argv[1].replace('puma://', '')
argv = ' '.join(sys.argv).replace('%20', ' ').split(' ')
argv[1] = argv[1].replace('puma://', '')
feedback = "http://puma-01.elettra.eu/knob/index.php?host="+host+"&pid="
with open('/home/elettra/tmp/lz/launcher_'+host+'.log', 'a') as mylog:
# mylog.write(process_name+' '+' '.join(params)+"\n")
mylog.write(time.strftime("%Y-%m-%d %H:%M:%S ")+' '.join(argv)+"\n")
mylog.flush()
# Path to the executable
executable_path = ('/runtime/bin/'+sys.argv[1]).replace('/bin/elettra/', '/elettra/bin/')
executable_path = ('/runtime/bin/'+argv[1]).replace('/bin/elettra/', '/elettra/bin/')
def is_process_running(process_name, params):
"""Check if a process with the given name and parameters is running."""
......@@ -27,20 +45,22 @@ def is_process_running(process_name, params):
pass
return False
process_name = sys.argv[1].replace('elettra/', '')
params = sys.argv[2:]
process_name = argv[1].replace('elettra/', '')
params = argv[2:]
if is_process_running(process_name, params):
print(f"The process '{process_name}' with parameters {params} is already running.")
sys.argv[1] = executable_path
# processInfo = subprocess.Popen('/usr/bin/python3 /home/elettra/tmp/lz/vibration.py '+' '.join(sys.argv[1:]), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# print(processInfo.stdout.read())
argv[1] = executable_path
print('/usr/bin/python3 /home/elettra/tmp/lz/vibration.py '+' '.join(argv[1:]))
processInfo = subprocess.Popen('/usr/bin/python3 /home/elettra/tmp/lz/vibration.py '+' '.join(argv[1:]), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(processInfo.stdout.read())
f = urllib.request.urlopen(feedback+'0')
myfile = f.read()
else:
print(f"The process '{process_name}' with parameters {params} is not running.")
try:
sys.argv[1] = executable_path
process = subprocess.Popen(sys.argv[1:])
argv[1] = executable_path
process = subprocess.Popen(argv[1:])
pid = process.pid
print(f"The PID of the launched process is: {pid}")
f = urllib.request.urlopen(feedback+str(pid))
......@@ -52,3 +72,4 @@ else:
f = urllib.request.urlopen(feedback+'-1&err='+str(e))
myfile = f.read()
#print(myfile)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment