mirror of
https://github.com/RubyMetric/chsrc
synced 2025-09-09 21:16:24 +08:00
Rewrite uv
recipe using rawstr4c
This commit is contained in:
parent
0dba3904cf
commit
0fb89b854b
@ -7,9 +7,11 @@
|
|||||||
* |
|
* |
|
||||||
* Created On : <2023-09-03>
|
* Created On : <2023-09-03>
|
||||||
* Major Revision : 1
|
* Major Revision : 1
|
||||||
* Last Modified : <2025-07-11>
|
* Last Modified : <2025-07-14>
|
||||||
* ------------------------------------------------------------*/
|
* ------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "rawstr4c.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注意这个前缀是 host/pipi/web/pacakges....
|
* 注意这个前缀是 host/pipi/web/pacakges....
|
||||||
* 下面有几个镜像站微调了这个路径,我们只要确认能找到 packages 目录就好
|
* 下面有几个镜像站微调了这个路径,我们只要确认能找到 packages 目录就好
|
||||||
|
16
src/recipe/lang/Python/rawstr4c.h
Normal file
16
src/recipe/lang/Python/rawstr4c.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generated by rawstr4c v0.1.0.1-2025/07/14
|
||||||
|
*
|
||||||
|
* Date: 2025-07-14T17:28:23.336582+08:00
|
||||||
|
*/
|
||||||
|
|
||||||
|
char RAWSTR_pl_python_uv_config_source_content[] = "\x5b\x5b\x69\x6e\x64\x65\x78\x5d\x5d\x0a\x75\x72\x6c\x20\x3d\x20\x22\x40\x75\x72\x6c\x22\x0a\x64\x65\x66\x61\x75\x6c\x74\x20\x3d\x20\x74\x72\x75\x65\x0a\x0a";
|
||||||
|
|
||||||
|
char RAWSTR_pl_python_get_uv_config[] = "\x67\x72\x65\x70\x20\x2d\x41\x20\x32\x20\x27\x69\x6e\x64\x65\x78\x27\x20\x40\x66\x40\x20\x7c\x20\x73\x65\x64\x20\x2d\x6e\x20\x27\x73\x2f\x5e\x75\x72\x6c\x20\x3d\x20\x22\x5c\x28\x2e\x2a\x5c\x29\x22\x2f\x5c\x31\x2f\x70\x27\x0a";
|
||||||
|
|
||||||
|
char RAWSTR_pl_python_set_uv_config[] = "\x40\x73\x65\x64\x40\x20\x27\x2f\x5e\x5c\x5b\x5c\x5b\x69\x6e\x64\x65\x78\x5c\x5d\x5c\x5d\x24\x2f\x2c\x2f\x5e\x64\x65\x66\x61\x75\x6c\x74\x20\x3d\x20\x74\x72\x75\x65\x24\x2f\x7b\x73\x7c\x5e\x75\x72\x6c\x20\x3d\x20\x22\x2e\x2a\x22\x24\x7c\x75\x72\x6c\x20\x3d\x20\x22\x40\x75\x72\x6c\x40\x22\x7c\x7d\x27\x20\x40\x66\x40\x0a";
|
||||||
|
|
||||||
|
char RAWSTR_pl_python_final_uv_cmd[] = "\x67\x72\x65\x70\x20\x2d\x71\x20\x27\x5e\x5b\x5b\x69\x6e\x64\x65\x78\x5d\x5d\x24\x27\x20\x40\x66\x40\x20\x26\x26\x20\x40\x75\x63\x6d\x64\x40\x20\x7c\x7c\x20\x40\x61\x63\x6d\x64\x40\x0a";
|
||||||
|
|
50
src/recipe/lang/Python/rawstr4c.md
Normal file
50
src/recipe/lang/Python/rawstr4c.md
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<!-- -----------------------------------------------------------
|
||||||
|
! SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
! -------------------------------------------------------------
|
||||||
|
! Config Type : rawstr4c (Markdown)
|
||||||
|
! Config Authors: Aoran Zeng <ccmywish@qq.com>
|
||||||
|
! | happy game <happygame1024@gmail.com>
|
||||||
|
! Contributors : Nil Null <nil@null.org>
|
||||||
|
! Created On : <2025-07-14>
|
||||||
|
! Last Modified : <2025-07-14>
|
||||||
|
! ---------------------------------------------------------- -->
|
||||||
|
|
||||||
|
# rawstr4c input for Python
|
||||||
|
|
||||||
|
- prefix = `RAWSTR_pl_python`
|
||||||
|
- output = `:global-variable-only-header`
|
||||||
|
- translate = `:hex`
|
||||||
|
- keep-postfix = `false`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### uv config source content
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[[index]]
|
||||||
|
url = "@url"
|
||||||
|
default = true
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Get uv config
|
||||||
|
|
||||||
|
```sh
|
||||||
|
grep -A 2 'index' @f@ | sed -n 's/^url = "\(.*\)"/\1/p'
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Set uv config
|
||||||
|
|
||||||
|
```sh
|
||||||
|
@sed@ '/^\[\[index\]\]$/,/^default = true$/{s|^url = ".*"$|url = "@url@"|}' @f@
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Final uv cmd
|
||||||
|
|
||||||
|
```sh
|
||||||
|
grep -q '^[[index]]$' @f@ && @ucmd@ || @acmd@
|
||||||
|
```
|
@ -6,7 +6,8 @@
|
|||||||
* | Aoran Zeng <ccmywish@qq.com>
|
* | Aoran Zeng <ccmywish@qq.com>
|
||||||
* |
|
* |
|
||||||
* Created On : <2024-12-11>
|
* Created On : <2024-12-11>
|
||||||
* Last Modified : <2025-07-11>
|
* Major Revision : 1
|
||||||
|
* Last Modified : <2025-07-14>
|
||||||
* ------------------------------------------------------------*/
|
* ------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,9 +20,9 @@
|
|||||||
* 4. /etc/uv/uv.toml
|
* 4. /etc/uv/uv.toml
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define UV_CONFIG "uv.toml"
|
#define PL_Python_uv_ConfigFile "uv.toml"
|
||||||
#define UV_LOCAL_CONFIG_PATH "./"
|
#define PL_Python_uv_Local_ConfigPath "./"
|
||||||
#define UV_USER_CONFIG_PATH "~/.config/uv/"
|
#define PL_Python_uv_User_ConfigPath "~/.config/uv/"
|
||||||
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
@ -29,7 +30,7 @@ pl_python_find_uv_config (bool mkdir)
|
|||||||
{
|
{
|
||||||
if (chsrc_in_local_mode())
|
if (chsrc_in_local_mode())
|
||||||
{
|
{
|
||||||
return xy_2strjoin (UV_LOCAL_CONFIG_PATH, UV_CONFIG);
|
return xy_2strjoin (PL_Python_uv_Local_ConfigPath, PL_Python_uv_ConfigFile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -49,16 +50,16 @@ pl_python_find_uv_config (bool mkdir)
|
|||||||
{
|
{
|
||||||
chsrc_ensure_dir (config_dir);
|
chsrc_ensure_dir (config_dir);
|
||||||
}
|
}
|
||||||
return xy_2strjoin (config_dir, UV_CONFIG);
|
return xy_2strjoin (config_dir, PL_Python_uv_ConfigFile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* config path on Linux or macOS */
|
/* config path on Linux or macOS */
|
||||||
if (mkdir)
|
if (mkdir)
|
||||||
{
|
{
|
||||||
chsrc_ensure_dir (UV_USER_CONFIG_PATH);
|
chsrc_ensure_dir (PL_Python_uv_User_ConfigPath);
|
||||||
}
|
}
|
||||||
return xy_2strjoin (UV_USER_CONFIG_PATH, UV_CONFIG);
|
return xy_2strjoin (PL_Python_uv_User_ConfigPath, PL_Python_uv_ConfigFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,13 +75,8 @@ pl_python_uv_getsrc (char *option)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* 获取 [[index]] 配置项的 url */
|
||||||
* grep -A 2 'index' config_file | sed -n 's/^url = "\(.*\)"/\1/p'
|
char *cmd = xy_str_gsub (RAWSTR_pl_python_get_uv_config, "@f@", uv_config);
|
||||||
* 获取 [[index]] 配置项的 url
|
|
||||||
*/
|
|
||||||
char *cmd = xy_strjoin (3, "grep -A 2 'index' ",
|
|
||||||
uv_config,
|
|
||||||
" | sed -n 's/^url = \"\\(.*\\)\"/\\1/p'");
|
|
||||||
chsrc_run (cmd, RunOpt_Default);
|
chsrc_run (cmd, RunOpt_Default);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,26 +104,21 @@ pl_python_uv_setsrc (char *option)
|
|||||||
}
|
}
|
||||||
chsrc_backup (uv_config);
|
chsrc_backup (uv_config);
|
||||||
|
|
||||||
const char *source_content = xy_strjoin (5,
|
const char *source_content = xy_str_gsub (RAWSTR_pl_python_uv_config_source_content, "@url@", source.url);
|
||||||
"[[index]]\\n",
|
|
||||||
"url = \"", source.url, "\"\\n",
|
|
||||||
"default = true\\n");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* sed -i '/^\[\[index\]\]$/,/^default = true$/{s|^url = ".*"$|url = " source.url "|}' uv_config
|
|
||||||
* 将 [[index]] 到 default = true 之间的 url = ".*" 替换为 url = "source.url"
|
|
||||||
*/
|
|
||||||
#if defined(XY_On_macOS) || defined(XY_On_BSD)
|
#if defined(XY_On_macOS) || defined(XY_On_BSD)
|
||||||
char *sed_cmd = "sed -i '' ";
|
char *sed_cmd = "sed -i '' ";
|
||||||
#else
|
#else
|
||||||
char *sed_cmd = "sed -i ";
|
char *sed_cmd = "sed -i ";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *update_source_cmd = xy_strjoin (5, sed_cmd,
|
/**
|
||||||
"'/^\\[\\[index\\]\\]$/,/^default = true$/{s|^url = \".*\"$|url = \"",
|
* 将 [[index]] 到 default = true 之间的 url = ".*" 替换为 url = "source.url"
|
||||||
source.url,
|
*/
|
||||||
"\"|;}' ",
|
char *update_source_cmd = xy_str_gsub (RAWSTR_pl_python_set_uv_config, "@sed@", sed_cmd);
|
||||||
uv_config);
|
update_source_cmd = xy_str_gsub (update_source_cmd, "@f@", uv_config);
|
||||||
|
update_source_cmd = xy_str_gsub (update_source_cmd, "@url@", source.url);
|
||||||
|
|
||||||
char *append_source_cmd = xy_strjoin (4, "printf '", source_content, "' >> ", uv_config);
|
char *append_source_cmd = xy_strjoin (4, "printf '", source_content, "' >> ", uv_config);
|
||||||
|
|
||||||
char *cmd = NULL;
|
char *cmd = NULL;
|
||||||
@ -150,14 +141,10 @@ pl_python_uv_setsrc (char *option)
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* uv_config 存在,如果存在 [[index]] 则更新,否则追加到文件末尾
|
* uv_config 存在,如果存在 [[index]] 则更新,否则追加到文件末尾
|
||||||
* run: grep -q '^[[index]]$' uv_config && update_source_cmd || append_source_cmd
|
|
||||||
*/
|
*/
|
||||||
cmd = xy_strjoin (6, "grep -q '^\\[\\[index\\]\\]$' ",
|
cmd = xy_str_gsub (RAWSTR_pl_python_final_uv_cmd, "@f@", uv_config);
|
||||||
uv_config,
|
cmd = xy_str_gsub (cmd, "@ucmd@", update_source_cmd);
|
||||||
" && ",
|
cmd = xy_str_gsub (cmd, "@acmd@", append_source_cmd);
|
||||||
update_source_cmd,
|
|
||||||
" || ",
|
|
||||||
append_source_cmd);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (NULL==cmd)
|
if (NULL==cmd)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user