Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import getopt
- import os
- import re
- import sys
- from lib.db_wrapper import DatabaseConnector as Database
- import sqlite3
- import subprocess
- def main(argv):
- # initialize variables
- database_location = "./db/parsed-files.sqlite"
- con = sqlite3.connect(database_location)
- cur = con.cursor()
- #Ask user for ID and password
- print('Welcome to RFID parsing utility.')
- userId = raw_input('Please type your internal ID: ')
- passw = raw_input('Please type your password: ')
- #Choose employee type - then execute module containing privilages
- cur.execute("SELECT * FROM Administrator "
- " WHERE ID=:userId AND Password=:passw", (userId, passw))
- user = cur.fetchone()
- if user:
- #execute admin module
- print('Admin module')
- admin_module(user)
- sys.exit(0)
- cur.execute("SELECT * FROM Manager WHERE ID=:userId AND Password=:passw", (userId, passw)).fetchone()
- user = cur.fetchone()
- if user:
- #execute manager module
- print('Manager module')
- sys.exit(0)
- cur.execute("SELECT * FROM 'Lab Employee' WHERE ID=:userId AND Password=:passw", (userId, passw)).fetchone()
- user = cur.fetchone()
- if user:
- #execute labEmp module
- print('Lab employee module')
- sys.exit(0)
- cur.execute("SELECT * FROM 'Office Worker' WHERE ID=:userId AND Password=:passw", (userId, passw)).fetchone()
- user = cur.fetchone()
- if user:
- #execute offWorker module
- print('Office Worker module')
- sys.exit(0)
- #User was not found in any above table
- print('User with given credentials doesnt exist in database.'
- '\nPlease contact laboratory administrator.')
- sys.exit(0)
- def admin_module(user):
- print('Welcome to RFID parsing utility ') + user[2] + ' ' + user[3]
- # option = 0
- # while(option != 99):
- print('Here are your options:'
- '\n1 - Add file to database'
- '\n2 - Parse all files to database'
- '\n3 - Add new user'
- '\n4 - Update user data'
- '\n5 - Show all items assigned to group'
- '\n6 - Show all items of certain type'
- '\n99 - Exit program')
- option = raw_input('Please choose one option: ')
- # print("You've chosen: ") + option
- if option == 1:
- file_location = raw_input('Please type file name \(it should be located in "RFID_files" folder\)')
- subprocess.call("python rfid-parsing-utility-db.py -i ./RFID_files/%s -o ./RFID_files_parsed/%s --regex ./preset-regex.json --database ./db/parsed-files.sqlite".format(file) % file_location, shell=True, universal_newlines=True)
- elif option == 2:
- os.system('python parse_all_files-db.py')
- elif option == 3:
- user_type = raw_input("Becouse of security, it is not allowed to add new administrator from script level. Please work directly on database.\nPlease type user grade. Options: Lab Employee / Office Worker / Manager ")
- try:
- with Database(database_location) as db_handler:
- if user_type == 'Lab Employee':
- user_ID = raw_input("Please type user ID: ")
- manager_ID = raw_input("Now type user Managers ID: ")
- Name = raw_input("Now type user name: ")
- Email = raw_input("Now type user email: ")
- Password = raw_input("And finally user password: ")
- db_handler.query('INSERT'
- 'INTO "Lab Employee" (ID, "Managers ID", Name, Email, Password) '
- 'VALUES ("{0}", "{1}", "{2}", "{3}", "{4}")'
- .format(user_ID, manager_ID, Name, Email, Password))
- elif user_type == 'Office Worker':
- user_ID = raw_input("Please type user ID: ")
- manager_ID = raw_input("Now type user Managers ID: ")
- Name = raw_input("Now type user name: ")
- Email = raw_input("Now type user email: ")
- Password = raw_input("And finally user password: ")
- db_handler.query('INSERT'
- 'INTO "Office Worker" (ID, "Managers ID", Name, Email, Password) '
- 'VALUES ("{0}", "{1}", "{2}", "{3}", "{4}")'
- .format(user_ID, manager_ID, Name, Email, Password))
- elif user_type == 'Manager':
- user_ID = raw_input("Please type user ID: ")
- Name = raw_input("Now type user name: ")
- Email = raw_input("Now type user email: ")
- Password = raw_input("And finally user password: ")
- db_handler.query('INSERT'
- 'INTO "Item" (ID, Name, Email, Password) '
- 'VALUES ("{0}", "{1}", "{2}", "{3}")'
- .format(user_ID, Name, Email, Password))
- else:
- print("Wrong user type! Please try again.")
- except sqlite3.Error as e:
- print("Database error " + str(e))
- elif option == 4:
- print("Option not yet implemented. Please be patient or remind author of script.")
- elif option == 5:
- team_name = raw_input("Please type team, which hardware you want to check: ")
- cur.execute("SELECT * FROM 'Item' WHERE 'HW Owner'=:team", (team_name))
- print("Hardware owned by ") + team_name + ": "
- print cur.fetchall()
- elif option == 6:
- hw_name = raw_input("Please type hw name, which you want to check: ")
- cur.execute("SELECT * FROM 'Item' WHERE 'HW Name'=:name", (hw_name))
- print("Hardware named ") + hw_name + ": "
- print cur.fetchall()
- elif option == 99:
- sys.exit(0)
- else:
- print("COS ZJEBALES")
- # else:
- # print('Wrong option!'
- # '\nPlease choose correct one')
- # print ("Option chosen ") + option
- if __name__ == "__main__":
- main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement