worked migration
This commit is contained in:
@@ -354,7 +354,7 @@ class Migration:
|
|||||||
exported_content = None # Initialize exported_content
|
exported_content = None # Initialize exported_content
|
||||||
try:
|
try:
|
||||||
exported_content, _ = self.from_c.export_dashboard(dash_id)
|
exported_content, _ = self.from_c.export_dashboard(dash_id)
|
||||||
with create_temp_file(content=exported_content, suffix=".zip", logger=self.logger) as tmp_zip_path, \
|
with create_temp_file(content=exported_content, dry_run=True, suffix=".zip", logger=self.logger) as tmp_zip_path, \
|
||||||
create_temp_file(suffix=".dir", logger=self.logger) as tmp_unpack_dir:
|
create_temp_file(suffix=".dir", logger=self.logger) as tmp_unpack_dir:
|
||||||
|
|
||||||
if not self.db_config_replacement:
|
if not self.db_config_replacement:
|
||||||
@@ -366,8 +366,8 @@ class Migration:
|
|||||||
if self.db_config_replacement:
|
if self.db_config_replacement:
|
||||||
update_yamls(db_configs=[self.db_config_replacement], path=str(tmp_unpack_dir))
|
update_yamls(db_configs=[self.db_config_replacement], path=str(tmp_unpack_dir))
|
||||||
|
|
||||||
with create_temp_file(suffix=".zip", logger=self.logger) as tmp_new_zip:
|
with create_temp_file(suffix=".zip", dry_run=True, logger=self.logger) as tmp_new_zip:
|
||||||
create_dashboard_export(zip_path=tmp_new_zip, source_paths=[str(tmp_unpack_dir)])
|
create_dashboard_export(zip_path=tmp_new_zip, source_paths=[str(p) for p in Path(tmp_unpack_dir).glob("**/*")])
|
||||||
self.to_c.import_dashboard(file_name=tmp_new_zip, dash_id=dash_id, dash_slug=dash_slug)
|
self.to_c.import_dashboard(file_name=tmp_new_zip, dash_id=dash_id, dash_slug=dash_slug)
|
||||||
|
|
||||||
self.logger.info("[execute_migration][Success] Dashboard %s imported.", title)
|
self.logger.info("[execute_migration][Success] Dashboard %s imported.", title)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ from superset_tool.utils.logger import SupersetLogger
|
|||||||
# @YIELDS: Path - Путь к временному ресурсу.
|
# @YIELDS: Path - Путь к временному ресурсу.
|
||||||
# @THROW: IOError - При ошибках создания ресурса.
|
# @THROW: IOError - При ошибках создания ресурса.
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def create_temp_file(content: Optional[bytes] = None, suffix: str = ".zip", mode: str = 'wb', logger: Optional[SupersetLogger] = None) -> Generator[Path, None, None]:
|
def create_temp_file(content: Optional[bytes] = None, suffix: str = ".zip", mode: str = 'wb', dry_run = False, logger: Optional[SupersetLogger] = None) -> Generator[Path, None, None]:
|
||||||
logger = logger or SupersetLogger(name="fileio")
|
logger = logger or SupersetLogger(name="fileio")
|
||||||
resource_path = None
|
resource_path = None
|
||||||
is_dir = suffix.startswith('.dir')
|
is_dir = suffix.startswith('.dir')
|
||||||
@@ -54,7 +54,7 @@ def create_temp_file(content: Optional[bytes] = None, suffix: str = ".zip", mode
|
|||||||
logger.debug("[create_temp_file][State] Created temporary file: %s", resource_path)
|
logger.debug("[create_temp_file][State] Created temporary file: %s", resource_path)
|
||||||
yield resource_path
|
yield resource_path
|
||||||
finally:
|
finally:
|
||||||
if resource_path and resource_path.exists():
|
if resource_path and resource_path.exists() and not dry_run:
|
||||||
try:
|
try:
|
||||||
if resource_path.is_dir():
|
if resource_path.is_dir():
|
||||||
shutil.rmtree(resource_path)
|
shutil.rmtree(resource_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user