Exemplo n.º 1
0
def deploy(args, unknown=None):
    _activate_venv()
    try:
        from PyInstaller.__main__ import run as prun
    except ImportError:
        if not args.dev:
            print("Please supply the '--dev' argument if you want to deploy")
            sys.exit(1)
        else:
            _update_pip(args)
        from PyInstaller.__main__ import run as prun

    import happypanda.core.command
    from happypanda.common import constants
    from happypanda.core import updater

    if not args.dev:
        args.client = True
        build(args, ["--prod"])
        run([is_tool(is_installed("npm")), "run", "build"])

    if constants.is_osx:
        os_name = "osx"
    elif constants.is_win:
        os_name = "win"
    elif constants.is_linux:
        os_name = "linux"

    sha_file_o = os.path.join(".", "dist", "sha256.txt")
    output_path = os.path.join(".", "dist", "happypandax")
    updater_path = "dist"
    dir_path = os.path.join(".", "dist", "happypandax")
    if constants.is_osx:
        dir_path = os.path.join(dir_path, constants.osx_bundle_name,
                                "Contents", "MacOS")
    installer_filename = ".installed"
    installer_file = os.path.join("deploy", installer_filename)
    hidden_imports = [
        'engineio.async_gevent',
        'logging.config',
        'sqlalchemy.ext.baked',
        'dogpile.cache.backends.memory',
    ]
    h_imports = []
    for h in hidden_imports:
        h_imports.append('--hidden-import')
        h_imports.append(h)
    if not prun(["happypandax.spec", "--noconfirm"]) and not prun([
            'updater.py', '--onefile', '--name', constants.updater_name,
            *h_imports, '--icon', constants.favicon_path, '--specpath', 'build'
    ]):
        upd_name = constants.updater_name
        if constants.is_win:
            upd_name += '.exe'

        if constants.is_osx:
            bundle_path_old = os.path.join("dist", constants.osx_bundle_name)
            bundle_path = os.path.join(output_path, constants.osx_bundle_name)
            os.replace(bundle_path_old, bundle_path)
        os.replace(os.path.join(updater_path, upd_name),
                   os.path.join(dir_path, upd_name))

        if os.environ.get('CI'):
            deploy_dir = os.path.join("dist", "files")
            if os.path.exists(deploy_dir):
                shutil.rmtree(deploy_dir)
            os.mkdir(deploy_dir)

        for p in ("", "installer"):
            if constants.preview:
                output_path_a = output_path + ".PREVIEW."
            output_path_a = output_path + ".".join(
                str(x) for x in constants.version)
            output_path_a = output_path_a + "." + os_name
            if p:
                output_path_a = output_path_a + "." + p

            installer_file_out = os.path.join(dir_path, installer_filename)
            if p == "installer":
                if constants.is_linux:
                    continue
                if not os.path.exists(installer_file_out):
                    shutil.copyfile(installer_file, installer_file_out)
            else:
                if os.path.exists(installer_file_out):
                    os.remove(installer_file_out)

            fmt = 'zip' if constants.is_win else 'gztar'
            if p == 'installer' and constants.is_win:
                fmt = '7z'
            elif p == 'installer' and constants.is_osx:
                fmt = 'dmg'

            output_path_a = output_path_a + '.' + (
                (fmt[2:] + '.' + fmt[:2]) if 'tar' in fmt else fmt)
            if os.path.exists(output_path_a):
                os.remove(output_path_a)

            if p == 'installer' and constants.is_osx:
                _osx_installer(bundle_path,
                               os.path.splitext(constants.osx_bundle_name)[0],
                               output_path_a)
            else:
                _compress_dir(output_path, output_path_a, fmt)

            if p != "installer":
                sha_value = updater.sha256_checksum(output_path_a)
                with open(sha_file_o, "w") as f:
                    f.write(sha_value)
                print("{}\n\tSHA256 Checksum: {}".format(
                    output_path_a, sha_value))

            if os.environ.get('CI'):
                deploy_file_o = os.path.join(deploy_dir,
                                             pathlib.Path(output_path_a).name)
                try:
                    os.replace(output_path_a, deploy_file_o)
                except FileNotFoundError as e:
                    print(e)

    print("Done")
Exemplo n.º 2
0
def file_checksum(args, u=None):
    _activate_venv()
    from happypanda.core import updater
    print("{}\n\tSHA256 Checksum: {}".format(args.f,
                                             updater.sha256_checksum(args.f)))
Exemplo n.º 3
0
    asset_files = ("happyupd.txt", "installedfromtest.txt",
                   "../Resources/hello.txt")
asset_url_win = "tests/data/happypandax0.0.2.win.zip"
asset_url_linux = "tests/data/happypandax0.0.2.linux.tar.gz"
asset_url_osx = "tests/data/happypandax0.0.2.osx.tar.gz"
if constants.is_win:
    asset_url_platform = asset_url_win
elif constants.is_linux:
    asset_url_platform = asset_url_linux
elif constants.is_osx:
    asset_url_platform = asset_url_osx

with open(asset_url_platform, "rb") as f:
    asset_data = f.read()

asset_data_checksum = updater.sha256_checksum(asset_url_platform)

github_repo_v0_0_2 = {
    "url":
    "https://api.github.com/repos/happypandax/server/releases/9067700",
    "assets_url":
    "https://api.github.com/repos/happypandax/server/releases/9067700/assets",
    "upload_url":
    "https://uploads.github.com/repos/happypandax/server/releases/9067700/assets{?name,label}",
    "html_url":
    "https://github.com/happypandax/server/releases/tag/v0.0.2",
    "id":
    9067700,
    "tag_name":
    "v0.0.2",
    "target_commitish":