super-test 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGE.txt +9 -0
- data/README.txt +13 -0
- data/bin/idb +19 -0
- data/bin/ii +113 -0
- data/bin/istart_mock +36 -0
- data/bin/istop_mock +16 -0
- data/bin/kk +181 -0
- data/bin/rubyatp +42 -0
- data/bin/start_mock +36 -0
- data/bin/stop_mock +16 -0
- data/bin/xgo +45 -0
- data/conf/conf.rb +11 -0
- data/conf/db03.yml +31 -0
- data/conf/db13.yml +37 -0
- data/conf/db19.yml +33 -0
- data/conf/online.yml +32 -0
- data/conf/super_test.yml +40 -0
- data/conf/system.yml +26 -0
- data/conf/sz00.yml +31 -0
- data/conf/sz06.yml +34 -0
- data/conf/wise00.yml +11 -0
- data/data/case.house +0 -0
- data/data/char.house +0 -0
- data/data/images/Bluehills.jpg +0 -0
- data/data/images/Sunset.jpg +0 -0
- data/data/images/Waterlilies.jpg +0 -0
- data/data/images/Winter.jpg +0 -0
- data/data/query.house +18595 -0
- data/data/user.house +8 -0
- data/lib/action/module/check_action.rb +58 -0
- data/lib/action/module/cnnt_action.rb +161 -0
- data/lib/action/module/datacenter_action.rb +48 -0
- data/lib/action/module/http_pack_helper.rb +163 -0
- data/lib/action/module/httpserver_action.rb +297 -0
- data/lib/action/module/inc.rb +21 -0
- data/lib/action/module/mcpack_action.rb +57 -0
- data/lib/action/module/sql_action.rb +84 -0
- data/lib/action/module/ssh_action.rb +37 -0
- data/lib/action/system/user_action.rb +180 -0
- data/lib/common/appium_helper.rb +217 -0
- data/lib/common/atp_helper.rb +74 -0
- data/lib/common/atp_report.rb +344 -0
- data/lib/common/data_house.rb +405 -0
- data/lib/common/data_model.rb +87 -0
- data/lib/common/http/assert_helper.rb +343 -0
- data/lib/common/http/fix_hpricot.rb +118 -0
- data/lib/common/http/html_helper.rb +362 -0
- data/lib/common/http/http_helper.rb +469 -0
- data/lib/common/http/multipart.rb +81 -0
- data/lib/common/isandbox_helper.rb +195 -0
- data/lib/common/json_helper.rb +43 -0
- data/lib/common/mock_helper.rb +168 -0
- data/lib/common/mtop_helper.rb +141 -0
- data/lib/common/myconf_helper.rb +49 -0
- data/lib/common/mylog_helper.rb +77 -0
- data/lib/common/pairwise.rb +121 -0
- data/lib/common/query_house.rb +89 -0
- data/lib/common/report_helper.rb +97 -0
- data/lib/common/robot_helper.rb +85 -0
- data/lib/common/socket/check.rb +325 -0
- data/lib/common/socket/conf_modifier.rb +149 -0
- data/lib/common/socket/context.rb +55 -0
- data/lib/common/socket/data.rb +392 -0
- data/lib/common/socket/data_helper.rb +41 -0
- data/lib/common/socket/env.rb +317 -0
- data/lib/common/socket/inc.rb +24 -0
- data/lib/common/socket/log.rb +213 -0
- data/lib/common/socket/log4s.rb +58 -0
- data/lib/common/socket/log_helper.rb +332 -0
- data/lib/common/socket/my_sql.rb +77 -0
- data/lib/common/socket/net.rb +74 -0
- data/lib/common/socket/network.rb +115 -0
- data/lib/common/socket/rlib/conf_modifier.rb +130 -0
- data/lib/common/socket/rlib/data_helper.rb +33 -0
- data/lib/common/socket/rlib/log_helper.rb +303 -0
- data/lib/common/socket/rlib/process_helper.rb +91 -0
- data/lib/common/socket/stub.rb +276 -0
- data/lib/common/socket/util.rb +266 -0
- data/lib/patterns/inc.rb +10 -0
- data/lib/patterns/mc_base_pattern.rb +474 -0
- data/lib/patterns/some_pattern.rb +145 -0
- data/lib/super_test.rb +114 -0
- data/log/super_test.log +0 -0
- data/log/super_test.log.wf +0 -0
- data/test/cover_me.rb +6 -0
- data/tool/jenny +0 -0
- data/tool/mcsend/mcsend2 +0 -0
- data/tool/mcsend/mcsend2_shead +0 -0
- data/tool/mcserver/conf/mcserver.conf +77 -0
- data/tool/mcserver/conf/mcserverauthip +17 -0
- data/tool/mcserver/mcserver +0 -0
- data/tool/mcserver/mcserver_trans +0 -0
- data/tool/mysql +0 -0
- data/tool/net/mcsend/mcsend +0 -0
- data/tool/net/mcsend/mcsend_trans +0 -0
- data/tool/net/mcsend/nshead.data +7 -0
- data/tool/net/mcsend/res_nshead.data +7 -0
- data/tool/net/my_client/my_client +0 -0
- data/tool/net/tsclient/client.tcl +205 -0
- data/tool/others/kk +190 -0
- data/tool/others/rubyatp +42 -0
- data/tool/others/supertest_install.sh +34 -0
- data/tool/trip/idb +0 -0
- data/tool/ts-agent/nshead.bft +12 -0
- data/tool/ts-agent/server.conf +10 -0
- data/tool/ts-agent/server.tcl +376 -0
- metadata +275 -0
@@ -0,0 +1,149 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
#============================================================
|
5
|
+
# This class supply conf modification related service
|
6
|
+
# e.g. modify single/batch conf items
|
7
|
+
# Author:: chenjie
|
8
|
+
# Data:: 2009-4-30
|
9
|
+
#============================================================
|
10
|
+
class ConfModifier
|
11
|
+
@lines = 0
|
12
|
+
|
13
|
+
def initialize(confPath)
|
14
|
+
@confPath = confPath
|
15
|
+
#lineNum : key
|
16
|
+
@dic= Hash.new
|
17
|
+
#key : value
|
18
|
+
@conf = Hash.new
|
19
|
+
|
20
|
+
file = File.open(@confPath)
|
21
|
+
cnt = 0
|
22
|
+
|
23
|
+
file.each{ |line|
|
24
|
+
#print line
|
25
|
+
cnt+=1
|
26
|
+
|
27
|
+
if line.strip[0, 1] == '#' or line.strip.length == 0
|
28
|
+
@dic[ cnt ] = line.strip
|
29
|
+
else
|
30
|
+
list = line.strip.split(":")
|
31
|
+
key = list[0].strip
|
32
|
+
if list[1] != nil then
|
33
|
+
list.delete_at(0)
|
34
|
+
value = list.join(":").strip
|
35
|
+
else
|
36
|
+
#只有key没有value的情况
|
37
|
+
value = ''
|
38
|
+
end
|
39
|
+
|
40
|
+
@dic[ cnt ] = key
|
41
|
+
@conf[key] = value
|
42
|
+
end
|
43
|
+
}
|
44
|
+
|
45
|
+
@lines = cnt
|
46
|
+
|
47
|
+
file.close
|
48
|
+
end
|
49
|
+
|
50
|
+
# === 功能:
|
51
|
+
# 修改单个配置项
|
52
|
+
# === Example:
|
53
|
+
# cm = ConfModifier.new conf_path
|
54
|
+
# cm.modify("timeout", "100")
|
55
|
+
def modify(key, newValue)
|
56
|
+
if @conf.has_key?(key)
|
57
|
+
puts "modify from [" + key + "=>" + @conf[key] + "] to [" + key + "=>" + newValue + " ]"
|
58
|
+
@conf[key] = newValue
|
59
|
+
else
|
60
|
+
puts "add new conf " + key + "=>" + newValue
|
61
|
+
@lines += 1
|
62
|
+
@dic[@lines] = key
|
63
|
+
@conf[key] = newValue
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# === 功能:
|
68
|
+
# 批量修改配置项
|
69
|
+
# === Example:
|
70
|
+
# hh ={"name"=>"friend", "timeout"=>"100"}
|
71
|
+
# cm = ConfModifier.new conf_path
|
72
|
+
# cm.modifyall(hh)
|
73
|
+
def modifyall(hash)
|
74
|
+
if hash != nil then
|
75
|
+
hash.each{|key,value|
|
76
|
+
modify(key, value)
|
77
|
+
}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# === 功能:
|
82
|
+
# 按顺序回写配置文件
|
83
|
+
# === Example:
|
84
|
+
# hh ={"name"=>"friend", "timeout"=>"100"}
|
85
|
+
# cm = ConfModifier.new conf_path
|
86
|
+
# cm.modifyall(hh)
|
87
|
+
# cm.writeconf
|
88
|
+
def writeconf
|
89
|
+
file = File.open(@confPath, 'w')
|
90
|
+
@dic.sort_by { |key, value| key }
|
91
|
+
@dic.each_key { |ki|
|
92
|
+
if @dic[ki].strip.length != 0
|
93
|
+
#key, value
|
94
|
+
if @conf.has_key?(@dic[ki])
|
95
|
+
file.print(@dic[ki] , " : ",@conf[@dic[ki]] , "\n")
|
96
|
+
else
|
97
|
+
file.print( @dic[ki] , "\n")
|
98
|
+
end
|
99
|
+
else
|
100
|
+
file.print( "\n")
|
101
|
+
end
|
102
|
+
}
|
103
|
+
|
104
|
+
file.close
|
105
|
+
end
|
106
|
+
|
107
|
+
# === 功能:
|
108
|
+
# 获取某个配置项的值
|
109
|
+
# === Example:
|
110
|
+
# cm = ConfModifier.new conf_path
|
111
|
+
# m_name = cm.get_conf("name")
|
112
|
+
def get_conf(key)
|
113
|
+
return @conf[key]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
if ARGV.length > 0 then
|
118
|
+
case ARGV[0]
|
119
|
+
when "modify_conf_single"
|
120
|
+
conf_path = ARGV[1]
|
121
|
+
key = ARGV[2]
|
122
|
+
new_value = ARGV[3]
|
123
|
+
cm = ConfModifier.new(conf_path)
|
124
|
+
cm.modify(key, new_value)
|
125
|
+
cm.writeconf
|
126
|
+
when "get_conf"
|
127
|
+
conf_path = ARGV[1]
|
128
|
+
key = ARGV[2]
|
129
|
+
cm = ConfModifier.new(conf_path)
|
130
|
+
puts cm.get_conf(key)
|
131
|
+
# else
|
132
|
+
# puts "ConfModifer: bad method name? #{ARGV[0]}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
=begin
|
138
|
+
if __FILE__ == $0
|
139
|
+
require "#{File.dirname(__FILE__)}/../../lib/base_case"
|
140
|
+
class MyTest < BaseCase
|
141
|
+
def no_test
|
142
|
+
conf_path = "#{File.dirname(__FILE__)}/../../test/env/dataminer.conf"
|
143
|
+
cm = ConfModifier.new conf_path
|
144
|
+
cm.modify('index_mode', '1')
|
145
|
+
cm.writeconf
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
=end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '.')
|
4
|
+
#require 'log4s'
|
5
|
+
|
6
|
+
#============================================================
|
7
|
+
# 这个类提供上下文相关服务
|
8
|
+
# 以减少case中的赋值语句和参数传递
|
9
|
+
# Author:: chenjie
|
10
|
+
# Data:: 2009-4-30
|
11
|
+
#============================================================
|
12
|
+
class Context
|
13
|
+
$globals = Hash.new
|
14
|
+
|
15
|
+
#keys: :MODULE_NAME, :CASE_NAME,:RES_HEAD, :RECV, :SEND, :DATABASE, :DB_HOST, :DBH
|
16
|
+
|
17
|
+
#stub related
|
18
|
+
#keys: :STUBS, :STUB_PORTS, :STUB_ACTIONS, :STUB_HEADS, :STUB_FILES
|
19
|
+
|
20
|
+
# === 功能:
|
21
|
+
# 清空上下文
|
22
|
+
# === Example:
|
23
|
+
# Context.clear
|
24
|
+
def Context.clear
|
25
|
+
$log.notice "Clear context"
|
26
|
+
$globlas.clear
|
27
|
+
end
|
28
|
+
|
29
|
+
# === 功能:
|
30
|
+
# 设置上下文
|
31
|
+
# === Example:
|
32
|
+
# Context.set("name", "100")
|
33
|
+
def Context.set(key, value)
|
34
|
+
$log.debug "Context setting key[#{key}] value[#{value}]"
|
35
|
+
$globals[key] = value
|
36
|
+
end
|
37
|
+
|
38
|
+
# === 功能:
|
39
|
+
# 获取上下文
|
40
|
+
# === Example:
|
41
|
+
# Context.get("name")
|
42
|
+
def Context.get(key)
|
43
|
+
$log.debug "Context getting key[#{key}], value [#{$globals[key]}]"
|
44
|
+
return $globals[key]
|
45
|
+
end
|
46
|
+
|
47
|
+
# === 功能:
|
48
|
+
# 删除上下文
|
49
|
+
# === Example:
|
50
|
+
# Context.delete("name")
|
51
|
+
def Context.delete key
|
52
|
+
$log.debug "Context deleting key[#{key}]"
|
53
|
+
$globals.delete key
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,392 @@
|
|
1
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), './rlib/')
|
2
|
+
#!/usr/bin/env ruby
|
3
|
+
# coding: utf-8
|
4
|
+
|
5
|
+
require 'data_helper'
|
6
|
+
|
7
|
+
#============================================================
|
8
|
+
# 这个类是数据相关服务的顶层接口,提供本机/远程数据相关服务
|
9
|
+
# e.g. compare file contents, get file match pattern's times...
|
10
|
+
# Author:: chenjie
|
11
|
+
# Date:: 2009-4-30
|
12
|
+
#============================================================
|
13
|
+
module DATA
|
14
|
+
# === 功能:
|
15
|
+
# 模块测试的时候的helper文件的load策略
|
16
|
+
#
|
17
|
+
# === 参数解释:
|
18
|
+
# - filepath: 运行的case文件的路径,从__FILE__获取
|
19
|
+
#
|
20
|
+
# === Example:
|
21
|
+
# 内部使用
|
22
|
+
#
|
23
|
+
def _init_file_(filepath)
|
24
|
+
=begin 以下的内容取消,由init_dir.rb实现
|
25
|
+
module_dir = `dirname #{filepath}`
|
26
|
+
module_base = "module"
|
27
|
+
module_helper_name = module_dir.chop!+"/"+module_base+"_helper.rb"
|
28
|
+
filepath.gsub(/.rb/, "")
|
29
|
+
case_helper_name = filepath+"_helper.rb"
|
30
|
+
if(File.exist?(module_helper_name))
|
31
|
+
require "#{module_helper_name}"
|
32
|
+
end
|
33
|
+
if(File.exist?(case_helper_name))
|
34
|
+
require "#{case_helper_name}"
|
35
|
+
end
|
36
|
+
=end
|
37
|
+
case_pwd = `pwd`
|
38
|
+
case_pwd_case = `basename #{case_pwd}`
|
39
|
+
case_pwd.gsub!(/#{case_pwd_case}/, "")
|
40
|
+
case_pwd_module = `basename #{case_pwd}`
|
41
|
+
Context.set(:MODULE_NAME, case_pwd_module.chop!)
|
42
|
+
Context.set(:CASE_NAME, case_pwd_case.chop!)
|
43
|
+
end
|
44
|
+
|
45
|
+
# ===功能
|
46
|
+
# get all data prefix(packno)
|
47
|
+
# === 参数
|
48
|
+
# - data_path
|
49
|
+
# return packno array
|
50
|
+
# ===example
|
51
|
+
# datas = get_all_pack data_path
|
52
|
+
def get_all_pack(data_path, suffix=".send")
|
53
|
+
#param check
|
54
|
+
if !File.directory?(data_path) || !File.exist?(data_path) then
|
55
|
+
$log.error "bad data_path=" + data_path
|
56
|
+
return
|
57
|
+
end
|
58
|
+
|
59
|
+
datas = Array.new
|
60
|
+
Dir.foreach(data_path) do |entry|
|
61
|
+
if entry.match("#{suffix}$") then
|
62
|
+
packno = entry[0, entry.size-suffix.length]
|
63
|
+
datas.push(packno)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
return datas.sort
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
# ===功能
|
72
|
+
# compare two files contents
|
73
|
+
# ===参数
|
74
|
+
# - p1 filename 1
|
75
|
+
# - p2 filename 2
|
76
|
+
#
|
77
|
+
# === Logic
|
78
|
+
#
|
79
|
+
# 1. if p1 exists and p2 not exists, return false
|
80
|
+
# 2. if both not exist, return true
|
81
|
+
# 3. same file ,return true
|
82
|
+
# 4. type or size different, return false
|
83
|
+
# 5. then compare content
|
84
|
+
# === example
|
85
|
+
# same_file_contents file1, file2
|
86
|
+
def same_file_contents(p1, p2)
|
87
|
+
return false if File.exists?(p1) != File.exists?(p2)
|
88
|
+
return true if !File.exists?(p1)
|
89
|
+
return true if File.expand_path(p1) == File.expand_path(p2)
|
90
|
+
return false if File.ftype(p1) != File.ftype(p2) || File.size(p1) != File.size(p2)
|
91
|
+
|
92
|
+
#compare content
|
93
|
+
open(p1) do |f1|
|
94
|
+
open(p2) do |f2|
|
95
|
+
blocksize = f1.lstat.blksize
|
96
|
+
same = true
|
97
|
+
while same && !f1.eof && !f2.eof?
|
98
|
+
same = f1.read(blocksize) == f2.read(blocksize)
|
99
|
+
end
|
100
|
+
return same
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
# === 功能:
|
107
|
+
#仅对比content字段的内容
|
108
|
+
# === Example:
|
109
|
+
# same_content_value(file1, file2)
|
110
|
+
def same_content_value(p1, p2)
|
111
|
+
return false if File.exists?(p1) != File.exists?(p2)
|
112
|
+
return true if !File.exists?(p1)
|
113
|
+
return true if File.expand_path(p1) == File.expand_path(p2)
|
114
|
+
return false if File.ftype(p1) != File.ftype(p2) || File.size(p1) != File.size(p2)
|
115
|
+
|
116
|
+
str1 = ""
|
117
|
+
open(p1, 'r:gbk').each{|line|
|
118
|
+
str1 += line.strip.chomp
|
119
|
+
}
|
120
|
+
str2 = ""
|
121
|
+
open(p2, 'r:gbk').each{|line|
|
122
|
+
str2 += line.strip.chomp
|
123
|
+
}
|
124
|
+
|
125
|
+
pattern = /"content":(.*)}/
|
126
|
+
content1 = str1.scan pattern
|
127
|
+
content2 = str2.scan pattern
|
128
|
+
|
129
|
+
return content1 == content2
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
# === 功能:
|
134
|
+
# compare two files' content by string
|
135
|
+
# ignore invisible characters by strip, chomp
|
136
|
+
# === Example:
|
137
|
+
# same_file_str(file1, file2)
|
138
|
+
def same_file_str p1, p2
|
139
|
+
return false if File.exists?(p1) != File.exists?(p2)
|
140
|
+
return true if !File.exists?(p1)
|
141
|
+
return true if File.expand_path(p1) == File.expand_path(p2)
|
142
|
+
return false if File.ftype(p1) != File.ftype(p2)
|
143
|
+
|
144
|
+
str1 = ""
|
145
|
+
open(p1, 'r:gbk').each{|line|
|
146
|
+
str1 += line.strip.chomp
|
147
|
+
}
|
148
|
+
str2 = ""
|
149
|
+
open(p2, 'r:gbk').each{|line|
|
150
|
+
str2 += line.strip.chomp
|
151
|
+
}
|
152
|
+
|
153
|
+
return str1 == str2
|
154
|
+
end
|
155
|
+
|
156
|
+
# === 功能:
|
157
|
+
# compare two files' content by string, check if p1's content is included by p2's content
|
158
|
+
# ignore invisible characters by strip, chomp
|
159
|
+
# === Example:
|
160
|
+
# include_file_str(file1, file2)
|
161
|
+
def include_file_str p1, p2
|
162
|
+
return false if File.exists?(p1) != File.exists?(p2)
|
163
|
+
return true if !File.exists?(p1)
|
164
|
+
return true if File.expand_path(p1) == File.expand_path(p2)
|
165
|
+
return false if File.ftype(p1) != File.ftype(p2)
|
166
|
+
|
167
|
+
str1 = ""
|
168
|
+
open(p1, 'r:gbk').each{|line|
|
169
|
+
str1 += line.strip.chomp
|
170
|
+
}
|
171
|
+
str2 = ""
|
172
|
+
open(p2, 'r:gbk').each{|line|
|
173
|
+
str2 += line.strip.chomp
|
174
|
+
}
|
175
|
+
|
176
|
+
minclude = str2.scan(str1)
|
177
|
+
if minclude.size > 0 then
|
178
|
+
return true
|
179
|
+
end
|
180
|
+
return false
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
# ===功能
|
185
|
+
# compare two files md5
|
186
|
+
# ===参数
|
187
|
+
# - p1 filename 1
|
188
|
+
# - p2 filename 2
|
189
|
+
#
|
190
|
+
# === Logic
|
191
|
+
# 1. if p1 exists and p2 not exists, return false
|
192
|
+
# 2. if both not exist, return true
|
193
|
+
# 3. same file ,return true
|
194
|
+
# 4. type or size different, return false
|
195
|
+
# 5. then compare md5
|
196
|
+
# ===example
|
197
|
+
# same_file_md5 file1, file2
|
198
|
+
def same_file_md5(p1, p2)
|
199
|
+
return false if File.exists?(p1) != File.exists?(p2)
|
200
|
+
return true if !File.exists?(p1)
|
201
|
+
return true if File.expand_path(p1) == File.expand_path(p2)
|
202
|
+
puts p1
|
203
|
+
puts p2
|
204
|
+
puts File.ftype(p1)
|
205
|
+
puts File.ftype(p2)
|
206
|
+
puts File.size(p1)
|
207
|
+
puts File.size(p2)
|
208
|
+
return false if File.ftype(p1) != File.ftype(p2) || File.size(p1) != File.size(p2)
|
209
|
+
|
210
|
+
#compare md5
|
211
|
+
md5 = `md5sum #{p1}`.split(" ")[0]
|
212
|
+
md6 = `md5sum #{p2}`.split(" ")[0]
|
213
|
+
puts md5
|
214
|
+
puts md6
|
215
|
+
|
216
|
+
if md5 == md6 then
|
217
|
+
return true
|
218
|
+
else
|
219
|
+
return false
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
|
224
|
+
# ===功能
|
225
|
+
# whether the file content match the specified pattern
|
226
|
+
# ===参数
|
227
|
+
# - filename, pattern
|
228
|
+
# return: true if the file content match the pattern, false if not
|
229
|
+
# ===example
|
230
|
+
# file_match? file1, "time"
|
231
|
+
def file_match?(filename, pattern)
|
232
|
+
return false if !File.exists?(filename)
|
233
|
+
open(filename, 'r:gbk').each{|line|
|
234
|
+
mdata = line.scan(pattern)
|
235
|
+
if mdata.size > 0 then
|
236
|
+
return true
|
237
|
+
end
|
238
|
+
}
|
239
|
+
|
240
|
+
return false
|
241
|
+
end
|
242
|
+
|
243
|
+
# ===功能
|
244
|
+
# 文件内容match正则串的次数
|
245
|
+
# return: int, the match times
|
246
|
+
# ===exmaple
|
247
|
+
# times = file_match_times file1, "time"
|
248
|
+
def file_match_times(filename, pattern)
|
249
|
+
return 0 if !File.exists?(filename)
|
250
|
+
|
251
|
+
times = 0
|
252
|
+
open(filename, 'r:gbk').each{|line|
|
253
|
+
mdata = line.scan(pattern)
|
254
|
+
if mdata.size > 0 then
|
255
|
+
times += mdata.size
|
256
|
+
end
|
257
|
+
}
|
258
|
+
|
259
|
+
return times
|
260
|
+
end
|
261
|
+
|
262
|
+
# ===功能
|
263
|
+
# 根据给定的mcpack key值获取value
|
264
|
+
# ===参数
|
265
|
+
# - filename: 文件名
|
266
|
+
# - key: mcpack key
|
267
|
+
# - index: 匹配的key的index
|
268
|
+
# Return the value according to the key, nil if nothing found
|
269
|
+
# ===example
|
270
|
+
# value = get_mcpack_value file1, "name"
|
271
|
+
def get_mcpack_value filename, key, index=1
|
272
|
+
return nil if !File.exists? filename
|
273
|
+
|
274
|
+
#build the mcpack string
|
275
|
+
mcstr = ""
|
276
|
+
open(filename, 'r:gbk').each{|line|
|
277
|
+
mcstr += line.strip.chomp
|
278
|
+
}
|
279
|
+
|
280
|
+
#pattern = /("#{key}":[^,\}]*)/
|
281
|
+
pattern = [/"#{key}":([^{][^,\}]*)/, /#{key}:([^{][^,\}]*)/]
|
282
|
+
#pattern = /#{key}:([^,\}]*)| "#{key}":([^,\}]*)|#{key}:({[^,]*})|"#{key}":({[^,]*})/
|
283
|
+
#mdata = mcstr.scan pattern
|
284
|
+
mdata = Array.new
|
285
|
+
pattern.each{|line|
|
286
|
+
mdata+=mcstr.scan line
|
287
|
+
}
|
288
|
+
|
289
|
+
if index > mdata.size
|
290
|
+
return nil
|
291
|
+
else
|
292
|
+
return mdata[index-1][0]
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
=begin
|
297
|
+
# get the data value from the staf returned string like below:
|
298
|
+
# - staf_str
|
299
|
+
# {
|
300
|
+
# Return Code: 0
|
301
|
+
# Key : <None>
|
302
|
+
# Files : [
|
303
|
+
# {
|
304
|
+
# Return Code: 0
|
305
|
+
# Data : 10555005
|
306
|
+
# }
|
307
|
+
# ]
|
308
|
+
# }
|
309
|
+
#
|
310
|
+
# return the data value 10555005
|
311
|
+
def get_staf_data(staf_str)
|
312
|
+
staf_str.split("\n").each{|line|
|
313
|
+
mdata = line.strip.scan(/^Data.*:(.*)/)
|
314
|
+
if mdata.size > 0 then
|
315
|
+
return mdata[0][0].to_s.strip
|
316
|
+
end
|
317
|
+
}
|
318
|
+
end
|
319
|
+
=end
|
320
|
+
|
321
|
+
#=========================
|
322
|
+
#local/remote
|
323
|
+
#=========================
|
324
|
+
|
325
|
+
# ===功能
|
326
|
+
# 指定机器、文件路径的文件是否存在
|
327
|
+
# Return true if the named file exists.
|
328
|
+
# ===example
|
329
|
+
# file_exist? host, path
|
330
|
+
def file_exist? host, file_path, user=USERNAME, password=PASSWORD
|
331
|
+
if Util.is_localhost? host then
|
332
|
+
return DataHelper.file_exist? file_path
|
333
|
+
else
|
334
|
+
#lib_path = Util.get_lib_path host
|
335
|
+
#res = Util.exe_ssh_cmd! host, "cd #{lib_path} && ruby data_helper.rb file_exist? #{file_path}"
|
336
|
+
#return res.strip.chomp
|
337
|
+
res = Util.exe_ssh_cmd! host, "if [ -f #{file_path} ];then echo true; else echo false; fi", user, password
|
338
|
+
return res.strip.chomp
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
# ===功能
|
343
|
+
# 获取文件大小
|
344
|
+
# Returns nil if file_name doesn’t exist or has zero size, the size of the file otherwise.
|
345
|
+
# ===example
|
346
|
+
# file_size? host, filepath
|
347
|
+
def file_size? host, file_path, user=USERNAME, password=PASSWORD
|
348
|
+
if Util.is_localhost? host then
|
349
|
+
return DataHelper.file_size? file_path
|
350
|
+
else
|
351
|
+
#lib_path = Util.get_lib_path host
|
352
|
+
#res = Util.exe_ssh_cmd! host, "cd #{lib_path} && ruby data_helper.rb file_size? #{file_path}"
|
353
|
+
#return res.strip.chomp.to_i
|
354
|
+
res = Util.exe_ssh_cmd! host, "ls -l #{file_path} |awk -F\" \" '{print $5}'", user, password
|
355
|
+
return res.strip.chomp.to_i
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
|
361
|
+
if __FILE__ == $0
|
362
|
+
require 'test/unit'
|
363
|
+
require "#{File.dirname(__FILE__)}/../conf/conf"
|
364
|
+
|
365
|
+
class MyTest < Test::Unit::TestCase
|
366
|
+
include DATA
|
367
|
+
def no_test_get_mcpack_value
|
368
|
+
puts get_mcpack_value "#{TEST_ROOT}data/mcpack.data", 'pow'
|
369
|
+
puts get_mcpack_value "#{TEST_ROOT}data/mcpack.data", 'limitid'
|
370
|
+
puts get_mcpack_value "#{TEST_ROOT}data/mcpack.data", 'title'
|
371
|
+
puts get_mcpack_value "#{TEST_ROOT}data/mcpack.data", 'link'
|
372
|
+
puts get_mcpack_value "#{TEST_ROOT}data/mcpack.data", 'pow', 2
|
373
|
+
value = get_mcpack_value "#{TEST_ROOT}data/mcpack.data", 'pow', 1
|
374
|
+
puts value
|
375
|
+
puts get_mcpack_value "#{TEST_ROOT}data/mcpack.data", 'pow', 3
|
376
|
+
|
377
|
+
end
|
378
|
+
def no_test_same_file_contents
|
379
|
+
puts "111"
|
380
|
+
puts same_file_contents '/home/space/tools/app-test/search/space/module-test/case/implementor/case3/data/1.expc', '/home/space/tools/app-test/search/space/module-test/case/implementor/case3/tmp/1.recv'
|
381
|
+
end
|
382
|
+
def no_test_same_file_md5
|
383
|
+
puts "test_same_file_md5"
|
384
|
+
puts (same_file_md5 '/home/space/tools/app-test/search/space/module-test/case/implementor/case3/data/1.expc', '/home/space/tools/app-test/search/space/module-test/case/implementor/case3/tmp/1.recv')
|
385
|
+
end
|
386
|
+
def test_same_file_str
|
387
|
+
puts "test_same_file_str"
|
388
|
+
puts (same_file_str '/home/space/tools/app-test/search/space/module-test/case/implementor/case13/data/5.expc', '/home/space/tools/app-test/search/space/module-test/case/implementor/case13/tmp/5.recv')
|
389
|
+
end
|
390
|
+
|
391
|
+
end
|
392
|
+
end
|