pcapr 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -77,11 +77,10 @@ class Pcapr
77
77
  base_dir = dir
78
78
  login
79
79
  protos.each do |proto|
80
- proto_dir = File.join(base_dir, proto.tr("\\/:*?\"<>|"," "))
81
- FileUtils.mkdir_p(proto_dir) unless File.directory?(proto_dir)
80
+ proto_dir = proto2dir_and_create(base_dir, proto)
82
81
  logger.info "proto: #{proto}, downloading...(pcap save as: #{proto_dir}"
83
82
  pcap_urls(proto).each do |pcap_url|
84
- file = File.join( proto_dir, File.basename(pcap_url).gsub(/\.html$/,"").tr("\\/:*?\"<>|"," ") )
83
+ file = pcap2file(proto_dir, pcap_url)
85
84
  logger.info " pcap file: #{pcap_url} save at '#{file}'"
86
85
  begin
87
86
  pcap_file(pcap_url, file)
@@ -109,6 +108,14 @@ class Pcapr
109
108
  end
110
109
  end
111
110
 
111
+ def proto2dir_and_create(base_dir, proto)
112
+ #must use strip to cut because mkdir_p ignore the space at last
113
+ proto_dir = File.join(base_dir, proto.tr("\\/:*?\"<>|"," ")).strip
114
+ FileUtils.mkdir_p(proto_dir) unless File.directory?(proto_dir)
115
+ proto_dir
116
+ end
112
117
 
113
-
118
+ def pcap2file(proto_dir, pcap_url)
119
+ File.join( proto_dir, File.basename(pcap_url).gsub(/\.html$/,"").tr("\\/:*?\"<>|"," ") )
120
+ end
114
121
  end
@@ -1,3 +1,3 @@
1
1
  class Pcapr
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -57,15 +57,15 @@ describe Pcapr do
57
57
  @o.pcap_urls("dns").should be_include("/view/siim/2011/11/3/7/capture.pcap.html")
58
58
  end
59
59
 
60
- #~ it "should have pcap files more than 3000(excute slow)" do
61
- #~ @o.login
62
- #~ files = []
63
- #~ @o.protos.each_with_index do |proto,i|
64
- #~ @o.logger.info("proto: #{proto}, index=#{i}")
65
- #~ files += @o.pcap_urls(proto)
66
- #~ end
67
- #~ files.should >= 3085
68
- #~ end
60
+ it "should mkdir success when convert pcap url to dir name" do
61
+ ["gtp <ftp>", "gtp <ftp-data>", "gtp", "gtp icmp", "tacacs+", "wtp+wsp"].each do |proto|
62
+ dir = @o.send(:proto2dir_and_create, $helper_dir, proto)
63
+ File.should be_directory(dir)
64
+ file = @o.send(:pcap2file, dir, "http://www.pcapr.net/view/nos/2011/3/1/13/QoS_DL_40kbps.pcap.html")
65
+ lambda { File.open(file,"w"){} }.should_not raise_error
66
+ FileUtils.rm_rf(dir)
67
+ end
68
+ end
69
69
 
70
70
  it "file get it but timeout" do
71
71
  begin
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 6
9
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - yafei LI
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-03-14 00:00:00 +08:00
17
+ date: 2012-03-15 00:00:00 +08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency