diff --git a/application/__init__.py b/application/__init__.py index e065bf8..c87a087 100644 --- a/application/__init__.py +++ b/application/__init__.py @@ -9,14 +9,14 @@ # Import all of the controllers for your application from application.controllers import * from application.config import config -from absolutepath import getAbsolutePath +from application.absolutepath import getAbsolutePath # from application.models import * # We need to track session information for using the # admin console. This is not fully understood yet. # The admin console does not work without it, though. import uuid -if config.flask.secretKey in ["UUID", "RANDOM"]: +if config['flask']['secretKey']in ["UUID", "RANDOM"]: app.secret_key = uuid.uuid4() else: app.secret_key = "secretsecretsecret" @@ -42,7 +42,7 @@ def index(self): return redirect("/", code = 302) admin = admin.Admin(app, - name = config.application.title, + name = config["application"]["title"], index_view = RoleVerifiedAdminIndexView(), template_mode = 'bootstrap3') from application.models import classes @@ -56,27 +56,27 @@ def index(self): # under Apache/Shibboleth import os from application.logic.validation import getUsernameFromEnv as gUFE -config.flask.username = gUFE() +config["flask"]["username"] = gUFE() # This hook ensures that a connection is opened to handle any queries # generated by the request. Opens every database, which is not ideal, # but because we don't know which will be used... -@app.before_request -def _db_connect(): - for db in config.databases.dynamic: - theDB = config.databases.dynamic[db].theDB - theDB.connect() +# @app.before_request +# def _db_connect(): +# for db in config["databases"]["dynamic"]: +# theDB = config["databases"]["dynamic"][db][theDB] +# theDB.connect() -# This hook ensures that the connection is closed when we've finished -# processing the request. -@app.teardown_appcontext -def _db_close(exc): - for db in config.databases.dynamic: - theDB = config.databases.dynamic[db].theDB - if not theDB.is_closed(): - theDB.close() +# # This hook ensures that the connection is closed when we've finished +# # processing the request. +# @app.teardown_appcontext +# def _db_close(exc): +# for db in config["databases"]["dynamic"]: +# theDB = config["databases"]["dynamic"][db] +# if not theDB.is_closed(): +# theDB.close() def authUser(env): @@ -85,7 +85,7 @@ def authUser(env): # we need to sanitize the environment variable # TODO: this looks like a function that can be taken out return env[envK].split("@")[0].split('/')[-1].lower() - elif ("DEBUG" in config) and config.sys["debug"]: + elif ("DEBUG" in config) and config["sys"]["debug"]: old_username = config["DEBUG"]["user"] converted_user = config["DEBUG"]["user"].split('@')[0].split('/')[-1].lower() #TODO: log diff --git a/application/config.py b/application/config.py index 3a7a1eb..060cc45 100644 --- a/application/config.py +++ b/application/config.py @@ -1,52 +1,44 @@ -# See the configure documentation for more about -# this library. -# http://configure.readthedocs.io/en/latest/# -from configure import Configuration -from absolutepath import getAbsolutePath - -# The configure library provides a pretty interface to our -# configuration data. This module doesn't do anything other -# than -config_path = getAbsolutePath('config/config.yaml') -config = Configuration.from_file(config_path).configure() - -# Added for splitting up Add New Chemical form config from config -chemConfig_path = getAbsolutePath('config/chemicalConfig.yaml') -chemConfig = Configuration.from_file(chemConfig_path).configure() - -# Added for add container page -contConfig_path = getAbsolutePath('config/containerConfig.yaml') -contConfig = Configuration.from_file(contConfig_path).configure() - -# Added for check in page -checkInConfig_path = getAbsolutePath('config/checkInConfig.yaml') -checkInConfig = Configuration.from_file(checkInConfig_path).configure() - -# Added for check out page -checkOutConfig_path = getAbsolutePath('config/OutConfig.yaml') -checkOutConfig = Configuration.from_file(checkOutConfig_path).configure() - -#Added for UserAcess page -userConfig_path = getAbsolutePath('config/useraccessConfig.yaml') -userConfig = Configuration.from_file(userConfig_path).configure() - -# Added for Manage Location Page -locationConfig_path = getAbsolutePath('config/locationConfig.yaml') -locationConfig = Configuration.from_file(locationConfig_path).configure() - -# Populates database with all locations added to locations.yaml -addLocationConfig_path = getAbsolutePath('config/locations.yaml') -addLocationConfig = Configuration.from_file(addLocationConfig_path).configure() - -# Populates database with all locations added to reports.yaml -reportConfig_path = getAbsolutePath('config/reports.yaml') -reportConfig = Configuration.from_file(reportConfig_path).configure() - -# This adds the application's base directory to the -# configuration object, so that the rest of the application -# can reference it. +import yaml import os -config.sys.base_dir = os.path.abspath(os.path.dirname(__file__)) + +# Read and parse the config.yaml file +with open('config/config.yaml', 'r') as f: + config = yaml.safe_load(f) + +# Read and parse the chemicalConfig.yaml file +with open('config/chemicalConfig.yaml', 'r') as f: + chemConfig = yaml.safe_load(f) + +# Read and parse the containerConfig.yaml file +with open('config/containerConfig.yaml', 'r') as f: + contConfig = yaml.safe_load(f) + +# Read and parse the checkInConfig.yaml file +with open('config/checkInConfig.yaml', 'r') as f: + checkInConfig = yaml.safe_load(f) + +# Read and parse the OutConfig.yaml file +with open('config/OutConfig.yaml', 'r') as f: + checkOutConfig = yaml.safe_load(f) + +# Read and parse the useraccessConfig.yaml file +with open('config/useraccessConfig.yaml', 'r') as f: + userConfig = yaml.safe_load(f) + +# Read and parse the locationConfig.yaml file +with open('config/locationConfig.yaml', 'r') as f: + locationConfig = yaml.safe_load(f) + +# Read and parse the locations.yaml file +with open('config/locations.yaml', 'r') as f: + addLocationConfig = yaml.safe_load(f) + +# Read and parse the reports.yaml file +with open('config/reports.yaml', 'r') as f: + reportConfig = yaml.safe_load(f) + +# Add the application's base directory to the config object +config['sys']['base_dir'] = os.path.abspath(os.path.dirname(__file__)) from application import app from application.customFilters import filters diff --git a/application/controllers/allCont/AddChemicalController.py b/application/controllers/allCont/AddChemicalController.py index 2b55703..0acb78a 100644 --- a/application/controllers/allCont/AddChemicalController.py +++ b/application/controllers/allCont/AddChemicalController.py @@ -19,7 +19,7 @@ def AddChemical(): auth = AuthorizedUser() user = auth.getUser() userLevel = auth.userLevel() - print user.username, userLevel + print (user.username, userLevel) if userLevel == "admin" or userLevel == "systemAdmin": if request.method == "GET": @@ -49,5 +49,5 @@ def checkName(): if chemical is not None: return jsonify({'required':True}) #Build the json dict for a success except: - print "This should log something..." + print( "This should log something...") return jsonify({'required':False}) diff --git a/application/controllers/allCont/AddUserController.py b/application/controllers/allCont/AddUserController.py index 36a1fae..4f59263 100644 --- a/application/controllers/allCont/AddUserController.py +++ b/application/controllers/allCont/AddUserController.py @@ -22,7 +22,7 @@ def AddUser(): userLevel = auth.userLevel() if userLevel == -1 or user == -1: abort(403) - print user.username, userLevel + print (user.username, userLevel) if userLevel == "admin": if request.method == "POST": status, flashMessage, flashFormat = createUser(request.form, user.username, True) # createUser function located in usersModel.py diff --git a/application/controllers/allCont/CheckInController.py b/application/controllers/allCont/CheckInController.py index 9791fd3..604a9e8 100644 --- a/application/controllers/allCont/CheckInController.py +++ b/application/controllers/allCont/CheckInController.py @@ -21,7 +21,7 @@ def CheckIn(): auth = AuthorizedUser() user = auth.getUser() userLevel = auth.userLevel() - print user.username, userLevel + print (user.username, userLevel) if userLevel == "admin" or userLevel == "systemAdmin": storageList = getStorages() diff --git a/application/controllers/allCont/CheckOutController.py b/application/controllers/allCont/CheckOutController.py index cac52d8..55b5cab 100644 --- a/application/controllers/allCont/CheckOutController.py +++ b/application/controllers/allCont/CheckOutController.py @@ -21,7 +21,7 @@ def CheckOut(): auth = AuthorizedUser() user = auth.getUser() userLevel = auth.userLevel() - print user.username, userLevel + print (user.username, userLevel) if userLevel == "admin" or userLevel == "systemAdmin": storageList = getStorages() diff --git a/application/controllers/allCont/ChemTableController.py b/application/controllers/allCont/ChemTableController.py index 9eee72e..bf7dde1 100644 --- a/application/controllers/allCont/ChemTableController.py +++ b/application/controllers/allCont/ChemTableController.py @@ -20,7 +20,7 @@ def ChemTable(): userLevel = auth.userLevel() if userLevel == -1 or user == -1: abort(403) - print user.username, userLevel + print (user.username, userLevel) contDict = contCount(getChemicals()) containers = getAllDataAboutContainers() @@ -29,7 +29,6 @@ def ChemTable(): config = config, containers = containers, contDict = contDict, - quote = quote, authLevel = userLevel) @app.route("/getEditData/", methods = ['GET']) #AJAX call to get data for edit chemical form diff --git a/application/controllers/allCont/ContainerInfoController.py b/application/controllers/allCont/ContainerInfoController.py index cde8337..72bbf48 100644 --- a/application/controllers/allCont/ContainerInfoController.py +++ b/application/controllers/allCont/ContainerInfoController.py @@ -27,7 +27,7 @@ def maContainerInfo(chemId, barcodeId): auth = AuthorizedUser() user = auth.getUser() userLevel = auth.userLevel() - print user.username, userLevel + print (user.username, userLevel) if userLevel == "admin" or userLevel == "systemAdmin": chemical = getChemical(chemId) diff --git a/application/controllers/allCont/HomeController.py b/application/controllers/allCont/HomeController.py index 5ae419e..5e5e784 100644 --- a/application/controllers/allCont/HomeController.py +++ b/application/controllers/allCont/HomeController.py @@ -30,7 +30,7 @@ def adminHome(): userLevel = auth.userLevel() if user == -1: render_template("views/UnathorizedView.html") - print user.username, userLevel + print (user.username, userLevel) if userLevel == "admin" or userLevel == "systemAdmin": buildings = getBuildings() @@ -60,7 +60,7 @@ def adminHome(): flash(flashMessage, flashFormat) elif data['location'] == "Storage": #If the form is editing a storage if data['action'] == 'edit': - print data + print (data) storage = Storages.get(Storages.sId == data['id']) #Get storage location to be edited and change all information to what was in form for i in data: setattr(storage, i, data[i]) diff --git a/application/controllers/allCont/ReportController.py b/application/controllers/allCont/ReportController.py index 312b06d..5fbb9cc 100644 --- a/application/controllers/allCont/ReportController.py +++ b/application/controllers/allCont/ReportController.py @@ -28,9 +28,9 @@ def report(): if userLevel == 'admin' or userLevel == 'superUser' or userLevel == 'systemAdmin': if request.method == "GET": allBuild = getBuildings() - inputs = [None] * len(reportConfig.ReportTypes.Inputs) - for key in reportConfig.ReportTypes.Inputs: - index = reportConfig.ReportTypes.Inputs[key] + inputs = [None] * len(reportConfig["ReportTypes"]["Inputs"]) + for key in reportConfig["ReportTypes"]["Inputs"]: + index = reportConfig["ReportTypes"]["Inputs"][key] inputs[index] = key return render_template("views/ReportView.html", authLevel = userLevel, diff --git a/application/controllers/allCont/RequestUserAccessController.py b/application/controllers/allCont/RequestUserAccessController.py index 0b10ee1..ac873bf 100644 --- a/application/controllers/allCont/RequestUserAccessController.py +++ b/application/controllers/allCont/RequestUserAccessController.py @@ -20,7 +20,7 @@ def RequestUserAccess(): userLevel = auth.userLevel() if userLevel == -1 or user == -1: abort(403) - print user.username, userLevel + print (user.username, userLevel) if request.method == "POST": status, flashMessage, flashFormat = createUser(request.form, user.username, False) diff --git a/application/controllers/allCont/UserApprovalController.py b/application/controllers/allCont/UserApprovalController.py index 0d608d4..8c2687a 100644 --- a/application/controllers/allCont/UserApprovalController.py +++ b/application/controllers/allCont/UserApprovalController.py @@ -20,7 +20,7 @@ def UserApproval(): userLevel = auth.userLevel() if userLevel == -1 or user == -1: abort(403) - print user.username, userLevel + print (user.username, userLevel) if userLevel == "admin": if request.method == "POST": @@ -35,7 +35,7 @@ def UserApproval(): flash(flashMessage, flashFormat) elif 'denyButton' in data: #TODO: delete users that were denied - print data['denyButton'] + print (data['denyButton']) for user in usersList: try: query = Users.delete().where(Users.userId == user) diff --git a/application/controllers/allCont/ViewChemicalController.py b/application/controllers/allCont/ViewChemicalController.py index 3ae2a5a..cd0decd 100644 --- a/application/controllers/allCont/ViewChemicalController.py +++ b/application/controllers/allCont/ViewChemicalController.py @@ -27,7 +27,7 @@ def ViewChemical(chemId): userLevel = auth.userLevel() if userLevel == -1 or user == -1: abort(403) - print user.username, userLevel + print (user.username, userLevel) hazardList = getChemicalHazards(chemId) try: diff --git a/application/controllers/allCont/ViewUserController.py b/application/controllers/allCont/ViewUserController.py index 41e1201..2251c79 100644 --- a/application/controllers/allCont/ViewUserController.py +++ b/application/controllers/allCont/ViewUserController.py @@ -19,7 +19,7 @@ def ViewUser(): userLevel = auth.userLevel() if userLevel == -1 or user == -1: abort(403) - print user.username, userLevel + print (user.username, userLevel) usersList = Users.select().where(Users.approve == True) if request.method == "POST": data = request.form diff --git a/application/controllers/allCont/deleteLocationController.py b/application/controllers/allCont/deleteLocationController.py index a03f28c..87f20ac 100644 --- a/application/controllers/allCont/deleteLocationController.py +++ b/application/controllers/allCont/deleteLocationController.py @@ -23,7 +23,7 @@ def maDelete(location, lId): userLevel = auth.userLevel() if userLevel == -1 or user == -1: abort(403) - print user.username, userLevel + print (user.username, userLevel) if userLevel == "admin": state = 0 if request.method == "GET": #Calls delete queries based on what type of location is being deleted. diff --git a/application/controllers/allCont/migrateChemController.py b/application/controllers/allCont/migrateChemController.py index e5f1874..08ee24a 100644 --- a/application/controllers/allCont/migrateChemController.py +++ b/application/controllers/allCont/migrateChemController.py @@ -25,7 +25,7 @@ def migrateChem(): auth = AuthorizedUser() user = auth.getUser() userLevel = auth.userLevel() - print user.username, userLevel + print (user.username, userLevel) #locdict = Batch.select().dicts().get() This was used for datamodel testing if userLevel == 'admin' or userLevel == "systemAdmin": @@ -81,7 +81,7 @@ def renderCorrectTemplate(barcode): #Try and Retrieve Container and Chemical Informatoin from CISPro if state != MIGRATED: containerObj = getCisProContainer(inputBar) - print containerObj + print (containerObj) if containerObj == False: flash("Container " + inputBar + " Is Not In CISPro Database", "list-group-item list-group-item-danger") state = UNKNOWN diff --git a/application/customFilters/filters.py b/application/customFilters/filters.py index bd3b5c6..85dd625 100644 --- a/application/customFilters/filters.py +++ b/application/customFilters/filters.py @@ -1,6 +1,6 @@ import datetime def formatDateTime(value, format="%m-%d-%Y"): - print type(value) + print (type(value)) return value.strftime(format) # return datetime.datetime.strptime(value, "%Y-%m-%d %H:%M:%S.%f") \ No newline at end of file diff --git "a/application/logic/\\" "b/application/logic/\\" index 6b359c7..c2781d0 100644 --- "a/application/logic/\\" +++ "b/application/logic/\\" @@ -16,7 +16,7 @@ def genLocationReport(loc_id): """ Returns a file of all chemicals and containers in a location """ - print loc_id + print (loc_id) #for cont in getChemInStor(loc_id): # print cont.chemId.name #for cont in getChemInRoom(loc_id): @@ -26,7 +26,7 @@ def genLocationReport(loc_id): #for cont in getChemInBuild(loc_id): # print cont.barcodeId for cont in getIBFlamLiquids(): - print cont.barcodeId + print (cont.barcodeId) return 0 def genHazardReport(building): diff --git a/application/logic/genBarcode.py b/application/logic/genBarcode.py index 4b71490..11c7789 100644 --- a/application/logic/genBarcode.py +++ b/application/logic/genBarcode.py @@ -1,6 +1,7 @@ from datetime import date def genBarcode(lstBcode): + """Takes a barcode and creates and returns the next one Input: Str in the form '16100024' Output: Str in the form '16100025""" @@ -9,15 +10,15 @@ def genBarcode(lstBcode): if len(month) < 2: #if month is less then 10 add a 0 to the front to make it match in len - month = '0' + month + month = '0' + month if lstBcode[0:2] == year: #If the last barcode was made in current year #The year is correct - if lstBcode[2:4] == month: #If the last barcode was made in current month - #The month is also correct so we increment the count - newbar = year + month + increment(lstBcode[4:8]) + if lstBcode[2:4] == month: #If the last barcode was made in current month + #The month is also correct so we increment the count + newbar = year + month + increment(lstBcode[4:8]) else: - newbar = year + month + "0000" + newbar = year + month + "0000" else: newbar = year + month +"0000" return newbar diff --git a/application/logic/validation.py b/application/logic/validation.py index d2161cd..6a2ba26 100644 --- a/application/logic/validation.py +++ b/application/logic/validation.py @@ -1,7 +1,8 @@ # See the configure documentation for more about # this library. # http://configure.readthedocs.io/en/latest/# -from configure import Configuration +# from configure import Configuration +import yaml from application.config import config from application.models import getModelFromName from application.absolutepath import getAbsolutePath @@ -9,8 +10,13 @@ from flask import request, redirect, url_for import os, re +# roleConfigFilePath = getAbsolutePath('config/roles.yaml') +# roleConfig = Configuration.from_file(roleConfigFilePath).configure() + + roleConfigFilePath = getAbsolutePath('config/roles.yaml') -roleConfig = Configuration.from_file(roleConfigFilePath).configure() +with open(roleConfigFilePath) as f: + roleConfig = yaml.load(f, Loader=yaml.FullLoader) def getUsernameFromEnv(): # FIXME: This is wrong. @@ -53,19 +59,19 @@ def userHasRole (username, role): if re.match('database', ug): # Get the name of the database db = re.split(" ", ug)[1] - print "DB is '{0}'".format(db) + print ("DB is '{0}'".format(db)) # Get the actual model from the name of the model. m = getModelFromName(db) - print "Model: {0}".format(m) + print ("Model: {0}".format(m)) # Do a "get", and require that their username and role are both # set. For example, look for {jadudm, admin}, not just the username. result = m.select().where(m.username == username, m.role == role).count() if result > 0: - print "User '{0}' validated via database {1}".format(username, db) + print ("User '{0}' validated via database {1}".format(username, db)) return True else: - print "User '{0}' not found in database {1}".format(username, db) + print ("User '{0}' not found in database {1}".format(username, db)) return False # Check if they are in the Active Directory @@ -82,7 +88,7 @@ def userHasRole (username, role): def checkValidUser (fun): @wraps(fun) def wrapper (*args, **kwargs): - print "Is Valid User" + print ("Is Valid User") return fun(*args, **kwargs) return wrapper @@ -92,10 +98,10 @@ def decorator (fun): def decorated_fun (*args, **kwargs): # print "Is Valid Role: %s" % expected_args[0] if userHasRole (getUsernameFromEnv(), requiredRole): - print "User has role." + print ("User has role.") return fun(*args, **kwargs) else: - print "User does not have role." + print ("User does not have role.") return redirect(url_for(config.application.default), code = 302) # return config.application.noRoleHandler return decorated_fun diff --git a/application/models/chemicalsModel.py b/application/models/chemicalsModel.py index 90ae001..5af9159 100644 --- a/application/models/chemicalsModel.py +++ b/application/models/chemicalsModel.py @@ -69,13 +69,13 @@ def createChemical(data): except: newChem = (Chemicals.create(**modelData), False) #Create instance of Chemical with mapped info in modelData False, because it couldn't get the chemical if newChem[1]: - print modelData + print (modelData) Chemicals.update(**modelData).where(Chemicals.name == newChem[0].name).execute() newChem[0].remove = False newChem[0].save() return(True, "Chemical Created Successfully!", "list-group-item list-group-item-success", newChem[0]) except Exception as e: - print e + print (e) return(False, "Chemical Could Not Be Created.", "list-group-item list-group-item-danger", None) def deleteChemical(chemId): diff --git a/application/models/containersModel.py b/application/models/containersModel.py index 1bd1d9e..e3026e5 100644 --- a/application/models/containersModel.py +++ b/application/models/containersModel.py @@ -58,7 +58,7 @@ def addContainer(data, user): application.models.historiesModel.updateHistory(cont, "Created", data['storageId'], user) return (True, "Container Created Successfully!", "list-group-item list-group-item-success", cont) except Exception as e: - print e + print (e) return (False, "Container Could Not Be Created!", "list-group-item list-group-item-danger", None) return Containers.get(Containers.barcodeId == barcode) @@ -72,7 +72,7 @@ def changeLocation(cont, status, data, user): Returns: Nothing """ #should return something for unit testing later - print data + print (data) if status: # True if checking out try: cont.storageId = data['storageId'] diff --git a/application/models/staticModels/batchModel.py b/application/models/staticModels/batchModel.py index cffd700..832b372 100644 --- a/application/models/staticModels/batchModel.py +++ b/application/models/staticModels/batchModel.py @@ -63,7 +63,7 @@ def getCisProContainer(barcode): .join(Locates, on=(Batch.Id_id == Locates.Location))\ .where((Batch.UniqueContainerID == barcode)|(Batch.UniqueContainerID == str(barcode).upper())).get() except Exception as e: - print e + print (e) return False diff --git a/application/models/util.py b/application/models/util.py index 89a11a2..d8b73a2 100644 --- a/application/models/util.py +++ b/application/models/util.py @@ -1,16 +1,21 @@ from application.config import * from application.absolutepath import getAbsolutePath from peewee import * +import yaml +from application.absolutepath import getAbsolutePath +from peewee import SqliteDatabase + +with open('config/config.yaml') as f: + config = yaml.load(f, Loader=yaml.FullLoader) -def getDB (dbName, dbType): - dbPath = config.databases[dbType][dbName].filename - dbPath = getAbsolutePath(dbPath) - # print "DB Name: {0}\nDB Path: {1}".format(dbName, dbPath) - theDB = SqliteDatabase (dbPath, - pragmas = ( ('busy_timeout', 100), - ('journal_mode', 'WAL') - ), - threadlocals = True) - config.databases[dbType][dbName].theDB = theDB - return theDB +def getDB(dbName, dbType): + dbPath = config['databases'][dbType][dbName]['filename'] + dbPath = getAbsolutePath(dbPath) + theDB = SqliteDatabase(dbPath, + pragmas=(('busy_timeout', 100), + ('journal_mode', 'WAL') + ), + threadlocals=True) + config['databases'][dbType][dbName]['theDB'] = theDB + return theDB diff --git a/locationPop.py b/locationPop.py index 07d2ef2..4e2d6a1 100644 --- a/locationPop.py +++ b/locationPop.py @@ -27,12 +27,12 @@ def init_db(): for c in classes: c.create_table(True) - print 'Database Initialized' + print ('Database Initialized') #### #Makes one building that the one floor is put in #### for building in addLocationConfig.buildings: - print building.keys() + print (building.keys()) currentBuildingId = buildingsModel.Buildings() currentBuildingId.name = building['name'] currentBuildingId.numFloors = building['numFloors'] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..85b65e7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,19 @@ +click==7.1.2 +configure==0.5 +et-xmlfile==1.0.1 +Flask==0.12.1 +Flask-Admin==1.4.0 +Flask-Session==0.2.3 +itsdangerous==1.1.0 +jdcal==1.4.1 +Jinja2==2.11.3 +MarkupSafe==1.1.1 +openpyxl==2.4.5 +peewee==2.9.2 +py==1.11.0 +pytest==3.0.5 +PyYAML==5.4.1 +Unidecode==0.4.20 +Werkzeug==0.16.0 +wtf-peewee==0.2.6 +WTForms==2.1 diff --git a/requirements2.txt b/requirements2.txt new file mode 100644 index 0000000..29b415c --- /dev/null +++ b/requirements2.txt @@ -0,0 +1,92 @@ +alembic==1.6.3 +appdirs==1.4.4 +attributedict==0.3.0 +attrs==21.2.0 +blessings==1.7 +blinker==1.4 +cachelib==0.9.0 +certifi==2020.12.5 +cffi==1.14.5 +chardet==4.0.0 +click==8.0.1 +codecov==2.1.11 +colorama==0.4.4 +coloredlogs==15.0 +colour-runner==0.1.1 +config2==0.3.2 +configparser==5.0.2 +coverage==5.5 +crayons==0.4.0 +cryptography==3.4.7 +deepdiff==5.5.0 +deepmerge==0.3.0 +distlib==0.3.1 +docopt==0.6.2 +dominate==2.6.0 +et-xmlfile==1.1.0 +exceptiongroup==1.1.0 +filelock==3.0.12 +Flask==2.2.2 +Flask-Admin==1.5.8 +Flask-Login==0.5.0 +Flask-Mail==0.9.1 +Flask-Migrate==3.0.0 +Flask-MySQL==1.5.2 +flask-nav==0.6 +flask-session2==1.3.1 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.0 +humanfriendly==9.1 +idna==2.10 +importlib-metadata==6.0.0 +iniconfig==1.1.1 +inspecta==0.1.3 +itsdangerous==2.0.1 +Jinja2==3.0.1 +Mako==1.1.4 +MarkupSafe==2.1.2 +more-itertools==8.8.0 +mybad==0.1.4 +openpyxl==3.0.10 +ordered-set==4.0.2 +packaging==20.9 +peewee==3.14.4 +peewee-migrations==0.3.19 +pluggy==0.13.1 +py==1.10.0 +py-solc-ast==1.2.9 +pycparser==2.20 +Pygments==2.9.0 +PyMySQL==1.0.2 +pyparsing==2.4.7 +pytest==7.2.0 +pytest-base-url==1.4.2 +pytest-html==2.1.1 +pytest-metadata==1.10.0 +pytest-watch==4.2.0 +python-dateutil==2.8.0 +python-editor==1.0.4 +pytz==2022.7.1 +PyYAML==5.4.1 +requests==2.25.1 +rootpath==0.1.1 +selenium==3.141.0 +setupextras==0.1.5 +six==1.16.0 +SQLAlchemy==1.4.15 +termcolor==1.1.0 +toml==0.10.2 +tomli==2.0.1 +tox==3.23.1 +Unidecode==1.3.6 +urllib3==1.26.4 +virtualenv==20.4.6 +visitor==0.1.3 +watchdog==2.1.2 +wcwidth==0.2.5 +webdriver-manager==3.4.2 +Werkzeug==2.2.2 +wtf-peewee==3.0.4 +WTForms==2.3.3 +XlsxWriter==3.0.3 +zipp==3.11.0 diff --git a/reset-db.py b/reset-db.py index 35e0fcf..1370ba5 100644 --- a/reset-db.py +++ b/reset-db.py @@ -9,8 +9,8 @@ def init_db (): # First, we create the databases. - for database in config.databases.dynamic: - filename = config.databases.dynamic[database].filename + for database in config["databases"]["dynamic"]: + filename = config["databases"]["dynamic"][database]["filename"] """Initializes the database.""" # Remove the DB @@ -33,8 +33,8 @@ def init_db (): auth_level="admin", emailadd="heggens@berea.edu", approve=True, - created_date=2022-01-31, - end_date=2025-01-30, + created_date=2022-1-31, + end_date=2025-1-30, reportto="Idk", created_by="heggens")) diff --git a/run.py b/run.py index b8c102e..acb46e3 100644 --- a/run.py +++ b/run.py @@ -15,4 +15,4 @@ pass # Run the web application. -app.run(debug = config.sys.debug, host = IP, port = config.sys.port) +app.run(debug = config["sys"]["debug"], host = IP, port = config["sys"]["port"]) diff --git a/setup.sh b/setup.sh index 6ac37d9..0c11055 100755 --- a/setup.sh +++ b/setup.sh @@ -1,53 +1,18 @@ -# This sets default values for the versions of the Python -# libraries we are installing. If we wish to override this -# (say, during VM or container setup), we do so by -# exporting these variables into the shell environment before -# sourcing this script. If these variables exist before this -# script is sourced, then the pre-existing values will be used. -FLASK_VERSION="${FLASK_VERSION:-0.12.1}" -WERKZEUG_VERSION="${WERKZEUG_VERSION:-0.16.0}" -WTFORMS_VERSION="${WTFORMS_VERSION:-2.1}" -FLASK_SESSION_VERSION="${FLASK_SESSION_VERSION:-0.2.3}" -FLASK_ADMIN_VERSION="${FLASK_ADMIN_VERSION:-1.4.0}" -PEEWEE_VERSION="${PEEWEE_VERSION:-2.9.2}" -WTF_PEEWEE_VERSION="${WTF_PEEWEE_VERSION:-0.2.6}" -PYYAML_VERSION="${PYYAML_VERSION:-3.11}" -CONFIGURE_VERSION="${CONFIGURE_VERSION:-0.5}" -PYTEST_VERSION="${PYTEST_VERSION:-3.0.5}" -OPENPYXL_VERSION="${OPENPYXL_VERSION:-2.4.5}" -UNIDECODE_VERSION="${UNIDECODE_VERSION:-0.4.20}" - -# Check for virtualenv -command -v virtualenv >/dev/null 2>&1 || { - echo >&2 "I require 'virtualenv' but it's not installed. Aborting."; - exit 1; - } - - # Check for pip -command -v pip >/dev/null 2>&1 || { - echo >&2 "I require 'pip' but it's not installed. Aborting."; - exit 1; -} - - -# If there is a virtual environment, destroy it. -if [ -d venv ]; then - echo "Deactivating and removing old virtualenv" - deactivate 2>&1 /dev/null - rm -rf venv -fi - # Check for correct python version -VERSION=`python2 -V | awk '{print $2}'` -if [ "${VERSION:0:1}" -ne "2" ] || [ "${VERSION:2:1}" -ne "7" ]; then - echo "You must use Python 2.7. You are using $VERSION" - return 1 +VERSION=`python3 -V | awk '{print $2}'` +MAJOR_VERSION=`echo $VERSION | cut -d'.' -f1` #make sure a python version above 3.7 is used +MINOR_VERSION=`echo $VERSION | cut -d'.' -f2` +if [ $MAJOR_VERSION -eq 3 ] && [ $MINOR_VERSION -ge 7 ]; then + echo -e "You are using Python $VERSION" else - echo -e "You are using Python $VERSION" + echo "You must use Python 3.7 or later. You are using $VERSION" + return 1 fi -# Create and activate a clean virtual environment. -virtualenv --python=python2.7 venv +if [ ! -d venv ] +then + python3 -m venv venv +fi . venv/bin/activate # Create a data directory @@ -56,41 +21,10 @@ mkdir -p data # Upgrade pip before continuing; avoids warnings. # This should not affect application behavior. -pip install --upgrade pip - -# Install specific versions of libraries to avoid -# different behaviors of applications over time. -pip install "werkzeug==$WERKZEUG_VERSION" - -pip install "flask==$FLASK_VERSION" #0.12.1 -# http://flask.pocoo.org/ - -pip install "wtforms==$WTFORMS_VERSION" #2.1 -# https://wtforms.readthedocs.io/en/latest/ - -pip install "flask-session==$FLASK_SESSION_VERSION" #0.2.3 -# http://pythonhosted.org/Flask-Session/ - -pip install "flask-admin==$FLASK_ADMIN_VERSION" #1.4.0 -# https://flask-admin.readthedocs.io/en/latest/ - -pip install "peewee==$PEEWEE_VERSION" # 2.9.2 -# http://docs.peewee-orm.com/en/latest/ - -pip install "wtf-peewee==$WTF_PEEWEE_VERSION" #0.2.6 -# https://github.com/coleifer/wtf-peewee - -pip install "configure==$CONFIGURE_VERSION" #0.5 -# http://configure.readthedocs.io/en/latest/# - -pip install "pytest==$PYTEST_VERSION" #3.0.5 -# http://docs.pytest.org/en/latest/ +pip3 install --upgrade pip -pip install "openpyxl==$OPENPYXL_VERSION" #2.4.5 -# https://github.com/jmcnamara/XlsxWriter +python -m pip install -r requirements.txt -pip install "unidecode==$UNIDECODE_VERSION" #0.4.20 -# https://pypi.python.org/pypi/Unidecode export FLASK_APP=run.py export FLASK_ENV=development diff --git a/test.py b/test.py index e6dcacd..981a2b1 100644 --- a/test.py +++ b/test.py @@ -6,5 +6,5 @@ def gcd(m, n, count=1): for i in range(1, 10): for r in range(1, 10): - print i, r - print gcd(i, r) \ No newline at end of file + print( i, r) + print (gcd(i, r)) \ No newline at end of file diff --git a/tools/cp.py b/tools/cp.py index 12fa1a3..0761731 100644 --- a/tools/cp.py +++ b/tools/cp.py @@ -19,11 +19,11 @@ args = parser.parse_args() def error (msg): - print "OOPS: {0}\n".format(msg) + print ("OOPS: {0}\n".format(msg)) exit() def announce (msg): - print msg + print (msg) def hasKey (d, k): return isinstance(d, dict) and (k in d) @@ -63,7 +63,7 @@ def checkValidMethods (h): result = True for m in h["methods"]: if not m in ["GET", "POST", "PUT", "DELETE"]: - print "==> {0} is not a valid method.".format(m) + print ("==> {0} is not a valid method.".format(m)) result = False return result @@ -72,7 +72,7 @@ def checkValidRoles (h): definedRoles = Configuration.from_file('config/roles.yaml').configure() for r in h["roles"]: if not r in definedRoles: - print "==> {0} is not a valid role.".format(r) + print ("==> {0} is not a valid role.".format(r)) result = False return result @@ -117,9 +117,9 @@ def checkSyntax (cc): # We now know there is a valid list of controllers in every directory for d in directories: - print "------------------" - print "Checking directory '{0}'".format(d["name"]) - print "------------------" + print ("------------------") + print ("Checking directory '{0}'".format(d["name"])) + print ("------------------") controllers = d["controllers"] @@ -182,39 +182,39 @@ def checkSyntax (cc): routes = [] funs = [] - print - print "Looking for repeats of routes and function names." - print "-------------------------------------------------" + + print ("Looking for repeats of routes and function names.") + print ("-------------------------------------------------") for d in directories: - print "Directory {0}".format(d["name"]) + print ("Directory {0}".format(d["name"])) controllers = d["controllers"] for c in controllers: - print "=> Controller: {0}".format(c["name"]) + print ("=> Controller: {0}".format(c["name"])) handlers = c["handlers"] for h in handlers: - print "==> Route {0}".format(h["route"]) - print "==> Func {0}".format(h["function"]) + print ("==> Route {0}".format(h["route"])) + print ("==> Func {0}".format(h["function"])) print routes.append(h["route"]) funs.append(h["function"]) - print "" + print ("") # Now, do a cute set uniqueness check. # http://stackoverflow.com/questions/5278122/checking-if-all-elements-in-a-list-are-unique repeats = findRepeats(routes) if len(repeats) > 0: - print "There are repeated routes in your controllers." - print routes - print repeats + print ("There are repeated routes in your controllers.") + print (routes) + print (repeats) for r in repeats: - print "route: {0}".format(r) + print ("route: {0}".format(r)) error("Routes cannot repeat.") repeats = findRepeats(funs) if len(repeats) > 0: - print "There are repeated function names in your controllers." + print ("There are repeated function names in your controllers.") for f in repeats: - print "function: {0}".format(f) + print ("function: {0}".format(f)) error ("Function names cannot repeat.") # If we get here, we pass syntax. @@ -222,7 +222,7 @@ def checkSyntax (cc): def createDirectory (dir): if not os.path.exists(dir): - print "Creating directory '{0}'".format(dir) + print ("Creating directory '{0}'".format(dir)) os.makedirs(dir) def touchFile (f): @@ -230,7 +230,7 @@ def touchFile (f): def copyDefault (src, dest): if not os.path.exists(dest): - print "Copying default file:\n\t'{0}'.".format(src) + print ("Copying default file:\n\t'{0}'.".format(src)) shutil.copy(src, dest) @@ -245,7 +245,7 @@ def handlerExists (f, h): result = False for line in f: if re.search(h["route"], line): - print "=> Route '{0}' already exists. Skipping.".format(h["route"]) + print ("=> Route '{0}' already exists. Skipping.".format(h["route"])) result = True return result @@ -260,7 +260,7 @@ def getParams(routeString): def createHandlerInController (controllerFile, d, c, h): # If the handler isn't already there if not handlerExists(controllerFile, h): - print "Adding route '{0}' to {1}.".format(h["route"], c["name"]) + print ("Adding route '{0}' to {1}.".format(h["route"], c["name"])) cf = open(controllerFile, 'a') cf.write("\n") @@ -333,11 +333,10 @@ def generateFiles (cc): syntaxOK = checkSyntax (cc) if syntaxOK: - print "Syntax checks." + print ("Syntax checks.") if syntaxOK and args.generate: - print - print "Generating files." - print "-----------------" + print( "Generating files.") + print ("-----------------") generateFiles (cc) diff --git a/tools/stressor.py b/tools/stressor.py index ed09637..d71ec9e 100755 --- a/tools/stressor.py +++ b/tools/stressor.py @@ -1,9 +1,11 @@ #!/usr/bin/env python from application.models import Mess from application.config import * -from httplib import * +from http.client import HTTPConnection from urllib import * from uuid import * +from urllib.parse import urlencode +from uuid import uuid4 import string import random @@ -25,5 +27,5 @@ def generate (size = 6, chars = string.ascii_uppercase + string.digits): conn.request("POST", "insert", params, headers) response = conn.getresponse() if response.status != 200: - print "Error on insert {0}: {1} {2}".format(i, response.status, response.reason) - print "Done with {0} inserts on string size {1}".format(numInserts, stringSize) + print ("Error on insert {0}: {1} {2}".format(i, response.status, response.reason)) + print ("Done with {0} inserts on string size {1}".format(numInserts, stringSize))