rtfs 0.0.1
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/CHANGES +4 -0
- data/MIT-LICENSE +20 -0
- data/README +3 -0
- data/lib/rtfs.rb +26 -0
- data/lib/rtfs/client.rb +80 -0
- data/lib/rtfs/meta.rb +56 -0
- data/lib/rtfs/version.rb +20 -0
- data/lib/rtfs/wrapper.rb +67 -0
- metadata +92 -0
data/CHANGES
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Nowa Zhu <nowazhu@gmail.com>, http://nowa.me.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/lib/rtfs.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# TFS Client for Ruby
|
2
|
+
# by nowa<nowazhu@gmail.com> 2011-07-23
|
3
|
+
|
4
|
+
#!/usr/local/bin/ruby
|
5
|
+
|
6
|
+
$:.unshift(File.dirname(__FILE__))
|
7
|
+
|
8
|
+
module RTFS; end
|
9
|
+
|
10
|
+
def require_local(suffix)
|
11
|
+
require(File.expand_path(File.join(File.dirname(__FILE__), suffix)))
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rubygems'
|
15
|
+
require 'nice-ffi'
|
16
|
+
require 'yaml'
|
17
|
+
|
18
|
+
require_local 'rtfs/wrapper.rb'
|
19
|
+
require_local 'rtfs/client.rb'
|
20
|
+
require_local 'rtfs/meta.rb'
|
21
|
+
require_local 'rtfs/version.rb'
|
22
|
+
|
23
|
+
# tfs = RTFS::Client.new({:ns_addr => '10.246.65.210:3100'})
|
24
|
+
# puts "tfsname: '#{tfs.put_file_and_get_url("/home/xifeng/1.png")}'"
|
25
|
+
# puts "#{tfs.get_file('T1H9t5XeRwXXaCwpjX')}"
|
26
|
+
# puts "#{tfs.file_stat('T1H9t5XeRwXXaCwpjX').inspect}"
|
data/lib/rtfs/client.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Code for client
|
2
|
+
# by nowa<nowazhu@gmail.com> 2011-07-23
|
3
|
+
|
4
|
+
module RTFS
|
5
|
+
TFSTOOL_PATH = "/home/admin/tfs/bin/tfstool"
|
6
|
+
|
7
|
+
class Client
|
8
|
+
attr_accessor :ns_addr
|
9
|
+
attr_accessor :tfstool_path
|
10
|
+
|
11
|
+
def initialize(options)
|
12
|
+
return nil unless options
|
13
|
+
@ns_addr = options[:ns_addr]
|
14
|
+
@tfstool_path = options[:tfstool_path] ? options[:tfstool_path] : TFSTOOL_PATH
|
15
|
+
raise NoTFSToolError.new unless File.exist?(@tfstool_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
# ��tfs��ȡ�ļ�
|
19
|
+
def get_file(tfs_name, local_file=nil)
|
20
|
+
local_file ||= tfs_name
|
21
|
+
`#{tfstool_cmd} -i "get #{tfs_name} #{local_file}"`
|
22
|
+
end
|
23
|
+
|
24
|
+
# �������tfs���������tfsname
|
25
|
+
# tfsname example: T1lpVcXftHXXaCwpjX
|
26
|
+
def put_file(local_file, tfs_name="NULL", suffix=nil)
|
27
|
+
suffix ||= ".#{local_file.split(".").last}"
|
28
|
+
result = `#{tfstool_cmd} -i "put #{local_file} #{tfs_name} #{suffix}"`
|
29
|
+
# puts "result: #{result}"
|
30
|
+
t = nil
|
31
|
+
if result.include?("=> ")
|
32
|
+
result = result.split("=> ").last
|
33
|
+
if result.include?(",")
|
34
|
+
t = result.split(",").first
|
35
|
+
end
|
36
|
+
end
|
37
|
+
t.nil? ? nil : t
|
38
|
+
end
|
39
|
+
|
40
|
+
# �����ļ���tfs�������ļ��Ŀɷ���cdn url
|
41
|
+
def put_file_and_get_url(local_file, tfs_name="NULL", suffix=nil)
|
42
|
+
suffix ||= ".#{local_file.split(".").last}"
|
43
|
+
t = put_file(local_file, tfs_name, suffix)
|
44
|
+
t.nil? ? nil : "http://img03.taobaocdn.com/tfscom/#{t}#{suffix}"
|
45
|
+
end
|
46
|
+
|
47
|
+
# ɾ��tfs file
|
48
|
+
def rm_file(tfs_name)
|
49
|
+
`#{tfstool_cmd} -i "rm #{tfs_name}"`
|
50
|
+
end
|
51
|
+
|
52
|
+
# ������tfs file�����Ƽ�ʹ��
|
53
|
+
# new name ����Ҳ�� tfsname ��ʽ
|
54
|
+
def rename_file(tfs_name, new_name)
|
55
|
+
`#{tfstool_cmd} -i "rename #{tfs_name} #{new_name}"`
|
56
|
+
end
|
57
|
+
|
58
|
+
# ��ȡtfs file��stat
|
59
|
+
def file_stat(tfs_name)
|
60
|
+
result = `#{tfstool_cmd} -i "stat #{tfs_name}"`
|
61
|
+
stat = {}
|
62
|
+
result.split("\n").each do |line|
|
63
|
+
line = line.split(':').map {|i| i.gsub!(" ", "")}
|
64
|
+
stat["#{line.first}"] = line.last
|
65
|
+
end
|
66
|
+
stat
|
67
|
+
end
|
68
|
+
|
69
|
+
protected
|
70
|
+
def tfstool_cmd
|
71
|
+
"#{@tfstool_path} -n -s #{@ns_addr}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class NoTFSToolError < RuntimeError
|
76
|
+
def to_s
|
77
|
+
"You must install tfs from yum or source first!"
|
78
|
+
end
|
79
|
+
end # NoTFSToolError
|
80
|
+
end
|
data/lib/rtfs/meta.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# meta.rb contains <tt>Top4R::Meta</tt> and related classes that
|
2
|
+
# help define the metadata of the <tt>Top4R</tt> project.
|
3
|
+
|
4
|
+
require('rubygems')
|
5
|
+
require('erb')
|
6
|
+
|
7
|
+
class RTFS::Meta #:nodoc:
|
8
|
+
attr_accessor :root_dir
|
9
|
+
attr_reader :gem_spec, :project_files, :spec_files
|
10
|
+
|
11
|
+
# Initializer for Top4R::Meta class. Takes <tt>root_dir</tt> as parameter.
|
12
|
+
def initialize(root_dir)
|
13
|
+
@root_dir = root_dir
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns package information defined in <tt>root_dir</tt>/pkg-info.yml
|
17
|
+
def pkg_info
|
18
|
+
yaml_file = File.join(@root_dir, 'pkg-info.yml')
|
19
|
+
ryaml = ERB.new(File.read(yaml_file), 0)
|
20
|
+
s = ryaml.result(binding)
|
21
|
+
YAML.load(s)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns RubyGems spec information
|
25
|
+
def spec_info
|
26
|
+
self.pkg_info['spec'] if self.pkg_info
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns list of project files
|
30
|
+
def project_files
|
31
|
+
@project_files ||= Dir.glob(File.join(@root_dir, 'lib/**/*.rb'))
|
32
|
+
@project_files
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns list of specification files
|
36
|
+
def spec_files
|
37
|
+
@spec_files ||= Dir.glob(File.join(@root_dir, 'spec/**/*_spec.rb'))
|
38
|
+
@spec_files
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns RubyGem specification for Top4R project
|
42
|
+
def gem_spec
|
43
|
+
@gem_spec ||= Gem::Specification.new do |spec|
|
44
|
+
self.spec_info.each do |key, val|
|
45
|
+
if val.is_a?(Hash)
|
46
|
+
val.each do |k, v|
|
47
|
+
spec.send(key, k, v)
|
48
|
+
end
|
49
|
+
else
|
50
|
+
spec.send("#{key}=", val)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
@gem_spec
|
55
|
+
end
|
56
|
+
end
|
data/lib/rtfs/version.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Version for RTFS
|
2
|
+
# by nowa<nowazhu@gmail.com> 2011-07-23
|
3
|
+
|
4
|
+
module RTFS::Version
|
5
|
+
MAJOR = 0
|
6
|
+
MINOR = 0
|
7
|
+
REVISION = 1
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# Returns X.Y.Z formatted version string
|
11
|
+
def to_version
|
12
|
+
"#{MAJOR}.#{MINOR}.#{REVISION}"
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns X-Y-Z formatted version name
|
16
|
+
def to_name
|
17
|
+
"#{MAJOR}_#{MINOR}_#{REVISION}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/rtfs/wrapper.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# ʹ��ffi��nice-ffi�����ö�̬���c�ӿ�
|
2
|
+
# tfsclient c apiĿǰ�в����ƣ�����c�ӿڵķ�װ���ò�����������
|
3
|
+
# ���Ŀǰ��ʹ�ø�wrapper���ļ��ݴ�
|
4
|
+
# by nowa<nowazhu@gmail.com> 2011-07-23
|
5
|
+
|
6
|
+
module LibC
|
7
|
+
extend FFI::Library
|
8
|
+
# figures out the correct libc for each platform including Windows
|
9
|
+
library = ffi_lib(FFI::Library::LIBC).first
|
10
|
+
|
11
|
+
# Size_t not working properly on Windows
|
12
|
+
find_type(:size_t) rescue typedef(:ulong, :size_t)
|
13
|
+
|
14
|
+
# memory allocators
|
15
|
+
attach_function :malloc, [:size_t], :pointer
|
16
|
+
attach_function :free, [:pointer], :void
|
17
|
+
|
18
|
+
# get a pointer to the free function; used for ZMQ::Message deallocation
|
19
|
+
Free = library.find_symbol('free')
|
20
|
+
|
21
|
+
# memory movers
|
22
|
+
attach_function :memcpy, [:pointer, :pointer, :size_t], :pointer
|
23
|
+
end # module LibC
|
24
|
+
|
25
|
+
module LibRTFS
|
26
|
+
extend NiceFFI::Library
|
27
|
+
|
28
|
+
libs_dir = "/home/admin/tfs/lib/"
|
29
|
+
pathset = NiceFFI::PathSet::DEFAULT.prepend(libs_dir)
|
30
|
+
|
31
|
+
load_library("tfsclient_c", pathset)
|
32
|
+
|
33
|
+
attach_function :t_initialize, [:string, :int, :int], :int
|
34
|
+
|
35
|
+
#enum OpenFlag
|
36
|
+
# {
|
37
|
+
# T_READ = 1,
|
38
|
+
# T_WRITE = 2,
|
39
|
+
# T_CREATE = 4,
|
40
|
+
# T_NEWBLK = 8,
|
41
|
+
# T_NOLEASE = 16,
|
42
|
+
# T_STAT = 32,
|
43
|
+
# T_LARGE = 64
|
44
|
+
# };
|
45
|
+
attach_function :t_open, [:string, :string, :string, :int, :string], :int
|
46
|
+
attach_function :t_read, [:int, :pointer, :int], :int
|
47
|
+
attach_function :t_write, [:int, :pointer, :int], :int
|
48
|
+
attach_function :t_lseek, [:int, :int, :int], :int
|
49
|
+
attach_function :t_pread, [:int, :pointer, :int, :int], :int
|
50
|
+
attach_function :t_pwrite, [:int, :pointer, :int, :int], :int
|
51
|
+
attach_function :t_fstat, [:int, :pointer, :int], :int
|
52
|
+
attach_function :t_close, [:int, :string, :int], :int
|
53
|
+
attach_function :t_unlink, [:string, :string, :int], :int
|
54
|
+
end
|
55
|
+
|
56
|
+
# �����ⲿ�ִ����������LibRTFS
|
57
|
+
# LibRTFS.t_initialize("10.232.35.32:3100", 5, 1000)
|
58
|
+
# fd = LibRTFS.t_open("test", ".png", nil, 2, nil)
|
59
|
+
# puts "fd: #{fd}"
|
60
|
+
#
|
61
|
+
# ori_file = nil
|
62
|
+
# File.open("/home/xifeng/1.png", "r") do |f|
|
63
|
+
# ori_file = f.read
|
64
|
+
# end
|
65
|
+
# buffer = LibC.malloc ori_file.size
|
66
|
+
# buffer.write_string ori_file, ori_file.size
|
67
|
+
# puts "write: #{LibRTFS.t_write(fd, buffer, ori_file.size)}"
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rtfs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Nowa Zhu
|
14
|
+
autorequire: rtfs
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-02 00:00:00 +08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: nice-ffi
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 4
|
33
|
+
version: "0.4"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description:
|
37
|
+
email: nowazhu@gmail.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- README
|
44
|
+
- CHANGES
|
45
|
+
- MIT-LICENSE
|
46
|
+
files:
|
47
|
+
- lib/rtfs/meta.rb
|
48
|
+
- lib/rtfs/version.rb
|
49
|
+
- lib/rtfs/client.rb
|
50
|
+
- lib/rtfs/wrapper.rb
|
51
|
+
- lib/rtfs.rb
|
52
|
+
- README
|
53
|
+
- CHANGES
|
54
|
+
- MIT-LICENSE
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://rtfs.labs.nowa.me
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
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
|
76
|
+
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
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: RTFS is a Ruby Client for TFS.
|
91
|
+
test_files: []
|
92
|
+
|