Skip to content

Commit

Permalink
fixed:UserManager.py and DownloadManager.py MySQLdb bugs
Browse files Browse the repository at this point in the history
modifications added

unused errors resolved
  • Loading branch information
BLasan committed Mar 24, 2020
1 parent 79dc87b commit 16804a4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 36 deletions.
43 changes: 21 additions & 22 deletions components/core/DownloadManager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Models import Download, Status
from DBCon import *
from DBCon import get_db_con,MySQLdb
import time
import sys
import sqlalchemy.pool as pool
Expand All @@ -23,7 +23,7 @@ def add_download(download):
try:
cursor.execute(sql, (download.link, download.userName, int(time.time()), download_name))
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
# Shows error thrown up by database
print(e)
Expand All @@ -46,7 +46,7 @@ def remove_download(id, userName):
return "Download started. Entry cannot be deleted."
cursor.execute(sql, [str(id), userName])
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -67,7 +67,7 @@ def rate_download(id, userName, rate):
cursor.execute(sql, (userName, id, rate))
db.commit()
update_rate(id)
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -85,7 +85,7 @@ def update_rate(id):
data = cursor.fetchone()
cursor.execute(sql, (data[0], id))
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -103,7 +103,7 @@ def get_downloads_user(userName, limit):
results = cursor.fetchall()
db.close()
return results
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"

Expand All @@ -119,7 +119,7 @@ def get_downloads(limit):
results = cursor.fetchall()
db.close()
return results
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"

Expand All @@ -138,7 +138,7 @@ def update_status_gid(gid, status, completed=False):
else:
cursor.execute(sql, (status, gid))
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -153,7 +153,7 @@ def set_gid(id, gid):
try:
cursor.execute(sql)
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -167,7 +167,7 @@ def set_name(gid, name):
try:
cursor.execute(sql, (name, gid))
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -181,7 +181,7 @@ def set_size(gid, size):
try:
cursor.execute(sql, (size, gid))
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -201,7 +201,7 @@ def get_to_download():
if verbose: print ("LIST", results)
downloads = [Download(result['link'], result['user_name'], result['id']) for result in results]
return downloads
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"

Expand All @@ -213,7 +213,7 @@ def set_path(gid, path):
try:
cursor.execute(sql, (path, gid))
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -232,7 +232,7 @@ def get_download_path(id):
path = results['path']
db.close()
return path
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"

Expand All @@ -249,12 +249,11 @@ def get_download_email(gid):
path = results['email']
db.close()
return path
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"

def get_to_delete(time, rate):
recordsPerPage = 15
db = threadpool.connect()
if db is not None:
cursor = db.cursor()
Expand All @@ -266,7 +265,7 @@ def get_to_delete(time, rate):
if verbose: print ("Time", time, "Rate", rate)
if verbose: print ("results", results)
return results
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"

Expand All @@ -278,7 +277,7 @@ def set_delete_status(path):
try:
cursor.execute(sql)
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -298,7 +297,7 @@ def get_download_status(id):
status = results['status']
db.close()
return status
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"

Expand All @@ -315,7 +314,7 @@ def get_id_from_gid(gid):
status = results['id']
db.close()
return status
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"

Expand All @@ -332,7 +331,7 @@ def get_username_from_gid(gid):
status = results['user_name']
db.close()
return status
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"

Expand All @@ -350,6 +349,6 @@ def get_gid_from_id(id):
gid = results['gid']
db.close()
return gid
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"
28 changes: 14 additions & 14 deletions components/core/UserManager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Models import User
from DBCon import *
from DBCon import get_db_con,MySQLdb
from ConfReader import get_conf_reader
import sqlalchemy.pool as pool

Expand Down Expand Up @@ -69,7 +69,7 @@ def add_user(user):
try:
cursor.execute(sql, (user.userName, user.password, user.auth, user.email))
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -83,9 +83,9 @@ def add_regular_user(user):
try:
cursor.execute(sql, (user.userName, user.password, user.auth, user.email))
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.IntegrityError:
db.rollback()
return e[1]
return "username taken"
return "success"
return "db connection error"

Expand All @@ -97,7 +97,7 @@ def remove_user(username):
try:
cursor.execute(sql, (username))
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -112,7 +112,7 @@ def update_user(user, username):
try:
cursor.execute(sql, (user.userName, user.auth, user.email, username))
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -128,7 +128,7 @@ def get_users():
results = cursor.fetchall()
db.close()
return results
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"

Expand All @@ -142,7 +142,7 @@ def get_blocked_users():
results = cursor.fetchall()
db.close()
return results
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"

Expand All @@ -154,7 +154,7 @@ def block_user(username):
try:
cursor.execute(sql, (1, username))
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -168,7 +168,7 @@ def unblock_user(username):
try:
cursor.execute(sql, (0, username))
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -184,7 +184,7 @@ def get_signup_requests():
results = cursor.fetchall()
db.close()
return results
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"

Expand All @@ -196,7 +196,7 @@ def approve_user(username):
try:
cursor.execute(sql, (1, username))
db.commit()
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
db.rollback()
return e[1]
return "success"
Expand All @@ -213,7 +213,7 @@ def get_heavy_users():
results = cursor.fetchall()
db.close()
return results
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"

Expand All @@ -233,6 +233,6 @@ def check_if_bandwidth_exceeded(username):
else:
return False
return result
except MySQLdb.Error as e:
except MySQLdb._mysql.Error as e:
return e[1]
return "db connection error"

0 comments on commit 16804a4

Please sign in to comment.