Beispiel #1
0
def cmd_upgrade(args):
    registry = cryregistry.load_engines()
    engine_path = cryregistry.engine_path(registry, args.engine_version)
    if engine_path is None:
        error_engine_path_not_found(args, args.engine_version)

    if getattr(sys, 'frozen', False):
        subcmd = [
            os.path.join(engine_path, 'Tools', 'CryVersionSelector',
                         'cryrun.exe')
        ]
    else:
        subcmd = [
            python3_path(),
            os.path.join(engine_path, 'Tools', 'CryVersionSelector',
                         'cryrun.py')
        ]

    if not os.path.isfile(subcmd[-1]):
        error_engine_tool_not_found(args, subcmd[-1])

    sys_argv = [x for x in sys.argv[1:] if x not in ('--silent', )]
    subcmd.extend(sys_argv)

    print_subprocess(subcmd)
    sys.exit(subprocess.call(subcmd))
Beispiel #2
0
def cmd_run_project (args, sys_argv=sys.argv[1:]):
    if not os.path.isfile (args.project_file):
        error_project_not_found (args)

    project = cryproject.load (args.project_file)
    if project is None:
        error_project_json_decode (args)

    engine_id = cryproject.engine_id(project)
    engine_path = ""

    # Start by checking for the ability to specifying use of the local engine
    if engine_id is '.':
        engine_path = os.path.dirname(args.project_file)
    else:
        # Now check the registry
        engine_registry = cryregistry.load_engines()
        engine_path = cryregistry.engine_path (engine_registry, engine_id)
        if engine_path is None:
            error_engine_path_not_found (args, engine_id)

    #---

    if getattr( sys, 'frozen', False ):
        subcmd = [
            os.path.join (engine_path, 'Tools', 'CryVersionSelector', 'cryrun.exe')
        ]
    else:
        subcmd = [
            python_path(),
            os.path.join (engine_path, 'Tools', 'CryVersionSelector', 'cryrun.py')
        ]

    if not os.path.isfile (subcmd[-1]):
        error_engine_tool_not_found (args, subcmd[-1])

    sys_argv = [x for x in sys_argv if x not in ('--silent', )]
    subcmd.extend (sys_argv)

    print_subprocess (subcmd)
    p = subprocess.Popen(subcmd, stderr=subprocess.PIPE)
    returncode = p.wait()

    if not args.silent and returncode != 0:
        title = command_title (args)
        text = p.stderr.read().strip().decode()
        if not text:
            text = SUBPROCESS_NO_STDERR
        if has_win_modules:
            result = MessageBox (None, text, title, win32con.MB_OKCANCEL | win32con.MB_ICONERROR)
            if result == win32con.IDOK:
                input() # Keeps the window from closing
        else:
            sys.stderr.write (text)

    if returncode != 0:
        sys.exit (returncode)
Beispiel #3
0
def cmd_run (args, sys_argv= sys.argv[1:]):
	if not os.path.isfile (args.project_file):
		error_project_not_found (args)
	
	project= cryproject.load (args.project_file)
	if project is None:
		error_project_json_decode (args)
	
	engine_id= cryproject.engine_id(project)	
	engine_registry= cryregistry.load_engines()
	engine_path= cryregistry.engine_path (engine_registry, engine_id)
	if engine_path is None:
		error_engine_path_not_found (args, engine_id)
		
	#---

	if getattr( sys, 'frozen', False ):
		subcmd= [
			os.path.join (engine_path, 'Tools', 'CryVersionSelector', 'cryrun.exe')
		]
	else:
		subcmd= [
			python3_path(),
			os.path.join (engine_path, 'Tools', 'CryVersionSelector', 'cryrun.py')
		]

	if not os.path.isfile (subcmd[-1]):
		error_engine_tool_not_found (args, subcmd[-1])

	sys_argv= [x for x in sys_argv if x not in ('--silent', )]
	subcmd.extend (sys_argv)

	(temp_fd, temp_path)= tempfile.mkstemp(suffix='.out', prefix=args.command + '_', text=True)
	temp_file= os.fdopen(temp_fd, 'w')

	print_subprocess (subcmd)
	p= subprocess.Popen(subcmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
	for line in p.stdout:
		temp_file.write (line)
		sys.stdout.write (line)
	
	returncode= p.wait()
	temp_file.close()
	
	if not args.silent and returncode != 0:
		title= command_title (args)
		text= p.stderr.read().strip()
		if not text:
			text= SUBPROCESS_NO_STDERR
		result= MessageBox (None, text, title, win32con.MB_OKCANCEL | win32con.MB_ICONERROR)
		if result == win32con.IDOK:
			subprocess.call(('notepad.exe', temp_path))
				
	os.remove (temp_path)
	sys.exit (returncode)
Beispiel #4
0
def cmd_run_project(args, sys_argv=sys.argv[1:]):
    """
    Runs the command on the project, by invoking it on the cryrun.exe
    that is used by the engine the project is registered to.
    """
    if not os.path.isfile(args.project_file):
        error_project_not_found(args)

    project = cryproject.CryProject()
    try:
        project.load(args.project_file)
    except Exception:
        error_project_json_decode(args)

    engine_id = project.engine_id()
    engine_path = ""

    # Start by checking for the ability to specifying use of the local engine
    if engine_id is '.':
        engine_path = os.path.dirname(args.project_file)
    else:
        # Now check the registry
        engine_registry = cryregistry.load_engines()
        engine_path = cryregistry.engine_path(engine_registry, engine_id)
        if engine_path is None:
            error_engine_path_not_found(args, engine_id)

    if getattr(sys, 'frozen', False):
        subcmd = [get_cryrun_path(engine_path)]
    else:
        subcmd = [get_python_path(), get_cryrun_path(engine_path)]

    if not os.path.isfile(subcmd[-1]):
        error_engine_tool_not_found(args, subcmd[-1])

    subcmd.extend(sys_argv)

    print_subprocess(subcmd)
    try:
        subprocess.run(subcmd,
                       stdout=None,
                       stderr=None,
                       check=True,
                       universal_newlines=True)
    except subprocess.CalledProcessError as e:
        error_subprocess_error(
            args,
            "Encountered an error while running command '{}'!".format(e.cmd),
            e.returncode)
Beispiel #5
0
def cmd_upgrade(args):
    """
    Upgrades the project by calling it's engines cryrun.exe.
    """
    registry = cryregistry.load_engines()
    engine_path = cryregistry.engine_path(registry, args.engine_id)
    if engine_path is None:
        error_engine_path_not_found(args, args.engine_id)

    if getattr(sys, 'frozen', False):
        subcmd = [get_cryrun_path(engine_path)]
    else:
        subcmd = [get_python_path(), get_cryrun_path(engine_path)]

    if not os.path.isfile(subcmd[-1]):
        error_engine_tool_not_found(args, subcmd[-1])

    sys_argv = [x for x in sys.argv[1:] if x not in ('--silent', )]
    subcmd.extend(sys_argv)

    print_subprocess(subcmd)
    sys.exit(subprocess.call(subcmd))