Example #1
0
def check_update_on_start(config: CommonConfig):
    if config.bypass_proxy:
        logger.info("检查更新前临时启用代理")
        use_proxy()

    check_update = config.check_update_on_start or config.check_update_on_end
    try:
        if is_run_in_github_action():
            logger.info("当前在github action环境下运行,无需检查更新")
            return

        if not check_update and not config.auto_update_on_start:
            logger.warning("启动时检查更新被禁用,若需启用请在config.toml中设置")
            return

        ui = get_update_info(config)

        if check_update:
            try_manaual_update(ui)

        if config.auto_update_on_start:
            show_update_info_on_first_run(ui)
    except Exception as e:
        logger.debug(f"更新失败 {e}")
        if check_update:
            update_fallback(config)
    finally:
        if config.bypass_proxy:
            logger.info("检查完毕,继续无视代理")
            bypass_proxy()
Example #2
0
def auto_update():
    args = parse_args()

    change_title("自动更新DLC")

    logger.info(color("bold_yellow") + f"更新器的进程为{os.getpid()}, 代码版本为{now_version}")
    logger.info(color("bold_yellow") + f"需要检查更新的小助手主进程为{args.pid}, 版本为{args.version}")

    # note: 工作目录预期为小助手的exe所在目录
    if args.cwd == invalid_cwd:
        logger.error("请不要直接双击打开自动更新工具,正确的用法是放到utils目录后,照常双击【DNF蚊子腿小助手.exe】来使用,小助手会自行调用自动更新DLC的")
        os.system("PAUSE")
        return

    logger.info(f"切换工作目录到{args.cwd}")
    os.chdir(args.cwd)

    if not exists_flag_file(".use_proxy"):
        bypass_proxy()
        logger.info(f"当前已默认无视系统代理(VPN),如果需要dlc使用代理,请在小助手目录创建 .use_proxy 目录或文件")

    uploader = Uploader()

    # 进行实际的检查是否需要更新操作
    latest_version = uploader.latest_version()
    logger.info(f"当前版本为{args.version},网盘最新版本为{latest_version}")

    if need_update(args.version, latest_version):
        update(args, uploader)
        start_new_version(args)
    else:
        logger.info("已经是最新版本,不需要更新")
def init_venv_and_requirements(venv_path=".venv",
                               requirements_path="requirements.txt",
                               disable_douban=False,
                               enable_proxy=False):
    if not enable_proxy:
        logger.info("当前已无视系统代理")
        bypass_proxy()

    # 初始化相关路径变量
    pyscript_path = os.path.join(venv_path, "Scripts")
    py_path = os.path.join(pyscript_path, "python")
    pip_path = os.path.join(pyscript_path, "pip")

    show_head_line(f"尝试初始化venv环境", color("bold_yellow"))

    subprocess.call([
        "python",
        "-m",
        "venv",
        venv_path,
    ])

    logger.info("尝试更新pip setuptools wheel")
    douban_op = ["-i", "https://pypi.doubanio.com/simple"]
    if disable_douban:
        douban_op = []
    subprocess.call([
        py_path,
        "-m",
        "pip",
        "install",
        *douban_op,
        "--upgrade",
        "pip",
        "setuptools",
        "wheel",
    ])

    logger.info("尝试安装依赖库和pyinstaller")
    subprocess.call([
        pip_path,
        "install",
        *douban_op,
        "-r",
        requirements_path,
        "--upgrade",
        "wheel",
        "pyinstaller",
    ])

    logger.info("安装pywin32_postinstall")
    subprocess.call([
        py_path,
        os.path.join(pyscript_path, "pywin32_postinstall.py"),
        "-install",
    ])
Example #4
0
            show_only_before_version=show_only_before_version,
        )

    nm.save()


def test():
    nm = NoticeManager(load_from_remote=False)

    for notice in nm.notices:
        notice.reset_first_run()
        notice.show_only_before_version = ""

    logger.info("测试环境已重置完毕,所有公告都已改为未展示状态,且关闭版本限制")

    nm.show_notices()

    os.system("PAUSE")


if __name__ == "__main__":
    TEST = False
    from util import bypass_proxy

    bypass_proxy()

    if not TEST:
        main()
    else:
        test()