mine 4.0.4__tar.gz → 4.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mine-4.0.4 → mine-4.2}/PKG-INFO +1 -1
- {mine-4.0.4 → mine-4.2}/mine/cli.py +28 -40
- mine-4.2/mine/daemon.py +29 -0
- {mine-4.0.4 → mine-4.2}/mine/manager.py +5 -5
- {mine-4.0.4 → mine-4.2}/mine/models/application.py +1 -8
- {mine-4.0.4 → mine-4.2}/mine/models/data.py +48 -45
- {mine-4.0.4 → mine-4.2}/mine/models/status.py +9 -10
- {mine-4.0.4 → mine-4.2}/mine/services.py +2 -1
- {mine-4.0.4 → mine-4.2}/mine/tests/test_cli.py +5 -5
- mine-4.2/mine/tests/test_models_data.py +44 -0
- {mine-4.0.4 → mine-4.2}/mine/tests/test_models_status.py +2 -2
- {mine-4.0.4 → mine-4.2}/pyproject.toml +1 -1
- mine-4.0.4/mine/tests/test_models_data.py +0 -33
- {mine-4.0.4 → mine-4.2}/LICENSE.md +0 -0
- {mine-4.0.4 → mine-4.2}/README.md +0 -0
- {mine-4.0.4 → mine-4.2}/mine/__init__.py +0 -0
- {mine-4.0.4 → mine-4.2}/mine/common.py +0 -0
- {mine-4.0.4 → mine-4.2}/mine/models/__init__.py +0 -0
- {mine-4.0.4 → mine-4.2}/mine/models/computer.py +0 -0
- {mine-4.0.4 → mine-4.2}/mine/models/config.py +0 -0
- {mine-4.0.4 → mine-4.2}/mine/models/timestamp.py +0 -0
- {mine-4.0.4 → mine-4.2}/mine/settings.py +0 -0
- {mine-4.0.4 → mine-4.2}/mine/tests/__init__.py +0 -0
- {mine-4.0.4 → mine-4.2}/mine/tests/conftest.py +0 -0
- {mine-4.0.4 → mine-4.2}/mine/tests/files/.gitignore +0 -0
- {mine-4.0.4 → mine-4.2}/mine/tests/files/mine-in.yml +0 -0
- {mine-4.0.4 → mine-4.2}/mine/tests/files/mine-out.yml +0 -0
- {mine-4.0.4 → mine-4.2}/mine/tests/test_manager.py +0 -0
- {mine-4.0.4 → mine-4.2}/mine/tests/test_models_application.py +0 -0
- {mine-4.0.4 → mine-4.2}/mine/tests/test_models_computer.py +0 -0
- {mine-4.0.4 → mine-4.2}/mine/tests/test_models_config.py +0 -0
- {mine-4.0.4 → mine-4.2}/mine/tests/test_models_timestamp.py +0 -0
- {mine-4.0.4 → mine-4.2}/mine/tests/test_services.py +0 -0
{mine-4.0.4 → mine-4.2}/PKG-INFO
RENAMED
|
@@ -3,20 +3,16 @@
|
|
|
3
3
|
"""Command-line interface."""
|
|
4
4
|
|
|
5
5
|
import argparse
|
|
6
|
-
import subprocess
|
|
7
6
|
import sys
|
|
8
7
|
import time
|
|
9
8
|
|
|
10
9
|
import datafiles
|
|
11
10
|
import log
|
|
12
|
-
from datafiles.model import create_model
|
|
13
11
|
from startfile import startfile
|
|
14
12
|
|
|
15
|
-
from . import CLI, DESCRIPTION, VERSION, common, services
|
|
16
|
-
from .manager import
|
|
17
|
-
from .models import
|
|
18
|
-
|
|
19
|
-
daemon = Application("Mine", versions=Versions(mac=CLI, windows=CLI, linux=CLI))
|
|
13
|
+
from . import CLI, DESCRIPTION, VERSION, common, daemon, services
|
|
14
|
+
from .manager import get_manager
|
|
15
|
+
from .models import Data
|
|
20
16
|
|
|
21
17
|
|
|
22
18
|
def main(args=None):
|
|
@@ -111,11 +107,17 @@ def main(args=None):
|
|
|
111
107
|
action="store_true",
|
|
112
108
|
help="actually delete the conflicted files",
|
|
113
109
|
)
|
|
110
|
+
sub.add_argument(
|
|
111
|
+
"-r",
|
|
112
|
+
"--reset",
|
|
113
|
+
action="store_true",
|
|
114
|
+
help="reset the internal status counter",
|
|
115
|
+
)
|
|
114
116
|
sub.add_argument(
|
|
115
117
|
"-s",
|
|
116
118
|
"--stop",
|
|
117
119
|
action="store_true",
|
|
118
|
-
help="stop the background daemon process
|
|
120
|
+
help="stop the background daemon process",
|
|
119
121
|
)
|
|
120
122
|
|
|
121
123
|
# Parse arguments
|
|
@@ -130,6 +132,7 @@ def main(args=None):
|
|
|
130
132
|
elif args.command == "clean":
|
|
131
133
|
kwargs["delete"] = True
|
|
132
134
|
kwargs["force"] = args.force
|
|
135
|
+
kwargs["reset"] = args.reset
|
|
133
136
|
kwargs["stop"] = args.stop
|
|
134
137
|
|
|
135
138
|
# Configure logging
|
|
@@ -161,6 +164,7 @@ def run(
|
|
|
161
164
|
edit=False,
|
|
162
165
|
delete=False,
|
|
163
166
|
force=False,
|
|
167
|
+
reset=False,
|
|
164
168
|
stop=False,
|
|
165
169
|
):
|
|
166
170
|
"""Run the program.
|
|
@@ -175,28 +179,28 @@ def run(
|
|
|
175
179
|
|
|
176
180
|
:param delete: attempt to delete conflicted files
|
|
177
181
|
:param force: actually delete conflicted files
|
|
182
|
+
:param reset: reset the internal status counter
|
|
178
183
|
:param stop: stop the background daemon process
|
|
179
184
|
|
|
180
|
-
"""
|
|
185
|
+
"""
|
|
181
186
|
manager = get_manager()
|
|
182
187
|
if not manager.is_running(services.APPLICATION):
|
|
183
188
|
manager.start(services.APPLICATION)
|
|
184
189
|
|
|
185
190
|
root = services.find_root()
|
|
186
191
|
path = path or services.find_config_path(root=root)
|
|
187
|
-
|
|
188
|
-
data: Data = create_model(Data, pattern=path, defaults=True)()
|
|
189
|
-
|
|
190
|
-
config = data.config
|
|
191
|
-
status = data.status
|
|
192
|
+
data = Data(path)
|
|
192
193
|
|
|
193
194
|
log.info("Identifying current computer...")
|
|
194
195
|
with datafiles.frozen(data):
|
|
195
|
-
computer = config.get_current_computer()
|
|
196
|
+
computer = data.config.get_current_computer()
|
|
196
197
|
log.info("Current computer: %s", computer)
|
|
197
198
|
|
|
198
199
|
if stop:
|
|
199
|
-
|
|
200
|
+
daemon.stop(manager)
|
|
201
|
+
if reset:
|
|
202
|
+
with datafiles.frozen(data):
|
|
203
|
+
data.prune_status(reset_counter=True)
|
|
200
204
|
if edit:
|
|
201
205
|
return startfile(path)
|
|
202
206
|
if delete:
|
|
@@ -205,22 +209,22 @@ def run(
|
|
|
205
209
|
if switch is True:
|
|
206
210
|
switch = computer
|
|
207
211
|
elif switch is False:
|
|
208
|
-
data.close_all_applications(
|
|
212
|
+
data.close_all_applications(manager)
|
|
209
213
|
elif switch:
|
|
210
|
-
switch = config.match_computer(switch)
|
|
214
|
+
switch = data.config.match_computer(switch)
|
|
211
215
|
|
|
212
216
|
if switch:
|
|
213
217
|
if switch != computer:
|
|
214
|
-
data.close_all_applications(
|
|
215
|
-
data.queue_all_applications(
|
|
218
|
+
data.close_all_applications(manager)
|
|
219
|
+
data.queue_all_applications(switch)
|
|
216
220
|
|
|
217
221
|
while True:
|
|
218
222
|
if services.delete_conflicts(root, config_only=True, force=True):
|
|
219
223
|
log.info("Delaying 10 seconds for changes to delete...")
|
|
220
224
|
time.sleep(10)
|
|
221
225
|
with datafiles.frozen(data):
|
|
222
|
-
data.launch_queued_applications(
|
|
223
|
-
data.update_status(
|
|
226
|
+
data.launch_queued_applications(computer, manager)
|
|
227
|
+
data.update_status(computer, manager)
|
|
224
228
|
|
|
225
229
|
if delay is None or delay <= 0:
|
|
226
230
|
break
|
|
@@ -244,26 +248,10 @@ def run(
|
|
|
244
248
|
|
|
245
249
|
if cleanup:
|
|
246
250
|
with datafiles.frozen(data):
|
|
247
|
-
data.prune_status(
|
|
251
|
+
data.prune_status()
|
|
248
252
|
|
|
249
253
|
if delay is None:
|
|
250
|
-
return
|
|
251
|
-
|
|
252
|
-
return True
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
def _restart_daemon(manager: BaseManager):
|
|
256
|
-
cmd = "nohup {} --daemon --verbose >> /tmp/mine.log 2>&1 &".format(CLI)
|
|
257
|
-
if daemon and not manager.is_running(daemon):
|
|
258
|
-
log.warning("Daemon is not running, attempting to restart...")
|
|
259
|
-
|
|
260
|
-
log.info("$ %s", cmd)
|
|
261
|
-
subprocess.call(cmd, shell=True)
|
|
262
|
-
if manager.is_running(daemon):
|
|
263
|
-
return True
|
|
264
|
-
|
|
265
|
-
log.error("Manually start daemon: %s", cmd)
|
|
266
|
-
return False
|
|
254
|
+
return daemon.restart(manager)
|
|
267
255
|
|
|
268
256
|
return True
|
|
269
257
|
|
mine-4.2/mine/daemon.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
|
|
3
|
+
import log
|
|
4
|
+
|
|
5
|
+
from . import CLI
|
|
6
|
+
from .manager import Manager
|
|
7
|
+
from .models import Application, Versions
|
|
8
|
+
|
|
9
|
+
application = Application("Mine", versions=Versions(mac=CLI, windows=CLI, linux=CLI))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def stop(manager: Manager):
|
|
13
|
+
manager.stop(application)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def restart(manager: Manager):
|
|
17
|
+
cmd = "nohup {} --daemon --verbose >> /tmp/mine.log 2>&1 &".format(CLI)
|
|
18
|
+
if application and not manager.is_running(application):
|
|
19
|
+
log.warning("Daemon is not running, attempting to restart...")
|
|
20
|
+
|
|
21
|
+
log.info("$ %s", cmd)
|
|
22
|
+
subprocess.call(cmd, shell=True)
|
|
23
|
+
if manager.is_running(application):
|
|
24
|
+
return True
|
|
25
|
+
|
|
26
|
+
log.error("Manually start daemon: %s", cmd)
|
|
27
|
+
return False
|
|
28
|
+
|
|
29
|
+
return True
|
|
@@ -50,7 +50,7 @@ def log_stopping(func):
|
|
|
50
50
|
return wrapped
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
class
|
|
53
|
+
class Manager(metaclass=abc.ABCMeta): # pragma: no cover (abstract)
|
|
54
54
|
"""Base application manager."""
|
|
55
55
|
|
|
56
56
|
NAME = FRIENDLY = ""
|
|
@@ -111,7 +111,7 @@ class BaseManager(metaclass=abc.ABCMeta): # pragma: no cover (abstract)
|
|
|
111
111
|
return None
|
|
112
112
|
|
|
113
113
|
|
|
114
|
-
class LinuxManager(
|
|
114
|
+
class LinuxManager(Manager): # pragma: no cover (manual)
|
|
115
115
|
"""Application manager for Linux."""
|
|
116
116
|
|
|
117
117
|
NAME = "Linux"
|
|
@@ -138,7 +138,7 @@ class LinuxManager(BaseManager): # pragma: no cover (manual)
|
|
|
138
138
|
break
|
|
139
139
|
|
|
140
140
|
|
|
141
|
-
class MacManager(
|
|
141
|
+
class MacManager(Manager): # pragma: no cover (manual)
|
|
142
142
|
"""Application manager for macOS."""
|
|
143
143
|
|
|
144
144
|
NAME = "Darwin"
|
|
@@ -207,7 +207,7 @@ class MacManager(BaseManager): # pragma: no cover (manual)
|
|
|
207
207
|
return process
|
|
208
208
|
|
|
209
209
|
|
|
210
|
-
class WindowsManager(
|
|
210
|
+
class WindowsManager(Manager): # pragma: no cover (manual)
|
|
211
211
|
"""Application manager for Windows."""
|
|
212
212
|
|
|
213
213
|
NAME = "Windows"
|
|
@@ -223,7 +223,7 @@ class WindowsManager(BaseManager): # pragma: no cover (manual)
|
|
|
223
223
|
pass
|
|
224
224
|
|
|
225
225
|
|
|
226
|
-
def get_manager(name=None) ->
|
|
226
|
+
def get_manager(name=None) -> Manager:
|
|
227
227
|
"""Return an application manager for the current operating system."""
|
|
228
228
|
log.info("Detecting the operating system...")
|
|
229
229
|
name = name or platform.system()
|
|
@@ -18,6 +18,7 @@ class Properties:
|
|
|
18
18
|
|
|
19
19
|
auto_queue: bool = False
|
|
20
20
|
single_instance: bool = False
|
|
21
|
+
keep_running: bool = False
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
@dataclass
|
|
@@ -39,11 +40,3 @@ class Application:
|
|
|
39
40
|
|
|
40
41
|
def __lt__(self, other):
|
|
41
42
|
return str(self).lower() < str(other).lower()
|
|
42
|
-
|
|
43
|
-
@property
|
|
44
|
-
def auto_queue(self):
|
|
45
|
-
return self.properties.auto_queue
|
|
46
|
-
|
|
47
|
-
@property
|
|
48
|
-
def no_wait(self):
|
|
49
|
-
return not self.properties.single_instance
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
"""Data structures that combine all program data."""
|
|
2
2
|
|
|
3
|
-
from dataclasses import dataclass, field
|
|
4
3
|
|
|
5
4
|
import crayons
|
|
6
5
|
import log
|
|
6
|
+
from datafiles import datafile, field
|
|
7
7
|
|
|
8
|
-
from ..manager import
|
|
8
|
+
from ..manager import Manager
|
|
9
|
+
from .computer import Computer
|
|
9
10
|
from .config import ProgramConfig
|
|
10
11
|
from .status import ProgramStatus
|
|
11
12
|
|
|
12
13
|
|
|
13
|
-
@
|
|
14
|
+
@datafile("{self.path}", defaults=True)
|
|
14
15
|
class Data:
|
|
15
16
|
"""Primary wrapper for all settings."""
|
|
16
17
|
|
|
18
|
+
path: str
|
|
17
19
|
config: ProgramConfig = field(default_factory=ProgramConfig)
|
|
18
20
|
status: ProgramStatus = field(default_factory=ProgramStatus)
|
|
19
21
|
|
|
@@ -29,45 +31,49 @@ class Data:
|
|
|
29
31
|
self._last_counter = self.status.counter
|
|
30
32
|
return changed
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
def prune_status(config: ProgramConfig, status: ProgramStatus):
|
|
34
|
+
def prune_status(self, *, reset_counter=False):
|
|
34
35
|
"""Remove undefined applications and computers."""
|
|
35
36
|
log.info("Cleaning up applications and computers...")
|
|
36
|
-
for
|
|
37
|
-
if not config.find_application(
|
|
38
|
-
status.applications.remove(
|
|
39
|
-
log.info("Removed application: %s",
|
|
37
|
+
for status in self.status.applications.copy():
|
|
38
|
+
if not self.config.find_application(status.application):
|
|
39
|
+
self.status.applications.remove(status)
|
|
40
|
+
log.info("Removed application: %s", status)
|
|
40
41
|
else:
|
|
41
|
-
for
|
|
42
|
-
if not config.find_computer(
|
|
43
|
-
|
|
44
|
-
log.info("Removed computer: %s",
|
|
42
|
+
for state in status.computers.copy():
|
|
43
|
+
if not self.config.find_computer(state.computer):
|
|
44
|
+
status.computers.remove(state)
|
|
45
|
+
log.info("Removed computer: %s", state)
|
|
46
|
+
if reset_counter:
|
|
47
|
+
self.status.counter = 0
|
|
48
|
+
for status in self.status.applications:
|
|
49
|
+
for computer in status.computers:
|
|
50
|
+
computer.timestamp.started = 0
|
|
51
|
+
computer.timestamp.stopped = 0
|
|
45
52
|
|
|
46
|
-
|
|
47
|
-
def queue_all_applications(config: ProgramConfig, status: ProgramStatus, computer):
|
|
53
|
+
def queue_all_applications(self, computer: Computer):
|
|
48
54
|
"""Queue applications for launch."""
|
|
49
55
|
log.info("Queuing applications for launch...")
|
|
50
|
-
for application in config.applications:
|
|
51
|
-
if application.auto_queue:
|
|
56
|
+
for application in self.config.applications:
|
|
57
|
+
if application.properties.auto_queue:
|
|
52
58
|
log.debug("Queuing %s on %s...", application, computer)
|
|
53
|
-
status.queue(application, computer)
|
|
59
|
+
self.status.queue(application, computer)
|
|
54
60
|
|
|
55
|
-
|
|
56
|
-
def launch_queued_applications(
|
|
57
|
-
config: ProgramConfig, status: ProgramStatus, computer, manager: BaseManager
|
|
58
|
-
):
|
|
61
|
+
def launch_queued_applications(self, computer: Computer, manager: Manager):
|
|
59
62
|
"""Launch applications that have been queued."""
|
|
60
63
|
log.info("Launching queued applications...")
|
|
61
|
-
for
|
|
62
|
-
if
|
|
63
|
-
application = config.get_application(
|
|
64
|
-
print(crayons.yellow(f"{application} is queued for {
|
|
65
|
-
if
|
|
66
|
-
latest = status.get_latest(application)
|
|
67
|
-
if
|
|
64
|
+
for status in self.status.applications:
|
|
65
|
+
if status.next:
|
|
66
|
+
application = self.config.get_application(status.application)
|
|
67
|
+
print(crayons.yellow(f"{application} is queued for {status.next}"))
|
|
68
|
+
if status.next == computer:
|
|
69
|
+
latest = self.status.get_latest(application)
|
|
70
|
+
if (
|
|
71
|
+
latest in (computer, None)
|
|
72
|
+
or not application.properties.single_instance
|
|
73
|
+
):
|
|
68
74
|
if not manager.is_running(application):
|
|
69
75
|
manager.start(application)
|
|
70
|
-
|
|
76
|
+
status.next = None
|
|
71
77
|
else:
|
|
72
78
|
print(
|
|
73
79
|
crayons.yellow(
|
|
@@ -77,27 +83,24 @@ class Data:
|
|
|
77
83
|
elif manager.is_running(application):
|
|
78
84
|
manager.stop(application)
|
|
79
85
|
|
|
80
|
-
|
|
81
|
-
def close_all_applications(config: ProgramConfig, manager: BaseManager):
|
|
86
|
+
def close_all_applications(self, manager: Manager):
|
|
82
87
|
"""Close all applications running on this computer."""
|
|
83
88
|
log.info("Closing all applications on this computer...")
|
|
84
|
-
for application in config.applications:
|
|
85
|
-
|
|
89
|
+
for application in self.config.applications:
|
|
90
|
+
if not application.properties.keep_running:
|
|
91
|
+
manager.stop(application)
|
|
86
92
|
|
|
87
|
-
|
|
88
|
-
def update_status(
|
|
89
|
-
config: ProgramConfig, status: ProgramStatus, computer, manager: BaseManager
|
|
90
|
-
):
|
|
93
|
+
def update_status(self, computer: Computer, manager: Manager):
|
|
91
94
|
"""Update each application's status."""
|
|
92
95
|
log.info("Recording application status...")
|
|
93
|
-
for application in config.applications:
|
|
94
|
-
latest = status.get_latest(application)
|
|
96
|
+
for application in self.config.applications:
|
|
97
|
+
latest = self.status.get_latest(application)
|
|
95
98
|
if manager.is_running(application):
|
|
96
99
|
if computer != latest:
|
|
97
|
-
if status.is_running(application, computer):
|
|
100
|
+
if self.status.is_running(application, computer):
|
|
98
101
|
# case 1: application just launched remotely
|
|
99
102
|
manager.stop(application)
|
|
100
|
-
status.stop(application, computer)
|
|
103
|
+
self.status.stop(application, computer)
|
|
101
104
|
print(
|
|
102
105
|
crayons.green(f"{application} is now running on {latest}")
|
|
103
106
|
)
|
|
@@ -106,7 +109,7 @@ class Data:
|
|
|
106
109
|
)
|
|
107
110
|
else:
|
|
108
111
|
# case 2: application just launched locally
|
|
109
|
-
status.start(application, computer)
|
|
112
|
+
self.status.start(application, computer)
|
|
110
113
|
print(
|
|
111
114
|
crayons.green(f"{application} is now running on {computer}")
|
|
112
115
|
)
|
|
@@ -114,9 +117,9 @@ class Data:
|
|
|
114
117
|
# case 3: application already running locally
|
|
115
118
|
print(crayons.cyan(f"{application} is running on {computer}"))
|
|
116
119
|
else:
|
|
117
|
-
if status.is_running(application, computer):
|
|
120
|
+
if self.status.is_running(application, computer):
|
|
118
121
|
# case 4: application just closed locally
|
|
119
|
-
status.stop(application, computer)
|
|
122
|
+
self.status.stop(application, computer)
|
|
120
123
|
print(crayons.red(f"{application} is now stopped on {computer}"))
|
|
121
124
|
elif latest:
|
|
122
125
|
# case 5: application already closed locally
|
|
@@ -80,20 +80,20 @@ class Status:
|
|
|
80
80
|
class ProgramStatus:
|
|
81
81
|
"""Dictionary of current program status."""
|
|
82
82
|
|
|
83
|
-
applications: list[Status] = field(default_factory=list)
|
|
84
83
|
counter: int = 0
|
|
84
|
+
applications: list[Status] = field(default_factory=list)
|
|
85
85
|
|
|
86
|
-
def find(self, application):
|
|
86
|
+
def find(self, application: Application):
|
|
87
87
|
"""Return the application status for an application."""
|
|
88
|
-
for
|
|
89
|
-
if
|
|
88
|
+
for status in self.applications:
|
|
89
|
+
if status.application == application.name:
|
|
90
90
|
break
|
|
91
91
|
else:
|
|
92
|
-
|
|
93
|
-
self.applications.append(
|
|
94
|
-
return
|
|
92
|
+
status = Status(application.name)
|
|
93
|
+
self.applications.append(status)
|
|
94
|
+
return status
|
|
95
95
|
|
|
96
|
-
def get_latest(self, application):
|
|
96
|
+
def get_latest(self, application: Application) -> str | None:
|
|
97
97
|
"""Get the last computer's name logged as running an application."""
|
|
98
98
|
for status in self.applications:
|
|
99
99
|
if status.application == application.name:
|
|
@@ -105,14 +105,13 @@ class ProgramStatus:
|
|
|
105
105
|
application,
|
|
106
106
|
", ".join(str(s) for s in states),
|
|
107
107
|
)
|
|
108
|
-
# TODO: consider returning the computer instance
|
|
109
108
|
return states[0].computer
|
|
110
109
|
|
|
111
110
|
log.debug(f"{application} marked as started on: nothing")
|
|
112
111
|
return None
|
|
113
112
|
|
|
114
113
|
@log_running
|
|
115
|
-
def is_running(self, application, computer):
|
|
114
|
+
def is_running(self, application: Application, computer: Computer):
|
|
116
115
|
"""Determine if an application is logged as running on a computer."""
|
|
117
116
|
for status in self.applications:
|
|
118
117
|
if status.application == application.name:
|
|
@@ -74,7 +74,8 @@ def delete_conflicts(root=None, config_only=False, force=False) -> int:
|
|
|
74
74
|
path = os.path.join(dirname, filename)
|
|
75
75
|
if force:
|
|
76
76
|
os.remove(path)
|
|
77
|
-
|
|
77
|
+
if not config_only:
|
|
78
|
+
print(path)
|
|
78
79
|
|
|
79
80
|
if count and not force:
|
|
80
81
|
print(f"\nRun again with '--force' to delete these {count} conflict(s)")
|
|
@@ -48,7 +48,7 @@ class TestMain:
|
|
|
48
48
|
cli.main(["-vvvv"])
|
|
49
49
|
assert mock_log.exception.call_count == 1
|
|
50
50
|
|
|
51
|
-
@patch("mine.
|
|
51
|
+
@patch("mine.daemon.application", None)
|
|
52
52
|
def test_path(self, tmp_path):
|
|
53
53
|
"""Verify a custom setting file path can be used."""
|
|
54
54
|
cli.main(["--file", tmp_path])
|
|
@@ -65,7 +65,7 @@ class TestMain:
|
|
|
65
65
|
cli.main(["--daemon", "42"])
|
|
66
66
|
mock_run.assert_called_once_with(path=None, delay=42)
|
|
67
67
|
|
|
68
|
-
@patch("mine.
|
|
68
|
+
@patch("mine.daemon.application", Application("?"))
|
|
69
69
|
def test_warning_when_daemon_is_not_running(self, tmp_path):
|
|
70
70
|
with pytest.raises(SystemExit):
|
|
71
71
|
cli.main(["--file", tmp_path])
|
|
@@ -92,21 +92,21 @@ class TestClean:
|
|
|
92
92
|
def test_clean(self, mock_run):
|
|
93
93
|
cli.main(["clean"])
|
|
94
94
|
mock_run.assert_called_once_with(
|
|
95
|
-
path=None, delay=None, delete=True, force=False, stop=False
|
|
95
|
+
path=None, delay=None, delete=True, force=False, reset=False, stop=False
|
|
96
96
|
)
|
|
97
97
|
|
|
98
98
|
@patch("mine.cli.run")
|
|
99
99
|
def test_clean_with_force(self, mock_run):
|
|
100
100
|
cli.main(["clean", "--force"])
|
|
101
101
|
mock_run.assert_called_once_with(
|
|
102
|
-
path=None, delay=None, delete=True, force=True, stop=False
|
|
102
|
+
path=None, delay=None, delete=True, force=True, reset=False, stop=False
|
|
103
103
|
)
|
|
104
104
|
|
|
105
105
|
@patch("mine.cli.run")
|
|
106
106
|
def test_clean_with_stop(self, mock_run):
|
|
107
107
|
cli.main(["clean", "--stop"])
|
|
108
108
|
mock_run.assert_called_once_with(
|
|
109
|
-
path=None, delay=None, delete=True, force=False, stop=True
|
|
109
|
+
path=None, delay=None, delete=True, force=False, reset=False, stop=True
|
|
110
110
|
)
|
|
111
111
|
|
|
112
112
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# pylint: disable=unused-variable
|
|
2
|
+
|
|
3
|
+
import datafiles
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from mine.models import Data
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def describe_data():
|
|
10
|
+
@pytest.fixture
|
|
11
|
+
def data(monkeypatch):
|
|
12
|
+
monkeypatch.setattr(datafiles.settings, "HOOKS_ENABLED", False)
|
|
13
|
+
return Data("tmp/mine.yml")
|
|
14
|
+
|
|
15
|
+
def describe_repr():
|
|
16
|
+
def it_should_always_be_a_simple_name(data: Data):
|
|
17
|
+
assert "settings" == repr(data)
|
|
18
|
+
|
|
19
|
+
def describe_modified():
|
|
20
|
+
def is_false_initially(data: Data):
|
|
21
|
+
assert False is data.modified
|
|
22
|
+
|
|
23
|
+
def is_true_when_the_counter_changes(data: Data):
|
|
24
|
+
data.status.counter += 1
|
|
25
|
+
|
|
26
|
+
assert True is data.modified
|
|
27
|
+
|
|
28
|
+
def is_false_after_reading(data: Data):
|
|
29
|
+
data.status.counter += 1
|
|
30
|
+
|
|
31
|
+
print(data.modified)
|
|
32
|
+
|
|
33
|
+
assert False is data.modified
|
|
34
|
+
|
|
35
|
+
def describe_prune_status():
|
|
36
|
+
def it_can_preserve_counter(data: Data):
|
|
37
|
+
data.status.counter = 1
|
|
38
|
+
data.prune_status()
|
|
39
|
+
assert data.status.counter > 0
|
|
40
|
+
|
|
41
|
+
def it_can_reset_counter(data: Data):
|
|
42
|
+
data.status.counter = 1
|
|
43
|
+
data.prune_status(reset_counter=True)
|
|
44
|
+
assert data.status.counter == 0
|
|
@@ -97,8 +97,8 @@ class TestProgramStatus:
|
|
|
97
97
|
def test_queue(self):
|
|
98
98
|
"""Verify queuing an application sets the next computer."""
|
|
99
99
|
self.status.queue(self.application, self.computer)
|
|
100
|
-
|
|
101
|
-
assert self.computer.name ==
|
|
100
|
+
status = self.status.find(self.application)
|
|
101
|
+
assert self.computer.name == status.next
|
|
102
102
|
|
|
103
103
|
def test_start(self):
|
|
104
104
|
"""Verify starting an application adds it to the list."""
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# pylint: disable=unused-variable
|
|
2
|
-
|
|
3
|
-
import datafiles
|
|
4
|
-
import pytest
|
|
5
|
-
|
|
6
|
-
from mine.models import Data
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def describe_data():
|
|
10
|
-
@pytest.fixture
|
|
11
|
-
def data(monkeypatch):
|
|
12
|
-
monkeypatch.setattr(datafiles.settings, "HOOKS_ENABLED", False)
|
|
13
|
-
return Data()
|
|
14
|
-
|
|
15
|
-
def describe_repr():
|
|
16
|
-
def it_should_always_be_a_simple_name(data):
|
|
17
|
-
assert "settings" == repr(data)
|
|
18
|
-
|
|
19
|
-
def describe_modified():
|
|
20
|
-
def is_false_initially(data):
|
|
21
|
-
assert False is data.modified
|
|
22
|
-
|
|
23
|
-
def is_true_when_the_counter_changes(data):
|
|
24
|
-
data.status.counter += 1
|
|
25
|
-
|
|
26
|
-
assert True is data.modified
|
|
27
|
-
|
|
28
|
-
def is_false_after_reading(data):
|
|
29
|
-
data.status.counter += 1
|
|
30
|
-
|
|
31
|
-
print(data.modified)
|
|
32
|
-
|
|
33
|
-
assert False is data.modified
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|