bencview 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +93 -0
- data/bencview +31 -0
- data/bencview.rb +152 -0
- data/json2bencode +13 -0
- data/package.gemspec +33 -0
- metadata +56 -87
- data/README.rdoc +0 -9
- data/Rakefile +0 -50
- data/bin/bencview +0 -107
- data/bin/bencview_clean +0 -58
- data/doc/LICENSE +0 -22
- data/doc/NEWS.rdoc +0 -11
- data/doc/README.rdoc +0 -9
- data/doc/bencview.rdoc +0 -59
- data/doc/bencview_clean.rdoc +0 -75
- data/etc/bencview.yaml +0 -2
- data/lib/bencview/meta.rb +0 -9
- data/lib/bencview/trestle.rb +0 -216
- data/test/helper.rb +0 -4
- data/test/helper_trestle.rb +0 -37
- data/test/rake_git.rb +0 -36
- data/test/test_bencview.rb +0 -43
- data/test/torrent/[rutracker.org].t3128973.torrent +0 -58
- data/test/torrent/[rutracker.org]2642547.torrent +0 -0
- data/test/torrent/[rutracker.org]314407.torrent +0 -0
- data/test/torrent/[rutracker.org]838460.torrent +0 -0
- data/test/torrent/stack overflow data dump - nov 2010.torrent +0 -0
- data/test/viewer_output_01.txt +0 -175
data/bin/bencview_clean
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*-ruby-*-
|
3
|
-
|
4
|
-
require 'bencode'
|
5
|
-
require_relative '../lib/bencview/trestle.rb'
|
6
|
-
|
7
|
-
include Bencview
|
8
|
-
|
9
|
-
$conf = Hash.new
|
10
|
-
u = Trestle.new($conf)
|
11
|
-
|
12
|
-
$conf[:banner] = "Usage: #{File.basename($0)} [options] file [file ...]"
|
13
|
-
$conf[:a] = 'http://tracker.openbittorrent.com/announce'
|
14
|
-
|
15
|
-
|
16
|
-
# --[ main ]------------------------------------------------------------
|
17
|
-
|
18
|
-
u.config_parse(['foobar']) {|src|
|
19
|
-
o = u.cl_parse(src) # create an OptionParser object
|
20
|
-
o.on('-a STR', 'An announce tracker URL') {|i|
|
21
|
-
$conf[:a] = i
|
22
|
-
}
|
23
|
-
u.cl_parse(src, o) # run cl parser
|
24
|
-
}
|
25
|
-
|
26
|
-
# print our env
|
27
|
-
if $conf[:verbose] >= 2
|
28
|
-
puts 'Libs dir: ' + Trestle.gem_libdir
|
29
|
-
pp $conf
|
30
|
-
end
|
31
|
-
|
32
|
-
Trestle.errx(1, $conf[:banner]) if ARGV.size == 0
|
33
|
-
|
34
|
-
ec = 0
|
35
|
-
ARGV.each {|i|
|
36
|
-
begin
|
37
|
-
t = BEncode.load_file i
|
38
|
-
rescue
|
39
|
-
STDERR.puts "#{File.basename i}: #{$!}"
|
40
|
-
ec += 1
|
41
|
-
next
|
42
|
-
end
|
43
|
-
|
44
|
-
t['comment'] = 'Leech without any rating!'
|
45
|
-
t['announce'] = $conf[:a]
|
46
|
-
t['announce-list'] = []
|
47
|
-
|
48
|
-
out = "" if (out = File.dirname(i) + '/') == "./"
|
49
|
-
out = out + File.basename(i, File.extname(i)) + '.CLEANED' + File.extname(i)
|
50
|
-
u.veputs(1, out)
|
51
|
-
begin
|
52
|
-
open(out, 'w+') {|fp| fp.write(BEncode.dump(t)) }
|
53
|
-
rescue
|
54
|
-
STDERR.puts $!.to_s
|
55
|
-
ec += 1
|
56
|
-
end
|
57
|
-
}
|
58
|
-
exit ec
|
data/doc/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
(The MIT License)
|
2
|
-
|
3
|
-
Copyright (c) 2010 Alexander Gromnitsky.
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
'Software'), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/doc/NEWS.rdoc
DELETED
data/doc/README.rdoc
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
bencview suite contains several utils to manage .torrent files.
|
2
|
-
|
3
|
-
bencview:: Torrent file viewer.
|
4
|
-
|
5
|
-
bencview_clean:: Cleans a list of announce trackers & replaces
|
6
|
-
main announce tracker (to be able to cheat,
|
7
|
-
for example, http://rutracker.org, ha-ha).
|
8
|
-
|
9
|
-
Read about them in corresponding <tt>*.rdoc</tt> files.
|
data/doc/bencview.rdoc
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
=Name
|
2
|
-
|
3
|
-
bencview--torrent file viewer.
|
4
|
-
|
5
|
-
|
6
|
-
==Synopsis
|
7
|
-
|
8
|
-
bencview [options] file [file ...]
|
9
|
-
|
10
|
-
|
11
|
-
==Description
|
12
|
-
|
13
|
-
The bencview utility reads torrent files and prints their metadata to
|
14
|
-
stdout.
|
15
|
-
|
16
|
-
The options are as follows:
|
17
|
-
|
18
|
-
-d:: Dump all as raw hash.
|
19
|
-
|
20
|
-
--config-dirs:: List all possible locations for the
|
21
|
-
configuration file. The first found wins.
|
22
|
-
|
23
|
-
--config NAME:: The name of the configuration file. If
|
24
|
-
it contains <tt>/</tt> in it, the list from
|
25
|
-
<tt>--config-dirs</tt> is ignored.
|
26
|
-
|
27
|
-
-V:: Show version and exit.
|
28
|
-
|
29
|
-
-v:: Be more verbose. You can supply it several
|
30
|
-
times, viz. <tt>-vv</tt> dumps even more
|
31
|
-
debug info.
|
32
|
-
|
33
|
-
==Configuration
|
34
|
-
|
35
|
-
bencview looks for its configuration at 3 places at start up.
|
36
|
-
|
37
|
-
1. At <tt>BENCVIEW_CONF</tt> env variable.
|
38
|
-
(Its format is exactly similar to CL options.)
|
39
|
-
|
40
|
-
2. At the configuration file. Its default name is
|
41
|
-
<tt>bencview.yaml</tt> and it can be stored in several
|
42
|
-
system directories which are observable by <tt>--config--dirs</tt> CL
|
43
|
-
option.
|
44
|
-
|
45
|
-
3. At command line.
|
46
|
-
|
47
|
-
Higher number levels overrides the values from lower number levels.
|
48
|
-
|
49
|
-
The configuration file must be in YAML format. Look into <tt>`gem env
|
50
|
-
gemdir`/gems/bencview-x.y.z/etc/</tt> directory for samples.
|
51
|
-
|
52
|
-
|
53
|
-
==Examples
|
54
|
-
|
55
|
-
% bencview foo.torrent bar.torrent
|
56
|
-
|
57
|
-
==See Also
|
58
|
-
|
59
|
-
{bencview_clean}[link:doc/bencview_clean_rdoc.html]
|
data/doc/bencview_clean.rdoc
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
=Name
|
2
|
-
|
3
|
-
bencview_clean--cleans a list of announce trackers & replaces main
|
4
|
-
announce tracker.
|
5
|
-
|
6
|
-
|
7
|
-
==Synopsis
|
8
|
-
|
9
|
-
bencview [options] file [file ...]
|
10
|
-
|
11
|
-
|
12
|
-
==Description
|
13
|
-
|
14
|
-
The bencview_clean utility reads a torrent file and creates a 'cleaner'
|
15
|
-
copy of it (with <tt>.CLEANED.torrent</tt> extension) to give you an
|
16
|
-
ability to download staff from such idiotic bittorent trackers which
|
17
|
-
require 'rating' or other bullshit to participate. (For example, see
|
18
|
-
http://rutracker.org)
|
19
|
-
|
20
|
-
If a creator of the torrent file has disabled DHT (because he is a
|
21
|
-
moron), you will not able to use 'cleaner' version of the torrent
|
22
|
-
file. Sorry.
|
23
|
-
|
24
|
-
The options are as follows:
|
25
|
-
|
26
|
-
-a URL:: An announce tracker URL.
|
27
|
-
|
28
|
-
--config-dirs:: List all possible locations for the
|
29
|
-
configuration file. The first found wins.
|
30
|
-
|
31
|
-
--config NAME:: The name of the configuration file. If
|
32
|
-
it contains <tt>/</tt> in it, the list from
|
33
|
-
<tt>--config-dirs</tt> is ignored.
|
34
|
-
|
35
|
-
-V:: Show version and exit.
|
36
|
-
|
37
|
-
-v:: Be more verbose. You can supply it several
|
38
|
-
times, viz. <tt>-vv</tt> dumps even more
|
39
|
-
debug info.
|
40
|
-
|
41
|
-
|
42
|
-
==Configuration
|
43
|
-
|
44
|
-
bencview_clean looks for its configuration at 3 places at start up.
|
45
|
-
|
46
|
-
1. At <tt>BENCVIEW_CONF</tt> env variable.
|
47
|
-
(Its format is exactly similar to CL options.)
|
48
|
-
|
49
|
-
2. At the configuration file. Its default name is
|
50
|
-
<tt>bencview.yaml</tt> and it can be stored in several
|
51
|
-
system directories which are observable by <tt>--config--dirs</tt> CL
|
52
|
-
option.
|
53
|
-
|
54
|
-
3. At command line.
|
55
|
-
|
56
|
-
Higher number levels overrides the values from lower number levels.
|
57
|
-
|
58
|
-
The configuration file must be in YAML format. Look into <tt>`gem env
|
59
|
-
gemdir`/gems/bencview-x.y.z/etc/</tt> directory for samples.
|
60
|
-
|
61
|
-
==Exit Status
|
62
|
-
|
63
|
-
The utility exits 0 on success, and >0 if an error occurs. For example,
|
64
|
-
if it read 3 files and 2 of them were invalid, the exit status will be 2
|
65
|
-
(the number of failures).
|
66
|
-
|
67
|
-
==Examples
|
68
|
-
|
69
|
-
% bencview_clean foo.torrent bar.torrent
|
70
|
-
% bencview_clean -v foobar.torrent
|
71
|
-
% bencview_clean -a 'http://tracker.example.org' foobar.torrent
|
72
|
-
|
73
|
-
==See Also
|
74
|
-
|
75
|
-
{bencview}[link:doc/bencview_rdoc.html]
|
data/etc/bencview.yaml
DELETED
data/lib/bencview/meta.rb
DELETED
data/lib/bencview/trestle.rb
DELETED
@@ -1,216 +0,0 @@
|
|
1
|
-
# :erb:
|
2
|
-
require 'yaml'
|
3
|
-
require 'shellwords.rb'
|
4
|
-
require 'optparse'
|
5
|
-
require 'pp'
|
6
|
-
require 'open4'
|
7
|
-
|
8
|
-
require_relative 'meta'
|
9
|
-
|
10
|
-
# :include: ../../README.rdoc
|
11
|
-
module Bencview
|
12
|
-
|
13
|
-
class Trestle
|
14
|
-
|
15
|
-
# Execute _cmd_ and return a list [exit_status, stderr,
|
16
|
-
# stdout]. Very handy.
|
17
|
-
def self.cmd_run(cmd)
|
18
|
-
so = sr = ''
|
19
|
-
status = Open4::popen4(cmd) { |pid, stdin, stdout, stderr|
|
20
|
-
so = stdout.read
|
21
|
-
sr = stderr.read
|
22
|
-
}
|
23
|
-
[status.exitstatus, sr, so]
|
24
|
-
end
|
25
|
-
|
26
|
-
# Return a directory with program libraries.
|
27
|
-
def self.gem_libdir
|
28
|
-
t = ["#{File.dirname(File.expand_path($0))}/../lib/#{Bencview::Meta::NAME}",
|
29
|
-
"#{Gem.dir}/gems/#{Bencview::Meta::NAME}-#{Bencview::Meta::VERSION}/lib/#{Bencview::Meta::NAME}",
|
30
|
-
"lib/#{Bencview::Meta::NAME}"]
|
31
|
-
t.each {|i| return i if File.readable?(i) }
|
32
|
-
fail "all paths are invalid: #{t}"
|
33
|
-
end
|
34
|
-
|
35
|
-
# Analogue to shell command +which+.
|
36
|
-
def self.in_path?(file)
|
37
|
-
return true if file =~ %r%\A/% and File.exist? file
|
38
|
-
|
39
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).any? do |path|
|
40
|
-
File.exist? File.join(path, file)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# Print an error message _t_ and exit if _ec_ > 0.
|
45
|
-
def self.errx(ec, t)
|
46
|
-
STDERR.puts File.basename($0) + ' error: ' + t.to_s
|
47
|
-
exit ec if ec > 0
|
48
|
-
end
|
49
|
-
|
50
|
-
# Print a warning.
|
51
|
-
def self.warnx(t)
|
52
|
-
STDERR.puts File.basename($0) + ' warning: ' + t.to_s
|
53
|
-
end
|
54
|
-
|
55
|
-
# #veputs uses this to decide to put a newline or not to put.
|
56
|
-
NNL_MARK = '__NNL__'
|
57
|
-
|
58
|
-
# Use this in your CL options to check if modifying some variable is
|
59
|
-
# not an idempotent act.
|
60
|
-
attr_reader :cl_opt_protect
|
61
|
-
|
62
|
-
# [conf] Typically must be a reference to some global variable.
|
63
|
-
def initialize(conf)
|
64
|
-
@conf = conf
|
65
|
-
@conf[:verbose] = 0
|
66
|
-
@conf[:banner] = "Usage: #{File.basename($0)} [options]"
|
67
|
-
@conf[:config] = Meta::NAME + '.yaml'
|
68
|
-
@conf[:config_dirs] = [ENV['HOME']+'/.'+Meta::NAME,
|
69
|
-
File.absolute_path("#{File.dirname(File.expand_path($0))}/../etc"),
|
70
|
-
'/usr/etc', '/usr/local/etc', '/etc',
|
71
|
-
"#{Gem.dir}/gems/#{Meta::NAME}-#{Meta::VERSION}/etc"
|
72
|
-
]
|
73
|
-
@conf[:config_env] = [Meta::NAME.upcase + '_CONF']
|
74
|
-
|
75
|
-
@cl_parsing_times = 0 # not used
|
76
|
-
@cl_opt_protect = false
|
77
|
-
end
|
78
|
-
|
79
|
-
# [level] A verbose level.
|
80
|
-
# [t] A string to print.
|
81
|
-
#
|
82
|
-
# Don't print _t_ with a newline if it contains NNL_MARK at the end.
|
83
|
-
def veputs(level, t)
|
84
|
-
t = t.dup
|
85
|
-
nnl = nil
|
86
|
-
if t.match(/#{NNL_MARK}$/)
|
87
|
-
t.sub!(/#{$&}/, '')
|
88
|
-
nnl = 1
|
89
|
-
end
|
90
|
-
|
91
|
-
if @conf[:verbose] >= level
|
92
|
-
nnl ? print(t) : puts(t)
|
93
|
-
STDOUT.flush
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
# Run all configuration parsing in a batch.
|
98
|
-
#
|
99
|
-
# [rvars] A list of variable names which must be in the
|
100
|
-
# configuration file.
|
101
|
-
#
|
102
|
-
# If no block is given, only standard CL options will be analysed.
|
103
|
-
def config_parse(rvars, &block)
|
104
|
-
cb = ->(b, src) {
|
105
|
-
if b
|
106
|
-
block.call src
|
107
|
-
else
|
108
|
-
# very basic default options
|
109
|
-
cl_parse(src, nil, true)
|
110
|
-
end
|
111
|
-
}
|
112
|
-
|
113
|
-
# 1. parse env
|
114
|
-
@conf[:config_env].each {|i|
|
115
|
-
# puts '0 run:'
|
116
|
-
cb.call(block_given?, ENV[i].shellsplit) if ENV.key?(i)
|
117
|
-
}
|
118
|
-
|
119
|
-
# 2. parse CL in case of '--config' option
|
120
|
-
# puts "\n1 run"
|
121
|
-
@cl_opt_protect = true
|
122
|
-
cb.call(block_given?, ARGV.dup)
|
123
|
-
@cl_opt_protect = false
|
124
|
-
|
125
|
-
# 3. load the configuration file & do the final CL parsing
|
126
|
-
begin
|
127
|
-
# puts "\n2 run"
|
128
|
-
r = config_flat_load(rvars)
|
129
|
-
rescue
|
130
|
-
Trestle.errx(1, "cannot load config: #{$!}")
|
131
|
-
end
|
132
|
-
veputs(1, "Loaded config: #{r}")
|
133
|
-
cb.call(block_given?, ARGV)
|
134
|
-
end
|
135
|
-
|
136
|
-
# Load a config file immediately if it contains '/' in its name,
|
137
|
-
# otherwise search through several dirs for it.
|
138
|
-
#
|
139
|
-
# [rvars] a list of requied variables in the config
|
140
|
-
#
|
141
|
-
# Return a loaded filename or nil on error.
|
142
|
-
def config_flat_load(rvars)
|
143
|
-
p = ->(f) {
|
144
|
-
if File.readable?(f)
|
145
|
-
begin
|
146
|
-
myconf = YAML.load_file(f)
|
147
|
-
rescue
|
148
|
-
abort("cannot parse #{f}: #{$!}")
|
149
|
-
end
|
150
|
-
rvars.each { |i|
|
151
|
-
fail "missing or nil '#{i}' in #{f}" if ! myconf.key?(i.to_sym) || ! myconf[i.to_sym]
|
152
|
-
}
|
153
|
-
@conf.merge!(myconf)
|
154
|
-
return @conf[:config]
|
155
|
-
end
|
156
|
-
return nil
|
157
|
-
}
|
158
|
-
|
159
|
-
if @conf[:config].index('/')
|
160
|
-
return p.call(@config[:config])
|
161
|
-
else
|
162
|
-
@conf[:config_dirs].each {|dir|
|
163
|
-
return dir+'/'+@conf[:config] if p.call(dir + '/' + @conf[:config])
|
164
|
-
}
|
165
|
-
end
|
166
|
-
|
167
|
-
return nil
|
168
|
-
end
|
169
|
-
|
170
|
-
|
171
|
-
# Parses CL-like options.
|
172
|
-
#
|
173
|
-
# [src] An array of options (usually +ARGV+).
|
174
|
-
#
|
175
|
-
# If _o_ is non nil function parses _src_ immediately, otherwise it
|
176
|
-
# only creates +OptionParser+ object and return it (if _simple_ is
|
177
|
-
# false).
|
178
|
-
def cl_parse(src, o = nil, simple = false)
|
179
|
-
if ! o then
|
180
|
-
# puts "NEW o (#{cl_opt_protect})" + src.to_s
|
181
|
-
o = OptionParser.new
|
182
|
-
o.banner = @conf[:banner]
|
183
|
-
o.on('-v', 'Be more verbose.') { |i|
|
184
|
-
# puts "cl_parsing_times "+cl_parsing_times.to_s
|
185
|
-
@conf[:verbose] += 1 unless cl_opt_protect
|
186
|
-
}
|
187
|
-
o.on('-V', 'Show version & exit.') { |i|
|
188
|
-
puts Meta::VERSION
|
189
|
-
exit 0
|
190
|
-
}
|
191
|
-
o.on('--config NAME', "Set a config name (default is #{@conf[:config]})") {|i|
|
192
|
-
@conf[:config] = i
|
193
|
-
}
|
194
|
-
o.on('--config-dirs', 'Show possible config locations') {
|
195
|
-
@conf[:config_dirs].each { |j|
|
196
|
-
f = j + '/' + @conf[:config]
|
197
|
-
puts (File.readable?(f) ? '* ' : ' ') + f
|
198
|
-
}
|
199
|
-
exit 0
|
200
|
-
}
|
201
|
-
|
202
|
-
return o if ! simple
|
203
|
-
end
|
204
|
-
|
205
|
-
begin
|
206
|
-
o.parse!(src)
|
207
|
-
@cl_parsing_times += 1
|
208
|
-
rescue
|
209
|
-
Trestle.errx(1, $!.to_s)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
end # trestle
|
214
|
-
end
|
215
|
-
|
216
|
-
# Don't remove this: falsework/0.2.2/naive/2010-12-26T04:50:00+02:00
|
data/test/helper.rb
DELETED
data/test/helper_trestle.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# :erb:
|
2
|
-
# Various staff for minitest. Include this file into your 'helper.rb'.
|
3
|
-
|
4
|
-
require 'fileutils'
|
5
|
-
include FileUtils
|
6
|
-
|
7
|
-
require_relative '../lib/bencview/trestle'
|
8
|
-
include Bencview
|
9
|
-
|
10
|
-
# don't run tests automatically if they were invoked as 'gem check -t ...'
|
11
|
-
if $0 =~ /gem/
|
12
|
-
require 'minitest/unit'
|
13
|
-
else
|
14
|
-
require 'minitest/autorun'
|
15
|
-
end
|
16
|
-
|
17
|
-
# Return the right directory for (probably executable) _c_.
|
18
|
-
def cmd(c)
|
19
|
-
case File.basename(Dir.pwd)
|
20
|
-
when Meta::NAME.downcase
|
21
|
-
# test probably is executed from the Rakefile
|
22
|
-
Dir.chdir('test')
|
23
|
-
when 'test'
|
24
|
-
# we are in the test directory, there is nothing special to do
|
25
|
-
else
|
26
|
-
# tests were invoked by 'gem check -t bencview'
|
27
|
-
begin
|
28
|
-
Dir.chdir(Trestle.gem_libdir + '/../../test')
|
29
|
-
rescue
|
30
|
-
raise "running tests from '#{Dir.pwd}' isn't supported: #{$!}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
'../bin/' + c
|
35
|
-
end
|
36
|
-
|
37
|
-
# Don't remove this: falsework/0.2.2/naive/2010-12-26T04:50:00+02:00
|
data/test/rake_git.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*-ruby-*-
|
3
|
-
# :erb:
|
4
|
-
|
5
|
-
# This is a helper for your Rakefile. Read the comments for each
|
6
|
-
# function.
|
7
|
-
|
8
|
-
require 'git'
|
9
|
-
require 'pp'
|
10
|
-
|
11
|
-
# Return a list of files in a git repository _repdir_.
|
12
|
-
#
|
13
|
-
# Add this to your gem spec:
|
14
|
-
#
|
15
|
-
# spec = Gem::Specification.new {|i|
|
16
|
-
# i.files = git_ls('.')
|
17
|
-
# }
|
18
|
-
#
|
19
|
-
# What it does is just collecting the list of the files from the git
|
20
|
-
# repository. The idea is to use that list for the gem spec. No more
|
21
|
-
# missing or redundant files in gems!
|
22
|
-
def git_ls(repdir, ignore_some = true)
|
23
|
-
ignore = ['/?\.gitignore$']
|
24
|
-
|
25
|
-
r = []
|
26
|
-
g = Git.open repdir
|
27
|
-
g.ls_files.each {|i, v|
|
28
|
-
next if ignore_some && ignore.index {|ign| i.match(/#{ign}/) }
|
29
|
-
r << i
|
30
|
-
}
|
31
|
-
r
|
32
|
-
end
|
33
|
-
|
34
|
-
pp git_ls('.') if __FILE__ == $0
|
35
|
-
|
36
|
-
# Don't remove this: falsework/0.2.2/naive/2010-12-26T04:50:00+02:00
|
data/test/test_bencview.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require_relative 'helper'
|
2
|
-
require 'bencode'
|
3
|
-
require 'digest/md5'
|
4
|
-
|
5
|
-
class TestBencview_1272419217 < MiniTest::Unit::TestCase
|
6
|
-
CMD = cmd('bencview') # get path to the exe & cd to tests directory
|
7
|
-
|
8
|
-
def setup
|
9
|
-
# this runs every time before test_*
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_cleaner
|
13
|
-
c = cmd('bencview_clean')
|
14
|
-
r = Trestle.cmd_run "#{c} qwerty asdfgh"
|
15
|
-
assert_equal(2, r[0])
|
16
|
-
assert_match(/No such file or directory/, r[1])
|
17
|
-
|
18
|
-
r = Trestle.cmd_run "#{c} -v torrent/[rutracker.org]2642547.torrent"
|
19
|
-
assert_equal(0, r[0])
|
20
|
-
|
21
|
-
t = BEncode.load_file r[2].strip
|
22
|
-
assert_equal('Leech without any rating!', t['comment'])
|
23
|
-
assert_equal([], t['announce-list'])
|
24
|
-
assert_equal('http://tracker.openbittorrent.com/announce', t['announce'])
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_viewer
|
28
|
-
r = Trestle.cmd_run "#{CMD} qwerty asdfgh"
|
29
|
-
assert_equal(2, r[0])
|
30
|
-
assert_match(/No such file or directory/, r[1])
|
31
|
-
|
32
|
-
r = Trestle.cmd_run "#{CMD} torrent/*.torrent"
|
33
|
-
assert_equal(0, r[0])
|
34
|
-
refute_equal(0, r[2].size)
|
35
|
-
|
36
|
-
r = Trestle.cmd_run "#{CMD} torrent/[rutracker.org]314407.torrent torrent/[rutracker.org].t3128973.torrent"
|
37
|
-
assert_equal(0, r[0])
|
38
|
-
achieved = Digest::MD5.hexdigest(r[2].encode('UTF-8', Encoding.default_external))
|
39
|
-
expected = Digest::MD5.hexdigest(File.read('viewer_output_01.txt').encode('UTF-8', 'KOI8-U'))
|
40
|
-
assert_equal(expected, achieved)
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|