def check_pymm_log_exists(): # open a local instance of config here in case # it has changed since importing this file pymmConfig = read_config() pymmLogDir = pymmConfig['logging']['pymm_log_dir'] pymmLogPath = os.path.join(pymmLogDir, 'pymm_log.txt') # sys.exit() opener = (((("#" * 75) + '\n') * 2) + ((' ') * 4) + 'THIS IS THE LOG FOR PYMEDIAMICROSERVICES' '\n\n' + ((' ') * 4) + 'THIS VERSION WAS STARTED ON ' + today + '\n' + ((("#" * 75) + '\n') * 2) + '\n') if not os.path.isfile(pymmLogPath): print('wait i need to make a logfile') if pymmLogDir == '': print("!~" * 75) print("CONFIGURATION PROBLEM:\n" "THERE IS NO DIRECTORY SET FOR THE SYSTEM-WIDE LOG.\n" "PLEASE RUN pymmconfig.py OR EDIT config.ini DIRECTLY\n" "TO ADD A VALID DIRECTORY FOR pymm_log.txt TO LIVE IN.\n" "WE'RE JUST GOING TO PUT IT ON YOUR DESKTOP FOR NOW...") desktop = get_desktop() pymmLogPath = os.path.join(desktop, 'pymm_log.txt') from pymmconfig import pymmconfig pymmconfig.set_value('logging', 'pymm_log_dir', desktop) with open(pymmLogPath, 'w+') as pymmLog: pymmLog.write(opener) else: open(pymmLogPath, 'x') with open(pymmLogPath, 'w+') as pymmLog: pymmLog.write(opener) else: pass
def create_user(pymm_db=pymm_db): print("This step will make a new user for the pymm database.\n") newUser = input("Please enter a name for the user: "******"Please enter the name you created for the pymm databse:") else: targetDB = pymm_db if targetDB != pymm_db: print("\n\nFYI!!!\nTHE DATABSE YOU ENTERED (" + targetDB + ")\n" "IS NOT THE SAME AS THE DATABSE IN YOUR CONFIG FILE (" + pymm_db + ")") userPass = input("Enter a password for the user: "******"Please enter the ip address for the user: "******"CREATE USER IF NOT EXISTS %s@%s IDENTIFIED BY %s;" grantPrivsSQL = "GRANT ALL PRIVILEGES ON {}.* TO %s@%s;".format(pymm_db) # print(createUserSQL) # print(grantPrivsSQL) try: connect = db.DB('root') connect.connect() connect.query(createUserSQL, newUser, userIP, userPass) connect.query(grantPrivsSQL, newUser, userIP) connect.close_cursor() connect.close_connection() # print("\n\nIMPORTANT!!\nTO FINISH USER SETUP, TYPE THIS TERMINAL COMMAND ON THE ~USER'S~ COMPUTER:\n" # "mysql_config_editor set --login-path="+newUser+"_db_access --host="+userIP+" --user="******" --password=\n" # "\nAND THEN TYPE IN THE USER PASSWORD ("+userPass+")\n" # "AND ~THEN~ GO INTO THE USER'S LOCAL PYMMCONFIG AND ENTER THESE VALUES:\n" # "pymm_db_name = "+newUser+"_db_access\n" # "pymm_db = "+pymm_db+"\n") pymmconfig.set_value("database users", newUser, userPass) except: print("stupid error") sys.exit()
def create_db(pymm_db=pymm_db): # check config file for existing db, ask for one if it doesn't exist if pymm_db == '': pymm_db = input("Please enter a name for the database: ") # mysql.connector only allows parameterization for INSERT and SELECT # use str.format() method instead createDbSQL = "CREATE DATABASE IF NOT EXISTS {}".format(pymm_db) # set 'use database' setting to True pymmconfig.set_value("database settings", 'use_db', 'y') useDB = "USE {}".format(pymm_db) try: connect = db.DB('root') connect.connect() cursor = connect.query(createDbSQL) cursor = connect.close_cursor() except: print("Error: uh, error.. :(") sys.exit() cursor = connect.query(useDB) print(cursor) createObjectTable = ('''CREATE TABLE IF NOT EXISTS object(\ objectIdentifierValueID BIGINT(20) NOT NULL AUTO_INCREMENT,\ objectIdentifierValue VARCHAR(1000) NOT NULL UNIQUE,\ objectCategory VARCHAR(30) NOT NULL,\ objectCategoryDetail VARCHAR(50) NOT NULL,\ objectDB_Insertion datetime NOT NULL DEFAULT NOW(),\ object_LastTouched datetime NOT NULL,\ PRIMARY KEY (objectIdentifierValueID)\ );\ ''') createEventTable = ('''CREATE TABLE IF NOT EXISTS event (\ eventIdentifierValue BIGINT(20) NOT NULL AUTO_INCREMENT,\ objectIdentifierValueID BIGINT(20),\ objectIdentifierValue VARCHAR(1000),\ eventType VARCHAR(100) NOT NULL,\ eventDateTime datetime NOT NULL DEFAULT NOW(),\ eventOutcome VARCHAR(30) NOT NULL,\ eventOutcomeDetail VARCHAR(1000),\ eventDetailCallingFunc VARCHAR(1000),\ eventDetailCOMPUTER VARCHAR(50) NOT NULL,\ linkingAgentIdentifierValue VARCHAR(30) NOT NULL,\ PRIMARY KEY (eventIdentifierValue),\ FOREIGN KEY (objectIdentifierValueID) REFERENCES object(objectIdentifierValueID)\ );\ ''') # messageDigestSOURCE is optionally read from an objects_manifest createFixityTable = ('''CREATE TABLE IF NOT EXISTS fixity (\ fixityIdentifierValue BIGINT NOT NULL AUTO_INCREMENT,\ eventIdentifierValue BIGINT(20) NOT NULL,\ objectIdentifierValueID BIGINT(20),\ objectIdentifierValue VARCHAR(1000),\ eventDateTime DATETIME NOT NULL DEFAULT NOW(),\ eventDetailCallingFunc VARCHAR(30) NOT NULL,\ messageDigestAlgorithm VARCHAR (20) NOT NULL,\ messageDigestFilepath VARCHAR (8000) NOT NULL,\ messageDigestHashValue VARCHAR (32) NOT NULL,\ messageDigestSOURCE VARCHAR (1000),\ PRIMARY KEY (fixityIdentifierValue),\ FOREIGN KEY (eventIdentifierValue) REFERENCES event(eventIdentifierValue),\ FOREIGN KEY (objectIdentifierValueID) REFERENCES object(objectIdentifierValueID)\ );\ ''') createChecksumIndex = "CREATE INDEX checksums ON fixity (messageDigestHashValue);" createLTOschemaTable = ('''CREATE TABLE IF NOT EXISTS ltoSchema (\ ltoSchemaValueID BIGINT NOT NULL AUTO_INCREMENT,\ ltoID VARCHAR(10) NOT NULL,\ fileName VARCHAR(200),\ filePath VARCHAR(400),\ fileSize VARCHAR(100),\ modifyTime VARCHAR(40),\ FULLTEXT (filePath),\ PRIMARY KEY (ltoSchemaValueID)\ );\ ''') createLTOidIndex = "CREATE INDEX ltoID_Index ON ltoSchema (ltoID);" createLTOcolumnIndex = ('''CREATE UNIQUE INDEX lto_column_index \ ON ltoSchema(ltoID,fileName,filePath,fileSize,modifyTime);\ ''') createObjectCharsTable = ( '''CREATE TABLE IF NOT EXISTS objectCharacteristics (\ objectCharacteristicValueID BIGINT NOT NULL AUTO_INCREMENT,\ objectIdentifierValueID BIGINT(20) NOT NULL,\ objectIdentifierValue VARCHAR(1000),\ mediaInfo LONGTEXT,\ ingestLog LONGTEXT,\ pbcoreOutput LONGTEXT,\ pbcoreXML MEDIUMBLOB,\ PRIMARY KEY (objectCharacteristicValueID),\ FOREIGN KEY (objectIdentifierValueID) REFERENCES object(objectIdentifierValueID)\ );\ ''') # THIS IS STRAIGHT FROM CUNY.... NOT SURE IF/HOW WE WILL USE IT. createFingerprintsTable = ('''CREATE TABLE IF NOT EXISTS fingerprints (\ hashNumber BIGINT NOT NULL AUTO_INCREMENT,\ objectIdentifierValue VARCHAR(1000) NOT NULL,\ startframe VARCHAR(100),\ endframe VARCHAR(100),\ hash1 VARCHAR(255),\ hash2 VARCHAR(255),\ hash3 VARCHAR(255),\ hash4 VARCHAR(255),\ hash5 VARCHAR(255),\ PRIMARY KEY (hashNumber),\ FOREIGN KEY (objectIdentifierValue) REFERENCES object(objectIdentifierValue)\ );\ ''') createHashIndex = "CREATE INDEX hashindex ON fingerprints (hash1(244));" sqlToDo = [ createObjectTable, createEventTable, createFixityTable, createChecksumIndex, createLTOschemaTable, createLTOidIndex, createLTOcolumnIndex, createObjectCharsTable, createFingerprintsTable, createHashIndex ] # preexistingDB = check_db_exists() for sql in sqlToDo: try: cursor = connect.query(sql) cursor = connect.close_cursor() except: print("mysql error... check your settings and try again.") sys.exit() pymmconfig.set_value("database settings", 'pymm_db', pymm_db) connect.close_connection()
def create_db(pymm_db=pymm_db): # check config file for existing db, ask for one if it doesn't exist if pymm_db == '': pymm_db = input("Please enter a name for the database: ") # mysql.connector won't allow %s substitution for db name... ? use str.format() method instead createDbSQL = "CREATE DATABASE IF NOT EXISTS {};".format(pymm_db) # set 'use database' setting to True pymmconfig.set_value("database settings", 'use_db', 'y') useDB = "USE {};".format(pymm_db) try: connect = db.DB('root') connect.connect() cursor = connect.query(createDbSQL) cursor = connect.close_cursor() except: print("Check your mysql settings and try again.") sys.exit() cursor = connect.query(useDB) cursor = connect.close_cursor() createObjectTable = ('''CREATE TABLE object(\ objectIdentifierValueID bigint NOT NULL AUTO_INCREMENT,\ objectIdentifierValue varchar(1000) NOT NULL UNIQUE,\ objectDB_Insertion datetime NOT NULL DEFAULT NOW(),\ object_LastTouched datetime NOT NULL,\ PRIMARY KEY (objectIdentifierValueID)\ );\ ''') createEventTable = ('''CREATE TABLE event (\ eventIdentifierValue BIGINT(20) NOT NULL AUTO_INCREMENT,\ objectIdentifierValue VARCHAR(1000),\ eventType varchar(100) NOT NULL,\ eventDateTime datetime NOT NULL DEFAULT NOW(),\ eventDetail varchar(30) NOT NULL,\ eventOutcome varchar(30),\ eventDetailOPT varchar(1000),\ eventDetailCOMPNAME varchar(50) NOT NULL,\ linkingAgentIdentifierValue varchar(30) NOT NULL,\ PRIMARY KEY (eventIdentifierValue),\ FOREIGN KEY (objectIdentifierValue) REFERENCES object(objectIdentifierValue)\ );\ ''') createFixityTable = ('''CREATE TABLE fixity (\ fixityIdentifierValue bigint NOT NULL AUTO_INCREMENT,\ eventIdentifierValue bigint NOT NULL,\ objectIdentifierValue varchar(1000),\ eventDateTime datetime NOT NULL DEFAULT NOW(),\ eventDetail varchar(30) NOT NULL,\ messageDigestAlgorithm varchar (20) NOT NULL,\ messageDigestSOURCE varchar (1000),\ messageDigestPATH varchar (8000) NOT NULL,\ messageDigestFILENAME varchar (8000) NOT NULL,\ messageDigestHASH varchar (32) NOT NULL,\ PRIMARY KEY (fixityIdentifierValue),\ FOREIGN KEY (eventIdentifierValue) REFERENCES event(eventIdentifierValue),\ FOREIGN KEY (objectIdentifierValue) REFERENCES object(objectIdentifierValue)\ );\ ''') createChecksumIndex = "CREATE INDEX checksums ON fixity (messageDigestHASH);" createLTOschemaTable = ('''CREATE TABLE ltoSchema (\ ltoSchemaValueID bigint NOT NULL AUTO_INCREMENT,\ ltoID varchar(10) NOT NULL,\ fileName varchar(200),\ filePath varchar(400),\ fileSize varchar(100),\ modifyTime varchar(40),\ FULLTEXT (filePath),\ PRIMARY KEY (ltoSchemaValueID)\ );\ ''') createLTOidIndex = "CREATE INDEX ltoID_Index ON ltoSchema (ltoID);" createLTOcolumnIndex = ('''CREATE UNIQUE INDEX lto_column_index \ ON ltoSchema(ltoID,fileName,filePath,fileSize,modifyTime);\ ''') createObjectCharsTable = ('''CREATE TABLE objectCharacteristics (\ objectCharacteristicValueID bigint NOT NULL AUTO_INCREMENT,\ objectIdentifierValue varchar(1000) NOT NULL UNIQUE,\ mediaInfo MEDIUMTEXT,\ captureLog TEXT,\ videoFingerprint MEDIUMTEXT,\ videoFingerprintSorted MEDIUMTEXT,\ PRIMARY KEY (objectCharacteristicValueID),\ FOREIGN KEY (objectIdentifierValue) REFERENCES object(objectIdentifierValue)\ );\ ''') createFingerprintsTable = ('''CREATE TABLE fingerprints (\ hashNumber bigint NOT NULL AUTO_INCREMENT,\ objectIdentifierValue varchar(1000) NOT NULL,\ startframe varchar(100),\ endframe varchar(100),\ hash1 varchar(255),\ hash2 varchar(255),\ hash3 varchar(255),\ hash4 varchar(255),\ hash5 varchar(255),\ PRIMARY KEY (hashNumber),\ FOREIGN KEY (objectIdentifierValue) REFERENCES object(objectIdentifierValue)\ );\ ''') createHashIndex = "CREATE INDEX hashindex ON fingerprints (hash1(244));" sqlToDo = [ createObjectTable, createEventTable, createFixityTable, createChecksumIndex, createLTOschemaTable, createLTOidIndex, createLTOcolumnIndex, createObjectCharsTable, createFingerprintsTable, createHashIndex ] if preexistingDB == '': # skip table/index creation if db exists already... if check_db_exists(pymm_db): for sql in sqlToDo: try: cursor = connect.query(sql) cursor = connect.close_cursor() except: print("mysql error... check your settings and try again.") sys.exit() pymmconfig.set_value("database settings", 'pymm_db', pymm_db) else: print("Your database, " + pymm_db + " already exists, silly goose. We are done here. Goodnight.") connect.close_connection()