Skip to content

Commit

Permalink
Merge pull request #10 from johnwason/rename_drekar
Browse files Browse the repository at this point in the history
Rename to drekar-launch
  • Loading branch information
johnwason authored Jun 13, 2023
2 parents 784b2d6 + 1e08385 commit efeb8e0
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 69 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
sudo apt-get install -y python3 python3-pip curl
- name: pip
run: |
pip3 install git+https://github.com/johnwason/simple-launch-process.git
pip3 install git+https://github.com/johnwason/drekar-launch-process.git
pip3 install .[test]
- name: test
run: |
Expand All @@ -54,7 +54,7 @@ jobs:
- uses: actions/checkout@v3
- name: pip
run: |
pip install git+https://github.com/johnwason/simple-launch-process.git
pip install git+https://github.com/johnwason/drekar-launch-process.git
pip install .[test]
- name: test
run: |
Expand All @@ -68,7 +68,7 @@ jobs:
python-version: '3.10'
- name: pip
run: |
python -m pip install git+https://github.com/johnwason/simple-launch-process.git
python -m pip install git+https://github.com/johnwason/drekar-launch-process.git
python -m pip install .[test]
- name: test
run: |
Expand Down
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# Simple Launch
# Drekar Launch

`simple-launch` is a simple tool to launch and manage multiple processes. It is based on the process management code
`drekar-launch` is a simple tool to launch and manage multiple processes. It is based on the process management code
extracted from the `pyri-core` module, part of the PyRI Open-Source Teach Pendant

`simple-launch` has a similar goal to `roslaunch`, but
`drekar-launch` has a similar goal to `roslaunch`, but
designed to be simpler and independent of ROS. It also has improvements in handling Windows process management
using Windows Job Objects. Yaml files are used to configure the processes to launch.

`simple-launch` will show a minimal GUI windows when the `--gui` is specified. This window shows same basic
information, and has a "Stop All" button that will shut down all tasks. This GUI is useful if `simple-launch` is
`drekar-launch` will show a minimal GUI windows when the `--gui` is specified. This window shows same basic
information, and has a "Stop All" button that will shut down all tasks. This GUI is useful if `drekar-launch` is
started interactively by the user rather than running as a background service.

See also `simple-launch-process`, a companion library that contains utility functions to use within processes
hosted by `simple-launch`. The functions `wait_exit()` and `wait_exit_callback()` assist in receiving shutdown
See also `drekar-launch-process`, a companion library that contains utility functions to use within processes
hosted by `drekar-launch`. The functions `wait_exit()` and `wait_exit_callback()` assist in receiving shutdown
signals in a reliable cross-platform manner.

See `simple-launch-process`: https://github.com/johnwason/simple-launch-process
See `drekar-launch-process`: https://github.com/johnwason/drekar-launch-process

## Installation

```
python -m pip install --user simple-launch
python -m pip install --user drekar-launch
```

On Ubuntu, it may be necessary to replace `python` with `python3`.

## Usage

Yaml files are used to configure the processes to launch. The following is an example of a `simple-launch.yaml`
Yaml files are used to configure the processes to launch. The following is an example of a `drekar-launch.yaml`
file that launches two Python servers.

```yaml
Expand All @@ -46,7 +46,7 @@ tasks:
start-delay: 1
```
The `example_http_server.py` program uses `simple-launch-process` to wait for the shutdown signal.
The `example_http_server.py` program uses `drekar-launch-process` to wait for the shutdown signal.

In this example, the `name` field is the name of the launch group. The `tasks` section contains a list of tasks to
launch. The following fields are used to configure the launch of each task:
Expand All @@ -63,21 +63,21 @@ launch. The following fields are used to configure the launch of each task:
* `environment` (optional): Key/value pairs to add to environment
* `env-file` (optional): File of environmental variable to override the environment

`simple-launch` by default will load `simple-launch.yaml` in the current directory. To run with default settings,
simply call `simple-launch`.
`drekar-launch` by default will load `drekar-launch.yaml` in the current directory. To run with default settings,
simply call `drekar-launch`.

```
simple-launch
drekar-launch
```
In some cases, it may be necessary to use `python` to launch. The `simple-launch` executable may not be installed
In some cases, it may be necessary to use `python` to launch. The `drekar-launch` executable may not be installed
to `PATH`.
```
python -m simple_launch
python -m drekar_launch
```
`simple-launch` accepts the following optional command line arguments:
`drekar-launch` accepts the following optional command line arguments:
* `--config=`: Specify an alternative configuration file
* `--config-js=`: Specify an alternative configuration file that uses Jinja2 templates
Expand All @@ -86,11 +86,11 @@ python -m simple_launch
* `--quiet`: Flag to suppress outputting to the terminal
* `--gui`: Show a simple GUI to stop the tasks
Simple Launch saves the output to log files located in the following locations:
Drekar Launch saves the output to log files located in the following locations:
* Windows: `%LOCALAPPDATA%\simple-launch\simple-launch\Logs`
* Windows: `%LOCALAPPDATA%\drekar-launch\drekar-launch\Logs`
* Linux: `$HOME/.cache/SuperApp/log`
* Mac OS: `$HOME//Library/Logs/simple-launch`
* Mac OS: `$HOME//Library/Logs/drekar-launch`
Logs should be periodically cleaned if too much disk space is used.
Expand Down
39 changes: 19 additions & 20 deletions simple_launch.py → drekar_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import signal
import subprocess
import jinja2
import simple_launch_process
import drekar_launch_process


class SimpleTask(NamedTuple):
class DrekarTask(NamedTuple):
name: str
program: str
cwd: str
Expand All @@ -44,7 +44,7 @@ class ProcessState(Enum):
PAUSE_PENDING = 0x6
PAUSED = 0x7

class SimpleProcess:
class DrekarProcess:
def __init__(self, parent, task_launch, log_dir, loop):
self.parent = parent
self.task_launch = task_launch
Expand Down Expand Up @@ -150,7 +150,7 @@ def kill(self):
except:
traceback.print_exc()

class SimpleCore:
class DrekarCore:
def __init__(self, name, task_launches, exit_event, log_dir, screen, loop):
self.name = name
self.task_launches = dict()
Expand All @@ -166,7 +166,7 @@ def __init__(self, name, task_launches, exit_event, log_dir, screen, loop):
self.exit_event = exit_event

def _do_start(self,s):
p = SimpleProcess(self, s, self.log_dir, self.loop)
p = DrekarProcess(self, s, self.log_dir, self.loop)
self._subprocesses[s.name] = p
self.loop.create_task(p.run())

Expand Down Expand Up @@ -277,17 +277,17 @@ async def create_subprocess_exec(process, args, env, cwd):

subprocess_impl_win32.win32_attach_job_and_resume_process(process, job_handle)

return SimpleSubprocessImpl(process,job_handle)
return DrekarSubprocessImpl(process,job_handle)

else:
#TODO: Use "start_new_session=True" arg for new process
process = await asyncio.create_subprocess_exec(process,*args, \
stdout=asyncio.subprocess.PIPE,stderr=asyncio.subprocess.PIPE,\
env=env, cwd=cwd, close_fds=True, start_new_session=True )
return SimpleSubprocessImpl(process)
return DrekarSubprocessImpl(process)


class SimpleSubprocessImpl:
class DrekarSubprocessImpl:
def __init__(self, asyncio_subprocess, job_handle = None):
self._process = asyncio_subprocess
self._job_handle = job_handle
Expand Down Expand Up @@ -528,7 +528,6 @@ def worker(hWnd, lParam):
def _win32_send_wm_close_hwnd_message(pid):
# check for main window first, then send to message windows
hwnds = subprocess_impl_win32._win32_find_main_hwnds(pid)
print(f"main hwnds: {hwnds}")
if not hwnds:
hwnds = subprocess_impl_win32._win32_find_message_hwnds(pid)
for hWnd in hwnds:
Expand All @@ -542,7 +541,7 @@ def _win32_send_ctrl_c_event(pid):
ctypes.windll.kernel32.GenerateConsoleCtrlEvent(0,pid)

def parse_task_launch_from_yaml(yaml_dict, cwd):
# parse yaml_dict into SimpleTask tuple
# parse yaml_dict into DrekarTask tuple
name = yaml_dict["name"]
program = yaml_dict["program"]
cwd = yaml_dict.get("cwd", cwd)
Expand Down Expand Up @@ -588,7 +587,7 @@ def parse_task_launch_from_yaml(yaml_dict, cwd):
if program is None:
raise Exception("Could not find program: {}".format(program))

return SimpleTask(
return DrekarTask(
name=name,
program=program,
cwd=cwd,
Expand Down Expand Up @@ -617,7 +616,7 @@ def parse_task_launches_from_yaml_dict(yaml_dict, cwd):
return name, task_launches


class SimpleGui:
class DrekarGui:

def __init__(self, name, core, exit_event):
self.name = name
Expand All @@ -630,7 +629,7 @@ def _create_root(self):
tk = importlib.import_module("tkinter")

root = tk.Tk()
root.title(self.name + " Simple Launch")
root.title(self.name + " Drekar Launch")
root.geometry("600x200")

root.protocol("WM_DELETE_WINDOW", self._set_exit_event)
Expand Down Expand Up @@ -737,30 +736,30 @@ def main():
with open (parser_results.config, "r") as f:
name, task_launch = parse_task_launches_from_yaml(f, parser_results.cwd)
else:
# use default config simple-launch.yaml
with open("simple-launch.yaml", "r") as f:
# use default config drekar-launch.yaml
with open("drekar-launch.yaml", "r") as f:
name, task_launch = parse_task_launches_from_yaml(f, parser_results.cwd)

name = parser_results.name if parser_results.name is not None else name
if name is None:
name = "simple-launch"
name = "drekar-launch"

timestamp = datetime.now().strftime("-%Y-%m-%d--%H-%M-%S")
log_dir = Path(appdirs.user_log_dir(appname="simple-launch")).joinpath(name).joinpath(name + timestamp)
log_dir = Path(appdirs.user_log_dir(appname="drekar-launch")).joinpath(name).joinpath(name + timestamp)
log_dir.mkdir(parents=True, exist_ok=True)
loop = asyncio.get_event_loop()

exit_event = asyncio.Event()
core = SimpleCore(parser_results.name, task_launch, exit_event, log_dir, not parser_results.quiet, loop)
core = DrekarCore(parser_results.name, task_launch, exit_event, log_dir, not parser_results.quiet, loop)
gui = None
if parser_results.gui:
gui = SimpleGui(name, core, exit_event)
gui = DrekarGui(name, core, exit_event)
gui.start()
loop.call_soon(lambda: core.start_all())
def ctrl_c_pressed():
loop.call_soon_threadsafe(lambda: exit_event.set())
loop.call_soon_threadsafe(lambda: core.close())
simple_launch_process.wait_exit_callback(ctrl_c_pressed)
drekar_launch_process.wait_exit_callback(ctrl_c_pressed)
print("Press Ctrl-C to exit")
loop.run_until_complete(exit_event.wait())
print("Exit received, closing")
Expand Down
4 changes: 2 additions & 2 deletions examples/http_client_server/example_http_server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
import simple_launch_process
import drekar_launch_process
from http import server as http_server


Expand All @@ -25,7 +25,7 @@ def do_GET(self):
def shutdown_server():
server.shutdown()

simple_launch_process.wait_exit_callback(shutdown_server)
drekar_launch_process.wait_exit_callback(shutdown_server)

print("Server started on port", port)
sys.stdout.flush()
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions examples/http_servers/example_http_server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
import simple_launch_process
import drekar_launch_process
from http import server as http_server


Expand All @@ -19,14 +19,14 @@ def do_GET(self):
self.send_response(404)
self.end_headers()

server=http_server.HTTPServer(('',port),
server=http_server.ThreadingHTTPServer(('',port),
MyHTTPRequestHandler)

def shutdown_server():
print("Receiving shutdown signal")
server.shutdown()

simple_launch_process.wait_exit_callback(shutdown_server)
drekar_launch_process.wait_exit_callback(shutdown_server)

print("Server started on port", port)
sys.stdout.flush()
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
requires = ["setuptools", "wheel"]

[project]
name = "simple-launch"
version = "0.1.1"
name = "drekar-launch"
version = "0.1.2"
authors = [
{name = "John Wason", email = "[email protected]"}
]
Expand All @@ -13,17 +13,17 @@ requires-python = ">=3.8"
dependencies = [
"pyyaml",
"appdirs",
"simple-launch-process",
"drekar-launch-process",
"jinja2"
]
readme = "README.md"

[project.scripts]
simple-launch = "simple_launch:main"
drekar-launch = "drekar_launch:main"

[tool.setuptools]
py-modules = [
"simple_launch"
"drekar_launch"
]

[project.optional-dependencies]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import sys
import simple_launch_process
import drekar_launch_process
from http import server as http_server
print(sys.argv)

Expand Down Expand Up @@ -31,7 +31,7 @@ def shutdown_server():
print("Receiving shutdown signal")
server.shutdown()

simple_launch_process.wait_exit_callback(shutdown_server)
drekar_launch_process.wait_exit_callback(shutdown_server)

print("Test server started on port", port)
sys.stdout.flush()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test_simple_launch
name: test_drekar_launch
tasks:
- name: test_http_server_1
program: python
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set server_text = "test_server_3_j2"%}

name: test_simple_launch
name: test_drekar_launch
tasks:
- name: test_http_server_1
program: python
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test_simple_launch
name: test_drekar_launch
tasks:
- name: test_http_server_1
program: python
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test_simple_launch
name: test_drekar_launch
tasks:
- name: test_http_server_1
program: python
Expand Down
Loading

0 comments on commit efeb8e0

Please sign in to comment.