From 019b0b060ba4dcaaf7df11b432568c1a26034fe2 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Fri, 16 Aug 2024 04:28:50 +0800 Subject: [PATCH] Split anaconda out --- include/source.h | 33 +--------------- src/chsrc.c | 81 +------------------------------------- src/recipe/catalog.c | 3 -- src/recipe/ware/Anaconda.c | 75 +++++++++++++++++++++++++++++++++++ src/recipe/ware/Flathub.c | 45 +++++++++++++++++++++ 5 files changed, 124 insertions(+), 113 deletions(-) create mode 100644 src/recipe/ware/Anaconda.c create mode 100644 src/recipe/ware/Flathub.c diff --git a/include/source.h b/include/source.h index 4051e87..f047d79 100644 --- a/include/source.h +++ b/include/source.h @@ -153,38 +153,10 @@ pl_dotnet_sources[] = { - /** - * @time 2023-09-11 更新 - * @note 目前只有一个源 + * @time 2023-09-10 更新 */ static SourceInfo -wr_flathub_sources[] = { - {&Upstream, NULL}, - {&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/flathub"}, -}, - - - - - -/** - * @time 2023-09-10 更新 - * @note 这些链接将会在setsrc函数中补充完整 - */ -wr_anaconda_sources[] = { - {&Upstream, NULL}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/anaconda/"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/anaconda/"}, - {&Zju, "https://mirrors.zju.edu.cn/anaconda/"}, - {&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/anaconda"} -}, - - - -/** - * @time 2023-09-10 更新 - */ wr_tex_sources[] = { {&Upstream, NULL}, {&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/ctan/systems/texlive/tlnet"}, @@ -203,6 +175,5 @@ wr_tex_sources[] = { def_sources_n(pl_clojure); def_sources_n(pl_dotnet); -def_sources_n(wr_flathub); def_sources_n(wr_tex); -def_sources_n(wr_anaconda); + diff --git a/src/chsrc.c b/src/chsrc.c index 2cdedd1..a16770b 100644 --- a/src/chsrc.c +++ b/src/chsrc.c @@ -182,86 +182,9 @@ wr_tex_setsrc (char *option) #include "recipe/ware/CocoaPods.c" #include "recipe/ware/Nix.c" #include "recipe/ware/Guix.c" - - - +#include "recipe/ware/Flathub.c" #include "recipe/ware/docker.c" - - -/** - * 参考: https://mirrors.sjtug.sjtu.edu.cn/docs/flathub - */ -void -wr_flathub_setsrc (char *option) -{ - SourceInfo source; - chsrc_yield_source (wr_flathub); - chsrc_confirm_source (&source); - - chsrc_note2 ("若出现问题,可先调用以下命令:"); - char *note = xy_strjoin (3, - "wget ", source.url, "/flathub.gpg\n" - "flatpak remote-modify --gpg-import=flathub.gpg flathub" - ); - puts (note); - - char *cmd = xy_2strjoin ("flatpak remote-modify flathub --url=", source.url); - chsrc_run (cmd, RunOpt_Default); - - chsrc_say_lastly (&source, ChsrcTypeAuto); -} - - - -void -wr_anaconda_setsrc (char *option) -{ - SourceInfo source; - chsrc_yield_source (wr_anaconda); - chsrc_confirm_source (&source); - - char *main = xy_2strjoin (source.url, "pkgs/main"); - char *r = xy_2strjoin (source.url, "pkgs/r"); - char *msys2 = xy_2strjoin (source.url, "pkgs/msys2"); - char *cloud = xy_2strjoin (source.url, "cloud"); - - char *file = xy_strjoin (22, - "channels:\n - defaults\n" - "show_channel_urls: true\ndefault_channels:" - "\n - ", main, - "\n - ", r, - "\n - ", msys2, - "\ncustom_channels:\n" - " conda-forge: ", cloud, - "\n msys2: ", cloud, - "\n bioconda: ", cloud, - "\n menpo: ", cloud, - "\n pytorch: ", cloud, - "\n pytorch-lts: ", cloud, - "\n simpleitk: ", cloud, - "\n deepmodeling: ", cloud); - - - // TODO: 待确认 windows 上也是这里吗? - char *config = xy_2strjoin (xy_os_home, "/.condarc"); - - if (xy_on_windows) - { - bool exist = chsrc_check_program ("conda"); - if (!exist) - { - chsrc_error ("未找到 conda 命令,请检查是否存在"); - exit (Exit_UserCause); - } - chsrc_run ("conda config --set show_channel_urls yes", RunOpt_Default); - } - - chsrc_note2 (xy_strjoin (3, "请向 ", config, " 中手动添加:")); - puts (file); - - chsrc_note2 ("然后运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引"); - chsrc_say_lastly (&source, ChsrcTypeSemiAuto); -} +#include "recipe/ware/Anaconda.c" #include "recipe/catalog.c" diff --git a/src/recipe/catalog.c b/src/recipe/catalog.c index 18ee059..9f0d0fb 100644 --- a/src/recipe/catalog.c +++ b/src/recipe/catalog.c @@ -91,9 +91,6 @@ static const char os_freebsd, os_netbsd, os_openbsd, }; - -def_target_noget (wr_flathub); -def_target_noget (wr_anaconda); def_target(wr_tex); static const char diff --git a/src/recipe/ware/Anaconda.c b/src/recipe/ware/Anaconda.c new file mode 100644 index 0000000..7b6cf4f --- /dev/null +++ b/src/recipe/ware/Anaconda.c @@ -0,0 +1,75 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------- + * File Authors : Aoran Zeng + * Contributors : Nil Null + * Created On : <2023-09-10> + * Last Modified : <2024-08-15> + * ------------------------------------------------------------*/ + +/** + * @time 2023-09-10 更新 + * @note 这些链接将会在setsrc函数中补充完整 + */ +static SourceInfo +wr_anaconda_sources[] = { + {&Upstream, NULL}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/anaconda/"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/anaconda/"}, + {&Zju, "https://mirrors.zju.edu.cn/anaconda/"}, + {&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/anaconda"} +}; +def_sources_n(wr_anaconda); + + +void +wr_anaconda_setsrc (char *option) +{ + SourceInfo source; + chsrc_yield_source (wr_anaconda); + chsrc_confirm_source (&source); + + char *main = xy_2strjoin (source.url, "pkgs/main"); + char *r = xy_2strjoin (source.url, "pkgs/r"); + char *msys2 = xy_2strjoin (source.url, "pkgs/msys2"); + char *cloud = xy_2strjoin (source.url, "cloud"); + + char *file = xy_strjoin (22, + "channels:\n - defaults\n" + "show_channel_urls: true\ndefault_channels:" + "\n - ", main, + "\n - ", r, + "\n - ", msys2, + "\ncustom_channels:\n" + " conda-forge: ", cloud, + "\n msys2: ", cloud, + "\n bioconda: ", cloud, + "\n menpo: ", cloud, + "\n pytorch: ", cloud, + "\n pytorch-lts: ", cloud, + "\n simpleitk: ", cloud, + "\n deepmodeling: ", cloud); + + + // TODO: 待确认 windows 上也是这里吗? + char *config = xy_2strjoin (xy_os_home, "/.condarc"); + + if (xy_on_windows) + { + bool exist = chsrc_check_program ("conda"); + if (!exist) + { + chsrc_error ("未找到 conda 命令,请检查是否存在"); + exit (Exit_UserCause); + } + chsrc_run ("conda config --set show_channel_urls yes", RunOpt_Default); + } + + chsrc_note2 (xy_strjoin (3, "请向 ", config, " 中手动添加:")); + puts (file); + + chsrc_note2 ("然后运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引"); + chsrc_say_lastly (&source, ChsrcTypeSemiAuto); +} + +def_target_noget (wr_anaconda); diff --git a/src/recipe/ware/Flathub.c b/src/recipe/ware/Flathub.c new file mode 100644 index 0000000..06a60c7 --- /dev/null +++ b/src/recipe/ware/Flathub.c @@ -0,0 +1,45 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------- + * File Authors : Aoran Zeng + * Contributors : Nil Null + * Created On : <2023-09-11> + * Last Modified : <2024-08-15> + * ------------------------------------------------------------*/ + +/** + * @time 2023-09-11 更新 + * @note 目前只有一个源 + */ +static SourceInfo +wr_flathub_sources[] = { + {&Upstream, NULL}, + {&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/flathub"}, +}; +def_sources_n(wr_flathub); + + +/** + * 参考: https://mirrors.sjtug.sjtu.edu.cn/docs/flathub + */ +void +wr_flathub_setsrc (char *option) +{ + SourceInfo source; + chsrc_yield_source (wr_flathub); + chsrc_confirm_source (&source); + + chsrc_note2 ("若出现问题,可先调用以下命令:"); + char *note = xy_strjoin (3, + "wget ", source.url, "/flathub.gpg\n" + "flatpak remote-modify --gpg-import=flathub.gpg flathub" + ); + puts (note); + + char *cmd = xy_2strjoin ("flatpak remote-modify flathub --url=", source.url); + chsrc_run (cmd, RunOpt_Default); + + chsrc_say_lastly (&source, ChsrcTypeAuto); +} + +def_target_noget (wr_flathub);