Skip to content

Commit

Permalink
Added pyyaml dependency, refactoring
Browse files Browse the repository at this point in the history
* unified argument positions in dump_db and anonymize_db
* removed _db postfix from dump script filename to comply with
  the anomymize filename script
* schema argument required in dump script
  • Loading branch information
asgeirrr committed May 10, 2017
1 parent ddc4e12 commit 4270d65
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
Binary file removed pgantomizer/.anonymize.py.swp
Binary file not shown.
2 changes: 2 additions & 0 deletions pgantomizer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .anonymize import load_anonymize_remove, anonymize_db
from .dump import dump_db
7 changes: 4 additions & 3 deletions pgantomizer/dump_db.py → pgantomizer/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import yaml


def dump_db(schema_path, dump_path, *db_args):
def dump_db(dump_path, schema_path, *db_args):
schema = yaml.load(open(schema_path))
cmd = 'pg_dump -Fc -Z 9 {args} {tables} -f {filename}'.format(
args='-d {} -U {} -h {} -p {} '.format(
Expand All @@ -25,7 +25,8 @@ def main():
'for later anonymization.',
epilog='Compressed Postgres format is used. See README.md for details.')
parser.add_argument('-v', '--verbose', action='store_true', help='increase output verbosity')
parser.add_argument('--schema', help='YAML config file with tables to dump', default='./schema.yaml')
parser.add_argument('--schema', help='YAML config file with tables to dump', default='./schema.yaml',
required=True)
parser.add_argument('--dump-file', help='path to the file where to dump the DB', default='to_anonymize.sql')
parser.add_argument('--db-name', help='name of the database to dump')
parser.add_argument('--user', help='name of the Postgres user with access to the database')
Expand All @@ -42,8 +43,8 @@ def main():
sys.exit('File with schema "{}" does not exist.'.format(args.schema))

dump_db(
args.schema,
args.dump_file,
args.schema,
*([args.db_name, args.user, args.host, args.port]
if args.db_name and args.user else [])
)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
keywords='postgres anonymization dump',
install_requires=[
'psycopg2>=2.6.1',
'pyyaml>=3.12',
],
entry_points={
'console_scripts': [
'pgantomizer_dump=pgantomizer.dump_db:main',
'pgantomizer_dump=pgantomizer.dump:main',
'pgantomizer=pgantomizer.anonymize:main'
]
}
Expand Down

0 comments on commit 4270d65

Please sign in to comment.