Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ jobs:
- uses: CERT-Polska/lint-python-action@v2
with:
source: karton/
python-version: 3.12
unittest:
runs-on: ubuntu-latest
strategy:
matrix:
minor: [9, 10, 11, 12]
minor: [10, 11, 12, 13]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ if __name__ == "__main__":
GenericUnpacker.main()
```

## Command line

This package also provies a command-line utility called "karton". You can use it for simple management tasks (but it's not designed as a fully capable management tool).

```
$ karton configure # create a new configuration file

$ karton list -s # list current binds
karton name version karton
------------------------------------------------------------------------
karton.yaramatcher 1.2.0 5.3.0
karton.autoit-ripper 1.2.1 5.3.3
karton.mwdb-reporter 1.3.0 5.3.2

$ karton logs # start streaming all system logs

$ karton delete karton.something # remove unused bind (will be GCed by system during the next operation)
```


## Karton systems

Some Karton systems are universal and useful to everyone. We decided to share them with the community.
Expand Down
32 changes: 26 additions & 6 deletions karton/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,23 @@ def configuration_wizard(config_filename: str) -> None:
log.info("Saved the new configuration file in %s", os.path.abspath(config_filename))


def print_bind_list(config: Config) -> None:
def print_bind_list(config: Config, output_format: str) -> None:
backend = KartonBackend(config=config)
for bind in backend.get_binds():
print(bind)

if output_format == "table":
# Print a human-readable table-like version
print(f"{'karton name':50} {'version':10} {'karton':10}")
print("-" * 72)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe shutil.get_terminal_size()? We can still set a max width to 72, but maybe we can set shorter padding on narrower terminal?

Copy link
Member

@psrok1 psrok1 Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, maybe not worth it, 72 characters isn't very wide

------------------------------------------------------------------------

for bind in backend.get_binds():
print(
f"{bind.identity:50} {bind.service_version or "-":10} {bind.version:10}"
)
elif output_format == "json":
# Use JSONL, each line is a JSON representing next bind
for bind in backend.get_binds():
print(backend.serialize_bind(bind))
else:
raise RuntimeError(f"Invalid output format: {output_format}")


def delete_bind(config: Config, karton_name: str) -> None:
Expand Down Expand Up @@ -180,7 +193,7 @@ def process(self, task):

def main() -> None:

parser = argparse.ArgumentParser(description="Your red pill to the karton-verse")
parser = argparse.ArgumentParser(description="Karton-core management utility")
parser.add_argument("--version", action="version", version=__version__)
parser.add_argument("-c", "--config-file", help="Alternative configuration path")
parser.add_argument(
Expand All @@ -189,7 +202,14 @@ def main() -> None:

subparsers = parser.add_subparsers(dest="command", help="sub-command help")

subparsers.add_parser("list", help="List active karton binds")
list_parser = subparsers.add_parser("list", help="List active karton binds")
list_parser.add_argument(
"-o",
"--output",
help="Short, human readable output, with names and versions only.",
default="table",
choices=("table", "json"),
)

logs_parser = subparsers.add_parser("logs", help="Start streaming logs")
logs_parser.add_argument(
Expand Down Expand Up @@ -253,7 +273,7 @@ def main() -> None:
return

if args.command == "list":
print_bind_list(config)
print_bind_list(config, args.output)
elif args.command == "delete":
karton_name = args.identity
print(
Expand Down