forked from INTO-CPS-Association/DTaaS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Packaging with poetry, Linting changes
- Loading branch information
Astitva
committed
Mar 31, 2024
1 parent
ba76a0e
commit 0516468
Showing
9 changed files
with
313 additions
and
128 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[tool.poetry] | ||
name = "dtaas-cli" | ||
version = "0.1.0" | ||
description = "DTaaS CLI" | ||
authors = ["Astitva Sehgal"] | ||
license = "INTO-CPS-Association" | ||
readme = "README.md" | ||
packages = [{include = "src"}] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.7" | ||
PyYAML = "^6.0.1" | ||
click = "^8.1.7" | ||
tomlkit = "^0.12.4" | ||
|
||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
[tool.poetry.scripts] | ||
dtaas = "src.cmd:dtaas" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,82 @@ | ||
"""This file supports the DTaaS config class""" | ||
|
||
import click | ||
from . import utils | ||
|
||
class Config: | ||
def __init__(self): | ||
"""The Config class for DTaaS""" | ||
|
||
def __init__(self): | ||
config, err = utils.importToml('dtaas.toml') | ||
if err!=None: | ||
if err is not None: | ||
raise click.ClickException("config initialisation failed: "+str(err)) | ||
self.data = config | ||
|
||
def getConfig(self): | ||
if self.data!=None: | ||
"""Gets the config dictionary""" | ||
if self.data is not None: | ||
return self.data,None | ||
return None, Exception("Config not initialised") | ||
|
||
def getCommon(self): | ||
"""Gets the 'common' section of config """ | ||
conf, err = self.getConfig() | ||
if err!=None: | ||
if err is not None: | ||
return None, err | ||
|
||
if 'common' not in conf: | ||
return None, Exception("Config file error: Missing 'common' tag") | ||
return conf['common'], None | ||
|
||
def getUsers(self): | ||
"""Gets the 'users' section of config """ | ||
conf, err = self.getConfig() | ||
if err!=None: | ||
if err is not None: | ||
return None, err | ||
|
||
if 'users' not in conf: | ||
return None, Exception("Config file error: Missing 'users' tag") | ||
return conf['users'], None | ||
|
||
|
||
def getPath(self): | ||
"""Gets the 'path' from config.common """ | ||
confCommon, err = self.getCommon() | ||
if err!=None: | ||
if err is not None: | ||
return None, err | ||
|
||
if 'path' not in confCommon or confCommon['path']=="": | ||
return None, Exception("Config file error: The path for DTaaS directory isn't set in TOML") | ||
return None, Exception("Config file error: DTaaS directory path not set in TOML") | ||
return str(confCommon['path']), None | ||
|
||
def getServerDNS(self): | ||
"""Gets the 'server-dns' from config.common """ | ||
confCommon, err = self.getCommon() | ||
if err!=None: | ||
if err is not None: | ||
return None, err | ||
|
||
if 'server-dns' not in confCommon and confCommon['server-dns']=="": | ||
return None, Exception("Config file error: The server dns isn't set in TOML") | ||
return str(confCommon['server-dns']), None | ||
|
||
def getAddUsersList(self): | ||
"""Gets the 'add' list from config.users """ | ||
confUsers, err = self.getUsers() | ||
if err!=None: | ||
if err is not None: | ||
return None, err | ||
|
||
if 'add' not in confUsers: | ||
return None, Exception("Config file error: No 'add' list in 'users' tag") | ||
addUsersList = [ str(username) for username in confUsers['add']] | ||
return addUsersList, None | ||
|
||
def getDeleteUsersList(self): | ||
"""Gets the 'delete' list from config.users """ | ||
confUsers, err = self.getUsers() | ||
if err!=None: | ||
if err is not None: | ||
return None, err | ||
|
||
if 'delete' not in confUsers: | ||
return None, Exception("Config file error: No 'delete' list in 'users' tag") | ||
deleteUsersList = [str(username) for username in confUsers['delete']] | ||
return deleteUsersList, None | ||
|
Oops, something went wrong.