summaryrefslogtreecommitdiffstats
path: root/notFinishedCode
diff options
context:
space:
mode:
authorRefik Hadzialic2011-07-15 16:57:13 +0200
committerRefik Hadzialic2011-07-15 16:57:13 +0200
commit21bc219e803e7b2d7ec5e24e770bf0530b9d4e2d (patch)
treeec4e31d67f185ce0602f9863a960741acc6cfe2c /notFinishedCode
parentMerge branch 'master' of lab.ks.uni-freiburg.de:lsfks/projekte/gsm-selftest (diff)
downloadgsm-selftest-21bc219e803e7b2d7ec5e24e770bf0530b9d4e2d.tar.gz
gsm-selftest-21bc219e803e7b2d7ec5e24e770bf0530b9d4e2d.tar.xz
gsm-selftest-21bc219e803e7b2d7ec5e24e770bf0530b9d4e2d.zip
I added two new functions that were requested by Tri, for checking is there a test between two devices and if not to insert the test!
Diffstat (limited to 'notFinishedCode')
-rw-r--r--notFinishedCode/dbClass.py82
1 files changed, 79 insertions, 3 deletions
diff --git a/notFinishedCode/dbClass.py b/notFinishedCode/dbClass.py
index f11b612..5e323cf 100644
--- a/notFinishedCode/dbClass.py
+++ b/notFinishedCode/dbClass.py
@@ -210,6 +210,65 @@ class DBMySQLConnection:
else:
return 0
+ def anyTasksFromTo(self, fromDevice, toDevice, taskNo):
+ #see are there any jobs to be executed and make a list out of it
+ if self.connectionCreated == 1:
+ try:
+ query = "SELECT * FROM `TempTaskTable` WHERE `from` = '" + str(fromDevice) + "' AND `to` = '" + str(toDevice) + "'"
+ self.cur.execute(query)
+ output = self.cur.fetchall() #get the mysql response
+ #parse the output from the mysql by creating a list
+ #with lists where each attribue(column) gets independent
+ #element of the list
+ notFound = 0 #used to test if a the task from to was found, if not insert it in the temporary task table
+ for record in output:
+ columns = list()
+ for entry in record:
+ columns.append(str(entry))
+ notFound = 1
+ self.tasksList.append(columns)
+ if notFound == 0:
+ if self.insertTaskIn2(fromDevice, toDevice, taskNo) == 1:
+ return 4 #i inserted the new task
+ else:
+ return 5 #i didn't insert the new task
+ else:
+ return 1 #the task was already in the database
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1146':
+ return 2 #the table doesn't exist
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def insertTaskIn2(self, fromDevice, toDevice, taskNo):
+ if self.connectionCreated == 1:
+ try:
+ #I used here a transaction since I want the mysql to execute a few commands and tell me was it successful rather than to execute some and there happens a mistake and one part is updated and the other isn't
+ newQuery = "START TRANSACTION; INSERT INTO `TaskTable` (`taskNo`, `from`, `to`, `status`) VALUES ('" + str(taskNo) + "', '" + str(fromDevice) + "', '" + str(toDevice) +"', '0'); SELECT @taskID := LAST_INSERT_ID(); INSERT INTO `TempTaskTable` (`taskID`, `taskNo`, `from`, `to`) VALUES (@taskID, '" + str(taskNo) + "', '" + str(fromDevice) + "', '"+ str(toDevice) + "'); COMMIT;"
+
+ successful = self.cur.execute(newQuery)
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 0:
+ return 1 #successfully added the result
+ else:
+ return 4 #hmmm
+ except MySQLdb.Error, e:
+ error = str(e)
+ if debugMode == 1:
+ print str(e)
+ if error[1:5] == '1062':
+ return 2 #duplicate entry for the key
+ return 3
+ else:
+ return 0
+
user = 'root'
passw = 'randompasswordSQL'
host = 'localhost'
@@ -221,9 +280,10 @@ print "do i have anything to do", x.anyTasksToDo()
for item in x.tasksList:
taskID = item[0]
- callFrom = item[1]
- callTo = item[2]
- print "call from to ", taskID , callFrom , callTo
+ taskNo = item[1]
+ callFrom = item[2]
+ callTo = item[3]
+ print "call from to ", taskID , callFrom , callTo, taskNo
print "remove a task ",x.removeTaskFromList('2')
@@ -239,6 +299,22 @@ print "update task result ", x.updateTaskResult(1,3)
print "update ping Table", x.updatePingResult(1,5,4,3,2,1)
print "delete a task from temp table", x.deleteTempTask(2)
print "add a result to the table", x.addResult(2,34)
+
+#new task to do
+#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
+#just made for Tri :)---------------------------------------------------------------
+print x.cleanTasksList()
+print "do i have any task from SIP1 to GSM1 to do", x.anyTasksFromTo('SIP2', 'GSM1', 2)
+for item in x.tasksList:
+ taskID = item[0]
+ callFrom = item[1]
+ callTo = item[2]
+ print "call from to ", taskID , callFrom , callTo
+
+#print x.insertTaskIn2('gsm4','sip8',2)
+#-----------------------------------------------------------------------------------
+#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
+
print "close connection to the DB", x.closeDBConn()
del x #delete