pybutt 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- old_tests/app.py +713 -0
- pybutt/__init__.py +17 -0
- pybutt/cli/__init__.py +11 -0
- pybutt/cli/app.py +94 -0
- pybutt/cli/combine_command.py +236 -0
- pybutt/cli/export_command.py +317 -0
- pybutt/cli/import_command.py +286 -0
- pybutt/cli/inspect_command.py +30 -0
- pybutt/cli/purge_command.py +235 -0
- pybutt/core/__init__.py +30 -0
- pybutt/core/base.py +124 -0
- pybutt/core/config.py +144 -0
- pybutt/core/logobs.py +445 -0
- pybutt/exceptions.py +82 -0
- pybutt/files/__init__.py +28 -0
- pybutt/files/combine.py +93 -0
- pybutt/files/inspect.py +51 -0
- pybutt/files/manifest.py +160 -0
- pybutt/io/__init__.py +6 -0
- pybutt/io/combiner.py +119 -0
- pybutt/io/exporter.py +612 -0
- pybutt/io/importer.py +928 -0
- pybutt/io/purger.py +44 -0
- pybutt-2.0.0.dist-info/METADATA +756 -0
- pybutt-2.0.0.dist-info/RECORD +39 -0
- pybutt-2.0.0.dist-info/WHEEL +5 -0
- pybutt-2.0.0.dist-info/entry_points.txt +2 -0
- pybutt-2.0.0.dist-info/licenses/LICENSE +21 -0
- pybutt-2.0.0.dist-info/top_level.txt +3 -0
- tests/conftest.py +22 -0
- tests/test_cli.py +979 -0
- tests/test_cli_help.py +130 -0
- tests/test_combiner.py +259 -0
- tests/test_core.py +1009 -0
- tests/test_exporter.py +637 -0
- tests/test_files.py +178 -0
- tests/test_import_retry_logic.py +837 -0
- tests/test_logobs.py +491 -0
- tests/test_purge.py +219 -0
pybutt/io/purger.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
|
|
3
|
+
from pybutt.core.base import SqlServerIOBase
|
|
4
|
+
from pybutt.core.config import quote_identifier, validate_identifier
|
|
5
|
+
from pybutt.core.logobs import get_logger
|
|
6
|
+
|
|
7
|
+
logger = get_logger("purger")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TablePurger(SqlServerIOBase):
|
|
11
|
+
"""Drop SQL tables listed in a manifest.
|
|
12
|
+
|
|
13
|
+
Sources should be provided as fully-qualified schema.table strings.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, config, sources: Iterable[str]):
|
|
17
|
+
super().__init__(config)
|
|
18
|
+
self.sources: list[str] = list(sources)
|
|
19
|
+
|
|
20
|
+
def _parse_schema_table(self, fq: str) -> tuple[str, str]:
|
|
21
|
+
parts = fq.split(".")
|
|
22
|
+
if len(parts) != 2:
|
|
23
|
+
raise ValueError(f"Invalid source table name: {fq}")
|
|
24
|
+
schema, table = parts
|
|
25
|
+
validate_identifier(schema)
|
|
26
|
+
validate_identifier(table)
|
|
27
|
+
return schema, table
|
|
28
|
+
|
|
29
|
+
def purge(self) -> list[str]:
|
|
30
|
+
"""Drop all tables in sources. Returns list of dropped table names."""
|
|
31
|
+
dropped: list[str] = []
|
|
32
|
+
conn = self.connection_p(autocommit=True)
|
|
33
|
+
try:
|
|
34
|
+
cur = conn.cursor()
|
|
35
|
+
for fq_name in self.sources:
|
|
36
|
+
schema, table = self._parse_schema_table(fq_name)
|
|
37
|
+
qualified = f"{quote_identifier(schema)}.{quote_identifier(table)}"
|
|
38
|
+
logger.info(f"Dropping table {qualified}")
|
|
39
|
+
cur.execute(f"DROP TABLE IF EXISTS {qualified}") # noqa: S608
|
|
40
|
+
dropped.append(fq_name)
|
|
41
|
+
logger.info(f"Dropped table {qualified}")
|
|
42
|
+
finally:
|
|
43
|
+
conn.close()
|
|
44
|
+
return dropped
|