Skip to content

Commit

Permalink
Packaging with poetry, Linting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Astitva committed Mar 31, 2024
1 parent ba76a0e commit 0516468
Show file tree
Hide file tree
Showing 9 changed files with 313 additions and 128 deletions.
Empty file added cli/README.md
Empty file.
2 changes: 1 addition & 1 deletion cli/dtaas.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ git-repo = "https://github.com/into-cps-association/DTaaS.git"

[common]
# absolute path to the DTaaS application directory
server-dns = "domain.com"
server-dns = "localhost"
path = "/home/astitva/Desktop/yamlstuff"

[users]
Expand Down
149 changes: 149 additions & 0 deletions cli/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions cli/pyproject.toml
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"
16 changes: 0 additions & 16 deletions cli/setup.py

This file was deleted.

23 changes: 12 additions & 11 deletions cli/src/cmd.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
""" This file defines all cli entrypoints for dtaas"""

import click
#from . import service
from .pkg import dtaas as dtaasPkg
from .pkg import config as configPkg
from .pkg import users as userPkg
from .pkg import utils



### Groups
@click.group()
def dtaas():
"""all commands to help with Digital Twins as a Service"""
pass
return

@dtaas.group()
def admin():
"administrative commands for DTaaS"
pass
return

@admin.group()
def user():
"""user management commands"""
pass
return

#### user group commands
@user.command()
Expand All @@ -30,10 +31,10 @@ def add():
Specify the list in dtaas.toml [users].add\n
"""

configObj = dtaasPkg.Config()
configObj = configPkg.Config()

err = userPkg.addUsers(configObj)
if err!=None:
if err is not None:
raise click.ClickException("Error while adding users: " + str(err))
click.echo("Users added successfully")

Expand All @@ -44,9 +45,9 @@ def delete():
Specify the users in dtaas.toml [users].delete\n
"""

configObj = dtaasPkg.Config()
configObj = configPkg.Config()

err = userPkg.deleteUser(configObj)
if err!=None:
if err is not None:
raise click.ClickException("Error while deleting users: " + str(err))
click.echo("User deleted successfully")
click.echo("User deleted successfully")
54 changes: 32 additions & 22 deletions cli/src/pkg/dtaas.py → cli/src/pkg/config.py
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

Loading

0 comments on commit 0516468

Please sign in to comment.