Skip to content

Commit

Permalink
VFv0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
s4dhulabs committed Oct 19, 2022
1 parent fef897d commit bc28e21
Show file tree
Hide file tree
Showing 67 changed files with 2,839 additions and 2,010 deletions.
63 changes: 43 additions & 20 deletions core/_dbops_/models/siddhis.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from ..config import db
from sqlalchemy.ext.mutable import MutableList
from sqlalchemy import PickleType
from sqlalchemy.types import JSON



class Siddhis(db.Model):
Expand All @@ -9,59 +13,78 @@ class Siddhis(db.Model):
db.Integer,
primary_key = True
)
_name_ = db.Column(
name = db.Column(
db.String(30),
unique = True,
nullable = False
)
_acronym_ = db.Column(
db.String(30),
unique = True,
author = db.Column(
db.String(100),
unique = False,
nullable = False
)
_category_ = db.Column(
db.String(30),
brief = db.Column(
db.String(100),
unique = True,
nullable = False
)
_framework_ = db.Column(
category = db.Column(
db.String(30),
unique = True,
unique = False,
nullable = False
)
_type_ = db.Column(
db.String(30),
unique = True,
framework = db.Column(
db.String(50),
unique = False,
nullable = False
)
_module_ = db.Column(
db.String(30),
info = db.Column(
db.String(100),
unique = True,
nullable = False
)
_author_ = db.Column(
db.String(30),
module = db.Column(
db.String(50),
unique = True,
nullable = False
)
_brief_ = db.Column(
package = db.Column(
db.String(50),
unique = False,
nullable = True
)
type = db.Column(
db.String(30),
unique = False,
nullable = False
)
tags = db.Column(
JSON,
unique = False,
nullable = False
)
description = db.Column(
db.String(1000),
unique = True,
nullable = False
)
_description_ = db.Column(
db.String(30),
references = db.Column(
JSON,
unique = False,
nullable = False
)
guide = db.Column(
JSON,
unique = True,
nullable = False
)


def __init__(self, **kwargs):
super().__init__(**kwargs)

def to_dict(self) -> dict:
return {c.name: getattr(self, c.name) for c in self.__table__.columns}

def __repr__(self):
return f"Session {self.session_id} successfully created!"
return f"successfully created!"

75 changes: 64 additions & 11 deletions core/_dbops_/vmnf_dbops.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,61 @@
from sqlalchemy_utils.functions import database_exists as db_exists
from .models.sessions import VFSessions as VFS
from sqlalchemy_filters import apply_filters
from .models.siddhis import Siddhis as VFSD
from res.vmnf_banners import case_header
from datetime import datetime as dt
from sqlalchemy import or_, and_
from sqlalchemy import func,exc,inspect
from neotermcolor import cprint
from .config import db, app
import os

from datetime import datetime as dt

def x():
print('in x')

class VFSiddhis:
def __init__(self, **vmnf_handler):
self.vmnf_handler = vmnf_handler
def __init__(self, **siddhi_specs:dict):
self.siddhi_specs = siddhi_specs

def register_siddhi(self,**data):
if self.get_session(data['session_id']):
if self.vmnf_handler.get('debug', False):
print(f"[{dt.now()}] Session {data['session_id']} already exists!")
return False
def commit(self,entry):
db.session.add(entry)
db.session.commit()

def register_siddhi(self):
if not inspect(db.engine).has_table("_SIDDHIS_"):
self.create_siddhi_tbl()

self.commit(VFSD(**self.siddhi_specs))

def handle_OpErr(self, exception):
if (str(exception.orig)).startswith('no such table:'):
case_header()
cprint("[vf:list] It seems like you haven't populated the database yet.\n", 'yellow')
os._exit(os.EX_OK)

def list_siddhis_db(self, filters:list):
try:
return (apply_filters(db.session.query(VFSD), filters).all())
except exc.OperationalError as OE:
self.handle_OpErr(OE)

def get_siddhi(self, siddhi_name):
try:
return VFSD.query.filter_by(name=siddhi_name.lower()).first()
except exc.OperationalError as OE:
self.handle_OpErr(OE)

def get_all_siddhis(self):
return VFSD.query.all()

self.commit(VFSD(**data))
def create_siddhi_tbl(self):
try:
VFSD.__table__.drop(db.engine)
except exc.OperationalError as OE:
pass

VFSD.__table__.create(db.engine)

class VFDBOps:
def __init__(self, **vmnf_handler):
Expand Down Expand Up @@ -52,11 +91,16 @@ def commit(self,entry):
def clean_db(self):
db.drop_all()

def get_session(self, _sid_):
def get_session(self,_sid_):
return VFS.query.filter_by(session_id=_sid_).first()

def get_all_sessions(self):
return VFS.query.all()
try:
return VFS.query.all()
except exc.OperationalError as OE:
self.create_db()

return False

def create_db(self):
if not db_exists(app.config["SQLALCHEMY_DATABASE_URI"]):
Expand All @@ -70,11 +114,20 @@ def register_session(self):
print(f"[{dt.now()}] Missing session data")
return False

if not inspect(db.engine).has_table("_SESSIONS_"):
self.create_sessions_tbl()

if self.get_session(self.session['session_id']):
print(f"[{dt.now()}] Session {data['session_id']} already exists!")
return False

self.commit(VFS(**self.session))

def create_sessions_tbl(self):
try:
VFS.__table__.drop(db.engine)
except exc.OperationalError as OE:
pass

VFS.__table__.create(db.engine)

Loading

0 comments on commit bc28e21

Please sign in to comment.