Skip to content

Commit

Permalink
Changed tools to entry points (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz authored Jan 28, 2024
1 parent b8f4698 commit 71669ea
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 26 deletions.
File renamed without changes.
13 changes: 5 additions & 8 deletions tools/stats.py → artifacts/scripts/stats.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Report statistics about the artifact collection."""
"""Console script to collect statistics about definitions."""

import collections
import os
Expand Down Expand Up @@ -122,18 +122,15 @@ def PrintStats(self):


def Main():
"""The main program function.
"""Entry point of console script to collect statistics about definitions.
Returns:
bool: True if successful or False if not.
int: exit code that is provided to sys.exit().
"""
statsbuilder = ArtifactStatistics()
statsbuilder.PrintStats()
return True
return 0


if __name__ == '__main__':
if not Main():
sys.exit(1)
else:
sys.exit(0)
sys.exit(Main())
19 changes: 8 additions & 11 deletions tools/validator.py → artifacts/scripts/validator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tool to validate artifact definitions."""
"""Console script to validate artifact definitions."""

import argparse
import glob
Expand Down Expand Up @@ -556,10 +556,10 @@ def GetUndefinedArtifacts(self):


def Main():
"""The main program function.
"""Entry point of console script to collect statistics about definitions.
Returns:
bool: True if successful or False if not.
int: exit code that is provided to sys.exit().
"""
args_parser = argparse.ArgumentParser(
description='Validates an artifact definitions file.')
Expand All @@ -576,12 +576,12 @@ def Main():
print('')
args_parser.print_help()
print('')
return False
return 1

if not os.path.exists(options.definitions):
print(f'No such file or directory: {options.definitions:s}')
print('')
return False
return 1

validator = ArtifactDefinitionsValidator()

Expand All @@ -595,14 +595,11 @@ def Main():

if not result:
print('FAILURE')
return False
return 1

print('SUCCESS')
return True
return 0


if __name__ == '__main__':
if not Main():
sys.exit(1)
else:
sys.exit(0)
sys.exit(Main())
8 changes: 5 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ package_dir =
artifacts = artifacts
packages = find:
python_requires = >=3.7
scripts =
tools/stats.py
tools/validator.py

[options.package_data]
artifacts =
Expand All @@ -39,6 +36,11 @@ exclude =
utils
where = .

[options.entry_points]
console_scripts =
stats = artifacts.scripts.stats:Main
validator = artifacts.scripts.validator:Main

[bdist_rpm]
release = 1
packager = Forensic artifacts <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion tests/validator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import unittest

from artifacts import errors
from tools import validator
from artifacts.scripts import validator

from tests import test_lib

Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ commands =
docformatter --version
pylint --version
yamllint -v
docformatter --check --diff --recursive artifacts setup.py tests tools
pylint --rcfile=.pylintrc artifacts setup.py tests tools
docformatter --check --diff --recursive artifacts setup.py tests
pylint --rcfile=.pylintrc artifacts setup.py tests
yamllint -c .yamllint.yaml artifacts/data test_data
2 changes: 1 addition & 1 deletion utils/update_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ artifacts (${VERSION}-1) unstable; urgency=low
EOT

# Regenerate the statistics documentation.
PYTHONPATH=. ./tools/stats.py > docs/sources/background/Stats.md
PYTHONPATH=. ./artifacts/scripts/stats.py > docs/sources/background/Stats.md

# Regenerate the API documentation.
tox -edocs
Expand Down

0 comments on commit 71669ea

Please sign in to comment.