10000 完善mk txt文本修改方式 · home-coder/yun-update-source@51beb88 · GitHub
[go: up one dir, main page]

Skip to content

Commit 51beb88

Browse files
committed
完善mk txt文本修改方式
1 parent 3f4c66e commit 51beb88

File tree

3 files changed

+81
-48
lines changed

3 files changed

+81
-48
lines changed

common.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ function load_local_config()
5656
config_register_path
5757
}
5858

59+
function call_version_manager()
60+
{
61+
debug_func "call_version_manager, $1"
62+
}
63+
5964
#
6065
#
6166
#@FUNC: 使用一次针对manifestmap整体的扫描确定更新情况,如果更新便直接更新。
@@ -66,10 +71,12 @@ function update_local_code()
6671
{
6772
debug_func "update_local_code"
6873
#检查是否需要更新,返回值: 1->更新并正常写入文件 0->已是最新版本无需更新
69-
call_process_server
74+
process_manifest_event
7075
UPDATE_FLAG=$?
7176
if [[ $UPDATE_FLAG -eq 0 ]]; then
7277
debug_import "No changes, nothing to commit. It is latest Version"
78+
call_version_manager "nochange"
79+
#git reset 2>&1 1>/dev/null
7380
else
7481
debug_import "Some changes, It will update itself ..."
7582
#XXX Beta版加下面的reset作为结果diff使用,Release 将去除该行
@@ -89,6 +96,7 @@ function wind_up_work()
8996
debug_func "wind_up_work"
9097
#如果编译返回值没有出错就提交代码
9198
#如果出错就git reset
99+
call_version_manager "changed"
92100
}
93101

94102
function common_main()

edit_util.sh

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ function format_local_file()
1515

1616
#############################################################################
1717
#@PARAM: 1:path 文本以 # 作为注释, 以 := 作为键和值的关系
18-
# FIXME: 文本中关键字如'PRODUCT_MANUFACTURER'必须在行首,前面不要有空格
18+
# FIXME: 仅仅支持文本中关键字如'PRODUCT_MANUFACTURER'必须在行首,
19+
# 前面不要有空格
1920
# 2:key
2021
# 3:value
2122
#@FUNC : 用 1:= $param_value表示替换结果, 如果不存在则追加 >>
@@ -24,8 +25,8 @@ function format_local_file()
2425
#############################################################################
2526
function write_mk_file()
2627
{
27-
debug_func "write_mk_file"
28-
debug_info $*
28+
debug_func "write_mk_file $*"
29+
2930
if [ $# -ne 3 ];then
3031
debug_error "param is wrong, exit(-1)"
3132
exit -1
@@ -34,7 +35,7 @@ function write_mk_file()
3435
local retflag=0
3536

3637
if [ ! -f $1 ]; then
37-
debug_info "There is not a '$param_file', now creat it"
38+
debug_warn "There is not a file->'$1', now creat it"
3839
touch $1
3940
retflag=1
4041
fi
@@ -48,14 +49,15 @@ function write_mk_file()
4849
add_prop="$param_key := $param_value"
4950
echo "$add_prop" >> $param_file
5051
retflag=1
51-
debug_warn "Just add <$param_key, $param_value>, Please ensure it is useful"
52+
debug_warn "Add <$param_key, $param_value>, Please ensure it is useful"
5253
else
5354
#2>&1 1>/dev/null
5455
#如果找到这样的关键字,则匹配后面的value如果不同则更新,并更新升级标志
5556
file_value=$(grep -r ^"$param_key" "$param_file" | awk -F ':=' '{gsub(" |\t","",$2); print $2}')
5657
if [[ x"$file_value" != x"$param_value" ]]; then
5758
retflag=1
5859
sed -i '/^'$param_key'/s/\(.*\):=.*/\1:= '$param_value'/g' $param_file
60+
debug_info "Change '$file_value' -> '$param_value'"
5961
else
6062
debug_info "same key-value, skip"
6163
fi
@@ -70,33 +72,49 @@ function write_mk_file()
7072
# 3:value
7173
#@FUNC : 用'$param_key'='$param_value'表示替换结果,如果不存在则追加 >>
7274
#
73-
#RET : @1->更新 @0->无需更新 TODO
75+
#RET : @1->更新 @0->无需更新
7476
#############################################################################
7577
function write_txt_file()
7678
{
77-
debug_func "write_txt_file"
78-
debug_info $*
79-
if [ ! -f $1 ] || [ $# -ne 3 ];then
79+
debug_func "write_txt_file $*"
80+
81+
if [ $# -ne 3 ];then
8082
debug_error "param is wrong, exit(-1)"
8183
exit -1
8284
fi
85+
86+
local retflag=0
87+
88+
if [ ! -f $1 ]; then
89+
debug_warn "There is not a file->'$1', now creat it"
90+
touch $1
91+
retflag=1
92+
else
93+
format_local_file $1
94+
fi
95+
8396
local param_file=$1
8497
local param_key=$2
8598
local param_value=$3
8699

87-
format_local_file $param_file
88-
if grep -r ^$param_key $param_file 2>&1 1>/dev/null; then
89-
sed -i '/^'$param_key='/s/.*/'$param_key'='$param_value',/g' $param_file
100+
#如果找不到以$pkey_value开头的行则认为不存在正在写入的key-value, 追加到文本尾, 并更新升级标志
101+
pkey_value="$param_key="$param_value,""
102+
if ! grep -r ^"$pkey_value" "$param_file"; then
103+
echo "$pkey_value" >> $param_file
104+
retflag=1
105+
debug_warn "Just add <$param_key, $param_value>, Please ensure it is useful"
90106
else
91-
debug_warn "Just add key-value, maybe not useful, Please check where it used"
92-
add_prop="$param_key=$param_value,"
93-
echo $add_prop >> $param_file
107+
debug_info "same key-value, skip"
94108
fi
109+
110+
#sed -i '/^'$param_key='/s/.*/'$param_key'='$param_value',/g' $param_file
111+
112+
return $retflag
95113
}
96114

97115
#############################################################################
98116
#@PARAM: 1:path 文本以 # 作为注释, 以 空格 作为键和值的关系;
99-
# FIXME:支持key的value为单项或者两项如"POWER WAKE"
117+
# FIXME:仅仅支持key的value为单项或者两项如"POWER WAKE"
100118
# 2:key
101119
# 3:value
102120
#@FUNC : 用'key' '$param_key' '$value'表示替换结果,如果不存在则追加 >>
@@ -105,15 +123,17 @@ function write_txt_file()
105123
#############################################################################
106124
function write_kl_file()
107125
{
108-
debug_func "write_kl_file"
109-
debug_info $*
126+
debug_func "write_kl_file $*"
127+
110128
if [ $# -lt 3 ];then
111129
debug_error "param is wrong, exit(-1)"
112130
exit -1
113131
fi
114132

115133
local retflag=0
134+
116135
if [ ! -f $1 ]; then
136+
debug_warn "There is not a file->'$1', now creat it"
117137
touch $1
118138
retflag=1
119139
else
@@ -156,7 +176,7 @@ function write_kl_file()
156176
debug_info "change "key $key_num $key_value_1 $key_value_2" -->"key $key_num $param_value_1""
157177
retflag=1
158178
else
159-
debug_info "same code, skip 666"
179+
debug_info "same code, skip"
160180
fi
161181
elif [[ $# -eq 4 ]]; then
162182
param_value_1="$3"
@@ -203,9 +223,8 @@ function write_kl_file()
203223
#############################################################################
204224
function write_fex_file()
205225
{
206-
debug_func "write_fex_file"
226+
debug_func "write_fex_file $*"
207227

208-
debug_info $*
209228
if [ ! -f $1 ] || [ $# -ne 4 ];then
210229
debug_error "param is wrong, exit(-1)"
211230
exit -1

process_server.sh

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
# process_server.sh 事件处理方法
33
#
44

5-
#
5+
#############################################################################
66
#所有平台都有external_product.txt文件,文件内容特殊 5个字段有顺序,特殊处理
77
#inside_model=PRODUCT_MANUFACTURER=product_company=product_hotline=product_email
88
#
99
#@RET :@1->更新并正常写入文件 @0->已是最新版本无需更新
1010
#
1111
#XXX:此方法是在文档中明确说明各个字段为必填选项情况下成立, 而且txt中的顺序不变的情况。这是external_product.txt文件设计的缺陷
12-
#
12+
# 如果txt的字段增加或者顺序有变,将external_product数组修改即可
13+
#############################################################################
1314
function process_external_product()
1415
{
1516
debug_func "process_external_product"
@@ -19,13 +20,16 @@ function process_external_product()
1920
#根据内部机型属性从manifest获取对应的键值
2021
local key_index="inside_model"
2122
local key_tmp=$(awk -v var="$key_index" '($2==var){print $1}' $DEVICE_REGISTER_PATH)
22-
local inside_model_value=${manifestmap["$key_tmp"]}
23-
if [ -z "$inside_model_value" ]; then
23+
local key=${manifestmap["$key_tmp"]}
24+
if [ -z "$key" ]; then
2425
debug_error "not exsit 'inside_model'...please ask manifest"
2526
exit -1
2627
fi
2728

28-
local external_product_file=$(awk -v mindex="$key_index" '($2==mindex){print $3}' $DEVICE_REGISTER_PATH)
29+
local path=$(awk -v mindex="$key_index" '($2==mindex){print $3}' $DEVICE_REGISTER_PATH)
30+
if [[ -f "$path" ]]; then
31+
debug_warn "the file->$path is invalid"
32+
fi
2933

3034
#取第一个字段在manifest查询到的value做为key, 其余字段在manifest中的查询结果拼接后作为为value
3135
#两个for,一个是先找到manifest定义的字段,er个然后通过该字段找到对应的value,并使用 = 拼接成一个value
@@ -43,10 +47,10 @@ function process_external_product()
4347
for var in "${external_product_tmp[@]}"; do
4448
if [[ -n "$var" ]]; then
4549
if [[ $first -eq 1 ]]; then
46-
local use_var=${manifestmap["$var"]}
50+
local value=${manifestmap["$var"]}
4751
first=0
4852
else
49-
use_var="${use_var}=${manifestmap["$var"]}"
53+
value="${value}=${manifestmap["$var"]}"
5054
fi
5155
else
5256
debug_error "is null ?! kidding me ? This is a must write data, please ask manifest"
@@ -55,20 +59,23 @@ function process_external_product()
5559
done
5660

5761
local retep=0
58-
write_txt_file "$external_product_file" "$inside_model_value" "$use_var"
62+
write_txt_file "$path" "$key" "$value"
5963
retep=$?
60-
[ $retep -eq 1 ] && git add $path || git checkout $path 2>&1 1>/dev/null
64+
if [[ -f "$path" ]]; then
65+
[ $retep -eq 1 ] && git add $path || git checkout $path 2>&1 1>/dev/null
66+
fi
6167

6268
return $retep
6369
}
6470

65-
#
71+
#############################################################################
6672
#@PARAM: TODO
6773
#
74+
#############################################################################
6875
function process_keyboard_layout()
6976
{
70-
debug_func "process_keyboard_layout"
71-
debug_info $*
77+
debug_func "process_keyboard_layout $*"
78+
7279
if [ -z $1 ] || [ $# -ne 2 ];then
7380
debug_error "param is wrong, exit(-1)"
7481
exit -1
@@ -101,16 +108,16 @@ function process_keyboard_layout()
101108
return $retkl
102109
}
103110

104-
#
111+
#############################################################################
105112
#@RET :@1->更新并正常写入文件 @0->已是最新版本无需更新 @出错处理:直接exit -1退出当前shell进程
106113
#@FUNC :两点-> 1.检测本地原始配置是否需要更新,满足更新条件则写入文件;2.修改后的本地配置和manifest中的是否达成一致
107114
#
108115
#处理流程 TODO
109116
#
110-
#
111-
function call_process_server()
117+
#############################################################################
118+
function process_manifest_event()
112119
{
113-
debug_func "call_process_server >>>>>"
120+
debug_func "process_manifest_event >>>>>"
114121

115122
if [[ ! -f "$DEVICE_REGISTER_PATH" ]]; then
116123
debug_error "$DEVICE_REGISTER_PATH is not exsit, please run 'config_register_path' first, exit (-1)"
@@ -119,21 +126,21 @@ function call_process_server()
119126

120127

121128

122-
##################################################################################################################################################
129+
#************************************************************************************************************************************************#
123130
#要兼容一些特殊情况 :1.特殊属性的特殊处理 :如external_product.txt文件内容的格式定义的很独特,特殊处理
124131
# 2.不同平台下的特殊处理 :如红外遥控配置的kl文件的命名方式有不同,有些兼容android通用平台,有些平台厂商有自定义的命名处理规则
125132
# 3.等待以后遇到添加
126133
#
127134
#其它共性情况统一处理 :如mk文件的操作等是具有简单的key-value对应填写关系的
128135
#
129136
#另外注意返回值的判定 :bash 不支持位运算,仅支持逻辑运算; 此处使用0+0+0+0==0方式判定最后的累计结果
130-
##################################################################################################################################################
137+
#************************************************************************************************************************************************#
131138

132139

133140

134141
local retflag=0
135142

136-
##---external product----#
143+
##---1. external product----#
137144
process_external_product
138145
let retflag=retflag+$?
139146

@@ -154,7 +161,7 @@ function call_process_server()
154161
debug_warn "Not yet register this '$key' in 'DEVICE_REGISTER_PATH'"
155162
fi
156163

157-
##---keyboad layout---#
164+
##---2. keyboad layout---#
158165
if [[ "$prop" == "customer_code" ]]; then
159166
continue
160167
elif [[ "${key:0:2}" == "0x" ]]; then
@@ -165,7 +172,7 @@ function call_process_server()
165172
continue
166173
fi
167174

168-
##---如果还有例外事件,add the Exception Event Function here---#
175+
##---3. 如果还有例外事件 XXX,add the Exception Event Function Here, and add a black list Below---#
169176

170177

171178
#---black list---#
@@ -179,7 +186,7 @@ function call_process_server()
179186
continue
180187
fi
181188

182-
##---normal event---#
189+
##---n. normal event---#
183190
local path=$(echo "$pp" |awk '{print $2}')
184191
local value=${manifestmap["$key"]}
185192
debug_import "$key", "$prop, $path", "是[ ${path##*.} ]类型文件"
@@ -201,19 +208,18 @@ function call_process_server()
201208
if [[ -f "$path" ]]; then
202209
[ $retnormal -eq 1 ] && git add $path || git checkout $path
203210
else
204-
debug_warn "the '$key' de path->$path is not exsit"
211+
debug_warn "the '$key'\`s path->$path is not exsit"
205212
fi
206213

207214
let retflag=retflag+$retnormal
208215
done
209216

210-
debug_func "call_process_server <<<<<"
217+
debug_func "process_manifest_event <<<<<"
211218

212219
[ $retflag -eq 0 ] && return 0 || return 1
213220
}
214-
215221
#测试用例
216222
##!/bin/bash
217223
#. ./include.sh
218224
#. ./edit_util.sh
219-
#call_process_server
225+
#process_manifest_event

0 commit comments

Comments
 (0)
0