Skip to content

Commit 2593e8b

Browse files
authored
Update README.md and minor fixes (#9)
* docs: Update README.md * fix: Remove deprecated CLI options * chore: Minor fixes
1 parent aaea15d commit 2593e8b

File tree

8 files changed

+331
-202
lines changed

8 files changed

+331
-202
lines changed

README.md

Lines changed: 288 additions & 153 deletions
Large diffs are not rendered by default.

pg_anon.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
from pg_anon import MainRoutine
44

55
if __name__ == "__main__":
6-
loop = asyncio.get_event_loop()
7-
loop.run_until_complete(MainRoutine().run())
6+
asyncio.run(MainRoutine().run())

pg_anon/__main__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55

66
def _run_pg_anon():
7-
loop = asyncio.get_event_loop()
8-
loop.run_until_complete(MainRoutine().run())
7+
asyncio.run(MainRoutine().run())
98

109

1110
if __name__ == "__main__":

pg_anon/common.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,12 @@
55
import subprocess
66
import sys
77
import traceback
8-
from enum import Enum
8+
from enum import StrEnum
99

1010
from pkg_resources import parse_version as version
1111

1212

13-
class BasicEnum:
14-
def __str__(self):
15-
return self.value
16-
17-
18-
class OutputFormat(BasicEnum, Enum):
19-
BINARY = "binary"
20-
TEXT = "text"
21-
22-
23-
class ResultCode(BasicEnum, Enum):
13+
class ResultCode(StrEnum):
2414
DONE = "done"
2515
FAIL = "fail"
2616
UNKNOWN = "unknown"
@@ -32,13 +22,13 @@ class PgAnonResult:
3222
result_data = None
3323

3424

35-
class VerboseOptions(BasicEnum, Enum):
25+
class VerboseOptions(StrEnum):
3626
INFO = "info"
3727
DEBUG = "debug"
3828
ERROR = "error"
3929

4030

41-
class AnonMode(BasicEnum, Enum):
31+
class AnonMode(StrEnum):
4232
DUMP = "dump" # dump table contents to files using dictionary
4333
RESTORE = "restore" # create tables in target database and load data from files
4434
INIT = "init" # create a schema with anonymization helper functions
@@ -51,7 +41,7 @@ class AnonMode(BasicEnum, Enum):
5141
CREATE_DICT = "create-dict" # create dictionary
5242

5343

54-
class ScanMode(BasicEnum, Enum):
44+
class ScanMode(StrEnum):
5545
FULL = "full"
5646
PARTIAL = "partial"
5747

pg_anon/context.py

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from pg_anon.common import (
55
exception_handler,
66
AnonMode,
7-
OutputFormat,
87
VerboseOptions,
98
ScanMode,
109
)
@@ -86,20 +85,6 @@ def get_arg_parser():
8685
parser.add_argument(
8786
"--mode", type=AnonMode, choices=list(AnonMode), default=AnonMode.INIT
8887
)
89-
parser.add_argument(
90-
"--copy-options",
91-
dest="copy_options",
92-
default="",
93-
help='Options for COPY command like "with binary".',
94-
)
95-
parser.add_argument(
96-
"--format",
97-
dest="format",
98-
type=OutputFormat,
99-
choices=list(OutputFormat),
100-
default=OutputFormat.BINARY.value,
101-
help="COPY data format, can be overwritten by --copy-options. Selects the data format to be read or written: text, csv or binary.",
102-
)
10388
parser.add_argument(
10489
"--verbose",
10590
dest="verbose",
@@ -109,9 +94,30 @@ def get_arg_parser():
10994
help="Enable verbose output",
11095
)
11196
parser.add_argument("--dict-file", type=str, default="")
112-
parser.add_argument("--threads", type=int, default=4)
113-
parser.add_argument("--pg-dump", type=str, default="/usr/bin/pg_dump")
114-
parser.add_argument("--pg-restore", type=str, default="/usr/bin/pg_restore")
97+
parser.add_argument(
98+
"--threads",
99+
type=int,
100+
default=4,
101+
help="Amount of threads for IO operations.",
102+
)
103+
parser.add_argument(
104+
"--processes",
105+
type=int,
106+
default=4,
107+
help="Amount of processes for multiprocessing operations.",
108+
)
109+
parser.add_argument(
110+
"--pg-dump",
111+
type=str,
112+
default="/usr/bin/pg_dump",
113+
help="Path to the `pg_dump` Postgres tool",
114+
)
115+
parser.add_argument(
116+
"--pg-restore",
117+
type=str,
118+
default="/usr/bin/pg_restore",
119+
help="Path to the `pg_dump` Postgres tool.",
120+
)
115121
parser.add_argument("--output-dir", type=str, default="")
116122
parser.add_argument("--input-dir", type=str, default="")
117123
parser.add_argument(
@@ -128,26 +134,24 @@ def get_arg_parser():
128134
)
129135
parser.add_argument("--clear-output-dir", action="store_true", default=False)
130136
parser.add_argument(
131-
"--drop-custom-check-constr", action="store_true", default=False
132-
)
133-
parser.add_argument(
134-
"--seq-init-by-max-value",
137+
"--drop-custom-check-constr",
135138
action="store_true",
136139
default=False,
137-
help="""Initialize sequences based on maximum values. Otherwise, the sequences will be initialized
138-
based on the values of the source database.""",
140+
help="Drop all CHECK constrains containing user-defined procedures to avoid performance "
141+
"degradation at the data loading stage.",
139142
)
140143
parser.add_argument(
141-
"--disable-checks",
144+
"--seq-init-by-max-value",
142145
action="store_true",
143146
default=False,
144-
help="""Disable checks of disk space and PostgreSQL version""",
147+
help="Initialize sequences based on maximum values. Otherwise, the sequences "
148+
"will be initialized based on the values of the source database.",
145149
)
146150
parser.add_argument(
147-
"--skip-data",
151+
"--disable-checks",
148152
action="store_true",
149153
default=False,
150-
help="""Don't copy data. Only the database structure will be dumped""",
154+
help="Disable checks of disk space and PostgreSQL version.",
151155
)
152156
parser.add_argument(
153157
"--scan-mode",

pg_anon/create_dict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ async def init_process(name, ctx, fields_info_chunk: List[FieldInfo]):
475475

476476
p = aioprocessing.AioProcess(
477477
target=process_impl,
478-
args=(name, ctx, queue, fields_info_chunk, ctx.conn_params, ctx.args.threads),
478+
args=(name, ctx, queue, fields_info_chunk, ctx.conn_params, ctx.args.processes),
479479
)
480480
p.start()
481481
res = None

pg_anon/pg_anon.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ def setup_logger(self):
115115
self.logger.setLevel(log_level)
116116

117117
def close_logger_handlers(self):
118+
if not self.logger: # FIXME: Return an exception for --help command
119+
return
118120
for handler in self.logger.handlers[
119121
:
120122
]: # iterate over a copy of the handlers list

pg_anon/restore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ async def make_restore(ctx):
245245

246246
if not db_is_empty and ctx.args.mode != AnonMode.SYNC_DATA_RESTORE:
247247
db_conn.close()
248-
raise Exception("Target DB is not empty!")
248+
raise Exception(f"Target DB {ctx.conn_params['database']} is not empty!")
249249

250250
metadata_file = open(
251251
os.path.join(ctx.current_dir, "dict", ctx.args.input_dir, "metadata.json"), "r"

0 commit comments

Comments
 (0)