diff --git a/ldvspec/ldvspec/connection/__init__.py b/ldvspec/connection/__init__.py similarity index 100% rename from ldvspec/ldvspec/connection/__init__.py rename to ldvspec/connection/__init__.py diff --git a/ldvspec/ldvspec/connection/config.py b/ldvspec/connection/config.py similarity index 58% rename from ldvspec/ldvspec/connection/config.py rename to ldvspec/connection/config.py index 229c7bb641a56ef2fda383c2e5742348e5857230..947d8c96042c4254fad4177bf46b4952903fbe7d 100644 --- a/ldvspec/ldvspec/connection/config.py +++ b/ldvspec/connection/config.py @@ -1,9 +1,14 @@ from configparser import ConfigParser -def read_config(section, filename='database.ini'): +def read_config(section, filename='database.cfg'): parser = ConfigParser() - parser.read(filename) + try: + parser.read(filename) + except FileNotFoundError as exc: + raise FileNotFoundError( + "Configuration file with filename {0} not found".format(filename) + ) from exc db_settings = {} if parser.has_section(section): diff --git a/ldvspec/ldvspec/connection/database.ini b/ldvspec/connection/database.cfg similarity index 100% rename from ldvspec/ldvspec/connection/database.ini rename to ldvspec/connection/database.cfg diff --git a/ldvspec/ldvspec/connection/retrieve_db_connection.py b/ldvspec/connection/retrieve_db_connection.py similarity index 88% rename from ldvspec/ldvspec/connection/retrieve_db_connection.py rename to ldvspec/connection/retrieve_db_connection.py index 6c9921ced3ee504bca80355bf9330a276654a768..af8659de67ab2ac9f68ae86aa2b84a4e5521c789 100644 --- a/ldvspec/ldvspec/connection/retrieve_db_connection.py +++ b/ldvspec/connection/retrieve_db_connection.py @@ -47,12 +47,20 @@ def open_tunnel(configuration_params): tunnel_username = configuration_params.get('tunnelusername', "no username for the tunnel given") host = configuration_params.get('host', "no host given") port = int(configuration_params.get('port', "no port given")) + + try: + ssh_config_file = os.path.expanduser("~/.ssh/config") + except FileNotFoundError as exc: + raise FileNotFoundError( + "Ssh config file not found on standard path '~/.ssh/config'. This is mandatory for opening the ssh tunnel" + ) from exc + logging.info("Creating ssh tunnel for %s and port %s with tunnel host %s and username %s", repr(host), port, repr(tunnel_host), repr(tunnel_username)) ssh_tunnel = SSHTunnelForwarder( ssh_address_or_host=tunnel_host, ssh_username=tunnel_username, - ssh_config_file=os.path.expanduser("~/.ssh/config"), + ssh_config_file=ssh_config_file, remote_bind_address=(host, port) ) ssh_tunnel.start() @@ -61,13 +69,13 @@ def open_tunnel(configuration_params): def main(): """ - Opens a database connection from configuration file database.ini + Opens a database connection from configuration file database.cfg """ logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.DEBUG) # Check the invocation arguments parser = argparse.ArgumentParser() - parser.add_argument("-s", "--section", help="Add the configuration's section from the database.ini.") + parser.add_argument("-s", "--section", help="Add the configuration's section from the database.cfg.") args = parser.parse_args() if not args.section: diff --git a/ldvspec/connection/test.py b/ldvspec/connection/test.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391