Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 22 additions & 6 deletions karton/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,20 @@ 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, short: bool) -> None:
backend = KartonBackend(config=config)
for bind in backend.get_binds():
print(bind)

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

Copy link
Copy Markdown
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?

@psrok1 psrok1 Jul 28, 2025

Copy link
Copy Markdown
Member

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}"
)
else:
for bind in backend.get_binds():
print(bind)


def delete_bind(config: Config, karton_name: str) -> None:
Expand Down Expand Up @@ -180,7 +190,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 +199,13 @@ 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(
"-s",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe -h for human? Similarly to du, for example

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Makes sense, though in this case it's both more human readable and more machine-readable. The default format looks like this:

image

This suggests that maybe changing the default output format instead is a better idea (especially since the CLI is intended for humans). But it is obviously a backward incompatible change (assuming someone parses the output for some reason).

For now though: I'm not sure about -h since it's often used for --help. But I don't like --short either, so i've implemented this change. I used --human instead of --human-readable like in du, because in du any prefix of a valid command is accepted, so both will work.

"--short",
help='Print names and versions only (human readable)"',
action="store_true",
)

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

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