ScriptCollection 4.4.65__py3-none-any.whl → 4.4.67__py3-none-any.whl
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.
- ScriptCollection/AgentRunner.py +15 -2
- ScriptCollection/AgentStatusReporting/AgentStatus.py +16 -0
- ScriptCollection/AgentStatusReporting/AgentStatusEventChannel.py +36 -0
- ScriptCollection/AgentStatusReporting/AgentStatusRelay.py +87 -0
- ScriptCollection/AgentStatusReporting/AgentStatusReporter.py +14 -0
- ScriptCollection/AgentStatusReporting/AgentStatusReportingSession.py +76 -0
- ScriptCollection/AgentStatusReporting/HerdrAgentStatusReporter.py +72 -0
- ScriptCollection/AgentStatusReporting/__init__.py +0 -0
- ScriptCollection/ScriptCollectionCore.py +1 -1
- ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py +7 -6
- ScriptCollection/TFCPS/TFCPS_Tools_General.py +0 -6
- {scriptcollection-4.4.65.dist-info → scriptcollection-4.4.67.dist-info}/METADATA +13 -8
- {scriptcollection-4.4.65.dist-info → scriptcollection-4.4.67.dist-info}/RECORD +16 -9
- {scriptcollection-4.4.65.dist-info → scriptcollection-4.4.67.dist-info}/WHEEL +0 -0
- {scriptcollection-4.4.65.dist-info → scriptcollection-4.4.67.dist-info}/entry_points.txt +0 -0
- {scriptcollection-4.4.65.dist-info → scriptcollection-4.4.67.dist-info}/top_level.txt +0 -0
ScriptCollection/AgentRunner.py
CHANGED
|
@@ -7,6 +7,7 @@ from enum import Enum
|
|
|
7
7
|
from .GeneralUtilities import GeneralUtilities
|
|
8
8
|
from .ScriptCollectionCore import ScriptCollectionCore
|
|
9
9
|
from .OCIImages.OCIImageManager import OCIImageManager
|
|
10
|
+
from .AgentStatusReporting.AgentStatusReportingSession import AgentStatusReportingSession
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class CodingAgent(Enum):
|
|
@@ -137,8 +138,11 @@ class AgentRunner:
|
|
|
137
138
|
repository_name = os.path.basename(os.path.normpath(host_repository_folder))
|
|
138
139
|
container_workspace_folder = f"/Workspace/{repository_name}"
|
|
139
140
|
agent_command = self.__get_agent_command(agentRunnerConfiguration.codingagent, prompt, interactive)
|
|
141
|
+
# The status of the agent is reported on the same way for every coding-agent. The session is None if there is nothing to report to.
|
|
142
|
+
status_session = AgentStatusReportingSession.try_create(dict(os.environ), f"scrais-{agentRunnerConfiguration.codingagent.value}", self.verbose)
|
|
143
|
+
status_start_line = None if status_session is None else status_session.get_start_report_line(prompt is not None)
|
|
140
144
|
# The entrypoint is always used: if an initialization-script is present it runs it first, and then always starts the agent.
|
|
141
|
-
entrypoint_script_content = self.__get_entrypoint_script_content(agent_command, initialization_script)
|
|
145
|
+
entrypoint_script_content = self.__get_entrypoint_script_content(agent_command, initialization_script, status_start_line)
|
|
142
146
|
with tempfile.NamedTemporaryFile("w", suffix=".sh", delete=False, newline="\n", encoding="utf-8") as entrypoint_file_handle:
|
|
143
147
|
host_entrypoint_file = entrypoint_file_handle.name
|
|
144
148
|
entrypoint_file_handle.write(entrypoint_script_content)
|
|
@@ -160,13 +164,19 @@ class AgentRunner:
|
|
|
160
164
|
initialization_script_absolute_path = os.path.abspath(initialization_script)
|
|
161
165
|
os.chmod(initialization_script_absolute_path, 0o755)
|
|
162
166
|
docker_command = docker_command + ["--volume", f"{initialization_script_absolute_path.replace(os.sep, '/')}:/Workspace/Temp/InitializationScript.sh:ro"]
|
|
167
|
+
if status_session is not None:
|
|
168
|
+
docker_command = docker_command + status_session.get_volume_arguments()
|
|
163
169
|
image = self.__get_image_to_use(agentRunnerConfiguration.image, host_repository_folder)
|
|
164
170
|
docker_command = docker_command + ["--workdir", container_workspace_folder, "--entrypoint", "sh", image, "/Workspace/Entrypoint.sh"]
|
|
165
171
|
# Nothing is installed in the container; the coding-agent-CLI is assumed to be available in the image.
|
|
166
172
|
# subprocess.run blocks until the container has exited, which happens when the agent is finished (or was terminated by the user in interactive mode).
|
|
167
173
|
# The exit-code of the container is returned (and not checked here), so that the caller can pass it through.
|
|
174
|
+
if status_session is not None:
|
|
175
|
+
status_session.start()
|
|
168
176
|
return subprocess.run(docker_command, check=False).returncode
|
|
169
177
|
finally:
|
|
178
|
+
if status_session is not None:
|
|
179
|
+
status_session.stop()
|
|
170
180
|
GeneralUtilities.ensure_file_does_not_exist(host_entrypoint_file)
|
|
171
181
|
|
|
172
182
|
@GeneralUtilities.check_arguments
|
|
@@ -183,11 +193,12 @@ class AgentRunner:
|
|
|
183
193
|
return configured_image
|
|
184
194
|
|
|
185
195
|
@GeneralUtilities.check_arguments
|
|
186
|
-
def __get_entrypoint_script_content(self, agent_command: list[str], initialization_script: str) -> str:
|
|
196
|
+
def __get_entrypoint_script_content(self, agent_command: list[str], initialization_script: str, status_start_line: str) -> str:
|
|
187
197
|
# The entrypoint-script is always used as the container's entrypoint (located at "/Workspace/Entrypoint.sh").
|
|
188
198
|
# It is regenerated before every container-start, so the decision whether the initialization-script is called is made here in python
|
|
189
199
|
# (no runtime-check in the script): if an initialization-script is present its call is included (and the script is removed afterwards),
|
|
190
200
|
# otherwise it is omitted. Afterwards the agent is always started (via exec, so signals reach the agent).
|
|
201
|
+
# status_start_line is None if the status is not reported; it is the only runtime-check, because only the container knows whether its image supports the status-report.
|
|
191
202
|
agent_command_line = shlex.join(agent_command)
|
|
192
203
|
lines = ["#!/bin/sh", "set -e"]
|
|
193
204
|
if initialization_script is not None:
|
|
@@ -199,6 +210,8 @@ class AgentRunner:
|
|
|
199
210
|
else:
|
|
200
211
|
# The counterpart of the message above: it makes clear that the agent is started unconfigured on purpose because no initialization-script is declared for this repository (see __get_initialization_script).
|
|
201
212
|
lines.append('echo "No initialization-script is configured for this repository; the agent is started without an initialization-script."')
|
|
213
|
+
if status_start_line is not None:
|
|
214
|
+
lines.append(status_start_line)
|
|
202
215
|
lines.append(f"exec {agent_command_line}")
|
|
203
216
|
return "\n".join(lines) + "\n"
|
|
204
217
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class AgentStatus(Enum):
|
|
5
|
+
"""The closed vocabulary of the channel between the container and the host."""
|
|
6
|
+
Working = "working"
|
|
7
|
+
Idle = "idle"
|
|
8
|
+
Blocked = "blocked"
|
|
9
|
+
|
|
10
|
+
@staticmethod
|
|
11
|
+
def parse_token(line: bytes) -> "AgentStatus":
|
|
12
|
+
# The line comes from a file which the container can write, so it is untrusted: only an exact token is accepted and everything else results in None.
|
|
13
|
+
for status in AgentStatus:
|
|
14
|
+
if line == status.value.encode("ascii"):
|
|
15
|
+
return status
|
|
16
|
+
return None
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import tempfile
|
|
3
|
+
from ..GeneralUtilities import GeneralUtilities
|
|
4
|
+
from .AgentStatus import AgentStatus
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class AgentStatusEventChannel:
|
|
8
|
+
"""The channel from the container to the host: one event-file in a dedicated host-folder which is mounted into the container."""
|
|
9
|
+
container_folder: str = "/Workspace/Temp/AgentStatus"
|
|
10
|
+
status_helper: str = "scrais-agent-status"
|
|
11
|
+
__host_folder: str = None
|
|
12
|
+
|
|
13
|
+
@GeneralUtilities.check_arguments
|
|
14
|
+
def __init__(self):
|
|
15
|
+
self.__host_folder = tempfile.mkdtemp(prefix="ScraisAgentStatus")
|
|
16
|
+
# The user of the container is unknown and it can be a user without the capability to bypass file-permissions (see drop_capabilities), so everybody must be able to write.
|
|
17
|
+
os.chmod(self.__host_folder, 0o777)
|
|
18
|
+
GeneralUtilities.ensure_file_exists(self.get_events_file())
|
|
19
|
+
os.chmod(self.get_events_file(), 0o666)
|
|
20
|
+
|
|
21
|
+
@GeneralUtilities.check_arguments
|
|
22
|
+
def get_events_file(self) -> str:
|
|
23
|
+
return os.path.join(self.__host_folder, "events")
|
|
24
|
+
|
|
25
|
+
@GeneralUtilities.check_arguments
|
|
26
|
+
def get_volume_arguments(self) -> list[str]:
|
|
27
|
+
return ["--volume", f"{self.__host_folder.replace(os.sep, '/')}:{self.container_folder}"]
|
|
28
|
+
|
|
29
|
+
@GeneralUtilities.check_arguments
|
|
30
|
+
def get_start_report_line(self, status: AgentStatus) -> str:
|
|
31
|
+
# An image without the status-helper does not report anything. The "|| true" prevents that this line can stop the entrypoint, which runs with "set -e".
|
|
32
|
+
return f"command -v {self.status_helper} >/dev/null 2>&1 && {self.status_helper} {status.value} || true"
|
|
33
|
+
|
|
34
|
+
@GeneralUtilities.check_arguments
|
|
35
|
+
def remove(self) -> None:
|
|
36
|
+
GeneralUtilities.ensure_directory_does_not_exist(self.__host_folder)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import threading
|
|
2
|
+
from ..GeneralUtilities import GeneralUtilities
|
|
3
|
+
from .AgentStatus import AgentStatus
|
|
4
|
+
from .AgentStatusReporter import AgentStatusReporter
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class AgentStatusRelay:
|
|
8
|
+
"""Forwards the valid states from the event-file to a reporter. The file is written by the container, so its content is untrusted.
|
|
9
|
+
To limit what a container can cause, a read is limited in size and it results in at most one report, which is the latest state of that read."""
|
|
10
|
+
poll_interval_in_seconds: float = 0.25
|
|
11
|
+
maximal_line_length: int = 64
|
|
12
|
+
maximal_read_size: int = 65536
|
|
13
|
+
__events_file: str = None
|
|
14
|
+
__reporter: AgentStatusReporter = None
|
|
15
|
+
__verbose: bool = None
|
|
16
|
+
__offset: int = 0
|
|
17
|
+
__unfinished_line: bytes = b""
|
|
18
|
+
__skip_rest_of_line: bool = False
|
|
19
|
+
__last_status: AgentStatus = None
|
|
20
|
+
__stop_requested: threading.Event = None
|
|
21
|
+
__thread: threading.Thread = None
|
|
22
|
+
|
|
23
|
+
@GeneralUtilities.check_arguments
|
|
24
|
+
def __init__(self, events_file: str, reporter: AgentStatusReporter, verbose: bool):
|
|
25
|
+
self.__events_file = events_file
|
|
26
|
+
self.__reporter = reporter
|
|
27
|
+
self.__verbose = verbose
|
|
28
|
+
self.__offset = 0
|
|
29
|
+
self.__unfinished_line = b""
|
|
30
|
+
self.__skip_rest_of_line = False
|
|
31
|
+
self.__last_status = None
|
|
32
|
+
self.__stop_requested = threading.Event()
|
|
33
|
+
self.__thread = threading.Thread(target=self.__poll, daemon=True)
|
|
34
|
+
|
|
35
|
+
@GeneralUtilities.check_arguments
|
|
36
|
+
def has_reported(self) -> bool:
|
|
37
|
+
return self.__last_status is not None
|
|
38
|
+
|
|
39
|
+
@GeneralUtilities.check_arguments
|
|
40
|
+
def start(self) -> None:
|
|
41
|
+
self.__thread.start()
|
|
42
|
+
|
|
43
|
+
@GeneralUtilities.check_arguments
|
|
44
|
+
def stop(self) -> None:
|
|
45
|
+
# The final read gets what the agent has written between the last poll and the end of the container.
|
|
46
|
+
self.__stop_requested.set()
|
|
47
|
+
if self.__thread.is_alive():
|
|
48
|
+
self.__thread.join()
|
|
49
|
+
self.process_new_events()
|
|
50
|
+
|
|
51
|
+
@GeneralUtilities.check_arguments
|
|
52
|
+
def process_new_events(self) -> None:
|
|
53
|
+
status = self.__read_latest_status()
|
|
54
|
+
if status is not None and status != self.__last_status:
|
|
55
|
+
self.__last_status = status
|
|
56
|
+
self.__reporter.report(status)
|
|
57
|
+
|
|
58
|
+
@GeneralUtilities.check_arguments
|
|
59
|
+
def __poll(self) -> None:
|
|
60
|
+
try:
|
|
61
|
+
while not self.__stop_requested.wait(self.poll_interval_in_seconds):
|
|
62
|
+
self.process_new_events()
|
|
63
|
+
except Exception as exception: # pylint: disable=broad-exception-caught
|
|
64
|
+
# This runs in an own thread beside the agent, so a failure only ends the reporting.
|
|
65
|
+
if self.__verbose:
|
|
66
|
+
GeneralUtilities.write_message_to_stderr(f"Reading the agent-status failed: {exception}")
|
|
67
|
+
|
|
68
|
+
@GeneralUtilities.check_arguments
|
|
69
|
+
def __read_latest_status(self) -> AgentStatus:
|
|
70
|
+
with open(self.__events_file, "rb") as events_file:
|
|
71
|
+
events_file.seek(self.__offset)
|
|
72
|
+
new_content = events_file.read(self.maximal_read_size)
|
|
73
|
+
self.__offset = self.__offset + len(new_content)
|
|
74
|
+
lines = (self.__unfinished_line + new_content).split(b"\n")
|
|
75
|
+
self.__unfinished_line = lines.pop()
|
|
76
|
+
latest_status: AgentStatus = None
|
|
77
|
+
for line in lines:
|
|
78
|
+
if self.__skip_rest_of_line:
|
|
79
|
+
self.__skip_rest_of_line = False
|
|
80
|
+
continue
|
|
81
|
+
status = AgentStatus.parse_token(line)
|
|
82
|
+
if status is not None:
|
|
83
|
+
latest_status = status
|
|
84
|
+
if self.maximal_line_length < len(self.__unfinished_line):
|
|
85
|
+
self.__unfinished_line = b""
|
|
86
|
+
self.__skip_rest_of_line = True
|
|
87
|
+
return latest_status
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from .AgentStatus import AgentStatus
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AgentStatusReporter(ABC):
|
|
6
|
+
"""Receives the state of the agent. An implementation must not raise on a failed report, because the agent has to keep running in that case."""
|
|
7
|
+
|
|
8
|
+
@abstractmethod
|
|
9
|
+
def report(self, status: AgentStatus) -> None:
|
|
10
|
+
raise NotImplementedError
|
|
11
|
+
|
|
12
|
+
@abstractmethod
|
|
13
|
+
def release(self) -> None:
|
|
14
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from ..GeneralUtilities import GeneralUtilities
|
|
2
|
+
from .AgentStatus import AgentStatus
|
|
3
|
+
from .AgentStatusEventChannel import AgentStatusEventChannel
|
|
4
|
+
from .AgentStatusRelay import AgentStatusRelay
|
|
5
|
+
from .AgentStatusReporter import AgentStatusReporter
|
|
6
|
+
from .HerdrAgentStatusReporter import HerdrAgentStatusReporter
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AgentStatusReportingSession:
|
|
10
|
+
"""The status-report of one run of a container. It knows no concrete coding-agent: the image connects its agents to the channel.
|
|
11
|
+
Nothing in here can stop the agent: a failure disables the report for this run and is shown in verbose output only."""
|
|
12
|
+
__channel: AgentStatusEventChannel = None
|
|
13
|
+
__relay: AgentStatusRelay = None
|
|
14
|
+
__reporter: AgentStatusReporter = None
|
|
15
|
+
__verbose: bool = None
|
|
16
|
+
|
|
17
|
+
@GeneralUtilities.check_arguments
|
|
18
|
+
def __init__(self, channel: AgentStatusEventChannel, relay: AgentStatusRelay, reporter: AgentStatusReporter, verbose: bool):
|
|
19
|
+
self.__channel = channel
|
|
20
|
+
self.__relay = relay
|
|
21
|
+
self.__reporter = reporter
|
|
22
|
+
self.__verbose = verbose
|
|
23
|
+
|
|
24
|
+
@staticmethod
|
|
25
|
+
@GeneralUtilities.check_arguments
|
|
26
|
+
def try_create(environment: dict[str, str], agent_name: str, verbose: bool) -> "AgentStatusReportingSession":
|
|
27
|
+
# Returns None if there is nothing to report to or if the channel can not be created.
|
|
28
|
+
reporter = HerdrAgentStatusReporter.try_create(environment, agent_name, verbose)
|
|
29
|
+
if reporter is None:
|
|
30
|
+
return None
|
|
31
|
+
try:
|
|
32
|
+
channel = AgentStatusEventChannel()
|
|
33
|
+
except OSError as exception:
|
|
34
|
+
AgentStatusReportingSession.__write_verbose_message(verbose, f"The agent-status is not reported because its channel can not be created: {exception}")
|
|
35
|
+
return None
|
|
36
|
+
return AgentStatusReportingSession(channel, AgentStatusRelay(channel.get_events_file(), reporter, verbose), reporter, verbose)
|
|
37
|
+
|
|
38
|
+
@GeneralUtilities.check_arguments
|
|
39
|
+
def get_volume_arguments(self) -> list[str]:
|
|
40
|
+
return self.__channel.get_volume_arguments()
|
|
41
|
+
|
|
42
|
+
@GeneralUtilities.check_arguments
|
|
43
|
+
def get_start_report_line(self, prompt_is_given: bool) -> str:
|
|
44
|
+
return self.__channel.get_start_report_line(AgentStatus.Working if prompt_is_given else AgentStatus.Idle)
|
|
45
|
+
|
|
46
|
+
@GeneralUtilities.check_arguments
|
|
47
|
+
def start(self) -> None:
|
|
48
|
+
try:
|
|
49
|
+
self.__relay.start()
|
|
50
|
+
except RuntimeError as exception:
|
|
51
|
+
AgentStatusReportingSession.__write_verbose_message(self.__verbose, f"The agent-status is not reported because reading it can not be started: {exception}")
|
|
52
|
+
|
|
53
|
+
@GeneralUtilities.check_arguments
|
|
54
|
+
def stop(self) -> None:
|
|
55
|
+
try:
|
|
56
|
+
self.__finish()
|
|
57
|
+
except Exception as exception: # pylint: disable=broad-exception-caught
|
|
58
|
+
# This runs after the agent has ended, so a failure must not replace its exit-code.
|
|
59
|
+
AgentStatusReportingSession.__write_verbose_message(self.__verbose, f"Finishing the report of the agent-status failed: {exception}")
|
|
60
|
+
|
|
61
|
+
@GeneralUtilities.check_arguments
|
|
62
|
+
def __finish(self) -> None:
|
|
63
|
+
try:
|
|
64
|
+
self.__relay.stop()
|
|
65
|
+
if self.__relay.has_reported():
|
|
66
|
+
self.__reporter.release()
|
|
67
|
+
else:
|
|
68
|
+
AgentStatusReportingSession.__write_verbose_message(self.__verbose, f"No agent-status was received. An image only reports the status if it contains '{AgentStatusEventChannel.status_helper}'.")
|
|
69
|
+
finally:
|
|
70
|
+
self.__channel.remove()
|
|
71
|
+
|
|
72
|
+
@staticmethod
|
|
73
|
+
@GeneralUtilities.check_arguments
|
|
74
|
+
def __write_verbose_message(verbose: bool, message: str) -> None:
|
|
75
|
+
if verbose:
|
|
76
|
+
GeneralUtilities.write_message_to_stderr(message)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import time
|
|
3
|
+
from ..GeneralUtilities import GeneralUtilities
|
|
4
|
+
from .AgentStatus import AgentStatus
|
|
5
|
+
from .AgentStatusReporter import AgentStatusReporter
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class HerdrAgentStatusReporter(AgentStatusReporter):
|
|
9
|
+
"""Reports the state of the agent with the herdr-CLI."""
|
|
10
|
+
source: str = "scrais"
|
|
11
|
+
timeout_in_seconds: int = 5
|
|
12
|
+
__herdr_program: str = None
|
|
13
|
+
__pane_id: str = None
|
|
14
|
+
__agent_name: str = None
|
|
15
|
+
__verbose: bool = None
|
|
16
|
+
__last_sequence_number: int = 0
|
|
17
|
+
|
|
18
|
+
@GeneralUtilities.check_arguments
|
|
19
|
+
def __init__(self, herdr_program: str, pane_id: str, agent_name: str, verbose: bool):
|
|
20
|
+
self.__herdr_program = herdr_program
|
|
21
|
+
self.__pane_id = pane_id
|
|
22
|
+
self.__agent_name = agent_name
|
|
23
|
+
self.__verbose = verbose
|
|
24
|
+
self.__last_sequence_number = 0
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
@GeneralUtilities.check_arguments
|
|
28
|
+
def try_create(environment: dict[str, str], agent_name: str, verbose: bool) -> "HerdrAgentStatusReporter":
|
|
29
|
+
# Returns None if scrais does not run in a herdr-pane.
|
|
30
|
+
pane_id = environment.get("HERDR_PANE_ID")
|
|
31
|
+
herdr_program = environment.get("HERDR_BIN_PATH")
|
|
32
|
+
if environment.get("HERDR_ENV") != "1" or not pane_id or not herdr_program:
|
|
33
|
+
return None
|
|
34
|
+
return HerdrAgentStatusReporter(herdr_program, pane_id, agent_name, verbose)
|
|
35
|
+
|
|
36
|
+
@GeneralUtilities.check_arguments
|
|
37
|
+
def get_report_command(self, status: AgentStatus) -> list[str]:
|
|
38
|
+
return [self.__herdr_program, "pane", "report-agent", self.__pane_id, "--source", self.source, "--agent", self.__agent_name, "--state", status.value, "--seq", str(self.__get_next_sequence_number())]
|
|
39
|
+
|
|
40
|
+
@GeneralUtilities.check_arguments
|
|
41
|
+
def get_release_command(self) -> list[str]:
|
|
42
|
+
return [self.__herdr_program, "pane", "release-agent", self.__pane_id, "--source", self.source, "--agent", self.__agent_name, "--seq", str(self.__get_next_sequence_number())]
|
|
43
|
+
|
|
44
|
+
@GeneralUtilities.check_arguments
|
|
45
|
+
def report(self, status: AgentStatus) -> None:
|
|
46
|
+
self.__run(self.get_report_command(status))
|
|
47
|
+
|
|
48
|
+
@GeneralUtilities.check_arguments
|
|
49
|
+
def release(self) -> None:
|
|
50
|
+
self.__run(self.get_release_command())
|
|
51
|
+
|
|
52
|
+
@GeneralUtilities.check_arguments
|
|
53
|
+
def __get_next_sequence_number(self) -> int:
|
|
54
|
+
# time_ns makes the number increase across runs; the comparison keeps it strictly increasing if the resolution of the clock is too coarse for two reports in quick succession.
|
|
55
|
+
self.__last_sequence_number = max(time.time_ns(), self.__last_sequence_number + 1)
|
|
56
|
+
return self.__last_sequence_number
|
|
57
|
+
|
|
58
|
+
@GeneralUtilities.check_arguments
|
|
59
|
+
def __run(self, command: list[str]) -> None:
|
|
60
|
+
# The command is an argument-list without shell, so that paths with spaces work and nothing can be injected.
|
|
61
|
+
# Stdin and the output are detached, because the terminal belongs to the agent.
|
|
62
|
+
try:
|
|
63
|
+
result = subprocess.run(command, check=False, stdin=subprocess.DEVNULL, capture_output=True, timeout=self.timeout_in_seconds)
|
|
64
|
+
if result.returncode != 0:
|
|
65
|
+
self.__write_failure(f"exit-code {result.returncode}")
|
|
66
|
+
except (OSError, subprocess.SubprocessError) as exception:
|
|
67
|
+
self.__write_failure(str(exception))
|
|
68
|
+
|
|
69
|
+
@GeneralUtilities.check_arguments
|
|
70
|
+
def __write_failure(self, reason: str) -> None:
|
|
71
|
+
if self.__verbose:
|
|
72
|
+
GeneralUtilities.write_message_to_stderr(f"Reporting the agent-status to herdr failed: {reason}")
|
|
File without changes
|
|
@@ -139,9 +139,6 @@ class TFCPS_CodeUnit_BuildCodeUnits:
|
|
|
139
139
|
#ensure <repo>/.gitignore is set up (ignores the cache-folder so cache-files never show up as uncommitted changes)
|
|
140
140
|
self.__ensure_global_gitignore_is_setup(self.repository)
|
|
141
141
|
|
|
142
|
-
#validate the openspec-specifications if openspec is set up in the repository
|
|
143
|
-
self.__validate_openspec()
|
|
144
|
-
|
|
145
142
|
self.sc.log.log(f"Start building codeunits at {GeneralUtilities.datetime_to_string_for_readable_entry(start_time,False)}. (Target environment-type: {self.target_environment_type})")
|
|
146
143
|
|
|
147
144
|
#ensure common cache-files are available
|
|
@@ -286,6 +283,7 @@ class TFCPS_CodeUnit_BuildCodeUnits:
|
|
|
286
283
|
self.sc.log.log("Do project-linting...")
|
|
287
284
|
self.__do_project_linting_using_codespell(repository_folder)
|
|
288
285
|
self.__sort_findings(repository_folder)
|
|
286
|
+
self.__validate_openspec(repository_folder)
|
|
289
287
|
|
|
290
288
|
@GeneralUtilities.check_arguments
|
|
291
289
|
def __sort_findings(self, repository_folder: str) -> None:
|
|
@@ -436,11 +434,14 @@ class TFCPS_CodeUnit_BuildCodeUnits:
|
|
|
436
434
|
self.sc.run_with_epew("openspec", "update --force", self.repository)
|
|
437
435
|
|
|
438
436
|
@GeneralUtilities.check_arguments
|
|
439
|
-
def __validate_openspec(self) -> None:
|
|
440
|
-
openspec_configuration_file: str = os.path.join(
|
|
437
|
+
def __validate_openspec(self,repository:str) -> None:
|
|
438
|
+
openspec_configuration_file: str = os.path.join(repository, "openspec", "config.yaml")
|
|
441
439
|
if os.path.isfile(openspec_configuration_file):
|
|
442
440
|
self.sc.log.log("Validate openspec-specifications...")
|
|
443
|
-
|
|
441
|
+
try:
|
|
442
|
+
self.sc.run_with_epew("openspec", "validate --all --strict", repository)
|
|
443
|
+
except Exception as e:
|
|
444
|
+
self.sc.log.log_exception(f"Openspec validation failed.",e,LogLevel.Warning)
|
|
444
445
|
|
|
445
446
|
@GeneralUtilities.check_arguments
|
|
446
447
|
def get_default_base_mount_folder(self) -> str:
|
|
@@ -2237,12 +2237,6 @@ class TFCPS_Tools_General:
|
|
|
2237
2237
|
target=f"{codeunit_folder}/Other/Reference/ReferenceContent/HowToBuild.md"
|
|
2238
2238
|
self.download_file(source,target)
|
|
2239
2239
|
|
|
2240
|
-
@GeneralUtilities.check_arguments
|
|
2241
|
-
def try_update_basic_repositoryreference_from_examples_repository(self, repository_folder:str):
|
|
2242
|
-
source=f"https://raw.githubusercontent.com/anionDev/CommonProjectStructureExamples/refs/heads/main/Other/Reference/RepositoryStructure.mdd"
|
|
2243
|
-
target=f"{repository_folder}/Other/Reference/RepositoryStructure.md"
|
|
2244
|
-
self.download_file(source,target)
|
|
2245
|
-
|
|
2246
2240
|
@GeneralUtilities.check_arguments
|
|
2247
2241
|
def update_dependent_oci_images(self, repo:str):
|
|
2248
2242
|
self.oci_image_manager.update_default_tag_for_images_in_image_definitions_file(repo,True)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scriptcollection
|
|
3
|
-
Version: 4.4.
|
|
3
|
+
Version: 4.4.67
|
|
4
4
|
Summary: The ScriptCollection is the place for reusable scripts.
|
|
5
5
|
Author-email: Marius Göcke <marius.goecke@gmail.com>
|
|
6
6
|
License-Expression: GPL-3.0-only
|
|
@@ -53,8 +53,7 @@ Requires-Dist: xmlschema>=4.3.2
|
|
|
53
53
|

|
|
54
54
|

|
|
55
55
|
|
|
56
|
-
[](https://www.codefactor.io/repository/github/anionDevelopment/scriptcollection/overview/main)
|
|
57
|
-
[](https://pepy.tech/project/scriptcollection)
|
|
56
|
+
[](https://www.codefactor.io/repository/github/anionDevelopment/scriptcollection/overview/main) [](https://pepy.tech/project/scriptcollection)
|
|
58
57
|

|
|
59
58
|
|
|
60
59
|
The ScriptCollection is the place for reusable scripts.
|
|
@@ -69,7 +68,8 @@ Most of the scripts are written in [python](https://www.python.org) 3.
|
|
|
69
68
|
|
|
70
69
|
Caution: Before executing **any** script of this repository read the sourcecode of the script (and the sourcecode of all functions called by this function directly or transitively) carefully and verify that the script does exactly what you want to do and nothing else.
|
|
71
70
|
|
|
72
|
-
Some functions are not entirely available on windows or require common third-party tools.
|
|
71
|
+
Some functions are not entirely available on windows or require common third-party tools.
|
|
72
|
+
See the [Runtime dependencies](#runtime-dependencies)-section for more information.
|
|
73
73
|
|
|
74
74
|
When using ScriptCollection it is not required but recommended for better usability to have [epew](https://github.com/anionDev/Epew) installed.
|
|
75
75
|
|
|
@@ -87,11 +87,14 @@ You can simply git-clone the ScriptCollection and then use the scripts under the
|
|
|
87
87
|
|
|
88
88
|
`git clone https://github.com/anionDevelopment/ScriptCollection.git`
|
|
89
89
|
|
|
90
|
-
It may be easier to pip-install the ScriptCollection but technically pip is not required.
|
|
90
|
+
It may be easier to pip-install the ScriptCollection but technically pip is not required.
|
|
91
|
+
Actually you need to git-clone (or download as zip-file from [GitHub](https://github.com/anionDevelopment/ScriptCollection)) the ScriptCollection to use the scripts in this repository which are not written in python.
|
|
91
92
|
|
|
92
93
|
## Troubleshooting
|
|
93
94
|
|
|
94
|
-
It is recommended to always use only the newest version of the ScriptCollection.
|
|
95
|
+
It is recommended to always use only the newest version of the ScriptCollection.
|
|
96
|
+
If you have an older version: Update it (e. g. using `pip3 install ScriptCollection --upgrade` if you installed the ScriptCollection via pip).
|
|
97
|
+
If you still have problems, then feel free to create an [issue](https://github.com/anionDevelopment/ScriptCollection/issues).
|
|
95
98
|
|
|
96
99
|
If you have installed the ScriptCollection as pip-package you can simply check the version by running `scshowversion` or using Python with the following commands:
|
|
97
100
|
|
|
@@ -144,7 +147,8 @@ pip3 install --force-reinstall ./ScriptCollection/Other/Artifacts/BuildResult_Wh
|
|
|
144
147
|
|
|
145
148
|
(Note: `x.x.x` must be replaced by the appropriate version-number.)
|
|
146
149
|
|
|
147
|
-
The complete build-pipeline (build, testcases, linting, reference-generation, etc.) is run by `scbuildcodeunits` in the repository-root (or `task bb` if [Task](https://taskfile.dev) is installed).
|
|
150
|
+
The complete build-pipeline (build, testcases, linting, reference-generation, etc.) is run by `scbuildcodeunits` in the repository-root (or `task bb` if [Task](https://taskfile.dev) is installed).
|
|
151
|
+
Afterwards `task dl` installs the built wheel locally.
|
|
148
152
|
|
|
149
153
|
### Coding style
|
|
150
154
|
|
|
@@ -165,7 +169,8 @@ For functions to read or change the permissions or the owner of a file the Scrip
|
|
|
165
169
|
- chown
|
|
166
170
|
- ls
|
|
167
171
|
|
|
168
|
-
These tools must be available on the system where the functions should be executed.
|
|
172
|
+
These tools must be available on the system where the functions should be executed.
|
|
173
|
+
Meanwhile these tools are also available on Windows but may have a slightly limited functionality.
|
|
169
174
|
|
|
170
175
|
## License
|
|
171
176
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
ScriptCollection/AgentRunner.py,sha256=
|
|
1
|
+
ScriptCollection/AgentRunner.py,sha256=8UiY6mAZoSSb1LlKGJ29qhLUW_0DtryrC2Kdn5cDPgg,19820
|
|
2
2
|
ScriptCollection/ArbTranslationsOrganizer.py,sha256=3TO4fjkYADcHGyUXdiQk-RtfCxtf9ojuBS3CbZtgXBE,12218
|
|
3
3
|
ScriptCollection/CertificateUpdater.py,sha256=yZc7KESc1F_Mc6HP2UfLmNHRc2MvtVqp0t60J_CqY3s,9755
|
|
4
4
|
ScriptCollection/Executables.py,sha256=Z-YRlSgD4GN7XjZuarXHZTPOuWtNr2rF5OzlwjJ3Yuo,82192
|
|
@@ -12,10 +12,17 @@ ScriptCollection/ProgramRunnerSudo.py,sha256=vwKq-MOcqsgiKhSf-MBUDBC_UyaU8evP3Ro
|
|
|
12
12
|
ScriptCollection/RepositoryDiagramGenerator.py,sha256=K_u2NW_p4ozdWD50irJEkkcDVa70TcUJpZN63TeXSLw,7092
|
|
13
13
|
ScriptCollection/RepositoryHistoryAnalyzer.py,sha256=u9141B9D-Kef-9uo3yR7BXKUMzIKLVsesnYk7H-cWm4,6157
|
|
14
14
|
ScriptCollection/SCLog.py,sha256=Fjf8Pdi63cXHGMxL_aI6A0dwGm7QIfrv3czjvpSUlaM,4705
|
|
15
|
-
ScriptCollection/ScriptCollectionCore.py,sha256=
|
|
15
|
+
ScriptCollection/ScriptCollectionCore.py,sha256=TIqhsMEv5XvRpZlih-5_U-wqGiwr3CbpOYShk1sMHrU,310633
|
|
16
16
|
ScriptCollection/TestKind.py,sha256=jqLJwNvQeyea7SZf-UFzMC9pM0znv4do7FIC1xq8u9M,1672
|
|
17
17
|
ScriptCollection/UnassignedVariablesCheck.py,sha256=8xNcp1D5HeOLO1a1NEerq2TsnpFhw7yzYPkaay-oisY,3804
|
|
18
18
|
ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
|
+
ScriptCollection/AgentStatusReporting/AgentStatus.py,sha256=eKz2RN1XEhPjaLxALmvtV-k2094RUTMEXT7HFKsSImg,563
|
|
20
|
+
ScriptCollection/AgentStatusReporting/AgentStatusEventChannel.py,sha256=LnAi5qA2NjRwcDEg8ALsOeHspO_CPcEs8A4GiaFd0bY,1732
|
|
21
|
+
ScriptCollection/AgentStatusReporting/AgentStatusRelay.py,sha256=JtfM5OQVnojUdGdiRipSZKePIk-A5L1SPxIMET1XYWM,3639
|
|
22
|
+
ScriptCollection/AgentStatusReporting/AgentStatusReporter.py,sha256=bql8GLSPi3X-owXObjIROp2KzoirjF_b-EtCQ12NA2k,447
|
|
23
|
+
ScriptCollection/AgentStatusReporting/AgentStatusReportingSession.py,sha256=jqBTAbw8evWqdJG_k79p0e74RHzBgCL7nvaEsIw371E,3685
|
|
24
|
+
ScriptCollection/AgentStatusReporting/HerdrAgentStatusReporter.py,sha256=4X1RGHQbTq-wEqGyCtV2i9hCoweddn8zTQeK8P17Jb8,3491
|
|
25
|
+
ScriptCollection/AgentStatusReporting/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
26
|
ScriptCollection/OCIImages/AbstractImageHandler.py,sha256=UB0lUYdAjFk8RIgsikKELRWDMZPlR_zNgwvCJS1naVs,2455
|
|
20
27
|
ScriptCollection/OCIImages/OCIImageManager.py,sha256=Yi_opHYlhLqjoYP_Z23dnNjnLbpc1kJS2vmjatUBDqY,25143
|
|
21
28
|
ScriptCollection/OCIImages/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -40,7 +47,7 @@ ScriptCollection/TFCPS/TFCPS_BuildCodeUnitsHook.py,sha256=67_DQwoH5bhxxSmwtuAeoW
|
|
|
40
47
|
ScriptCollection/TFCPS/TFCPS_CodeSpellCheck.py,sha256=zV62O7UiGjewx1yQUIWmUJ9D-5ipkV_f28uNhp-JWUs,5306
|
|
41
48
|
ScriptCollection/TFCPS/TFCPS_CodeUnitSpecific_Base.py,sha256=Rh7S84B8QbeWn5qJxRItoI7jquJYvFnNRi_WiX3FjWo,40414
|
|
42
49
|
ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnit.py,sha256=CB0K8OZNtQESdS2pqX9RQqN-lI5M-cbmXYOR0rbuRlk,9741
|
|
43
|
-
ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py,sha256=
|
|
50
|
+
ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py,sha256=5H8Artt40lrl3vvAHaZwiBPiL4ycHCZdk68s9mRIcI8,70924
|
|
44
51
|
ScriptCollection/TFCPS/TFCPS_CreateRelease.py,sha256=BVK3fpEyjcXYVHIb6YYLH7bWe6iKRaCtPrJ3tXAemYw,6582
|
|
45
52
|
ScriptCollection/TFCPS/TFCPS_FindingsSorter.py,sha256=3ChuKf-Myr3sBtQhYGw6dHlk93HO6PAH-Jq1oPYdW1s,4804
|
|
46
53
|
ScriptCollection/TFCPS/TFCPS_Generic.py,sha256=mRBcf7XuNWOSXbZYc3NuJow18AMZ30D6Z-BtyNYfNcM,2072
|
|
@@ -49,7 +56,7 @@ ScriptCollection/TFCPS/TFCPS_MergeToStable.py,sha256=GdpFcgIFRvdc1Q9b7uXlPlN99s7
|
|
|
49
56
|
ScriptCollection/TFCPS/TFCPS_OCIImageSecretScan.py,sha256=Jb7AaMcJDW-gYEYBUVZAG3QLTTNWmXlvVEW-lZsykws,14821
|
|
50
57
|
ScriptCollection/TFCPS/TFCPS_PreBuildCodeunitsScript.py,sha256=XLVsFTA1jvfDbZ7wYJgIdEByZhF_bYVbA5jkisuvK4k,2322
|
|
51
58
|
ScriptCollection/TFCPS/TFCPS_RemoteBuild.py,sha256=2Tx5HLk1ZftBWDCTiGZdP2QiiGNyWsEuTCSt33dNQjc,23891
|
|
52
|
-
ScriptCollection/TFCPS/TFCPS_Tools_General.py,sha256=
|
|
59
|
+
ScriptCollection/TFCPS/TFCPS_Tools_General.py,sha256=iiMy4LDY-bQk6PEi0onVhhKPsoWJHhgMaS5xDQVSlM8,160357
|
|
53
60
|
ScriptCollection/TFCPS/TFCPS_VisualRegressionTests.py,sha256=F90CF5kLCgV_M3yN696xWzF1cglWLXecau9My2ZyGxw,42230
|
|
54
61
|
ScriptCollection/TFCPS/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
55
62
|
ScriptCollection/TFCPS/CPP/TFCPS_CodeUnitSpecific_CPP.py,sha256=BNZPMjGiWLMBH7QDtP06WEVLMnI38NLX4Dpd13bSbi4,16614
|
|
@@ -75,8 +82,8 @@ ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py,sha256=yyjWPMHQjPLkML
|
|
|
75
82
|
ScriptCollection/TFCPS/Rust/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
76
83
|
ScriptCollection/TFCPS/TypeScript/TFCPS_CodeUnitSpecific_TypeScript.py,sha256=ILVhJHvwG5TvPBBqSvyACYb7W9QnWrJpxKgHu8IQu4g,9249
|
|
77
84
|
ScriptCollection/TFCPS/TypeScript/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
78
|
-
scriptcollection-4.4.
|
|
79
|
-
scriptcollection-4.4.
|
|
80
|
-
scriptcollection-4.4.
|
|
81
|
-
scriptcollection-4.4.
|
|
82
|
-
scriptcollection-4.4.
|
|
85
|
+
scriptcollection-4.4.67.dist-info/METADATA,sha256=ItwhmyrDdan16Rtin5x-2mX33PfHWM2SNJr28T51hes,8032
|
|
86
|
+
scriptcollection-4.4.67.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
87
|
+
scriptcollection-4.4.67.dist-info/entry_points.txt,sha256=kI-HqAydo8a0FGjGeXh6i1pGU73Pit0xACdjxBxNkis,6254
|
|
88
|
+
scriptcollection-4.4.67.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
|
|
89
|
+
scriptcollection-4.4.67.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|