Skip to content

Commit a397fa9

Browse files
committed
Implement nettacker command
1 parent 5fe4b03 commit a397fa9

File tree

7 files changed

+263
-264
lines changed

7 files changed

+263
-264
lines changed

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)