cleepcli 1.49.2__tar.gz → 1.49.4__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.
- {cleepcli-1.49.2/cleepcli.egg-info → cleepcli-1.49.4}/PKG-INFO +9 -1
- {cleepcli-1.49.2 → cleepcli-1.49.4}/README.md +8 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/bin/ccli +16 -5
- {cleepcli-1.49.2 → cleepcli-1.49.4}/bin/cleep-cli +16 -5
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/version.py +1 -1
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/watch.py +8 -1
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/watchsvc.py +104 -10
- {cleepcli-1.49.2 → cleepcli-1.49.4/cleepcli.egg-info}/PKG-INFO +9 -1
- {cleepcli-1.49.2 → cleepcli-1.49.4}/tests/test_file_sync_all.py +34 -1
- {cleepcli-1.49.2 → cleepcli-1.49.4}/tests/test_watchsvc.py +87 -4
- {cleepcli-1.49.2 → cleepcli-1.49.4}/LICENSE +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/MANIFEST.in +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/__init__.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/check.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/ci.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/cleepapi.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/config.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/console.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/docs.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/file.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/git.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/module.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/package.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/pico.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/systemd/cleep-watch.service +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/test.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli/tools.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli.egg-info/SOURCES.txt +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli.egg-info/dependency_links.txt +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli.egg-info/requires.txt +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/cleepcli.egg-info/top_level.txt +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/pyproject.toml +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/requirements.txt +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/setup.cfg +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/setup.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/tests/test_check.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/tests/test_config.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/tests/test_console.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/tests/test_coverage.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/tests/test_docs_breaking.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/tests/test_module_scaffold.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/tests/test_pico.py +0 -0
- {cleepcli-1.49.2 → cleepcli-1.49.4}/tests/test_watch.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cleepcli
|
|
3
|
-
Version: 1.49.
|
|
3
|
+
Version: 1.49.4
|
|
4
4
|
Summary: Cleep-cli helps developers to build great Cleep applications from command line.
|
|
5
5
|
Home-page: https://github.com/CleepDevice/cleep-cli
|
|
6
6
|
Author: Tanguy Bonneau
|
|
@@ -96,6 +96,14 @@ cleep-cli watchsvc enable
|
|
|
96
96
|
|
|
97
97
|
The unit runs `cleep-cli watch`, survives `systemctl restart cleep`, and on each start performs a catch-up `syncall` so files written while the watcher was down are applied.
|
|
98
98
|
|
|
99
|
+
After `pip install` / upgrade of `cleepcli`, the next `watchsvc install` (idempotent ensure) restarts the unit when the on-disk binary is newer than the running process, so the watcher loads the new CLI without a forced bounce on every Cleep boot.
|
|
100
|
+
|
|
101
|
+
Resume watching after a deliberate pause (e.g. create-app already ran `modsync`) without catch-up restarting Cleep:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
cleep-cli watchsvc start --skip-catchup
|
|
105
|
+
```
|
|
106
|
+
|
|
99
107
|
Manual one-shot resync (when the UI looks stale) — `syncall` also mints a fresh asset bust and reloads the device UI:
|
|
100
108
|
|
|
101
109
|
```
|
|
@@ -60,6 +60,14 @@ cleep-cli watchsvc enable
|
|
|
60
60
|
|
|
61
61
|
The unit runs `cleep-cli watch`, survives `systemctl restart cleep`, and on each start performs a catch-up `syncall` so files written while the watcher was down are applied.
|
|
62
62
|
|
|
63
|
+
After `pip install` / upgrade of `cleepcli`, the next `watchsvc install` (idempotent ensure) restarts the unit when the on-disk binary is newer than the running process, so the watcher loads the new CLI without a forced bounce on every Cleep boot.
|
|
64
|
+
|
|
65
|
+
Resume watching after a deliberate pause (e.g. create-app already ran `modsync`) without catch-up restarting Cleep:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
cleep-cli watchsvc start --skip-catchup
|
|
69
|
+
```
|
|
70
|
+
|
|
63
71
|
Manual one-shot resync (when the UI looks stale) — `syncall` also mints a fresh asset bust and reloads the device UI:
|
|
64
72
|
|
|
65
73
|
```
|
|
@@ -438,9 +438,14 @@ def watch(quiet, loglevel, rpc_url, skip_catchup):
|
|
|
438
438
|
@click.option(
|
|
439
439
|
'--restart-if-active',
|
|
440
440
|
is_flag=True,
|
|
441
|
-
help='With install: restart
|
|
441
|
+
help='With install: force-restart if already running. Default install also restarts when the unit changed or cleep-cli binary is newer than the running watch.',
|
|
442
442
|
)
|
|
443
|
-
|
|
443
|
+
@click.option(
|
|
444
|
+
'--skip-catchup',
|
|
445
|
+
is_flag=True,
|
|
446
|
+
help='With start: resume watching without catch-up sync/restart (e.g. after create-app modsync).',
|
|
447
|
+
)
|
|
448
|
+
def watchsvc_cmd(action, restart_if_active, skip_catchup):
|
|
444
449
|
"""
|
|
445
450
|
Manage the durable cleep-watch systemd unit.
|
|
446
451
|
|
|
@@ -451,9 +456,14 @@ def watchsvc_cmd(action, restart_if_active):
|
|
|
451
456
|
cleep-cli watchsvc install
|
|
452
457
|
cleep-cli watchsvc enable
|
|
453
458
|
|
|
454
|
-
After
|
|
459
|
+
After ``pip install cleepcli``, a later ``watchsvc install`` (or enable) restarts
|
|
460
|
+
the watcher when the on-disk binary is newer than the running process. Force with::
|
|
461
|
+
|
|
462
|
+
cleep-cli watchsvc install --restart-if-active
|
|
463
|
+
|
|
464
|
+
Resume after a deliberate pause without restarting Cleep::
|
|
455
465
|
|
|
456
|
-
cleep-cli watchsvc
|
|
466
|
+
cleep-cli watchsvc start --skip-catchup
|
|
457
467
|
"""
|
|
458
468
|
svc = WatchService()
|
|
459
469
|
if action == 'status':
|
|
@@ -465,12 +475,13 @@ def watchsvc_cmd(action, restart_if_active):
|
|
|
465
475
|
|
|
466
476
|
if action == 'install':
|
|
467
477
|
ok = svc.install(restart_if_active=restart_if_active)
|
|
478
|
+
elif action == 'start':
|
|
479
|
+
ok = svc.start(skip_catchup=skip_catchup)
|
|
468
480
|
else:
|
|
469
481
|
handlers = {
|
|
470
482
|
'uninstall': svc.uninstall,
|
|
471
483
|
'enable': svc.enable,
|
|
472
484
|
'disable': svc.disable,
|
|
473
|
-
'start': svc.start,
|
|
474
485
|
'stop': svc.stop,
|
|
475
486
|
'restart': svc.restart,
|
|
476
487
|
}
|
|
@@ -438,9 +438,14 @@ def watch(quiet, loglevel, rpc_url, skip_catchup):
|
|
|
438
438
|
@click.option(
|
|
439
439
|
'--restart-if-active',
|
|
440
440
|
is_flag=True,
|
|
441
|
-
help='With install: restart
|
|
441
|
+
help='With install: force-restart if already running. Default install also restarts when the unit changed or cleep-cli binary is newer than the running watch.',
|
|
442
442
|
)
|
|
443
|
-
|
|
443
|
+
@click.option(
|
|
444
|
+
'--skip-catchup',
|
|
445
|
+
is_flag=True,
|
|
446
|
+
help='With start: resume watching without catch-up sync/restart (e.g. after create-app modsync).',
|
|
447
|
+
)
|
|
448
|
+
def watchsvc_cmd(action, restart_if_active, skip_catchup):
|
|
444
449
|
"""
|
|
445
450
|
Manage the durable cleep-watch systemd unit.
|
|
446
451
|
|
|
@@ -451,9 +456,14 @@ def watchsvc_cmd(action, restart_if_active):
|
|
|
451
456
|
cleep-cli watchsvc install
|
|
452
457
|
cleep-cli watchsvc enable
|
|
453
458
|
|
|
454
|
-
After
|
|
459
|
+
After ``pip install cleepcli``, a later ``watchsvc install`` (or enable) restarts
|
|
460
|
+
the watcher when the on-disk binary is newer than the running process. Force with::
|
|
461
|
+
|
|
462
|
+
cleep-cli watchsvc install --restart-if-active
|
|
463
|
+
|
|
464
|
+
Resume after a deliberate pause without restarting Cleep::
|
|
455
465
|
|
|
456
|
-
cleep-cli watchsvc
|
|
466
|
+
cleep-cli watchsvc start --skip-catchup
|
|
457
467
|
"""
|
|
458
468
|
svc = WatchService()
|
|
459
469
|
if action == 'status':
|
|
@@ -465,12 +475,13 @@ def watchsvc_cmd(action, restart_if_active):
|
|
|
465
475
|
|
|
466
476
|
if action == 'install':
|
|
467
477
|
ok = svc.install(restart_if_active=restart_if_active)
|
|
478
|
+
elif action == 'start':
|
|
479
|
+
ok = svc.start(skip_catchup=skip_catchup)
|
|
468
480
|
else:
|
|
469
481
|
handlers = {
|
|
470
482
|
'uninstall': svc.uninstall,
|
|
471
483
|
'enable': svc.enable,
|
|
472
484
|
'disable': svc.disable,
|
|
473
|
-
'start': svc.start,
|
|
474
485
|
'stop': svc.stop,
|
|
475
486
|
'restart': svc.restart,
|
|
476
487
|
}
|
|
@@ -18,7 +18,7 @@ from watchdog.events import (
|
|
|
18
18
|
import watchdog.events as events
|
|
19
19
|
from .cleepapi import CleepApi
|
|
20
20
|
from .file import File
|
|
21
|
-
from .watchsvc import WATCH_SERVICE
|
|
21
|
+
from .watchsvc import WATCH_SERVICE, consume_skip_catchup_once
|
|
22
22
|
|
|
23
23
|
_WATCHED_EVENT_TYPES = (
|
|
24
24
|
EVENT_TYPE_CREATED,
|
|
@@ -558,6 +558,13 @@ class CleepWatchdog:
|
|
|
558
558
|
)
|
|
559
559
|
return False
|
|
560
560
|
|
|
561
|
+
# One-shot flag from ``watchsvc start --skip-catchup`` (create-app resume).
|
|
562
|
+
if consume_skip_catchup_once():
|
|
563
|
+
self.logger.info(
|
|
564
|
+
"Skipping catch-up sync (one-shot flag from watchsvc start)"
|
|
565
|
+
)
|
|
566
|
+
self.catch_up = False
|
|
567
|
+
|
|
561
568
|
# Catch-up before inotify: Desktop (or editors) may have written while
|
|
562
569
|
# this process was stopped (cleep restart, create-app pause, boot).
|
|
563
570
|
if self.catch_up:
|
|
@@ -16,6 +16,48 @@ from .console import Console
|
|
|
16
16
|
|
|
17
17
|
WATCH_SERVICE = "cleep-watch.service"
|
|
18
18
|
WATCH_UNIT_DST = "/lib/systemd/system/%s" % WATCH_SERVICE
|
|
19
|
+
# One-shot flag for ``watchsvc start --skip-catchup``: watch consumes and deletes it.
|
|
20
|
+
SKIP_CATCHUP_ONCE_PATH = "/run/cleep-watch.skip-catchup"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def arm_skip_catchup_once():
|
|
24
|
+
"""
|
|
25
|
+
Arm a one-shot skip of watch catch-up on the next watch process start.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
bool: True if the flag file was written
|
|
29
|
+
"""
|
|
30
|
+
try:
|
|
31
|
+
directory = os.path.dirname(SKIP_CATCHUP_ONCE_PATH)
|
|
32
|
+
if directory:
|
|
33
|
+
os.makedirs(directory, exist_ok=True)
|
|
34
|
+
with open(SKIP_CATCHUP_ONCE_PATH, "w", encoding="utf-8") as handle:
|
|
35
|
+
handle.write("1\n")
|
|
36
|
+
return True
|
|
37
|
+
except OSError as error:
|
|
38
|
+
logging.getLogger("WatchService").error(
|
|
39
|
+
"Unable to arm skip-catchup flag %s: %s",
|
|
40
|
+
SKIP_CATCHUP_ONCE_PATH,
|
|
41
|
+
error,
|
|
42
|
+
)
|
|
43
|
+
return False
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def consume_skip_catchup_once():
|
|
47
|
+
"""
|
|
48
|
+
Consume the one-shot skip-catchup flag if present.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
bool: True when catch-up must be skipped for this watch start
|
|
52
|
+
"""
|
|
53
|
+
if not os.path.exists(SKIP_CATCHUP_ONCE_PATH):
|
|
54
|
+
return False
|
|
55
|
+
try:
|
|
56
|
+
os.remove(SKIP_CATCHUP_ONCE_PATH)
|
|
57
|
+
except OSError:
|
|
58
|
+
# Still honor the flag even if unlink fails (avoid surprise restart).
|
|
59
|
+
pass
|
|
60
|
+
return True
|
|
19
61
|
|
|
20
62
|
|
|
21
63
|
def bundled_unit_path():
|
|
@@ -63,15 +105,54 @@ class WatchService:
|
|
|
63
105
|
return True
|
|
64
106
|
return new != old
|
|
65
107
|
|
|
108
|
+
@staticmethod
|
|
109
|
+
def _cli_executable_path():
|
|
110
|
+
"""
|
|
111
|
+
On-disk ``cleep-cli`` path used by the watch unit ExecStart.
|
|
112
|
+
"""
|
|
113
|
+
return shutil.which("cleep-cli") or "/usr/local/bin/cleep-cli"
|
|
114
|
+
|
|
115
|
+
def _cli_binary_newer_than_running(self):
|
|
116
|
+
"""
|
|
117
|
+
Return True when the installed cleep-cli binary is newer than the
|
|
118
|
+
running watch main process (typical after ``pip install cleepcli``).
|
|
119
|
+
|
|
120
|
+
Used so ``watchsvc install`` (without ``--restart-if-active``) still
|
|
121
|
+
picks up an upgraded CLI once, without bouncing on every Cleep boot.
|
|
122
|
+
"""
|
|
123
|
+
path = self._cli_executable_path()
|
|
124
|
+
if not path or not os.path.isfile(path):
|
|
125
|
+
return False
|
|
126
|
+
try:
|
|
127
|
+
bin_mtime = os.path.getmtime(path)
|
|
128
|
+
except OSError:
|
|
129
|
+
return False
|
|
130
|
+
resp = self._systemctl(
|
|
131
|
+
"show",
|
|
132
|
+
"-p",
|
|
133
|
+
"ExecMainStartTimestampUSec",
|
|
134
|
+
"--value",
|
|
135
|
+
WATCH_SERVICE,
|
|
136
|
+
timeout=5.0,
|
|
137
|
+
)
|
|
138
|
+
raw = "".join(resp.get("stdout") or []).strip()
|
|
139
|
+
if not raw.isdigit():
|
|
140
|
+
return False
|
|
141
|
+
start_sec = int(raw) / 1_000_000.0
|
|
142
|
+
if start_sec <= 0:
|
|
143
|
+
return False
|
|
144
|
+
return bin_mtime > start_sec
|
|
145
|
+
|
|
66
146
|
def install(self, restart_if_active=False):
|
|
67
147
|
"""
|
|
68
148
|
Copy the bundled unit to systemd and reload the daemon.
|
|
69
149
|
|
|
70
150
|
Args:
|
|
71
|
-
restart_if_active (bool): when True, restart the unit if it
|
|
72
|
-
already running
|
|
73
|
-
|
|
74
|
-
|
|
151
|
+
restart_if_active (bool): when True, always restart the unit if it
|
|
152
|
+
is already running. Default False: still restart when the unit
|
|
153
|
+
file changed or when the on-disk cleep-cli binary is newer than
|
|
154
|
+
the running watch process (pip upgrade). Idempotent ensure on
|
|
155
|
+
every Cleep boot must not bounce otherwise (catch-up would
|
|
75
156
|
restart Cleep again).
|
|
76
157
|
|
|
77
158
|
Returns:
|
|
@@ -83,6 +164,7 @@ class WatchService:
|
|
|
83
164
|
return False
|
|
84
165
|
unit_changed = self._unit_content_changed(src)
|
|
85
166
|
was_active = self.is_active()
|
|
167
|
+
cli_upgraded = was_active and self._cli_binary_newer_than_running()
|
|
86
168
|
try:
|
|
87
169
|
os.makedirs(os.path.dirname(WATCH_UNIT_DST), exist_ok=True)
|
|
88
170
|
shutil.copyfile(src, WATCH_UNIT_DST)
|
|
@@ -93,11 +175,15 @@ class WatchService:
|
|
|
93
175
|
self.logger.error("systemctl daemon-reload failed after install")
|
|
94
176
|
return False
|
|
95
177
|
self.logger.info("Installed %s", WATCH_UNIT_DST)
|
|
96
|
-
# Restart
|
|
97
|
-
|
|
98
|
-
if was_active and (restart_if_active or unit_changed):
|
|
178
|
+
# Restart after forced upgrade, unit change, or pip-replaced cleep-cli.
|
|
179
|
+
if was_active and (restart_if_active or unit_changed or cli_upgraded):
|
|
99
180
|
self.logger.info(
|
|
100
|
-
"Restarting %s to apply watcher changes"
|
|
181
|
+
"Restarting %s to apply watcher changes "
|
|
182
|
+
"(forced=%s unit_changed=%s cli_upgraded=%s)",
|
|
183
|
+
WATCH_SERVICE,
|
|
184
|
+
restart_if_active,
|
|
185
|
+
unit_changed,
|
|
186
|
+
cli_upgraded,
|
|
101
187
|
)
|
|
102
188
|
return self.restart()
|
|
103
189
|
return True
|
|
@@ -163,9 +249,15 @@ class WatchService:
|
|
|
163
249
|
)
|
|
164
250
|
return True
|
|
165
251
|
|
|
166
|
-
def start(self):
|
|
252
|
+
def start(self, skip_catchup=False):
|
|
167
253
|
"""
|
|
168
|
-
Start the unit
|
|
254
|
+
Start the unit.
|
|
255
|
+
|
|
256
|
+
Args:
|
|
257
|
+
skip_catchup (bool): when True, arm a one-shot flag so the next
|
|
258
|
+
watch process skips catch-up sync/restart (e.g. resume after
|
|
259
|
+
create-app already ran ``modsync``). Default False: catch-up
|
|
260
|
+
runs on ExecStart.
|
|
169
261
|
|
|
170
262
|
Returns:
|
|
171
263
|
bool: True on success
|
|
@@ -173,6 +265,8 @@ class WatchService:
|
|
|
173
265
|
if not os.path.isfile(WATCH_UNIT_DST):
|
|
174
266
|
if not self.install():
|
|
175
267
|
return False
|
|
268
|
+
if skip_catchup and not arm_skip_catchup_once():
|
|
269
|
+
return False
|
|
176
270
|
resp = self._systemctl("start", WATCH_SERVICE)
|
|
177
271
|
if not self._ok(resp):
|
|
178
272
|
self.logger.error(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cleepcli
|
|
3
|
-
Version: 1.49.
|
|
3
|
+
Version: 1.49.4
|
|
4
4
|
Summary: Cleep-cli helps developers to build great Cleep applications from command line.
|
|
5
5
|
Home-page: https://github.com/CleepDevice/cleep-cli
|
|
6
6
|
Author: Tanguy Bonneau
|
|
@@ -96,6 +96,14 @@ cleep-cli watchsvc enable
|
|
|
96
96
|
|
|
97
97
|
The unit runs `cleep-cli watch`, survives `systemctl restart cleep`, and on each start performs a catch-up `syncall` so files written while the watcher was down are applied.
|
|
98
98
|
|
|
99
|
+
After `pip install` / upgrade of `cleepcli`, the next `watchsvc install` (idempotent ensure) restarts the unit when the on-disk binary is newer than the running process, so the watcher loads the new CLI without a forced bounce on every Cleep boot.
|
|
100
|
+
|
|
101
|
+
Resume watching after a deliberate pause (e.g. create-app already ran `modsync`) without catch-up restarting Cleep:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
cleep-cli watchsvc start --skip-catchup
|
|
105
|
+
```
|
|
106
|
+
|
|
99
107
|
Manual one-shot resync (when the UI looks stale) — `syncall` also mints a fresh asset bust and reloads the device UI:
|
|
100
108
|
|
|
101
109
|
```
|
|
@@ -91,6 +91,8 @@ def test_watch_catch_up_calls_sync_all():
|
|
|
91
91
|
"cleepcli.watch.ActionsExecutor"
|
|
92
92
|
) as executor_cls, patch(
|
|
93
93
|
"cleepcli.watch.time.sleep", side_effect=KeyboardInterrupt
|
|
94
|
+
), patch(
|
|
95
|
+
"cleepcli.watch.consume_skip_catchup_once", return_value=False
|
|
94
96
|
):
|
|
95
97
|
file_cls.return_value.sync_all.return_value = True
|
|
96
98
|
handler = handler_cls.return_value
|
|
@@ -117,7 +119,9 @@ def test_watch_catch_up_fails_when_backend_restart_fails():
|
|
|
117
119
|
"cleepcli.watch.CleepHandler"
|
|
118
120
|
) as handler_cls, patch(
|
|
119
121
|
"cleepcli.watch.ActionsExecutor"
|
|
120
|
-
) as executor_cls
|
|
122
|
+
) as executor_cls, patch(
|
|
123
|
+
"cleepcli.watch.consume_skip_catchup_once", return_value=False
|
|
124
|
+
):
|
|
121
125
|
file_cls.return_value.sync_all.return_value = True
|
|
122
126
|
handler_cls.return_value._watched = {"/tmp"}
|
|
123
127
|
executor = executor_cls.return_value
|
|
@@ -140,6 +144,8 @@ def test_watch_skip_catch_up():
|
|
|
140
144
|
"cleepcli.watch.ActionsExecutor"
|
|
141
145
|
) as executor_cls, patch(
|
|
142
146
|
"cleepcli.watch.time.sleep", side_effect=KeyboardInterrupt
|
|
147
|
+
), patch(
|
|
148
|
+
"cleepcli.watch.consume_skip_catchup_once", return_value=False
|
|
143
149
|
):
|
|
144
150
|
handler = handler_cls.return_value
|
|
145
151
|
handler._watched = {"/tmp"}
|
|
@@ -155,3 +161,30 @@ def test_watch_skip_catch_up():
|
|
|
155
161
|
executor.cleep.ensure_frontend_nocache.assert_not_called()
|
|
156
162
|
executor.cleep.restart_backend.assert_not_called()
|
|
157
163
|
executor.cleep.restart_frontend.assert_not_called()
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def test_watch_consumes_skip_catchup_once_flag():
|
|
167
|
+
CleepWatchdog = _import_watch_with_fake_watchdog()
|
|
168
|
+
|
|
169
|
+
with patch("cleepcli.watch.File") as file_cls, patch(
|
|
170
|
+
"cleepcli.watch.os.path.exists", return_value=True
|
|
171
|
+
), patch("cleepcli.watch.Observer"), patch(
|
|
172
|
+
"cleepcli.watch.CleepHandler"
|
|
173
|
+
) as handler_cls, patch(
|
|
174
|
+
"cleepcli.watch.ActionsExecutor"
|
|
175
|
+
) as executor_cls, patch(
|
|
176
|
+
"cleepcli.watch.time.sleep", side_effect=KeyboardInterrupt
|
|
177
|
+
), patch(
|
|
178
|
+
"cleepcli.watch.consume_skip_catchup_once", return_value=True
|
|
179
|
+
):
|
|
180
|
+
handler = handler_cls.return_value
|
|
181
|
+
handler._watched = {"/tmp"}
|
|
182
|
+
handler.schedule_all = Mock()
|
|
183
|
+
executor = executor_cls.return_value
|
|
184
|
+
executor.cleep.ensure_frontend_nocache = Mock()
|
|
185
|
+
executor.cleep.restart_backend = Mock()
|
|
186
|
+
|
|
187
|
+
watchdog = CleepWatchdog("https://127.0.0.1:443", catch_up=True)
|
|
188
|
+
assert watchdog.watch() is True
|
|
189
|
+
file_cls.return_value.sync_all.assert_not_called()
|
|
190
|
+
executor.cleep.restart_backend.assert_not_called()
|
|
@@ -4,7 +4,13 @@
|
|
|
4
4
|
import os
|
|
5
5
|
from unittest.mock import Mock, patch
|
|
6
6
|
|
|
7
|
-
from cleepcli.watchsvc import
|
|
7
|
+
from cleepcli.watchsvc import (
|
|
8
|
+
WatchService,
|
|
9
|
+
WATCH_UNIT_DST,
|
|
10
|
+
arm_skip_catchup_once,
|
|
11
|
+
bundled_unit_path,
|
|
12
|
+
consume_skip_catchup_once,
|
|
13
|
+
)
|
|
8
14
|
|
|
9
15
|
|
|
10
16
|
def test_bundled_unit_path_exists():
|
|
@@ -42,7 +48,7 @@ def test_install_does_not_restart_when_active_and_unit_unchanged():
|
|
|
42
48
|
"cleepcli.watchsvc.os.makedirs"
|
|
43
49
|
), patch("cleepcli.watchsvc.os.path.isfile", return_value=True), patch.object(
|
|
44
50
|
svc, "_unit_content_changed", return_value=False
|
|
45
|
-
):
|
|
51
|
+
), patch.object(svc, "_cli_binary_newer_than_running", return_value=False):
|
|
46
52
|
assert svc.install() is True
|
|
47
53
|
svc.restart.assert_not_called()
|
|
48
54
|
|
|
@@ -58,7 +64,7 @@ def test_install_restarts_when_active_and_unit_changed():
|
|
|
58
64
|
"cleepcli.watchsvc.os.makedirs"
|
|
59
65
|
), patch("cleepcli.watchsvc.os.path.isfile", return_value=True), patch.object(
|
|
60
66
|
svc, "_unit_content_changed", return_value=True
|
|
61
|
-
):
|
|
67
|
+
), patch.object(svc, "_cli_binary_newer_than_running", return_value=False):
|
|
62
68
|
assert svc.install() is True
|
|
63
69
|
svc.restart.assert_called_once_with()
|
|
64
70
|
|
|
@@ -74,11 +80,49 @@ def test_install_restarts_when_flag_and_active():
|
|
|
74
80
|
"cleepcli.watchsvc.os.makedirs"
|
|
75
81
|
), patch("cleepcli.watchsvc.os.path.isfile", return_value=True), patch.object(
|
|
76
82
|
svc, "_unit_content_changed", return_value=False
|
|
77
|
-
):
|
|
83
|
+
), patch.object(svc, "_cli_binary_newer_than_running", return_value=False):
|
|
78
84
|
assert svc.install(restart_if_active=True) is True
|
|
79
85
|
svc.restart.assert_called_once_with()
|
|
80
86
|
|
|
81
87
|
|
|
88
|
+
def test_install_restarts_when_cli_binary_newer_than_running():
|
|
89
|
+
"""pip upgrade leaves a newer on-disk binary; install must bounce watch once."""
|
|
90
|
+
svc = WatchService()
|
|
91
|
+
svc.console = Mock()
|
|
92
|
+
svc.console.command.return_value = {"returncode": 0, "stdout": "", "stderr": ""}
|
|
93
|
+
svc.is_active = Mock(return_value=True)
|
|
94
|
+
svc.restart = Mock(return_value=True)
|
|
95
|
+
|
|
96
|
+
with patch("cleepcli.watchsvc.shutil.copyfile"), patch(
|
|
97
|
+
"cleepcli.watchsvc.os.makedirs"
|
|
98
|
+
), patch("cleepcli.watchsvc.os.path.isfile", return_value=True), patch.object(
|
|
99
|
+
svc, "_unit_content_changed", return_value=False
|
|
100
|
+
), patch.object(svc, "_cli_binary_newer_than_running", return_value=True):
|
|
101
|
+
assert svc.install() is True
|
|
102
|
+
svc.restart.assert_called_once_with()
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def test_cli_binary_newer_than_running_compares_mtime_to_service_start():
|
|
106
|
+
svc = WatchService()
|
|
107
|
+
svc.console = Mock()
|
|
108
|
+
# service started at t=100s (100_000_000 us)
|
|
109
|
+
svc.console.command.return_value = {
|
|
110
|
+
"returncode": 0,
|
|
111
|
+
"stdout": ["100000000"],
|
|
112
|
+
"stderr": "",
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
with patch.object(WatchService, "_cli_executable_path", return_value="/usr/local/bin/cleep-cli"), patch(
|
|
116
|
+
"cleepcli.watchsvc.os.path.isfile", return_value=True
|
|
117
|
+
), patch("cleepcli.watchsvc.os.path.getmtime", return_value=150.0):
|
|
118
|
+
assert svc._cli_binary_newer_than_running() is True
|
|
119
|
+
|
|
120
|
+
with patch.object(WatchService, "_cli_executable_path", return_value="/usr/local/bin/cleep-cli"), patch(
|
|
121
|
+
"cleepcli.watchsvc.os.path.isfile", return_value=True
|
|
122
|
+
), patch("cleepcli.watchsvc.os.path.getmtime", return_value=50.0):
|
|
123
|
+
assert svc._cli_binary_newer_than_running() is False
|
|
124
|
+
|
|
125
|
+
|
|
82
126
|
def test_enable_installs_when_missing():
|
|
83
127
|
svc = WatchService()
|
|
84
128
|
svc.install = Mock(return_value=True)
|
|
@@ -107,3 +151,42 @@ def test_status_active():
|
|
|
107
151
|
}
|
|
108
152
|
with patch("cleepcli.watchsvc.os.path.isfile", return_value=True):
|
|
109
153
|
assert svc.status() == "active"
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def test_start_skip_catchup_arms_flag():
|
|
157
|
+
svc = WatchService()
|
|
158
|
+
svc.console = Mock()
|
|
159
|
+
svc.console.command.return_value = {"returncode": 0, "stdout": "", "stderr": ""}
|
|
160
|
+
|
|
161
|
+
with patch("cleepcli.watchsvc.os.path.isfile", return_value=True), patch(
|
|
162
|
+
"cleepcli.watchsvc.arm_skip_catchup_once", return_value=True
|
|
163
|
+
) as arm:
|
|
164
|
+
assert svc.start(skip_catchup=True) is True
|
|
165
|
+
arm.assert_called_once_with()
|
|
166
|
+
svc.console.command.assert_called_with(
|
|
167
|
+
"/bin/systemctl start %s" % "cleep-watch.service", 60.0
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def test_start_default_does_not_arm_skip_catchup():
|
|
172
|
+
svc = WatchService()
|
|
173
|
+
svc.console = Mock()
|
|
174
|
+
svc.console.command.return_value = {"returncode": 0, "stdout": "", "stderr": ""}
|
|
175
|
+
|
|
176
|
+
with patch("cleepcli.watchsvc.os.path.isfile", return_value=True), patch(
|
|
177
|
+
"cleepcli.watchsvc.arm_skip_catchup_once"
|
|
178
|
+
) as arm:
|
|
179
|
+
assert svc.start() is True
|
|
180
|
+
arm.assert_not_called()
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def test_arm_and_consume_skip_catchup_once(tmp_path, monkeypatch):
|
|
184
|
+
flag = tmp_path / "cleep-watch.skip-catchup"
|
|
185
|
+
monkeypatch.setattr("cleepcli.watchsvc.SKIP_CATCHUP_ONCE_PATH", str(flag))
|
|
186
|
+
|
|
187
|
+
assert consume_skip_catchup_once() is False
|
|
188
|
+
assert arm_skip_catchup_once() is True
|
|
189
|
+
assert flag.is_file()
|
|
190
|
+
assert consume_skip_catchup_once() is True
|
|
191
|
+
assert not flag.exists()
|
|
192
|
+
assert consume_skip_catchup_once() is False
|
|
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
|
|
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
|