Skip to content

Commit

Permalink
Merge pull request #119 from jacebrowning/stop-daemon
Browse files Browse the repository at this point in the history
Add a flag to stop the daemon
  • Loading branch information
jacebrowning committed Jul 20, 2023
2 parents ef62039 + fa73fbf commit 15dbba7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
11 changes: 11 additions & 0 deletions mine/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ def main(args=None):
action="store_true",
help="actually delete the conflicted files",
)
sub.add_argument(
"-s",
"--stop",
action="store_true",
help="stop the background daemon process ",
)

# Parse arguments
args = parser.parse_args(args=args)
Expand All @@ -118,6 +124,7 @@ def main(args=None):
elif args.command == "clean":
kwargs["delete"] = True
kwargs["force"] = args.force
kwargs["stop"] = args.stop

# Configure logging
common.configure_logging(args.verbose)
Expand Down Expand Up @@ -148,6 +155,7 @@ def run(
edit=False,
delete=False,
force=False,
stop=False,
):
"""Run the program.
Expand All @@ -161,6 +169,7 @@ def run(
:param delete: attempt to delete conflicted files
:param force: actually delete conflicted files
:param stop: stop the background daemon process
""" # pylint: disable=too-many-arguments,too-many-branches
manager = get_manager()
Expand All @@ -180,6 +189,8 @@ def run(
computer = config.get_current_computer()
log.info("Current computer: %s", computer)

if stop:
manager.stop(daemon)
if edit:
return startfile(path)
if delete:
Expand Down
2 changes: 2 additions & 0 deletions mine/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def stop(self, application):
process = self._get_process(name)
if process.is_running():
process.terminate()
process.wait()


class MacManager(BaseManager): # pragma: no cover (manual)
Expand Down Expand Up @@ -189,6 +190,7 @@ def stop(self, application):
process = self._get_process(name)
if process and process.is_running():
process.terminate()
process.wait()

@staticmethod
def _start_app(path):
Expand Down
13 changes: 11 additions & 2 deletions mine/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,22 @@ class TestClean:
def test_clean(self, mock_run):
cli.main(["clean"])
mock_run.assert_called_once_with(
path=None, delay=None, delete=True, force=False
path=None, delay=None, delete=True, force=False, stop=False
)

@patch("mine.cli.run")
def test_clean_with_force(self, mock_run):
cli.main(["clean", "--force"])
mock_run.assert_called_once_with(path=None, delay=None, delete=True, force=True)
mock_run.assert_called_once_with(
path=None, delay=None, delete=True, force=True, stop=False
)

@patch("mine.cli.run")
def test_clean_with_stop(self, mock_run):
cli.main(["clean", "--stop"])
mock_run.assert_called_once_with(
path=None, delay=None, delete=True, force=False, stop=True
)


class TestEdit:
Expand Down
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.0.1"
version = "4.0.2"
description = "Share application state across computers using Dropbox."

license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions tests/files/mine-out.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ config:
serial: abc123
address: AA:BB:CC:DD:EE:FF
hostname: Jaces-MacBook
mine: v4.0.1
mine: v4.0.2
- name: macbook-pro
serial: def456
address: 11:22:33:44:55:66
hostname: Jaces-MacBook-2
mine: v4.0.1
mine: v4.0.2
applications:
- name: itunes
properties:
Expand Down

0 comments on commit 15dbba7

Please sign in to comment.