Skip to content

Commit

Permalink
last fix and ready to publish 0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyprien committed May 17, 2019
1 parent eea2323 commit 9e550d4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
44 changes: 32 additions & 12 deletions mysqlrocket/mysqlrocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

from __future__ import print_function
from __future__ import absolute_import
from builtins import input
from mysqlrocket import ressources
import sys
Expand All @@ -14,6 +15,7 @@
from argparse import ArgumentParser
import MySQLdb as mysql


def query_yes_no(question, default="yes"):
valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
if default == None:
Expand Down Expand Up @@ -51,7 +53,7 @@ def __init__(self):
self.name = "default"
self.host = "localhost"
self.user = "root"
self.port = 3306
self.port = "3306"
self.password = ""
self.mysql = "/usr/bin/mysql"
self.mysqldump = "/usr/bin/mysqldump"
Expand All @@ -66,7 +68,7 @@ def config_remove(self, config_id):
remove_config = query_yes_no("Are you sure you want to remove config?")
if remove_config:
self.config.remove_section(config_id)
with open(self.config_file, "wb") as configfile:
with open(self.config_file, "w") as configfile:
self.config.write(configfile)
print(
"\nConfiguration file has been update: "
Expand Down Expand Up @@ -120,7 +122,7 @@ def load(self, config_id):
else:
self.config.set(config_id, "host", self.host)
if input_port:
self.config.set(config_id, "port", int(input_port))
self.config.set(config_id, "port", input_port)
self.port = input_port
else:
self.config.set(config_id, "port", self.port)
Expand All @@ -147,7 +149,7 @@ def load(self, config_id):
self.config.set(config_id, "excluded", self.excluded)
if not os.path.exists(os.path.dirname(self.config_file)):
os.makedirs(os.path.dirname(self.config_file))
with open(self.config_file, "wb") as configfile:
with open(self.config_file, "w") as configfile:
self.config.write(configfile)
print(
"\nConfiguration file has been saved to: "
Expand All @@ -173,7 +175,10 @@ def mk(self, db_name, db_password):
db_password = "".join([random.choice(dictionnary) for i in range(8)])
try:
conn = mysql.connect(
host=self.host, port=self.port, user=self.user, passwd=self.password
host=self.host,
port=int(self.port),
user=self.user,
passwd=self.password,
)
cursor = conn.cursor()
cursor.execute(
Expand Down Expand Up @@ -252,7 +257,10 @@ def showdb(self, db_pattern="%"):
db_list = []
try:
conn = mysql.connect(
host=self.host, port=self.port, user=self.user, passwd=self.password
host=self.host,
port=int(self.port),
user=self.user,
passwd=self.password,
)
cursor = conn.cursor()
cursor.execute(
Expand Down Expand Up @@ -288,7 +296,10 @@ def rm(self, db_name):
exit()
try:
conn = mysql.connect(
host=self.host, port=self.port, user=self.user, passwd=self.password
host=self.host,
port=int(self.port),
user=self.user,
passwd=self.password,
)
cursor = conn.cursor()
cursor.execute(
Expand Down Expand Up @@ -364,7 +375,10 @@ def fs(self, db_name):
exit()
try:
conn = mysql.connect(
host=self.host, port=self.port, user=self.user, passwd=self.password
host=self.host,
port=int(self.port),
user=self.user,
passwd=self.password,
)
cursor = conn.cursor()
cursor.execute(
Expand Down Expand Up @@ -462,15 +476,15 @@ def ld(self, db_name, fl_name):
if self.password == "":
p1 = subprocess.Popen(
self.mysql + " -u %s -h %s %s" % (self.user, self.host, db_name),
stdin=file(fl_name),
stdin=open(fl_name, "r"),
shell=True,
)
else:
p1 = subprocess.Popen(
self.mysql
+ " -u %s -p%s -h %s %s"
% (self.user, self.password, self.host, db_name),
stdin=file(fl_name),
stdin=open(fl_name, "r"),
shell=True,
)
print(fl_name + " has been imported to: " + db_name)
Expand All @@ -480,7 +494,10 @@ def ld(self, db_name, fl_name):
def st(self, st_extended=False):
try:
conn = mysql.connect(
host=self.host, port=self.port, user=self.user, passwd=self.password
host=self.host,
port=int(self.port),
user=self.user,
passwd=self.password,
)
cursor = conn.cursor()
print("MySQL connection was successful!")
Expand All @@ -503,7 +520,10 @@ def get_db_properties(self, db_name):
db.name = db_name
try:
conn = mysql.connect(
host=self.host, port=self.port, user=self.user, passwd=self.password
host=self.host,
port=int(self.port),
user=self.user,
passwd=self.password,
)
cursor = conn.cursor()
cursor.execute(
Expand Down
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@
description=__description__,
long_description=open("README.rst").read(),
include_package_data=True,
install_requires=["appdirs", "mysqlclient", "argparse"],
install_requires=[
"appdirs",
'configparser;python_version<"3"',
'future;python_version<"3"',
'MySQL-python;python_version<"3"',
'mysqlclient;python_version>="3"',
"argparse",
],
url="https://github.com/cypx/mysqlrocket",
classifiers=[
"Programming Language :: Python",
Expand Down

0 comments on commit 9e550d4

Please sign in to comment.