Skip to content

Commit

Permalink
Merge pull request #125 from jacebrowning/keep-running
Browse files Browse the repository at this point in the history
Add an option for applications to keep running
  • Loading branch information
jacebrowning committed Jul 23, 2023
2 parents a43c42b + 5fddcfb commit e83dac8
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 57 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: main

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.10"
- "3.11"

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- uses: Gr1N/setup-poetry@v8

- name: Check dependencies
run: make doctor

- uses: actions/cache@v2
with:
path: .venv
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}

- name: Install dependencies
run: make install

- name: Check code
run: make check

- name: Test code
run: make test

- name: Upload coverage
uses: codecov/codecov-action@v1
with:
fail_ci_if_error: true
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## 4.2 (2023-07-23)

- Added `keep_running` option for applications that can stay running forever.

## 4.1 (2023-07-22)

- Added a flag to manually stop the background daemon process.
Expand Down
9 changes: 1 addition & 8 deletions mine/models/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Properties:

auto_queue: bool = False
single_instance: bool = False
keep_running: bool = False


@dataclass
Expand All @@ -39,11 +40,3 @@ def __ne__(self, other):

def __lt__(self, other):
return str(self).lower() < str(other).lower()

@property
def auto_queue(self):
return self.properties.auto_queue

@property
def no_wait(self):
return not self.properties.single_instance
10 changes: 7 additions & 3 deletions mine/models/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def queue_all_applications(self, computer: Computer):
"""Queue applications for launch."""
log.info("Queuing applications for launch...")
for application in self.config.applications:
if application.auto_queue:
if application.properties.auto_queue:
log.debug("Queuing %s on %s...", application, computer)
self.status.queue(application, computer)

Expand All @@ -67,7 +67,10 @@ def launch_queued_applications(self, computer: Computer, manager: Manager):
print(crayons.yellow(f"{application} is queued for {status.next}"))
if status.next == computer:
latest = self.status.get_latest(application)
if latest in (computer, None) or application.no_wait:
if (
latest in (computer, None)
or not application.properties.single_instance
):
if not manager.is_running(application):
manager.start(application)
status.next = None
Expand All @@ -84,7 +87,8 @@ def close_all_applications(self, manager: Manager):
"""Close all applications running on this computer."""
log.info("Closing all applications on this computer...")
for application in self.config.applications:
manager.stop(application)
if not application.properties.keep_running:
manager.stop(application)

def update_status(self, computer: Computer, manager: Manager):
"""Update each application's status."""
Expand Down
8 changes: 3 additions & 5 deletions mine/tests/test_models_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def describe_data():
@pytest.fixture
def data(monkeypatch):
monkeypatch.setattr(datafiles.settings, "HOOKS_ENABLED", False)
return Data("../../tests/files/mine.yml")
return Data("tmp/mine.yml")

def describe_repr():
def it_should_always_be_a_simple_name(data: Data):
Expand All @@ -34,13 +34,11 @@ def is_false_after_reading(data: Data):

def describe_prune_status():
def it_can_preserve_counter(data: Data):
data.datafile.load() # type: ignore
assert data.status.counter > 0
data.status.counter = 1
data.prune_status()
assert data.status.counter > 0

def it_can_reset_counter(data: Data):
data.datafile.load() # type: ignore
assert data.status.counter > 0
data.status.counter = 1
data.prune_status(reset_counter=True)
assert data.status.counter == 0
3 changes: 1 addition & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]

name = "mine"
version = "4.1"
version = "4.2"
description = "Share application state across computers using Dropbox."

license = "MIT"
Expand Down
6 changes: 4 additions & 2 deletions tests/files/mine-out.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ config:
serial: abc123
address: AA:BB:CC:DD:EE:FF
hostname: Jaces-MacBook
mine: v4.1
mine: v4.2
- name: macbook-pro
serial: def456
address: 11:22:33:44:55:66
hostname: Jaces-MacBook-2
mine: v4.1
mine: v4.2
applications:
- name: itunes
properties:
auto_queue: false
single_instance: false
keep_running: false
versions:
mac: ''
windows: iTunes.exe
Expand All @@ -23,6 +24,7 @@ config:
properties:
auto_queue: false
single_instance: false
keep_running: false
versions:
mac: iPhoto
windows:
Expand Down

0 comments on commit e83dac8

Please sign in to comment.