Skip to content

Commit

Permalink
save config
Browse files Browse the repository at this point in the history
implement all ue4v settings
  • Loading branch information
mastercoms committed Oct 30, 2020
1 parent d7732ed commit 43a87d3
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 65 deletions.
16 changes: 11 additions & 5 deletions pbpy/pbconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
from xml.etree.ElementTree import parse
from functools import lru_cache

from pbpy import pbtools

# Singleton Config
config = None

user_config = None

def get(key):
if key is None or config is None or config.get(str(key)) is None:
print(f"Invalid config get request: {key}")
sys.exit(1)
pbtools.error_state(f"Invalid config get request: {key}", hush=True)

return config.get(str(key))

Expand All @@ -27,6 +28,8 @@ def init_user_config():
global user_config
user_config = configparser.ConfigParser()
user_config.read(get_user_config_filename())
if not user_config.has_section("ue4v-user"):
user_config["ue4v-user"] = {}


def get_user_config():
Expand All @@ -35,9 +38,12 @@ def get_user_config():
return user_config

def get_user(section, key, default=None):
if user_config is None:
init_user_config()
return user_config.get(section, key, fallback=default)
return get_user_config().get(section, key, fallback=default)


def shutdown():
with open(get_user_config_filename(), 'w') as user_config_file:
get_user_config().write(user_config_file)


def generate_config(config_path, parser_func):
Expand Down
14 changes: 9 additions & 5 deletions pbpy/pbtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,16 @@ def remove_file(file_path):
return not os.path.isfile(file_path)


def error_state(msg=None, fatal_error=False):
def error_state(msg=None, fatal_error=False, hush=False):
if msg is not None:
pblog.error(msg)
if fatal_error:
# This is a fatal error, so do not let user run PBSync until issue is fixed
with open(error_file, 'w') as error_state_file:
error_state_file.write("1")
pblog.info(f"Logs are saved in {pbconfig.get('log_file_path')}.")
if not hush:
pblog.info(f"Logs are saved in {pbconfig.get('log_file_path')}.")
pbconfig.shutdown()
sys.exit(1)


Expand All @@ -225,9 +227,9 @@ def get_running_process(process_name):

def wipe_workspace():
current_branch = pbgit.get_current_branch_name()
response = input(f"This command will wipe your workspace and get latest changes from {current_branch}. Are you sure? [y/N]")
response = input(f"This command will wipe your workspace and get latest changes from {current_branch}. Are you sure? [y/N] ")

if response != "y" and response != "Y":
if len(response) < 1 or response[0].lower() != "y":
return False

pbgit.abort_all()
Expand All @@ -252,7 +254,9 @@ def maintain_repo():

# try to remove commit graph lock before running commit graph
try:
os.remove(os.path.join(os.getcwd(), ".git", "objects", "info", "commit-graphs", "commit-graph-chain.lock"))
commit_graph_lock = os.path.join(os.getcwd(), ".git", "objects", "info", "commit-graphs", "commit-graph-chain.lock")
if (os.path.exists(commit_graph_lock)):
os.remove(commit_graph_lock)
except Exception as e:
pblog.error(e)

Expand Down
126 changes: 110 additions & 16 deletions pbpy/pbunreal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from os import remove
from functools import lru_cache
from urllib.parse import urlparse
from pathlib import Path
from gslib.command_runner import CommandRunner
from gslib.commands.cp import CpCommand
from gslib.commands.rsync import RsyncCommand
Expand Down Expand Up @@ -152,7 +153,86 @@ def get_engine_version_with_prefix():


def get_engine_install_root():
return pbconfig.get_user("ue4v-user", "download_dir")
root = pbconfig.get_user("ue4v-user", "download_dir")
if root is None:
curdir = Path().resolve()

if pbconfig.get("is_ci"):
if os.name == "nt":
return curdir.anchor
else:
return curdir.parent

print("======================================================================")
print("| A custom UE4 engine build needs to be downloaded for this project. |")
print("| These builds can be quite large. Lots of disk space is required. |")
print("======================================================================\n")
print(f"Project path: {curdir}\n")
print("Which directory should these engine downloads be stored in?\n")

options = []

# parent directory
options.append(curdir.parent)

# home directory
options.append(Path.home())

# drive
if os.name == "nt":
options.append(Path(curdir.anchor))

# go into ue4 folder
options = [(path / 'ue4').resolve() for path in options]

# remove duplicates
options = list(dict.fromkeys(options))

# add custom option
custom = "custom location"
options.append(custom)

for i, option in enumerate(options):
print(f"{i + 1}) {option}")

directory = None
while True:
response = input(f"\nSelect an option (1-{len(options)}) and press enter: ")
try:
choice = int(response) - 1
if choice >= 0 and choice < len(options):
directory = options[choice]
if directory == custom:
try:
response = input("\nCustom location: ")
directory = Path(response.strip()).resolve()
try:
directory.relative_to(curdir)
relative = True
except ValueError:
relative = False
if relative:
print("download directory cannot reside in the project directory")
continue
except Exception as e:
pblog.error(str(e))
directory = None

if directory:
try:
directory.mkdir(exist_ok=True)
break
except Exception as e:
pblog.error(str(e))
continue
except ValueError:
pass

pblog.error(f"Invalid option {response}. Try again:\n")
if directory:
root = str(directory)
pbconfig.get_user_config()["ue4v-user"]["download_dir"] = root
return root


def get_latest_available_engine_version(bucket_url):
Expand Down Expand Up @@ -259,15 +339,15 @@ def get_versionator_gsuri():

@lru_cache()
def is_versionator_symbols_enabled():
symbols = pbconfig.get_user_config().getboolean("ue4v-user", "symbols")
symbols = pbconfig.get_user_config().getboolean("ue4v-user", "symbols", fallback=None)
if symbols is not None:
return symbols

if pbconfig.get("is_ci"):
return False

# Symbols configuration variable is not on the file, let's add it
response = input("Do you want to download debugging symbols for accurate crash logging? You can change this setting later in the .ue4v-user config file. [y/N]")
response = input("Do you want to download debugging symbols for accurate crash logging? You can change this setting later in the .ue4v-user config file. [y/N] ")
if len(response) > 0 and response[0].lower() == "y":
pbconfig.get_user_config()["ue4v-user"]["symbols"] = "true"
return True
Expand All @@ -283,7 +363,7 @@ def get_bundle_verification_file(bundle_name):
return "Engine/Binaries/Win64/UE4Editor."


def run_ue4versionator(bundle_name=None, download_symbols=False):
def download_engine(bundle_name=None, download_symbols=False):
required_free_gb = 7

if download_symbols:
Expand All @@ -292,7 +372,6 @@ def run_ue4versionator(bundle_name=None, download_symbols=False):
required_free_space = required_free_gb * 1000 * 1000 * 1000

root = get_engine_install_root()
# TODO: prompt for root
if root is not None:
if not pbconfig.get("is_ci") and os.path.isdir(root):
total, used, free = disk_usage(root)
Expand Down Expand Up @@ -351,7 +430,7 @@ def run_ue4versionator(bundle_name=None, download_symbols=False):
patterns.append(f"{bundle_name}-symbols")
else:
patterns.append(f"{bundle_name}")
patterns = [pattern + f"-{version}.7z" if legacy_archives else "/" for pattern in patterns]
patterns = [f"{pattern}-{version}.7z" if legacy_archives else "/" for pattern in patterns]
gcs_bucket = get_versionator_gsuri()
for pattern in patterns:
gcs_uri = f"{gcs_bucket}{pattern}"
Expand All @@ -360,17 +439,32 @@ def run_ue4versionator(bundle_name=None, download_symbols=False):

# Extract and register with ue4versionator
# TODO: handle registration
command_set = ["ue4versionator.exe"]
if False:
if os.name == "nt":
try:
import winreg
engine_ver = f"{bundle_name}-{version}"
engine_id = f"ue4v:{engine_ver}"
with winreg.CreateKeyEx(winreg.HKEY_CURRENT_USER, r"SOFTWARE\Epic Games\Unreal Engine\Builds", access=winreg.KEY_SET_VALUE) as key:
# This does not work for some reason.
winreg.SetValueEx(key, engine_id, 0, winreg.REG_SZ, str(os.path.join(root, engine_ver)))
except Exception as e:
pblog.error(str(e))
return False
return True
else:
command_set = ["ue4versionator.exe"]

command_set.append("-assume-valid")
command_set.append("-assume-valid")

if bundle_name is not None:
command_set.append("-bundle")
command_set.append(str(bundle_name))
if bundle_name is not None:
command_set.append("-bundle")
command_set.append(str(bundle_name))

if pbconfig.get("is_ci"):
# If we're CI, use another config file
command_set.append("-user-config")
command_set.append(pbconfig.get_user_config_filename())
if pbconfig.get("is_ci"):
# If we're CI, use another config file
command_set.append("-user-config")
command_set.append(pbconfig.get_user_config_filename())

return subprocess.run(command_set, shell=True).returncode
return subprocess.run(command_set, shell=True).returncode == 0
return False
Loading

0 comments on commit 43a87d3

Please sign in to comment.