Skip to content

Commit 008d673

Browse files
authored
Merge pull request #891 from arkid15r/add-nettacker-command
Implement `nettacker` command
2 parents 5fe4b03 + 05b24cd commit 008d673

File tree

8 files changed

+299
-266
lines changed

8 files changed

+299
-266
lines changed

.github/workflows/ci_cd.yml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,40 @@ jobs:
104104
name: dist
105105
path: dist
106106

107+
test-build-package:
108+
name: Test build on ${{ matrix.os }}
109+
runs-on: ${{ matrix.os }}
110+
needs: build-package
111+
strategy:
112+
matrix:
113+
os:
114+
- macos-latest
115+
- ubuntu-latest
116+
steps:
117+
- name: Check out repository
118+
uses: actions/checkout@v4
119+
120+
- name: Set up Python
121+
uses: actions/setup-python@v5
122+
with:
123+
python-version: '3.11'
124+
125+
- name: Get package artifacts
126+
uses: actions/download-artifact@v4
127+
with:
128+
name: dist
129+
path: dist
130+
131+
- name: Run tests
132+
shell: bash
133+
run: |
134+
rm -rf nettacker
135+
python -m pip install dist/*.whl
136+
nettacker --version
137+
python -m pip uninstall -y nettacker
138+
python -m pip install dist/*.tar.gz
139+
nettacker --version
140+
107141
test-docker-image:
108142
name: Test Docker image
109143
needs:
@@ -231,7 +265,7 @@ jobs:
231265
github.ref_name == 'master'
232266
environment: dev
233267
needs:
234-
- build-package
268+
- test-build-package
235269
permissions:
236270
contents: read
237271
id-token: write
@@ -257,7 +291,7 @@ jobs:
257291
startsWith(github.event.ref, 'refs/tags/v')
258292
environment: release
259293
needs:
260-
- build-package
294+
- test-build-package
261295
permissions:
262296
contents: read
263297
id-token: write

nettacker.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""OWASP Nettacker application entry point."""
22

3-
from nettacker.core.app import Nettacker
3+
from nettacker.main import run
44

55
if __name__ == "__main__":
6-
app = Nettacker()
7-
app.run()
6+
run()

nettacker/config.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from functools import lru_cache
33
from pathlib import Path
44

5-
import tomli
6-
5+
from nettacker import version
76
from nettacker.core.utils.common import now, generate_random_token
87

98
CWD = Path.cwd()
@@ -18,10 +17,8 @@ def version_info():
1817
Returns:
1918
an array of version and code name
2019
"""
21-
with open("pyproject.toml", "rb") as toml_file:
22-
tools = tomli.load(toml_file)["tool"]
2320

24-
return tools["poetry"]["version"], tools["nettacker"]["release_name"]
21+
return version.__version__, version.__release_name__
2522

2623

2724
class ConfigBase:

nettacker/core/app.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,17 @@ def check_dependencies(self):
6969
if sys.platform not in {"darwin", "linux"}:
7070
die_failure(_("error_platform"))
7171

72-
if not os.path.exists(Config.path.home_dir):
73-
try:
74-
os.mkdir(Config.path.home_dir)
75-
os.mkdir(Config.path.tmp_dir)
76-
os.mkdir(Config.path.results_dir)
77-
except Exception:
78-
die_failure("cannot access the directory {0}".format(Config.path.home_dir))
79-
if not os.path.exists(Config.path.tmp_dir):
80-
try:
81-
os.mkdir(Config.path.tmp_dir)
82-
except Exception:
83-
die_failure("cannot access the directory {0}".format(Config.path.tmp_dir))
84-
if not os.path.exists(Config.path.results_dir):
85-
try:
86-
os.mkdir(Config.path.results_dir)
87-
except Exception:
88-
die_failure("cannot access the directory {0}".format(Config.path.results_dir))
72+
try:
73+
Config.path.tmp_dir.mkdir(exist_ok=True, parents=True)
74+
Config.path.results_dir.mkdir(exist_ok=True, parents=True)
75+
except PermissionError:
76+
die_failure("Cannot access the directory {0}".format(Config.path.tmp_dir))
8977

9078
if Config.db.engine == "sqlite":
9179
try:
92-
if not os.path.isfile(Config.path.database_file):
80+
if not Config.path.database_file.exists():
9381
sqlite_create_tables()
94-
except Exception:
82+
except PermissionError:
9583
die_failure("cannot access the directory {0}".format(Config.path.home_dir))
9684
elif Config.db.engine == "mysql":
9785
try:

nettacker/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""Nettacker main.py."""
2+
3+
from nettacker.core.app import Nettacker
4+
5+
6+
def run():
7+
app = Nettacker()
8+
app.run()

nettacker/version.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Nettacker version."""
2+
3+
__version__ = "0.4.0"
4+
__version_tuple__ = (0, 4, 0)
5+
__release_name__ = "QUIN"

poetry.lock

Lines changed: 236 additions & 236 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ packages = [{ include = "nettacker"}]
4141
[tool.nettacker]
4242
release_name = "QUIN"
4343

44+
[tool.poetry.scripts]
45+
nettacker = "nettacker.main:run"
46+
4447
[tool.poetry.dependencies]
4548
python = "^3.9, <3.13"
4649
aiohttp = "^3.9.5"
@@ -59,7 +62,6 @@ pyyaml = "^6.0.1"
5962
requests = "^2.32.3"
6063
sqlalchemy = "^2.0.22"
6164
texttable = "^1.7.0"
62-
tomli = "^2.0.1"
6365
zipp = "^3.19.1"
6466

6567
[tool.poetry.group.dev.dependencies]

0 commit comments

Comments
 (0)