rtfs 0.0.4 → 0.1.0

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.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg/*
2
+ .DS_Store
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.1.0 / 2012-04-25
2
+
3
+ * ����webservice��ʽ
4
+ * Client.new��ʽ�ij�Client.tfs
5
+
1
6
  === 0.0.1 / 2011-08-02
2
7
 
3
8
  * Birthday!
data/README.markdown CHANGED
@@ -20,6 +20,7 @@ config/tfs.yml
20
20
 
21
21
  defaults: &defaults
22
22
  host: '127.0.0.1:3100'
23
+ appkey: "......."
23
24
 
24
25
  development:
25
26
  <<: *defaults
@@ -34,7 +35,9 @@ config/initialize/tfs.rb
34
35
 
35
36
  require 'rtfs'
36
37
  tfs_config = YAML.load_file("#{Rails.root}/config/tfs.yml")[Rails.env]
37
- $tfs = RTFS::Client.new(:ns_addr => tfs_config['host'])
38
+ $tfs = RTFS::Client.tfs(tfs_config.merge({:ns_addr => tfs_config['host']}))
39
+
40
+ :ns_addr include http:// tfs used webservice
38
41
 
39
42
  Configure without TFS install
40
43
  -----------------------------
@@ -93,7 +96,7 @@ config/initialize/tfs.rb
93
96
  $tfs = FakeTfs::Client.new(:ns_addr => tfs_config['host'])
94
97
  else
95
98
  require 'rtfs'
96
- $tfs = RTFS::Client.new(:ns_addr => tfs_config['host'])
99
+ $tfs = RTFS::Client.tfs(tfs_config.merge({:ns_addr => tfs_config['host']}))
97
100
  end
98
101
 
99
102
 
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ $:.unshift('lib')
2
+
3
+ require 'rubygems'
4
+ gem('rspec')
5
+
6
+ ROOT_DIR = File.join(File.dirname(__FILE__))
7
+
8
+ require 'rake'
9
+ require 'rtfs'
10
+
11
+ import('tasks/pkg.rake')
@@ -0,0 +1,18 @@
1
+ # Generated: <%= Time.now.utc.to_s %>
2
+ Gem::Specification.new do |s|
3
+ s.name = "<%= spec['name'] %>"
4
+ s.version = "<%= spec['version'] %>"
5
+ s.platform = Gem::Platform::RUBY
6
+ s.has_rdoc = true
7
+ s.extra_rdoc_files = [<% spec['extra_rdoc_files'].each do |f| %>"<%= f %>",<% end %>]
8
+ s.summary = "<%= spec['summary'] %>"
9
+ s.author = "<%= spec['author'] %>"
10
+ s.email = "<%= spec['email'] %>"
11
+ s.homepage = "<%= spec['homepage'] %>"
12
+ s.rubyforge_project = "<%= spec['rubyforge_project'] %>"
13
+ <% spec['add_dependency'].each do |gem, version| %>s.add_dependency("<%= gem %>", "<%= version %>")<% end %>
14
+ # s.require_path = "<%= spec['require_path'] %>"
15
+ s.files = [<% spec['files'].each {|f| %>"<%= f %>",<% } %>]
16
+ s.bindir = 'bin'
17
+ s.executables = ['top4rsh']
18
+ end
data/lib/rtfs.rb CHANGED
@@ -16,9 +16,11 @@ require 'nice-ffi'
16
16
  require 'yaml'
17
17
 
18
18
  # require_local 'rtfs/wrapper.rb'
19
- require_local 'rtfs/client.rb'
20
- require_local 'rtfs/meta.rb'
21
- require_local 'rtfs/version.rb'
19
+ require 'rtfs/client.rb'
20
+ require 'rtfs/web_service.rb'
21
+ require 'rtfs/tfstool.rb'
22
+ require 'rtfs/meta.rb'
23
+ require 'rtfs/version.rb'
22
24
 
23
25
  # tfs = RTFS::Client.new({:ns_addr => '10.246.65.210:3100'})
24
26
  # puts "tfsname: '#{tfs.put_file_and_get_url("/home/xifeng/1.png")}'"
data/lib/rtfs/client.rb CHANGED
@@ -1,86 +1,20 @@
1
1
  # Code for client
2
2
  # by nowa<nowazhu@gmail.com> 2011-07-23
3
3
  module RTFS
4
- TFSTOOL_PATH = "/home/admin/tfs/bin/tfstool"
5
4
 
6
5
  class Client
7
- attr_accessor :ns_addr
8
- attr_accessor :tfstool_path
9
6
 
10
7
  # 参数:
11
8
  # :ns_addr TFS 服务器地址,如 127.0.0.1:3100
12
9
  # :tfstool_path tfstool 安装路径,默认 /home/admin/tfs/bin/tfstool
13
- def initialize(options)
10
+ def self.tfs(options)
14
11
  return nil unless options
15
- @ns_addr = options[:ns_addr]
16
- @tfstool_path = options[:tfstool_path] ? options[:tfstool_path] : TFSTOOL_PATH
17
- raise NoTFSToolError.new unless File.exist?(@tfstool_path)
18
- end
19
-
20
- # 获取文件
21
- def get(tfs_name, local_file=nil)
22
- local_file ||= tfs_name
23
- `#{tfstool_cmd} -i "get #{tfs_name} #{local_file}"`
24
- end
25
-
26
- # 上传文件
27
- # 参数:
28
- # file_path 需要上传的文件路径
29
- # :ext 扩展名,默认会取 file_path 的扩展名, 如: .jpg
30
- # 返回值
31
- # T1lpVcXftHXXaCwpjX
32
- def put(file_path, options = {})
33
- ext = options[:ext] || File.extname(file_path)
34
- tfs_name = "NULL"
35
- result = `#{tfstool_cmd} -i "put #{file_path} #{tfs_name} #{ext}"`
36
- # puts "result: #{result}"
37
- t = nil
38
- if result.include?("=> ")
39
- result = result.split("=> ").last
40
- if result.include?(",")
41
- t = result.split(",").first
42
- end
43
- end
44
- t.nil? ? nil : t
45
- end
46
-
47
- # 上传文件 并返回完整 url (only for Taobao)
48
- def put_and_get_url(file_path, options = {})
49
- ext = options[:ext] || File.extname(file_path)
50
- t = put(file_path, :ext => ext)
51
- t.nil? ? nil : "http://img03.taobaocdn.com/tfscom/#{t}#{ext}"
52
- end
53
-
54
- # 删除文件, 不能带扩展名
55
- def rm(tfs_name)
56
- `#{tfstool_cmd} -i "rm #{tfs_name}"`
57
- end
58
-
59
- # 改名, 不能带扩展名
60
- def rename(tfs_name, new_name)
61
- `#{tfstool_cmd} -i "rename #{tfs_name} #{new_name}"`
62
- end
63
-
64
- # 文件信息查看, 不能带扩展名
65
- def stat(tfs_name)
66
- result = `#{tfstool_cmd} -i "stat #{tfs_name}"`
67
- stat = {}
68
- result.split("\n").each do |line|
69
- line = line.split(':').map {|i| i.gsub!(" ", "")}
70
- stat["#{line.first}"] = line.last
12
+ if options[:ns_addr].include?("http://")
13
+ return RTFS::WebService.new(options)
14
+ else
15
+ return RTFS::Tfstool.new(options)
71
16
  end
72
- stat
73
17
  end
74
-
75
- protected
76
- def tfstool_cmd
77
- "#{@tfstool_path} -n -s #{@ns_addr}"
78
- end
18
+
79
19
  end
80
-
81
- class NoTFSToolError < RuntimeError
82
- def to_s
83
- "You must install tfs from yum or source first!"
84
- end
85
- end # NoTFSToolError
86
- end
20
+ end
@@ -0,0 +1,89 @@
1
+ module RTFS
2
+
3
+ TFSTOOL_PATH = "/home/admin/tfs/bin/tfstool"
4
+ class Tfstool
5
+
6
+ attr_accessor :ns_addr
7
+ attr_accessor :tfstool_path
8
+
9
+ # 参数:
10
+ # :ns_addr TFS 服务器地址,如 127.0.0.1:3100
11
+ # :tfstool_path tfstool 安装路径,默认 /home/admin/tfs/bin/tfstool
12
+ def initialize(options)
13
+ return nil unless options
14
+ @ns_addr = options[:ns_addr]
15
+ @tfstool_path = options[:tfstool_path] ? options[:tfstool_path] : TFSTOOL_PATH
16
+ if not File.exist?(@tfstool_path)
17
+ puts "[RTFS] debuger: #{@tfstool_path}"
18
+ raise NoTFSToolError.new
19
+ end
20
+ end
21
+
22
+ # 获取文件
23
+ def get(tfs_name, local_file=nil)
24
+ local_file ||= tfs_name
25
+ `#{tfstool_cmd} -i "get #{tfs_name} #{local_file}"`
26
+ end
27
+
28
+ # 上传文件
29
+ # 参数:
30
+ # file_path 需要上传的文件路径
31
+ # :ext 扩展名,默认会取 file_path 的扩展名, 如: .jpg
32
+ # 返回值
33
+ # T1lpVcXftHXXaCwpjX
34
+ def put(file_path, options = {})
35
+ ext = options[:ext] || File.extname(file_path)
36
+ tfs_name = "NULL"
37
+ result = `#{tfstool_cmd} -i "put #{file_path} #{tfs_name} #{ext}"`
38
+ # puts "result: #{result}"
39
+ t = nil
40
+ if result.include?("=> ")
41
+ result = result.split("=> ").last
42
+ if result.include?(",")
43
+ t = result.split(",").first
44
+ end
45
+ end
46
+ t.nil? ? nil : t
47
+ end
48
+
49
+ # 上传文件 并返回完整 url (only for Taobao)
50
+ def put_and_get_url(file_path, options = {})
51
+ ext = options[:ext] || File.extname(file_path)
52
+ t = put(file_path, :ext => ext)
53
+ t.nil? ? nil : "http://img03.taobaocdn.com/tfscom/#{t}#{ext}"
54
+ end
55
+
56
+ # 删除文件, 不能带扩展名
57
+ def rm(tfs_name)
58
+ `#{tfstool_cmd} -i "rm #{tfs_name}"`
59
+ end
60
+
61
+ # 改名, 不能带扩展名
62
+ def rename(tfs_name, new_name)
63
+ `#{tfstool_cmd} -i "rename #{tfs_name} #{new_name}"`
64
+ end
65
+
66
+ # 文件信息查看, 不能带扩展名
67
+ def stat(tfs_name)
68
+ result = `#{tfstool_cmd} -i "stat #{tfs_name}"`
69
+ stat = {}
70
+ result.split("\n").each do |line|
71
+ line = line.split(':').map {|i| i.gsub!(" ", "")}
72
+ stat["#{line.first}"] = line.last
73
+ end
74
+ stat
75
+ end
76
+
77
+ protected
78
+ def tfstool_cmd
79
+ "#{@tfstool_path} -n -s #{@ns_addr}"
80
+ end
81
+ end
82
+
83
+ class NoTFSToolError < RuntimeError
84
+ def to_s
85
+ "You must install tfs from yum or source first!"
86
+ end
87
+ end # NoTFSToolError
88
+
89
+ end
@@ -0,0 +1,82 @@
1
+ # encoding utf-8
2
+ require 'rest-client'
3
+ require "json"
4
+
5
+ module RTFS
6
+ class WebService
7
+
8
+ attr_accessor :appkey
9
+ attr_accessor :ns_addr
10
+
11
+ def initialize(options)
12
+ return nil unless options
13
+ @ns_addr = options[:ns_addr]
14
+ @appkey = options[:appkey]
15
+ end
16
+
17
+ # 获取文件
18
+ def get(tfs_name, local_file=nil)
19
+ RestClient.get(get_url("/v1/#{appkey}/#{tfs_name}"))
20
+ end
21
+
22
+ # 上传文件
23
+ # 参数:
24
+ # file_path 需要上传的文件路径
25
+ # :ext 扩展名,默认会取 file_path 的扩展名, 如: .jpg
26
+ # 返回值
27
+ # T1lpVcXftHXXaCwpjX
28
+ def put(file_path, options = {})
29
+ ext = options[:ext] || File.extname(file_path)
30
+ response = RestClient.post(get_url("/v1/#{appkey}",{:suffix => ext, :simple_name => options[:simple_name] || 0}),File.open(file_path).read, :accept => :json )
31
+ json = JSON.parse(response)
32
+ json && json["TFS_FILE_NAME"] ? json["TFS_FILE_NAME"] : nil
33
+
34
+ end
35
+
36
+ # 上传文件 并返回完整 url (only for Taobao)
37
+ def put_and_get_url(file_path, options = {})
38
+ ext = options[:ext] || File.extname(file_path)
39
+ t = put(file_path, :ext => ext)
40
+ t.nil? ? nil : "http://img0#{rand(4)+1}.taobaocdn.com/tfscom/#{t}#{ext}"
41
+ end
42
+
43
+ # 删除文件, 不能带扩展名
44
+ def rm(tfs_name,options = {})
45
+ response = RestClient.delete(get_url("/v1/#{appkey}/#{tfs_name}", options))
46
+ response && response.code == 200 ? true : nil
47
+ end
48
+
49
+ # 改名, 不能带扩展名
50
+ def rename(tfs_name, new_name)
51
+ #`#{tfstool_cmd} -i "rename #{tfs_name} #{new_name}"`
52
+ end
53
+
54
+ # 文件信息查看, 不能带扩展名
55
+ def stat(tfs_name,options = {})
56
+ response = RestClient.get(get_url("/v1/#{appkey}/metadata/#{tfs_name}", options))
57
+ response && response.code == 200 ? JSON.parse(response) : nil
58
+ end
59
+
60
+ def client_name
61
+ "WebService"
62
+ end
63
+
64
+ private
65
+
66
+
67
+ def appkey
68
+ @appkey
69
+ end
70
+
71
+ def get_url(url,opts = {})
72
+ return url unless opts
73
+ url = "#{@ns_addr}#{url}"
74
+ params = []
75
+ opts.each{|k,v|
76
+ params << "#{k}=#{v}"
77
+ }
78
+ url.include?("?") ? "#{url}&#{params.join("&")}" : "#{url}?#{params.join("&")}"
79
+ end
80
+
81
+ end
82
+ end
data/pkg-info.yml ADDED
@@ -0,0 +1,27 @@
1
+ <% require('pathname') %>
2
+ spec:
3
+ name: rtfs
4
+ version: <%= RTFS::Version.to_version %>
5
+ summary: RTFS is a Ruby Client for TFS.
6
+ require_path: lib
7
+ has_rdoc: false
8
+ extra_rdoc_files:
9
+ - README.markdown
10
+ - CHANGES
11
+ - MIT-LICENSE
12
+ autorequire: rtfs
13
+ # bindir: bin
14
+ add_dependency:
15
+ nice-ffi: >=0.4
16
+ requirements:
17
+ - Ruby 1.8.7+
18
+ # - json gem, version 0.4.3 or higher
19
+ # - jcode (for unicode support)
20
+ required_ruby_version: >=1.8.7
21
+ author: Nowa Zhu
22
+ email: nowazhu@gmail.com
23
+ homepage: http://rtfs.labs.nowa.me
24
+ rubyforge_project: rtfs
25
+ files: <% (self.project_files + self.spec_files).each do |file| %>
26
+ - <%= Pathname.new(file).relative_path_from(Pathname.new(@root_dir)) %>
27
+ <% end %>
data/rtfs.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ # Generated: Sun Oct 09 04:07:05 UTC 2011
2
+ Gem::Specification.new do |s|
3
+ s.name = "rtfs"
4
+ s.version = "0.1.0"
5
+ s.platform = Gem::Platform::RUBY
6
+ s.has_rdoc = true
7
+ s.extra_rdoc_files = ["README.markdown","CHANGES","MIT-LICENSE",]
8
+ s.summary = "RTFS is a Ruby Client for TFS."
9
+ s.author = "Nowa Zhu"
10
+ s.email = "nowazhu@gmail.com"
11
+ s.homepage = "https://github.com/nowa/rtfs"
12
+ s.add_dependency("nice-ffi", ">=0.4")
13
+ s.add_dependency("rest-client", ">=1.6.0")
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.require_paths = ["lib"]
17
+ s.bindir = 'bin'
18
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
data/tasks/pkg.rake ADDED
@@ -0,0 +1,22 @@
1
+ require 'rake/gempackagetask'
2
+
3
+ meta = RTFS::Meta.new(ROOT_DIR)
4
+ namespace :package do
5
+ desc "Create Gem Packages"
6
+ Rake::GemPackageTask.new(meta.gem_spec) do |pkg|
7
+ pkg.need_zip = true
8
+ pkg.need_tar = true
9
+ end
10
+ end
11
+
12
+ namespace :gemspec do
13
+ desc "Create GemSpec"
14
+ task :generate do
15
+ spec = meta.pkg_info['spec']
16
+ rgs = ERB.new(File.read(File.join(ROOT_DIR, 'config', 'templates', 'github.gemspec.erb')), 0)
17
+ s = rgs.result(spec.send(:binding))
18
+ gs_file = File.join(ROOT_DIR, 'rtfs.gemspec')
19
+ File.delete(gs_file) if File.exist?(gs_file)
20
+ File.open(gs_file, 'w') {|f| f.write(s); }
21
+ end
22
+ end
metadata CHANGED
@@ -1,92 +1,87 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rtfs
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 4
10
- version: 0.0.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Nowa Zhu
14
- autorequire: rtfs
9
+ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-10-09 00:00:00 +08:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: nice-ffi
16
+ requirement: &2168210780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0.4'
22
+ type: :runtime
23
23
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: *2168210780
25
+ - !ruby/object:Gem::Dependency
26
+ name: rest-client
27
+ requirement: &2168210300 !ruby/object:Gem::Requirement
25
28
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- - 4
33
- version: "0.4"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.0
34
33
  type: :runtime
35
- version_requirements: *id001
34
+ prerelease: false
35
+ version_requirements: *2168210300
36
36
  description:
37
37
  email: nowazhu@gmail.com
38
38
  executables: []
39
-
40
39
  extensions: []
41
-
42
- extra_rdoc_files:
40
+ extra_rdoc_files:
43
41
  - README.markdown
44
42
  - CHANGES
45
43
  - MIT-LICENSE
46
- files:
44
+ files:
45
+ - .gitignore
46
+ - CHANGES
47
+ - MIT-LICENSE
48
+ - README.markdown
49
+ - Rakefile
50
+ - config/templates/github.gemspec.erb
51
+ - lib/rtfs.rb
52
+ - lib/rtfs/client.rb
47
53
  - lib/rtfs/meta.rb
54
+ - lib/rtfs/tfstool.rb
48
55
  - lib/rtfs/version.rb
49
- - lib/rtfs/client.rb
56
+ - lib/rtfs/web_service.rb
50
57
  - lib/rtfs/wrapper.rb
51
- - lib/rtfs.rb
52
- - README.markdown
53
- - CHANGES
54
- - MIT-LICENSE
55
- has_rdoc: true
56
- homepage: http://rtfs.labs.nowa.me
58
+ - pkg-info.yml
59
+ - rtfs.gemspec
60
+ - spec/spec.opts
61
+ - tasks/pkg.rake
62
+ homepage: https://github.com/nowa/rtfs
57
63
  licenses: []
58
-
59
64
  post_install_message:
60
65
  rdoc_options: []
61
-
62
- require_paths:
66
+ require_paths:
63
67
  - lib
64
- required_ruby_version: !ruby/object:Gem::Requirement
68
+ required_ruby_version: !ruby/object:Gem::Requirement
65
69
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- hash: 57
70
- segments:
71
- - 1
72
- - 8
73
- - 7
74
- version: 1.8.7
75
- required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
75
  none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- hash: 3
81
- segments:
82
- - 0
83
- version: "0"
84
- requirements:
85
- - Ruby 1.8.7+
86
- rubyforge_project: rtfs
87
- rubygems_version: 1.3.7
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.10
88
83
  signing_key:
89
84
  specification_version: 3
90
85
  summary: RTFS is a Ruby Client for TFS.
91
- test_files: []
92
-
86
+ test_files:
87
+ - spec/spec.opts