@@ -30,14 +30,23 @@ from textwrap import dedent
3030from pathlib import Path
3131import urllib .request as urlrequest
3232
33- import psycopg2
33+ missing_modules = []
3434
35- from osmium .replication .server import ReplicationServer
36- from osmium .replication .utils import get_replication_header
37- from osmium import WriteHandler
35+ try :
36+ import psycopg2
37+ except ImportError :
38+ missing_modules .append ('psycopg2' )
39+
40+ try :
41+ from osmium .replication .server import ReplicationServer
42+ from osmium .replication .utils import get_replication_header
43+ from osmium import WriteHandler
44+ except ImportError :
45+ missing_modules .append ('osmium' )
3846
3947LOG = logging .getLogger ()
4048
49+
4150def pretty_format_timedelta (seconds ):
4251 minutes = int (seconds / 60 )
4352 (hours , minutes ) = divmod (minutes , 60 )
@@ -484,9 +493,17 @@ def main():
484493 parser = get_parser ()
485494 args = parser .parse_args ()
486495
496+ if missing_modules :
497+ LOG .fatal ("Missing required Python libraries %(mods)s.\n \n "
498+ "To install them via pip run: pip install %(mods)s\n \n "
499+ "ERROR: libraries could not be loaded." ,
500+ dict (mods = " " .join (missing_modules )))
501+ return 1
502+
503+
487504 if args .subcommand is None :
488505 parser .print_help ()
489- sys . exit ( 1 )
506+ return 1
490507
491508 logging .basicConfig (stream = sys .stderr ,
492509 format = '{asctime} [{levelname}]: {message}' ,
0 commit comments