depends_update 0.0.1 → 0.0.2
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/lib/depends_update.rb +5 -2
- data/lib/depends_update/init.rb +170 -0
- data/lib/svn/svntree.rb +137 -0
- data/lib/version.rb +1 -1
- metadata +6 -4
data/lib/depends_update.rb
CHANGED
@@ -6,10 +6,13 @@
|
|
6
6
|
# rake depends_update 命令来依据定义的依赖关系更新,很显然 .depends_update 定义了我
|
7
7
|
# 们的依赖关系
|
8
8
|
|
9
|
-
|
9
|
+
require 'rubygems'
|
10
10
|
require 'rake'
|
11
|
+
require 'depends_update/init.rb'
|
12
|
+
|
13
|
+
|
11
14
|
|
12
15
|
desc 'depends update this code repository'
|
13
16
|
task :depends_update do
|
14
|
-
|
17
|
+
DependUpdate::Depends.depends_update
|
15
18
|
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require 'svn/svntree'
|
5
|
+
require 'ruby-debug'
|
6
|
+
|
7
|
+
module DependUpdate
|
8
|
+
class Depends
|
9
|
+
extend DependUpdate
|
10
|
+
|
11
|
+
def initalize(&block)
|
12
|
+
return nil unless block_given?
|
13
|
+
yield self
|
14
|
+
end
|
15
|
+
|
16
|
+
def depend(*args)
|
17
|
+
dest = args.first
|
18
|
+
options = args.last.is_a?(::Hash) ? args.pop : {}
|
19
|
+
|
20
|
+
case options.keys.first.to_s
|
21
|
+
when "svn"
|
22
|
+
pattern = options[:svn]
|
23
|
+
command = SVN::SVNCommand
|
24
|
+
else
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
repos_root = command.repos_current_path()
|
30
|
+
repos_current = command.repos_root_path()
|
31
|
+
from = options.values.first
|
32
|
+
|
33
|
+
if pattern !~ /[\*|\?]/ # 非模式匹配
|
34
|
+
# dest == Directory
|
35
|
+
if pattern == /^(http[s]?|svn):\/\// # 不同仓库
|
36
|
+
from_path = pattern
|
37
|
+
to_path = dest
|
38
|
+
elsif pattern == /^\// # 根目录
|
39
|
+
from_path = url_join_path(from,repos_root)
|
40
|
+
to_path = dest
|
41
|
+
else
|
42
|
+
from_path = url_join_path(from,repos_current)
|
43
|
+
to_path = dest
|
44
|
+
end
|
45
|
+
puts "更新文件 #{from_path} 到 #{to_path}"
|
46
|
+
command.export(from_path,to_path)
|
47
|
+
else
|
48
|
+
if pattern == /^(http[s]?|svn):\/\// # 不同仓库
|
49
|
+
from_paths = command.ReposTree.new pattern
|
50
|
+
to_path = dest
|
51
|
+
elsif pattern == /^\// # 根目录
|
52
|
+
from_paths = command.ReposTree.new url_join_path(from,repos_root)
|
53
|
+
to_path = dest
|
54
|
+
else
|
55
|
+
from_paths = command.ReposTree.new url_join_path(form,repos_current)
|
56
|
+
to_path = dest
|
57
|
+
end
|
58
|
+
|
59
|
+
from_paths.each do |from_path|
|
60
|
+
puts "更新文件 #{from_path} 到 #{to_path}"
|
61
|
+
command.export(from_path,to_path)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def url_join_path(*paths)
|
68
|
+
return unless paths.respond_to?('length') && paths.length > 1
|
69
|
+
paths.inject do |snext,sconcat|
|
70
|
+
if snext.index(/[\/|\\]/) == 0 && sconcat.rindex(/[\/|\\]/) == sconcat.length - 1
|
71
|
+
sconcat + '/' + snext
|
72
|
+
else
|
73
|
+
sconcat + snext
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def download(uri)
|
81
|
+
filename = File.basename(uri)
|
82
|
+
puts "downloadding #{uri}"
|
83
|
+
writeOut = open(filename, "wb")
|
84
|
+
writeOut.write(open(uri).read)
|
85
|
+
writeOut.close
|
86
|
+
puts "downloaded #{uri}"
|
87
|
+
filename
|
88
|
+
end
|
89
|
+
|
90
|
+
def get_depends_file
|
91
|
+
|
92
|
+
modulepath = File.expand_path(".depends",Dir.pwd)
|
93
|
+
return modulepath
|
94
|
+
end
|
95
|
+
|
96
|
+
def depends_list
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
SVN32_URL = 'http://www.sliksvn.com/pub/Slik-Subversion-1.6.16-win32.msi'
|
101
|
+
svn64_url = 'http://www.sliksvn.com/pub/Slik-Subversion-1.6.16-x64.msi'
|
102
|
+
|
103
|
+
def get_os(*os_string)
|
104
|
+
if os_string.respond_to?('length') && os_string.length == 0
|
105
|
+
os = RUBY_PLATFORM
|
106
|
+
else
|
107
|
+
os = os_string[0]
|
108
|
+
end
|
109
|
+
|
110
|
+
case os
|
111
|
+
when /mingw/,/cygwin/
|
112
|
+
:windows
|
113
|
+
when /linux/
|
114
|
+
:linux
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def svn_installed?
|
119
|
+
begin
|
120
|
+
`svn`
|
121
|
+
true
|
122
|
+
rescue Errno::ENOENT
|
123
|
+
false
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def load_depends_settings
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
def depends_update
|
132
|
+
|
133
|
+
if get_os == :windows
|
134
|
+
svn = DependUpdate::SVN32_URL
|
135
|
+
unless svn_installed?
|
136
|
+
svnfile = download svn
|
137
|
+
`#{svnfile}`
|
138
|
+
FileUtils.rm svnfile
|
139
|
+
end
|
140
|
+
return unless svn_installed?
|
141
|
+
end
|
142
|
+
puts get_depends_file
|
143
|
+
|
144
|
+
File.read(get_depends_file).each_line do |line|
|
145
|
+
values = line.split(',')
|
146
|
+
|
147
|
+
if values && values.length && values.length > 1
|
148
|
+
|
149
|
+
dest = values[0]
|
150
|
+
value = values[1]
|
151
|
+
|
152
|
+
options ||= {}
|
153
|
+
option_name ||= :svn
|
154
|
+
|
155
|
+
if value.split('=') && value.split('=') && value.split('=').length > 1
|
156
|
+
option_name = value.split('=').first.strip.to_sym
|
157
|
+
url_value = value.split('=').last.strip
|
158
|
+
else
|
159
|
+
url_value = value.strip
|
160
|
+
end
|
161
|
+
|
162
|
+
options[option_name] = url_value
|
163
|
+
|
164
|
+
d = ::DependUpdate::Depends.new
|
165
|
+
d.depend(dest, options)
|
166
|
+
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
data/lib/svn/svntree.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module SVN
|
4
|
+
class SVNTree
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
attr_accessor :items
|
8
|
+
attr_accessor :url
|
9
|
+
|
10
|
+
def initialize(url,*args)
|
11
|
+
@url = url
|
12
|
+
@items = SVN::SVNCommand.ls(url)
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](*args)
|
16
|
+
svn_tree = load_child(self)
|
17
|
+
|
18
|
+
svn_tree.reject do |item|
|
19
|
+
match = false
|
20
|
+
args.each do |p|
|
21
|
+
match = File.fnmatch(p,item,File::FNM_PATHNAME | File::FNM_DOTMATCH)
|
22
|
+
break if match
|
23
|
+
end
|
24
|
+
!match
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def each(&block)
|
29
|
+
@items.each do |member|
|
30
|
+
if member.rindex(/[\\|\/]/) == member.length - 1
|
31
|
+
block.call(SVNTree.new url + member)
|
32
|
+
else
|
33
|
+
block.call(member)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def load_child(items,*args)
|
40
|
+
if args && args.length
|
41
|
+
prefix = args.first
|
42
|
+
end
|
43
|
+
|
44
|
+
ret_array ||= []
|
45
|
+
prefix ||= ""
|
46
|
+
|
47
|
+
items.each do |item|
|
48
|
+
if item.class == SVN::SVNTree
|
49
|
+
to_prefix = prefix + item.url[items.url.length,10000]
|
50
|
+
ret_array.concat load_child(item,to_prefix)
|
51
|
+
else
|
52
|
+
ret_array << prefix + item
|
53
|
+
end
|
54
|
+
end
|
55
|
+
ret_array
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
module SVNCommand
|
60
|
+
class << self
|
61
|
+
|
62
|
+
def ls(path)
|
63
|
+
`svn list #{path}`.split("\n")
|
64
|
+
end
|
65
|
+
|
66
|
+
def export(url,*args)
|
67
|
+
to_path = args.first
|
68
|
+
to_path = to_path.chomp.strip
|
69
|
+
|
70
|
+
if to_path.rindex(/[\/|\\]/) == to_path.length - 1 # Directory
|
71
|
+
path_name = to_path
|
72
|
+
else
|
73
|
+
last_separator = to_path.rindex(/[\/|\\]/)
|
74
|
+
if last_separator && last_separator > 0 # 有目录
|
75
|
+
path_name = to_path[0..last_separator]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
FileUtils.mkdir_p(path_name) unless File.directory? path_name
|
81
|
+
|
82
|
+
`svn export --force #{url} #{to_path} `
|
83
|
+
end
|
84
|
+
|
85
|
+
def info()
|
86
|
+
ret = `svn info`
|
87
|
+
end
|
88
|
+
|
89
|
+
def repos_current_path
|
90
|
+
svn_info = info().split("\n")
|
91
|
+
get_svn_info_values(svn_info[1])
|
92
|
+
end
|
93
|
+
|
94
|
+
def repos_root_path
|
95
|
+
svn_info = info().split("\n")
|
96
|
+
get_svn_info_values(svn_info[2])
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
private
|
101
|
+
def get_svn_info_values(svn_info)
|
102
|
+
s = svn_info.chomp
|
103
|
+
s[s.index(":") + 1, 10000].chomp.strip
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
class ReposTree < SVN::SVNTree
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
# tree = SVN::SVNTree.new ("http://svn.localsvn.local/svn/repos1")
|
115
|
+
# tree.items =>
|
116
|
+
# |-- MIT-LICENSE
|
117
|
+
# |-- README
|
118
|
+
# |-- Rakefile
|
119
|
+
# |-- init.rb
|
120
|
+
# |-- install.rb
|
121
|
+
# |-- lib/
|
122
|
+
# |-- test/
|
123
|
+
# |-- uninstall.rb
|
124
|
+
# |-- wanew_client_validate.gemspec
|
125
|
+
#
|
126
|
+
# tree["lib/"] => SVN::SVNTree
|
127
|
+
# tree["README"] => SVN::SVNItem
|
128
|
+
# tree.items["lib/"] => SVN::SVNTree
|
129
|
+
# tree.each do |e|
|
130
|
+
# if (e.is_a(SVN::SVNTree))
|
131
|
+
# e.each do |i|
|
132
|
+
# puts i
|
133
|
+
# end
|
134
|
+
# end
|
135
|
+
# end
|
136
|
+
|
137
|
+
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: depends_update
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- wanliu corporation
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-06-02 00:00:00 +08:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|
@@ -30,7 +30,9 @@ extensions: []
|
|
30
30
|
extra_rdoc_files: []
|
31
31
|
|
32
32
|
files:
|
33
|
+
- lib/depends_update/init.rb
|
33
34
|
- lib/depends_update.rb
|
35
|
+
- lib/svn/svntree.rb
|
34
36
|
- lib/version.rb
|
35
37
|
- MIT-LICENSE
|
36
38
|
has_rdoc: true
|