Skip to content

Commit

Permalink
Bug fixes in the product-exporter script
Browse files Browse the repository at this point in the history
  • Loading branch information
anfimovdm committed Oct 9, 2024
1 parent c0185d6 commit e90055b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion scripts/exporters/base_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(
self,
repodata_cache_dir: str,
logger_name: str = '',
log_file_path: Path = Path('/srv/exporter.log'),
log_file_path: str = '/srv/exporter.log',
verbose: bool = False,
export_method: Literal['write', 'hardlink', 'symlink'] = 'hardlink',
export_path: str = settings.pulp_export_path,
Expand Down
36 changes: 25 additions & 11 deletions scripts/exporters/products_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

from alws.config import settings
from alws.dependencies import get_async_db_session
from alws.errors import DataNotFoundError
from alws.models import Platform, Product, Repository
from alws.utils import pulp_client
from alws.utils.fastapi_sqla_setup import setup_all
from scripts.exporters.base_exporter import BasePulpExporter

Expand Down Expand Up @@ -56,14 +58,6 @@ def parse_args():
required=False,
help="Repodata cache directory",
)
parser.add_argument(
"-v",
"--verbose",
action="store_true",
default=False,
required=False,
help="Verbose output",
)
parser.add_argument(
"-method",
"--export-method",
Expand All @@ -72,6 +66,22 @@ def parse_args():
required=False,
help="Method of exporting (choices: write, hardlink, symlink)",
)
parser.add_argument(
"-l",
"--log",
type=str,
default='/srv/product-exporter.log',
required=False,
help="Path to export log",
)
parser.add_argument(
"-v",
"--verbose",
action="store_true",
default=False,
required=False,
help="Verbose output",
)
return parser.parse_args()


Expand All @@ -80,7 +90,7 @@ def __init__(
self,
repodata_cache_dir: str,
logger_name: str = 'product-exporter',
log_file_path: Path = Path('/srv/product-exporter.log'),
log_file_path: str = '/srv/product-exporter.log',
verbose: bool = False,
export_method: Literal['write', 'hardlink', 'symlink'] = 'hardlink',
export_path: str = settings.pulp_export_path,
Expand All @@ -97,7 +107,7 @@ def __init__(
async def export_product_repos(
self,
product_name: str,
distr_name,
distr_name: str,
arches: List[str],
):
self.logger.info(
Expand All @@ -121,6 +131,8 @@ async def export_product_repos(
)
async with get_async_db_session() as session:
product = (await session.execute(query)).scalars().first()
if not product:
raise DataNotFoundError(f'Cannot find product: {product_name}')
return await self.export_repositories(
list({repo.id for repo in product.repositories})
)
Expand All @@ -133,7 +145,7 @@ async def repo_post_processing(
async with SEMAPHORE:
result = False
try:
exporter.regenerate_repo_metadata(repo_path)
exporter.regenerate_repo_metadata(str(Path(repo_path).parent))
except Exception as exc:
result = False
exporter.logger.exception("Post-processing failed: %s", str(exc))
Expand All @@ -147,7 +159,9 @@ async def main():
repodata_cache_dir=args.cache_dir,
verbose=args.verbose,
export_method=args.export_method,
log_file_path=args.log,
)
pulp_client.PULP_SEMAPHORE = asyncio.Semaphore(10)
exported_paths = await exporter.export_product_repos(
product_name=args.product,
distr_name=args.distribution,
Expand Down

0 comments on commit e90055b

Please sign in to comment.