Refactor target group mode

This commit is contained in:
Aoran Zeng 2025-07-11 10:12:27 +08:00
parent 8b9c0b565b
commit e953aceb54
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
9 changed files with 69 additions and 42 deletions

View File

@ -9,7 +9,7 @@
* | Yangmoooo <yangmoooo@outlook.com> * | Yangmoooo <yangmoooo@outlook.com>
* | * |
* Created On : <2023-08-29> * Created On : <2023-08-29>
* Last Modified : <2025-06-20> * Last Modified : <2025-07-11>
* *
* chsrc framework * chsrc framework
* ------------------------------------------------------------*/ * ------------------------------------------------------------*/
@ -30,11 +30,42 @@
static int chsrc_get_cpucore (); static int chsrc_get_cpucore ();
/**
* Target Group
*
* 1. target group target follower target
* 2. target leader targetvirtual target APT virtual package
*
* 使: Python Node.js
*/
struct
{
boolean in;
int leader_selected_index; /* leader target 选中的索引 */
}
TargetGroupMode =
{
.in = false,
.leader_selected_index = -1
};
bool
chsrc_in_target_group_mode ()
{
return TargetGroupMode.in;
}
void
chsrc_set_target_group_mode ()
{
TargetGroupMode.in = true;
}
bool ProgMode_CMD_Measure = false; bool ProgMode_CMD_Measure = false;
bool ProgMode_CMD_Reset = false; bool ProgMode_CMD_Reset = false;
bool ProgMode_Target_Group = false;
int ProgMode_Leader_Selected_Index = -1;
/* 此时 chsrc_run() 不再是recipe中指定要运行的一个外部命令而是作为一个功能实现的支撑 */ /* 此时 chsrc_run() 不再是recipe中指定要运行的一个外部命令而是作为一个功能实现的支撑 */
bool ProgMode_Run_as_a_Service = false; bool ProgMode_Run_as_a_Service = false;
@ -139,10 +170,8 @@ chsrc_log_backup (const char *filename)
#define NoMark "x" #define NoMark "x"
#define HalfYesMark "⍻" #define HalfYesMark "⍻"
/**
* @translation Done static void
*/
void
log_check_result (const char *check_what, const char *check_type, bool exist) log_check_result (const char *check_what, const char *check_type, bool exist)
{ {
char *chk_msg = NULL; char *chk_msg = NULL;
@ -176,10 +205,7 @@ log_check_result (const char *check_what, const char *check_type, bool exist)
} }
/** static void
* @translation Done
*/
void
log_cmd_result (bool result, int exit_status) log_cmd_result (bool result, int exit_status)
{ {
char *run_msg = NULL; char *run_msg = NULL;
@ -234,7 +260,6 @@ is_url (const char *str)
* *
* @param prog_name * @param prog_name
* *
* @translation Done
*/ */
bool bool
query_program_exist (char *check_cmd, char *prog_name, int mode) query_program_exist (char *check_cmd, char *prog_name, int mode)
@ -798,26 +823,30 @@ is_reset_mode ()
/** /**
* **5 Source_t * @brief @var:source
* option:
* 1. Mirror Code
* 2. NULL: ()
* 3. URL
* 4. ChgType_Reset
* Leader target
* 5. ProgMode_Leader_Selected_Index
* *
* @dependency option * **5 Source_t
*
* 1. Mirror Code chsrc set <target> <code>
* 2. URL chsrc set <target> https://ur
* 3. chsrc set <target>
* 4. chsrc reset <target>
*
* Target Group leader target :
*
* 5. leader target
*
* @dependency @var:option
*/ */
#define chsrc_yield_for_the_source(for_what) \ #define chsrc_yield_for_the_source(for_what) \
if (ProgMode_Target_Group==true && ProgMode_Leader_Selected_Index==-1) \ if (chsrc_in_target_group_mode() && TargetGroupMode.leader_selected_index==-1) \
{ \ { \
ProgMode_Leader_Selected_Index = use_specific_mirror_or_auto_select (option, for_what); \ TargetGroupMode.leader_selected_index = use_specific_mirror_or_auto_select (option, for_what); \
source = for_what##_sources[ProgMode_Leader_Selected_Index]; \ source = for_what##_sources[TargetGroupMode.leader_selected_index]; \
} \ } \
else if (ProgMode_Target_Group==true && ProgMode_Leader_Selected_Index!=-1) \ else if (chsrc_in_target_group_mode() && TargetGroupMode.leader_selected_index!=-1) \
{ \ { \
source = for_what##_sources[ProgMode_Leader_Selected_Index]; \ source = for_what##_sources[TargetGroupMode.leader_selected_index]; \
} \ } \
else if (is_url (option)) \ else if (is_url (option)) \
{ \ { \
@ -844,8 +873,6 @@ is_reset_mode ()
* *
* 1. * 1.
* 2. * 2.
*
* @translation Done
*/ */
#define chsrc_confirm_source confirm_source(&source) #define chsrc_confirm_source confirm_source(&source)
void void

View File

@ -74,7 +74,7 @@ pl_nodejs_setsrc (char *option)
bool npm_exist, yarn_exist, pnpm_exist; bool npm_exist, yarn_exist, pnpm_exist;
pl_nodejs_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist); pl_nodejs_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist);
ProgMode_Target_Group = true; chsrc_set_target_group_mode ();
chsrc_yield_source_and_confirm (pl_nodejs); chsrc_yield_source_and_confirm (pl_nodejs);
if (npm_exist) if (npm_exist)

View File

@ -42,7 +42,7 @@ pl_nodejs_yarn_setsrc (char *option)
{ {
Source_t source; Source_t source;
chsrc_yield_for_the_source (pl_nodejs); chsrc_yield_for_the_source (pl_nodejs);
if (ProgMode_Target_Group!=true) if (!chsrc_in_target_group_mode())
chsrc_confirm_source; chsrc_confirm_source;
char *cmd = NULL; char *cmd = NULL;
@ -71,7 +71,7 @@ pl_nodejs_yarn_setsrc (char *option)
chsrc_run (cmd, RunOpt_No_Last_New_Line); chsrc_run (cmd, RunOpt_No_Last_New_Line);
} }
if (ProgMode_Target_Group!=true) if (!chsrc_in_target_group_mode())
{ {
chsrc_determine_chgtype (ChgType_Auto); chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source); chsrc_conclude (&source);

View File

@ -28,7 +28,7 @@ pl_nodejs_npm_setsrc (char *option)
{ {
Source_t source; Source_t source;
chsrc_yield_for_the_source (pl_nodejs); chsrc_yield_for_the_source (pl_nodejs);
if (ProgMode_Target_Group!=true) if (!chsrc_in_target_group_mode())
chsrc_confirm_source; chsrc_confirm_source;
char *cmd = NULL; char *cmd = NULL;
@ -40,7 +40,7 @@ pl_nodejs_npm_setsrc (char *option)
chsrc_run (cmd, RunOpt_No_Last_New_Line); chsrc_run (cmd, RunOpt_No_Last_New_Line);
if (ProgMode_Target_Group!=true) if (!chsrc_in_target_group_mode())
{ {
chsrc_determine_chgtype (ChgType_Auto); chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source); chsrc_conclude (&source);

View File

@ -29,7 +29,7 @@ pl_nodejs_pnpm_setsrc (char *option)
{ {
Source_t source; Source_t source;
chsrc_yield_for_the_source (pl_nodejs); chsrc_yield_for_the_source (pl_nodejs);
if (ProgMode_Target_Group!=true) if (!chsrc_in_target_group_mode())
chsrc_confirm_source; chsrc_confirm_source;
char *cmd = NULL; char *cmd = NULL;
@ -41,7 +41,7 @@ pl_nodejs_pnpm_setsrc (char *option)
chsrc_run (cmd, RunOpt_No_Last_New_Line); chsrc_run (cmd, RunOpt_No_Last_New_Line);
if (ProgMode_Target_Group!=true) if (!chsrc_in_target_group_mode())
{ {
chsrc_determine_chgtype (ChgType_Auto); chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source); chsrc_conclude (&source);

View File

@ -30,7 +30,7 @@ pl_python_pdm_setsrc (char *option)
{ {
Source_t source; Source_t source;
chsrc_yield_for_the_source (pl_python); chsrc_yield_for_the_source (pl_python);
if (ProgMode_Target_Group!=true) if (!chsrc_in_target_group_mode())
chsrc_confirm_source; chsrc_confirm_source;
char *cmd = NULL; char *cmd = NULL;
@ -42,7 +42,7 @@ pl_python_pdm_setsrc (char *option)
chsrc_run (cmd, RunOpt_No_Last_New_Line); chsrc_run (cmd, RunOpt_No_Last_New_Line);
if (ProgMode_Target_Group!=true) if (!chsrc_in_target_group_mode())
{ {
chsrc_determine_chgtype (ChgType_Auto); chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source); chsrc_conclude (&source);

View File

@ -29,7 +29,7 @@ pl_python_poetry_setsrc (char *option)
{ {
Source_t source; Source_t source;
chsrc_yield_for_the_source (pl_python); chsrc_yield_for_the_source (pl_python);
if (ProgMode_Target_Group!=true) if (!chsrc_in_target_group_mode())
chsrc_confirm_source; chsrc_confirm_source;
char *cmd = NULL; char *cmd = NULL;
@ -40,7 +40,7 @@ pl_python_poetry_setsrc (char *option)
cmd = xy_2strjoin ("poetry source add my_mirror ", source.url); cmd = xy_2strjoin ("poetry source add my_mirror ", source.url);
chsrc_run (cmd, RunOpt_No_Last_New_Line); chsrc_run (cmd, RunOpt_No_Last_New_Line);
if (ProgMode_Target_Group!=true) if (!chsrc_in_target_group_mode())
{ {
chsrc_determine_chgtype (ChgType_Auto); chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source); chsrc_conclude (&source);

View File

@ -57,7 +57,7 @@ pl_python_setsrc (char *option)
pl_python_check_unofficial_pkger (&poetry_exist, &pdm_exist, &uv_exist); pl_python_check_unofficial_pkger (&poetry_exist, &pdm_exist, &uv_exist);
ProgMode_Target_Group = true; chsrc_set_target_group_mode ();
chsrc_yield_source_and_confirm (pl_python); chsrc_yield_source_and_confirm (pl_python);

View File

@ -40,7 +40,7 @@ pl_python_pip_setsrc (char *option)
Source_t source; Source_t source;
chsrc_yield_for_the_source (pl_python); chsrc_yield_for_the_source (pl_python);
if (ProgMode_Target_Group!=true) if (!chsrc_in_target_group_mode())
chsrc_confirm_source; chsrc_confirm_source;
char *py_prog_name = NULL; char *py_prog_name = NULL;
@ -52,7 +52,7 @@ pl_python_pip_setsrc (char *option)
char *cmd = xy_2strjoin (py_prog_name, xy_2strjoin (" -m pip config --user set global.index-url ", source.url)); char *cmd = xy_2strjoin (py_prog_name, xy_2strjoin (" -m pip config --user set global.index-url ", source.url));
chsrc_run (cmd, RunOpt_No_Last_New_Line); chsrc_run (cmd, RunOpt_No_Last_New_Line);
if (ProgMode_Target_Group!=true) if (!chsrc_in_target_group_mode())
{ {
chsrc_determine_chgtype (ChgType_Auto); chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source); chsrc_conclude (&source);