@@ -389,14 +389,17 @@ def upload(
389389 _ ("You must specify one (and only one) of --file or --directory." )
390390 )
391391
392- # Sanity: If directory, repository required
392+ # Sanity: If using temp repository, both directory and repository are required
393393 final_dest_repo_ctx = kwargs ["repository" ]
394- if directory and not final_dest_repo_ctx :
394+ if kwargs [ "use_temp_repository" ] and not ( directory and final_dest_repo_ctx ) :
395395 raise click .ClickException (
396- _ ("You must specify a --repository to use --directory uploads." )
396+ _ (
397+ "You must specify both --directory and --repository "
398+ "to use --use-temp-repository."
399+ )
397400 )
398401
399- # Sanity: ignore publish|use_temp unless directory has been specified
402+ # Sanity: ignore publish|use_temp unless destination-repository has been specified
400403 use_tmp = final_dest_repo_ctx and kwargs ["use_temp_repository" ]
401404 do_publish = final_dest_repo_ctx and kwargs ["publish" ]
402405
@@ -416,10 +419,11 @@ def upload(
416419 )
417420 else :
418421 # Upload a directory-full of RPMs
422+ dest_repo_ctx = None
419423 try :
420424 dest_repo_ctx = _determine_upload_repository (final_dest_repo_ctx , pulp_ctx , use_tmp )
421425 result = _upload_rpms (entity_ctx , dest_repo_ctx , directory , chunk_size )
422- if use_tmp :
426+ if use_tmp and dest_repo_ctx :
423427 result = _copy_to_final (dest_repo_ctx , final_dest_repo_ctx , pulp_ctx )
424428 finally :
425429 if use_tmp and dest_repo_ctx :
@@ -488,23 +492,36 @@ def _copy_to_final(
488492
489493def _upload_rpms (
490494 entity_ctx : PulpContentContext ,
491- dest_repo_ctx : PulpRpmRepositoryContext ,
495+ dest_repo_ctx : t . Optional [ PulpRpmRepositoryContext ] ,
492496 directory : t .Any ,
493497 chunk_size : int ,
494498) -> t .Any :
495499 rpms_path = f"{ directory } /*.rpm"
496500 rpm_names = glob .glob (rpms_path )
497501 if not rpm_names :
498502 raise click .ClickException (_ ("Directory {} has no .rpm files in it." ).format (directory ))
499- click .echo (
500- _ (
501- "About to upload {} files for {}." .format (
502- len (rpm_names ),
503- dest_repo_ctx .entity ["name" ],
504- )
505- ),
506- err = True ,
507- )
503+
504+ # Build message based on whether we have a repository or not
505+ if dest_repo_ctx :
506+ click .echo (
507+ _ (
508+ "About to upload {} files for {}." .format (
509+ len (rpm_names ),
510+ dest_repo_ctx .entity ["name" ],
511+ )
512+ ),
513+ err = True ,
514+ )
515+ else :
516+ click .echo (
517+ _ (
518+ "About to upload {} files from {}." .format (
519+ len (rpm_names ),
520+ directory ,
521+ )
522+ ),
523+ err = True ,
524+ )
508525 # Upload all *.rpm into the destination
509526 successful_uploads = 0
510527 for name in rpm_names :
@@ -525,9 +542,11 @@ def _upload_rpms(
525542
526543
527544def _determine_upload_repository (
528- final_dest_repo_ctx : PulpRpmRepositoryContext , pulp_ctx : PulpCLIContext , use_tmp : bool
529- ) -> PulpRpmRepositoryContext :
530- if use_tmp :
545+ final_dest_repo_ctx : t .Optional [PulpRpmRepositoryContext ],
546+ pulp_ctx : PulpCLIContext ,
547+ use_tmp : bool ,
548+ ) -> t .Optional [PulpRpmRepositoryContext ]:
549+ if use_tmp and final_dest_repo_ctx :
531550 dest_repo_ctx = PulpRpmRepositoryContext (pulp_ctx )
532551 body : t .Dict [str , t .Any ] = {
533552 "name" : f"uploadtmp_{ final_dest_repo_ctx .entity ['name' ]} _{ uuid4 ()} " ,
0 commit comments