示例#1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--dev',
        help='Continue doing build without checking git status',
        action='store_true')
    args = parser.parse_known_args()[0]

    # Files is relative to this python script
    cur_dir = os.path.dirname(os.path.abspath(__file__))

    plugin_file = ue4util.get_real_abspath(
        os.path.join(cur_dir, '../../UnrealCV.uplugin'))
    if args.dev:
        plugin_output_folder = os.path.join(cur_dir, 'tmp')
        build_plugin(plugin_file, plugin_output_folder)
    else:
        if not is_valid(plugin_file):
            return False

        plugin_version = gitutil.get_short_version(cur_dir)
        plugin_output_folder = ue4util.get_real_abspath(
            os.path.join(cur_dir, 'built_plugin/%s' % plugin_version))
        ue4util.mkdirp(plugin_output_folder)
        info_filename = os.path.join(plugin_output_folder, 'unrealcv-info.txt')

        # Build plugin to disk
        build_plugin(plugin_file, plugin_output_folder)
        save_version_info(info_filename, plugin_file)
示例#2
0
文件: ziputil.py 项目: yzou2/unrealcv
def get_all_files(files, include_folder=True, verbose=False):
    '''
    Recursive expand folder and get all files in abspath format
    '''
    all_files = []
    for path in files:
        if verbose:
            print 'path: %s' % path

        if os.path.isfile(path) or include_folder:
            all_files.append(path)

        if os.path.isdir(path):
            for dirname, subdirs, files in os.walk(path):
                # print 'dirname: %s' % dirname
                # print 'subdirs: %s' % subdirs
                # print 'files: %s' % files
                for filename in files:
                    all_files.append(os.path.join(dirname, filename))

                for subdir in subdirs:
                    if include_folder:
                        all_files.append(os.path.join(dirname, subdir))

    return [ue4util.get_real_abspath(v) for v in all_files]
示例#3
0
def package(project_file, project_output_folder):
    '''
    Build project
    '''

    # UATScriptTemplate = '{UATScript} BuildCookRun -project={ProjectFile} -archivedirectory={OutputFolder} -noP4 -platform={Platform} -clientconfig=Development -serverconfig=Development -cook -allmaps -stage -pak -archive -build'
    # See help information in Engine/Source/Programs/AutomationTool/AutomationUtils/ProjectParams.cs

    # cmd = UATScriptTemplate.format(
    #     UATScript = ue4util.get_UAT_script(),
    #     Platform = ue4util.get_platform_name(),
    #     OutputFolder = ue4util.get_real_abspath(project_output_folder),
    #     ProjectFile = project_file
    #     )
    cmd = [
        ue4util.get_UAT_script(), 'BuildCookRun',
        '-project=%s' % project_file,
        '-archivedirectory=%s' %
        ue4util.get_real_abspath(project_output_folder), '-noP4',
        '-platform=%s' % ue4util.get_platform_name(),
        '-clientconfig=Development', '-serverconfig=Development', '-cook',
        '-allmaps', '-stage', '-pak', '-archive', '-build'
    ]
    print cmd
    # ue4util.run_ue4cmd(cmd, False)
    subprocess.call(cmd)
示例#4
0
def main():
    # Files is relative to this python script
    cur_dir = os.path.dirname(os.path.abspath(__file__))

    plugin_file = ue4util.get_real_abspath(
        os.path.join(cur_dir, '../../UnrealCV.uplugin'))
    if not is_valid(plugin_file):
        return False

    plugin_version = gitutil.get_short_version(cur_dir)
    plugin_output_folder = ue4util.get_real_abspath(
        os.path.join(cur_dir, 'built_plugin/%s' % plugin_version))
    ue4util.mkdirp(plugin_output_folder)
    info_filename = os.path.join(plugin_output_folder, 'unrealcv-info.txt')

    # Build plugin to disk
    build_plugin(plugin_file, plugin_output_folder)
    save_version_info(info_filename, plugin_file)
示例#5
0
def main():
    plugin_file = ue4util.get_real_abspath('../../UnrealCV.uplugin')
    if not is_valid(plugin_file):
        return False

    plugin_version = gitutil.get_short_version('.')
    plugin_output_folder = ue4util.get_real_abspath('./built_plugin/%s' %
                                                    plugin_version)
    ue4util.mkdirp(plugin_output_folder)
    info_filename = os.path.join(plugin_output_folder, 'unrealcv-info.txt')

    # Build plugin to disk
    build_plugin(plugin_file, plugin_output_folder)
    save_version_info(info_filename, plugin_file)

    # Upload built plugin to upload location
    upload_confs = ue4config.conf['PluginOutput']
    for upload_conf in upload_confs:
        upload_plugin(plugin_output_folder, upload_conf)
示例#6
0
def zip_project(zipfilename, project_name, project_output_folder):
    files = get_files(project_output_folder, project_name)

    zip_root_folder = ue4util.get_real_abspath(project_output_folder) + '/'
    if check_files_ok(files): # Make sure all files we want exist
        all_files = ziputil.get_all_files(files)
        print 'Start zipping files to %s, Zip root folder is %s' % (zipfilename, zip_root_folder)
        ziputil.zipfiles(all_files, zip_root_folder, zipfilename, verbose=False)
        return True
    else:
        return False
示例#7
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--engine_path', help='The folder that contains Unreal Engine 4')
    args = parser.parse_args()

    # Files are relative to this python script
    cur_dir = os.path.dirname(os.path.abspath(__file__))
    plugin_file = ue4util.get_real_abspath(os.path.join(cur_dir, '../../UnrealCV.uplugin'))

    output_folder = os.path.join(cur_dir, '../../built')

    util = UE4PluginUtil(args.engine_path)
    util.build_plugin(plugin_file, output_folder)
示例#8
0
def main():
    # Parse command line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('project_file')
    args = parser.parse_args()

    # Read project information
    project_file = ue4util.get_real_abspath(args.project_file)
    project_name = ue4util.get_project_name(project_file)
    project_output_folder = './built_project/%s' % project_name
    info_filename = os.path.join(project_output_folder,
                                 '%s-info.txt' % project_name)

    # Get plugin information
    project_folder = os.path.dirname(project_file)
    plugin_infofile = os.path.join(project_folder, 'Plugins', 'unrealcv',
                                   'unrealcv-info.txt')
    if not os.path.isfile(plugin_infofile):
        print 'Plugin not exist'
        return
    else:
        with open(plugin_infofile, 'r') as f:
            plugin_info = json.load(f)
            plugin_version = plugin_info['plugin_version']

    if os.path.isdir(project_output_folder):
        print 'Output directory %s exist, delete it first' % project_output_folder
    else:
        # Package game and save version info
        package(project_file, project_output_folder)

        # Save version info after build finished
        save_version_info(info_filename, project_file, project_output_folder,
                          plugin_version)

    # Zip files
    zipfilename = os.path.join(
        project_output_folder,
        get_zipfilename_from_infofile(info_filename, plugin_infofile))
    zip_project(zipfilename, project_file, project_output_folder)

    # Upload built games to output targets
    upload_confs = ue4config.conf['ProjectOutput']
    upload_handlers = dict(
        scp=uploadutil.upload_scp,
        s3=uploadutil.upload_s3,
    )
    for upload_conf in upload_confs:
        tgt_type = upload_conf['Type']
        upload_handlers[tgt_type](upload_conf, [zipfilename],
                                  os.path.dirname(zipfilename))
示例#9
0
def package(project_file, project_output_folder):
    '''
    Build project
    '''

    UATScriptTemplate = '{UATScript} BuildCookRun -project={ProjectFile} -archivedirectory={OutputFolder} -noP4 -platform={Platform} -clientconfig=Development -serverconfig=Development -cook -allmaps -stage -pak -archive -build'
    # See help information in Engine/Source/Programs/AutomationTool/AutomationUtils/ProjectParams.cs

    cmd = UATScriptTemplate.format(
        UATScript=ue4config.conf['UATScript'].replace(' ', '\ '),
        Platform=ue4util.get_platform_name(),
        OutputFolder=ue4util.get_real_abspath(project_output_folder),
        ProjectFile=project_file)

    ue4util.run_ue4cmd(cmd, False)
示例#10
0
def upload_scp(scp_conf, files, local_root):
    '''
    Local root will be subtracted from the abspath of files
    '''
    import os, paramiko
    assert (scp_conf['Type'] == 'scp')

    absfiles = ziputil.get_all_files(files, include_folder=True)
    local_root = ue4util.get_real_abspath(local_root) + '/'

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    # ssh.load_system_host_keys()
    # ssh.load_host_keys(os.path.expanduser(os.path.join('~', '.ssh', 'known_hosts')))
    ssh.connect(scp_conf['Host'],
                username=scp_conf['Username'],
                password=scp_conf['Password'])
    remote_root = scp_conf['RemoteRoot']

    sftp = ssh.open_sftp()

    # client = scp.Client(host = scp_conf['host'], user = scp_conf['user'], password = scp_conf['password'])
    for local_filename in absfiles:
        relative_filename = local_filename.replace(local_root, '')
        # print 'local filename: %s, relative filename: %s' % (local_filename, relative_filename)

        if os.path.isdir(local_filename):
            remote_dir = os.path.join(remote_root, relative_filename)
            print 'Mkdir remote dir %s' % remote_dir
            try:
                sftp.mkdir(remote_dir)
            except:
                pass  # maybe exist
            continue
        else:
            remote_filename = os.path.join(remote_root, relative_filename)
            print '%s -> %s' % (local_filename, remote_filename)
            # client.transfer(filename, remote_filename)
            sftp.put(local_filename, remote_filename)

    sftp.close()
    ssh.close()
示例#11
0
文件: ziputil.py 项目: yzou2/unrealcv
def zipfiles(srcfiles, srcroot, dst, verbose=False):
    '''
    srcfiles: files in abspath format
    srcroot: root will be subtracted for converting to relative path
    dst: zip file
    '''
    srcroot = ue4util.get_real_abspath(
        srcroot)  # Make sure it has the same format as srcfiles
    print 'zip files %s ... to file %s, with root %s' % (srcfiles[0], dst,
                                                         srcroot)
    zf = zipfile.ZipFile("%s" % (dst), "w", zipfile.ZIP_DEFLATED)

    for srcfile in srcfiles:
        # arcname = srcfile[len(srcroot) + 1:]
        arcname = srcfile.replace(srcroot, '').lstrip('/')
        # Make sure it is a relative path, absolute path is quite dangerous and might overwrite something
        if verbose:
            print 'zipping %s as %s' % (srcfile, arcname)
        assert arcname == '' or arcname[
            0] != '/'  # Make sure this is not staring from the root
        zf.write(srcfile, arcname)

    zf.close()
示例#12
0
def upload_scp(remote,
               files,
               local_root,
               password=None,
               key_filename=None,
               DEBUG=False):
    '''
    Local root will be subtracted from the abspath of files
    '''
    import os, paramiko

    # Make sure the remote is with a correct format
    if '@' in remote:
        [username, remain] = remote.split('@')
    else:
        remain = remote
        username = None

    [host, remote_root] = remain.split(':')

    absfiles = ziputil.get_all_files(files, include_folder=True)
    local_root = ue4util.get_real_abspath(local_root) + ue4util.get_path_sep()
    if DEBUG:
        print 'Local root is %s' % repr(local_root)
        print 'Remote root is %s' % repr(remote_root)

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    # ssh.load_system_host_keys()
    # ssh.load_host_keys(os.path.expanduser(os.path.join('~', '.ssh', 'known_hosts')))
    # ssh.connect(scp_conf['Host'], username = scp_conf['Username'], password = scp_conf['Password'])

    ssh.load_system_host_keys()
    # ssh.connect(scp_conf['Host'])

    ssh.connect(host,
                username=username,
                password=password,
                key_filename=key_filename)
    # Use private key for authentication
    # remote_root = scp_conf['RemoteRoot']

    sftp = ssh.open_sftp()

    # client = scp.Client(host = scp_conf['host'], user = scp_conf['user'], password = scp_conf['password'])
    for local_filename in absfiles:
        if local_root not in local_filename:
            exit('The local_root %s is not found is the abs filename %s' %
                 (repr(local_root), repr(local_filename)))
        relative_filename = local_filename.replace(local_root, '')
        # print 'local filename: %s, relative filename: %s' % (local_filename, relative_filename)

        if os.path.isdir(local_filename):
            # remote_dir = os.path.join(remote_root, relative_filename)
            remote_dir = '/'.join([remote_root, relative_filename
                                   ])  # Make sure we use '/' here
            if DEBUG:
                print 'Mkdir remote dir %s' % repr(remote_dir)

            try:
                sftp.mkdir(remote_dir)
            except:
                pass  # maybe exist
            continue
        else:
            # remote_filename = os.path.join(remote_root, relative_filename)
            remote_filename = '/'.join([remote_root, relative_filename])
            if DEBUG:
                print '%s -> %s' % (repr(local_filename),
                                    repr(remote_filename))
            # client.transfer(filename, remote_filename)
            sftp.put(local_filename, remote_filename)

    sftp.close()
    ssh.close()
示例#13
0
    parser = argparse.ArgumentParser()
    parser.add_argument('project', help='Project name')
    parser.add_argument('remote')
    parser.add_argument('--password', help = 'Account password')
    parser.add_argument('--pkey', help = 'Private key')
    args = parser.parse_args()

    remote = args.remote
    project_name = args.project


    # project_output_folder = os.path.join(cur_dir, 'built_project/%s' % project_name)
    # info_filename = os.path.join(project_output_folder, '%s-info.txt' % project_name)
    cur_dir = os.path.dirname(os.path.abspath(__file__))
    info_filename = os.path.join(cur_dir, 'built_project/%s' % project_name, '%s-info.txt' % project_name)
    info_filename = ue4util.get_real_abspath(info_filename)
    project_output_folder = get_project_output_folder(info_filename)

    # project_folder = os.path.dirname(project_file)
    # plugin_infofile = os.path.join(project_folder, 'Plugins', 'unrealcv', 'unrealcv-info.txt')

    # Zip files
    zipfilename = os.path.join(project_output_folder, get_zipfilename_from_infofile(info_filename))
    print 'Zip project to file %s' % zipfilename
    zip_project(zipfilename, project_name, project_output_folder)

    # Upload built games to output targets
    print 'Upload project from %s -> %s' % (zipfilename, remote)
    uploadutil.upload_scp(remote, [zipfilename], os.path.dirname(zipfilename),
        password = args.password,
        key_filename = args.pkey,
示例#14
0
def main():
    # Files is relative to this python script
    cur_dir = os.path.dirname(os.path.abspath(__file__))

    # Parse command line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('project_file')
    parser.add_argument('--engine_path')  # Add here just as a placeholder
    # parser.add_argument('--clean', action='store_true')
    # args = parser.parse_args()
    args, _ = parser.parse_known_args()

    # Read project information
    project_file = ue4util.get_real_abspath(args.project_file)
    project_name = ue4util.get_project_name(project_file)

    # Get plugin information
    project_folder = os.path.dirname(project_file)
    plugin_infofile = os.path.join(project_folder, 'Plugins', 'unrealcv',
                                   'unrealcv-info.txt')
    if not os.path.isfile(plugin_infofile):
        exit('Plugin not exist in the project')
    else:
        with open(plugin_infofile, 'r') as f:
            plugin_info = json.load(f)
            plugin_version = plugin_info['plugin_version']

    project_version = gitutil.get_short_version(project_folder)
    project_output_folder = os.path.join(
        cur_dir, 'built_project/%s/%s-%s' %
        (project_name, project_version, plugin_version))
    info_filename = os.path.join(project_output_folder,
                                 '%s-info.txt' % project_name)

    # if args.clean and os.path.isdir(project_output_folder):
    #     # Use a very strict check to avoid acciently perform the delete
    #     # --force might be dangerous, use it with care
    #     project_output_folder = ue4util.get_real_abspath(project_output_folder)
    #     print 'Try to delete existing compiled project %s' % project_output_folder
    #     assert(project_name in project_output_folder)
    #     assert('*' not in project_output_folder)
    #     assert(project_output_folder.count('/') > 2)
    #     assert(len(project_output_folder) > 10)
    #     shutil.rmtree(project_output_folder)

    if os.path.isdir(project_output_folder):
        print 'Output directory %s exist, delete it first' % project_output_folder
    else:
        # Package game and save version info
        package(project_file, project_output_folder)

        # Save version info after build finished
        # Save one to version folder
        save_version_info(info_filename, project_file, project_output_folder,
                          plugin_version)

        # Save one to project folder
        project_root_folder = os.path.join(cur_dir,
                                           'built_project/%s' % project_name)
        root_info_filename = os.path.join(project_root_folder,
                                          '%s-info.txt' % project_name)
        save_version_info(root_info_filename, project_file,
                          project_output_folder, plugin_version)
示例#15
0
    # Copy binaries to a remote server with scp
    # Upload built plugin to upload location
    parser = argparse.ArgumentParser()
    parser.add_argument('remote')
    parser.add_argument('--version')
    parser.add_argument('--password', help = 'Account password')
    parser.add_argument('--pkey', help = 'Private key')

    cur_dir = os.path.dirname(os.path.abspath(__file__))

    args = parser.parse_args()
    if args.version:
        plugin_version = args.version
    else:
        plugin_version = gitutil.get_short_version(cur_dir)
    remote = args.remote
    # remote = '%s@%s:%s'

    plugin_output_folder = ue4util.get_real_abspath(os.path.join(cur_dir, 'built_plugin/%s' % plugin_version))
    if not os.path.isdir(plugin_output_folder):
        exit('Version %s of plugin does not exist, compile first' % plugin_version)

    print 'Upload plugin from %s -> %s' % (repr(plugin_output_folder), repr(remote))
    # Use repr so that I can correctly see the difference between / and \\
    local_root = os.path.join(cur_dir, 'built_plugin')
    uploadutil.upload_scp(remote, [plugin_output_folder], local_root,
        password=args.password,
        key_filename=args.pkey,
        DEBUG=False)
    # uploadutil.upload_scp()
示例#16
0
import argparse, shutil, os
import ue4util
def install_plugin(project_file, plugin_folder):
    project_folder = os.path.dirname(project_file)
    install_folder = os.path.join(project_folder, 'Plugins', 'unrealcv')
    if os.path.isdir(install_folder):
        shutil.rmtree(install_folder) # Complete remove old version, a little dangerous

    shutil.copytree(plugin_folder, install_folder)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('plugin_version')
    parser.add_argument('project_file')
    args = parser.parse_args()

    plugin_version = args.plugin_version
    project_file = ue4util.get_real_abspath(args.project_file)

    plugin_folder = 'built_plugin/%s' % plugin_version
    install_plugin(project_file, plugin_folder)