Refactoring
This commit is contained in:
23
getMySQL.py
Normal file
23
getMySQL.py
Normal file
@ -0,0 +1,23 @@
|
||||
import getpass
|
||||
import sys
|
||||
|
||||
|
||||
# noinspection PyPackageRequirements
|
||||
def get_mysql():
|
||||
"""
|
||||
Extrahiert die MySQL-Anmeldedaten aus ~/.my.cnf . \n
|
||||
Funktioniert wahrscheinlich nur auf Linux, vor allem für den Server gedacht.
|
||||
:return: [username: str, password: str]:
|
||||
"""
|
||||
if sys.platform == "linux":
|
||||
systemUser = getpass.getuser()
|
||||
file = open("/home/"+systemUser+"/.my.cnf", "r")
|
||||
content = file.read()
|
||||
username = content.find("user=")
|
||||
password = content.find("password=")
|
||||
username = content[username+5:password-1]
|
||||
readOnly = content.find("[clientreadonly]")
|
||||
password = content[password+9:readOnly-2]
|
||||
return username, password
|
||||
else:
|
||||
return "username-goes-here", "password-goes-here"
|
||||
Reference in New Issue
Block a user