Skip to content

Commit b667dc9

Browse files
committed
add uproject arg and minor cleanup
1 parent f0286cf commit b667dc9

File tree

2 files changed

+97
-79
lines changed

2 files changed

+97
-79
lines changed

pbpy/pbunreal.py

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,14 @@ def get_versionator_gs_base(fallback=None, host_only=False):
523523
return None
524524

525525

526+
@lru_cache()
527+
def get_s3_endpoint_url():
528+
endpoint = get_versionator_gs_base(host_only=True)
529+
if endpoint:
530+
return f"https://{endpoint}"
531+
return None
532+
533+
526534
@lru_cache()
527535
def get_versionator_gsuri(fallback=None):
528536
domain = get_versionator_gs_base(fallback)
@@ -947,31 +955,17 @@ def download_engine(bundle_name: str, download_symbols: bool):
947955
f"Comparing target engine version {get_engine_version_with_prefix()} with local engine version {branch_version}"
948956
)
949957

950-
if not branch_version or get_engine_version_with_prefix() == branch_version:
951-
# fast version
958+
def change_args(args: list[str]):
952959
env = None
953-
args = [
954-
pbinfo.format_repo_folder(longtail_path),
955-
"get",
956-
"--source-path",
957-
f"{gcs_bucket}lt/{bundle_name}/{version}.json",
958-
"--target-path",
959-
str(base_path),
960-
"--cache-path",
961-
f"Saved/longtail/cache/{bundle_name}",
962-
"--enable-file-mapping",
963-
]
964960
if cs == "s3":
965961
if is_custom_s3_uri(gcs_bucket):
966-
endpoint = get_versionator_gs_base(host_only=True)
962+
endpoint = get_s3_endpoint_url()
967963
if endpoint is None:
968964
pbtools.error_state(
969965
"Custom S3 endpoint configured, but unable to parse from URI."
970966
)
971967
return
972-
args.extend(
973-
["--s3-endpoint-resolver-uri", f"https://{endpoint}"]
974-
)
968+
args.extend(["--s3-endpoint-resolver-uri", endpoint])
975969
with open("Build/s3.json") as f:
976970
s3_creds = json.load(f)
977971
env = {
@@ -982,13 +976,11 @@ def download_engine(bundle_name: str, download_symbols: bool):
982976
env["AWS_REGION"] = s3_creds["region"]
983977
elif cs == "gcs":
984978
env = {"GOOGLE_APPLICATION_CREDENTIALS": "Build/credentials.json"}
985-
proc = pbtools.run_stream(
986-
args,
987-
env=env,
988-
logfunc=pbtools.progress_stream_log,
989-
)
990-
else:
979+
return env
980+
981+
if branch_version and get_engine_version_with_prefix() != branch_version:
991982
# verify a new version install
983+
pblog.info("Version upgrade detected, ")
992984
args = [
993985
pbinfo.format_repo_folder(longtail_path),
994986
"get",
@@ -1002,35 +994,36 @@ def download_engine(bundle_name: str, download_symbols: bool):
1002994
"--validate",
1003995
"--enable-file-mapping",
1004996
]
1005-
env = None
1006-
if cs == "s3":
1007-
if is_custom_s3_uri(gcs_bucket):
1008-
endpoint = get_versionator_gs_base(host_only=True)
1009-
if endpoint is None:
1010-
pbtools.error_state(
1011-
"Custom S3 endpoint configured, but unable to parse from URI."
1012-
)
1013-
return
1014-
args.extend(
1015-
["--s3-endpoint-resolver-uri", f"https://{endpoint}"]
1016-
)
1017-
with open("Build/s3.json") as f:
1018-
s3_creds = json.load(f)
1019-
env = {
1020-
"AWS_ACCESS_KEY_ID": s3_creds["key"],
1021-
"AWS_SECRET_ACCESS_KEY": s3_creds["secret"],
1022-
}
1023-
if "region" in s3_creds:
1024-
env["AWS_REGION"] = s3_creds["region"]
1025-
elif cs == "gcs":
1026-
env = {"GOOGLE_APPLICATION_CREDENTIALS": "Build/credentials.json"}
997+
env = change_args(args)
1027998
proc = pbtools.run_stream(
1028999
args,
10291000
env=env,
10301001
logfunc=pbtools.progress_stream_log,
10311002
)
1003+
# print out a newline
1004+
print("")
1005+
1006+
# fast, cached version. we always run this option so we fill in the cache.
1007+
args = [
1008+
pbinfo.format_repo_folder(longtail_path),
1009+
"get",
1010+
"--source-path",
1011+
f"{gcs_bucket}lt/{bundle_name}/{version}.json",
1012+
"--target-path",
1013+
str(base_path),
1014+
"--cache-path",
1015+
f"Saved/longtail/cache/{bundle_name}",
1016+
"--enable-file-mapping",
1017+
]
1018+
env = change_args(args)
1019+
proc = pbtools.run_stream(
1020+
args,
1021+
env=env,
1022+
logfunc=pbtools.progress_stream_log,
1023+
)
10321024
# print out a newline
10331025
print("")
1026+
10341027
if proc.returncode:
10351028
pbtools.error_state(
10361029
f"Failed to download engine update. Make sure your system time is synced. If this issue persists, please request help from {pbconfig.get('support_channel')}."
@@ -1602,13 +1595,13 @@ def build_installed_build():
16021595
env = None
16031596
if cs == "s3":
16041597
if is_custom_s3_uri(uri):
1605-
endpoint = get_versionator_gs_base(host_only=True)
1598+
endpoint = get_s3_endpoint_url()
16061599
if endpoint is None:
16071600
pbtools.error_state(
16081601
"Custom S3 endpoint configured, but unable to parse from URI."
16091602
)
16101603
return
1611-
args.extend(["--s3-endpoint-resolver-uri", f"https://{endpoint}"])
1604+
args.extend(["--s3-endpoint-resolver-uri", endpoint])
16121605
with open(project_path / "Build" / "s3.json") as f:
16131606
s3_creds = json.load(f)
16141607
env = {

pbsync/__main__.py

Lines changed: 57 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ def main(argv):
282282
"--debugbranch",
283283
help="If provided, CliqueSync will use the provided branch as expected branch",
284284
)
285+
parser.add_argument(
286+
"--uproject",
287+
help=f"Multi-project folders only: project name to choose from. If not provided, it will prompt the user for one, or in CI environments, use the first one found.",
288+
default="",
289+
)
285290

286291
if len(argv) > 0:
287292
args = parser.parse_args(argv)
@@ -382,7 +387,6 @@ def pbsync_config_parser_func(root):
382387

383388
uproject_name = pbconfig.get("uproject_name")
384389
if not uproject_name.endswith(".uproject"):
385-
386390
if not uproject_name:
387391
projects_folder = Path.cwd()
388392
project_files = [list(projects_folder.glob("*.uproject"))[0]]
@@ -396,42 +400,63 @@ def pbsync_config_parser_func(root):
396400
)
397401
return
398402

399-
print(
400-
"========================================================================="
401-
)
402-
print(
403-
"| This is a multi-project directory. |"
404-
)
405-
print(
406-
"| You need to select the project you'd like to sync. |"
407-
)
408-
print(
409-
"=========================================================================\n"
410-
)
411-
print(f">>>>> Multi-project path: {projects_folder}\n")
412-
print("Which project would you like to sync?\n")
413-
414-
options = [file.stem for file in project_files]
403+
should_select = not pbconfig.get("is_ci") and not args.uproject
415404

416-
for i, option in enumerate(options):
417-
print(f"{i + 1}) {option}")
405+
if should_select:
406+
print(
407+
"========================================================================="
408+
)
409+
print(
410+
"| This is a multi-project directory. |"
411+
)
412+
print(
413+
"| You need to select the project you'd like to sync. |"
414+
)
415+
print(
416+
"=========================================================================\n"
417+
)
418+
print(f">>>>> Multi-project path: {projects_folder}\n")
419+
print("Which project would you like to sync?\n")
418420

421+
options = [file.stem for file in project_files]
419422
uproject_file = None
420-
while True:
421-
response = input(f"\nSelect an option (1-{len(options)}) and press enter: ")
422-
try:
423-
choice = int(response) - 1
424-
if choice >= 0 and choice < len(options):
425-
uproject_file = project_files[choice].relative_to(Path.cwd())
426-
print("")
427-
pblog.success(f"Syncing project {options[choice]}.")
428-
break
429-
except ValueError:
430-
print("\n")
431-
432-
pblog.error(f"Invalid option {response}. Try again:\n")
423+
424+
if should_select:
425+
for i, option in enumerate(options):
426+
print(f"{i + 1}) {option}")
427+
while True:
428+
response = input(
429+
f"\nSelect an option (1-{len(options)}) and press enter: "
430+
)
431+
try:
432+
choice = int(response) - 1
433+
if choice >= 0 and choice < len(options):
434+
uproject_file = project_files[choice]
435+
print("")
436+
break
437+
except ValueError:
438+
print("\n")
439+
440+
pblog.error(f"Invalid option {response}. Try again:\n")
441+
else:
442+
if args.uproject:
443+
selected_project = args.uproject
444+
try:
445+
uproject_file = project_files[options.index(selected_project)]
446+
except ValueError:
447+
error_state(
448+
f"Could not find specified uproject '{selected_project}' in multi-project folder '{projects_folder}'"
449+
)
450+
return
451+
else:
452+
pblog.warning(
453+
"CI environment detected, defaulting to first project found"
454+
)
455+
uproject_file = project_files[0]
433456

434457
if uproject_file:
458+
uproject_file = uproject_file.relative_to(Path.cwd())
459+
pblog.success(f"Syncing project {uproject_file}.")
435460
pbunreal.select_uproject_name(str(uproject_file))
436461

437462
# Do not process further if we're in an error state

0 commit comments

Comments
 (0)