diff --git a/messkit/commands.py b/messkit/commands.py index 1997b18..dea2d17 100644 --- a/messkit/commands.py +++ b/messkit/commands.py @@ -81,19 +81,20 @@ class Install(commands.Subcommand): sys.exit(1) # get db info - dbhost = self.basic_prompt('postgres host', 'localhost') - dbport = self.basic_prompt('postgres port', '5432') - dbname = self.basic_prompt('postgres db', 'messkit') - dbuser = self.basic_prompt('postgres user', 'rattail') + dbtype = self.basic_prompt('db type', 'postgresql') + dbhost = self.basic_prompt('db host', 'localhost') + dbport = self.basic_prompt('db port', '3306' if dbtype == 'mysql' else '5432') + dbname = self.basic_prompt('db name', 'messkit') + dbuser = self.basic_prompt('db user', 'rattail') # get db password dbpass = None while not dbpass: - dbpass = self.basic_prompt('postgres pass', is_password=True) + dbpass = self.basic_prompt('db pass', is_password=True) # test db connection rprint("\n\ttesting db connection... ", end='') - dburl = self.make_db_url(dbhost, dbport, dbname, dbuser, dbpass) + dburl = self.make_db_url(dbtype, dbhost, dbport, dbname, dbuser, dbpass) error = self.test_db_connection(dburl) if error: rprint("[bold red]cannot connect![/bold red] ..error was:") @@ -191,6 +192,7 @@ class Install(commands.Subcommand): if self.basic_prompt("make poser dir?", True, is_bool=True): rprint() + # make poser dir poser_handler = self.app.get_poser_handler() poserdir = poser_handler.make_poser_dir() @@ -247,7 +249,7 @@ class Install(commands.Subcommand): return text or default - def make_db_url(self, dbhost, dbport, dbname, dbuser, dbpass): + def make_db_url(self, dbtype, dbhost, dbport, dbname, dbuser, dbpass): try: # newer style from sqlalchemy.engine import URL @@ -257,7 +259,12 @@ class Install(commands.Subcommand): from sqlalchemy.engine.url import URL factory = URL - return factory(drivername='postgresql+psycopg2', + if dbtype == 'mysql': + drivername = 'mysql+mysqlconnector' + else: + drivername = 'postgresql+psycopg2' + + return factory(drivername=drivername, username=dbuser, password=dbpass, host=dbhost,