# HG changeset patch # User Radek Brich # Date 1359133457 -3600 # Node ID 703bba75760513575757b9134c67a8989fd6a094 # Parent bb6b20106ff59ecbd46818afb36c3a20b7235237 PgDiff: check schema existance. diff -r bb6b20106ff5 -r 703bba757605 pgtoolkit/pgdiff.py --- a/pgtoolkit/pgdiff.py Fri Jan 25 17:44:49 2013 +0100 +++ b/pgtoolkit/pgdiff.py Fri Jan 25 18:04:17 2013 +0100 @@ -28,6 +28,10 @@ from pgtoolkit.highlight import * +class PgDiffError(Exception): + pass + + class DiffBase: COLORS = { '+' : BOLD | GREEN, @@ -476,7 +480,13 @@ Order: include, exclude include=[] means include everything + + Raises: + PgDiffError: when schema from include list is not found in src db + ''' + for schema in include: + self._check_schema_exist(schema) self.include_schemas.clear() self.include_schemas.update(include) self.exclude_schemas.clear() @@ -489,3 +499,8 @@ self.exclude_tables.clear() self.exclude_tables.update(exclude) + + def _check_schema_exist(self, schema): + if not schema in self.src.schemas: + raise PgDiffError('Schema "%s" not found in source database.' % schema) + diff -r bb6b20106ff5 -r 703bba757605 schemadiff.py --- a/schemadiff.py Fri Jan 25 17:44:49 2013 +0100 +++ b/schemadiff.py Fri Jan 25 18:04:17 2013 +0100 @@ -25,16 +25,19 @@ pgd = pgdiff.PgDiff(srcbrowser, dstbrowser) - if self.args.schema: - pgd.filter_schemas(include=self.args.schema) + try: + if self.args.schema: + pgd.filter_schemas(include=self.args.schema) + + if self.args.table: + pgd.filter_tables(include=self.args.table) - if self.args.table: - pgd.filter_tables(include=self.args.table) - - if self.args.sql: - pgd.print_patch() - else: - pgd.print_diff() + if self.args.sql: + pgd.print_patch() + else: + pgd.print_diff() + except pgdiff.PgDiffError as e: + print('PgDiff error:', str(e)) tool = SchemaDiffTool()