[Aversa-commits] aversa/bin aversa.rb bt-downloader.rb
bt-metainfo-viewer.rb bt-rename.rb bt-tracker.rb
test_aversa_command.sh
teamikl at rubyforge.org
teamikl at rubyforge.org
Thu Sep 9 20:32:43 EDT 2004
Update of /var/cvs/aversa/aversa/bin
In directory rubyforge.org:/tmp/cvs-serv29004
Modified Files:
aversa.rb bt-downloader.rb bt-metainfo-viewer.rb bt-rename.rb
bt-tracker.rb test_aversa_command.sh
Log Message:
Tidy indents.
I commited before tidy indent for diff. coz added top-level module Aversa
Index: test_aversa_command.sh
===================================================================
RCS file: /var/cvs/aversa/aversa/bin/test_aversa_command.sh,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** test_aversa_command.sh 10 Sep 2004 00:11:03 -0000 1.1
--- test_aversa_command.sh 10 Sep 2004 00:32:39 -0000 1.2
***************
*** 35,36 ****
--- 35,38 ----
aversa rename --help
+ aversa track -v
+ aversa track -h
Index: bt-downloader.rb
===================================================================
RCS file: /var/cvs/aversa/aversa/bin/bt-downloader.rb,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** bt-downloader.rb 10 Sep 2004 00:01:57 -0000 1.4
--- bt-downloader.rb 10 Sep 2004 00:32:39 -0000 1.5
***************
*** 222,266 ****
module Aversa
! class Download < ApplicationBase
! def define_options(opt)
! super
! opt.on('-f [VAL]', '--file [VAL]', 'input metainfo file.') {|v| @file = v }
! opt
! end
! def main(*argv)
! @file ||= argv.shift
! ##
! # XXX save-directory of Storage.
! # If you want to save the download file to other directory,
! # you have to chdir, now.
! # I will change Storage class to care save file path in future.
! #
! # Dir.chdir(File.dirname(ARGV[0]))
! # Prepare BitTorrent download client object.
! # The argument is a path of metainfo file.
! bt = Net::BitTorrent::Client.new(@file)
!
! # Start upload server (seeder), the argument is range of upload port.
! bt.setup_upload_peer((6900...7000))
! # Connect to tracker(announce url) and get peers list.
! bt.connect_to_tracker()
! # Connect to peers and shakehand.
! bt.connect_to_peers()
!
! # Start servers
! Thread.start(bt) do |bt_client|
! Thread.pass
! bt_client.start_server
! end
! # Scheduler start
! bt.start_task_scheduler
! end
! end
end
--- 222,265 ----
module Aversa
! class Download < ApplicationBase
! def define_options(opt)
! super
! opt.on('-f [VAL]', '--file [VAL]', 'input metainfo file.') {|v| @file = v }
! end
! def main(*argv)
! @file ||= argv.shift
! ##
! # XXX save-directory of Storage.
! # If you want to save the download file to other directory,
! # you have to chdir, now.
! # I will change Storage class to care save file path in future.
! #
! # Dir.chdir(File.dirname(ARGV[0]))
! # Prepare BitTorrent download client object.
! # The argument is a path of metainfo file.
! bt = Net::BitTorrent::Client.new(@file)
!
! # Start upload server (seeder), the argument is range of upload port.
! bt.setup_upload_peer((6900...7000))
! # Connect to tracker(announce url) and get peers list.
! bt.connect_to_tracker()
! # Connect to peers and shakehand.
! bt.connect_to_peers()
!
! # Start servers
! Thread.start(bt) do |bt_client|
! Thread.pass
! bt_client.start_server
! end
! # Scheduler start
! bt.start_task_scheduler
! end
! end
end
Index: aversa.rb
===================================================================
RCS file: /var/cvs/aversa/aversa/bin/aversa.rb,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** aversa.rb 10 Sep 2004 00:11:03 -0000 1.9
--- aversa.rb 10 Sep 2004 00:32:39 -0000 1.10
***************
*** 75,190 ****
module Aversa
! class Application
!
! ##
! # If restrict file/module naming rules,
! # we can generate this table from exists files, dynamically.
! #
! @@module_table = {
! 'download' => { 'require' => 'bt-downloader.rb',
! 'include' => 'Download' },
! 'showinfo' => { 'require' => 'bt-metainfo-viewer.rb',
! 'include' => 'MetaInfoView' },
! 'makeinfo' => { 'require' => 'bt-metainfo-maker.rb',
! 'include' => 'MetaInfoMak' },
! 'track' => { 'require' => 'bt-tracker.rb',
! 'include' => 'Track' },
! 'rename' => { 'require' => 'bt-rename.rb',
! 'include' => 'MetaInfoRename' },
! }
- ##
- # Each module can supply meta information for help and version,
- # by implementing these special methods:
- #
! def self.help
! "(Aversa) Help message"
! end
! def self.version
! "(Aversa) Version v0.0.1"
! end
- ##
- # Here is a main entry point.
- def self.main(*argv)
- command = argv.shift
- app = Aversa::Application.new
##
! # If command is a toplevel command, and if the top level command has arguments
! # aversa help ... show 'aversa' s help
! # aversa help showinfo ... show 'showinfo' module's help
! #
! case command
! when '-h', '--help', 'help', nil
! if argv.empty?
! puts help
exit
- else
- # change options (-h showinfo --> showinfo --help)
- command = argv.shift || :dummy
- argv.unshift('--help')
end
- when '-v', '--version', 'version'
- puts version
- exit
- end
! begin
! app.__send__(command, *argv)
! rescue NoMethodError
! puts help
end
- end
! ##
! # Generate methods for each module_table's keys.
! @@module_table.each_key do |method_name|
! define_method(method_name.to_sym) do |*args|
! begin
! app = load_module(method_name).new
! opt = app.define_options(OptionParser.new)
! opt.banner = "Usage: #{$0} #{method_name} [options]"
! app.main(*opt.parse(*args))
! rescue OptionParser::InvalidOption => err
! puts err.message
! puts opt.help
! rescue ArgumentError
! puts opt.help
end
end
! end
!
! ##
! # load module and return the module object.
! def load_module(module_name)
! unless @@module_table.has_key? module_name
! raise NoMethodError, "Unknown command '#{module_name}'"
! end
! require_file = @@module_table[module_name]['require']
! include_name = @@module_table[module_name]['include']
! unless File.exists?(require_file)
! raise Errno::ENOENT, "No such file: #{require_file}"
! end
!
! unless require require_file
! raise LoadError, "No such file to load: #{require_file}"
! end
! unless Aversa.constants.include?(include_name)
! raise NameError, "uninitialized constant: #{include_name}"
end
- Aversa.const_get(include_name)
end
end
- end
Aversa::Application.main(*ARGV) if $0 == __FILE__
--- 75,190 ----
module Aversa
! class Application
! ##
! # If restrict file/module naming rules,
! # we can generate this table from exists files, dynamically.
! #
+ @@module_table = {
+ 'download' => { 'require' => 'bt-downloader.rb',
+ 'include' => 'Download' },
+ 'showinfo' => { 'require' => 'bt-metainfo-viewer.rb',
+ 'include' => 'MetaInfoView' },
+ 'makeinfo' => { 'require' => 'bt-metainfo-maker.rb',
+ 'include' => 'MetaInfoMak' },
+ 'track' => { 'require' => 'bt-tracker.rb',
+ 'include' => 'Track' },
+ 'rename' => { 'require' => 'bt-rename.rb',
+ 'include' => 'MetaInfoRename' },
+ }
! ##
! # Each module can supply meta information for help and version,
! # by implementing these special methods:
! #
! def self.help
! "(Aversa) Help message"
! end
+ def self.version
+ "(Aversa) Version v0.0.1"
+ end
##
! # Here is a main entry point.
! def self.main(*argv)
! command = argv.shift
! app = Aversa::Application.new
!
! ##
! # If command is a toplevel command, and if the top level command has arguments
! # aversa help ... show 'aversa' s help
! # aversa help showinfo ... show 'showinfo' module's help
! #
! case command
! when '-h', '--help', 'help', nil
! if argv.empty?
! puts help
! exit
! else
! # change options (-h showinfo --> showinfo --help)
! command = argv.shift || :dummy
! argv.unshift('--help')
! end
! when '-v', '--version', 'version'
! puts version
exit
end
! begin
! app.__send__(command, *argv)
! rescue NoMethodError
! puts help
! end
end
! ##
! # Generate methods for each module_table's keys.
! @@module_table.each_key do |method_name|
! define_method(method_name.to_sym) do |*args|
! begin
! app = load_module(method_name).new
! opt = app.define_options(OptionParser.new)
! opt.banner = "Usage: #{$0} #{method_name} [options]"
! app.main(*opt.parse(*args))
! rescue OptionParser::InvalidOption => err
! puts err.message
! puts opt.help
! rescue ArgumentError
! puts opt.help
! end
end
end
!
! ##
! # load module and return the module object.
! def load_module(module_name)
! unless @@module_table.has_key? module_name
! raise NoMethodError, "Unknown command '#{module_name}'"
! end
! require_file = @@module_table[module_name]['require']
! include_name = @@module_table[module_name]['include']
! unless File.exists?(require_file)
! raise Errno::ENOENT, "No such file: #{require_file}"
! end
!
! unless require require_file
! raise LoadError, "No such file to load: #{require_file}"
! end
! unless Aversa.constants.include?(include_name)
! raise NameError, "uninitialized constant: #{include_name}"
! end
! Aversa.const_get(include_name)
end
end
end
Aversa::Application.main(*ARGV) if $0 == __FILE__
Index: bt-tracker.rb
===================================================================
RCS file: /var/cvs/aversa/aversa/bin/bt-tracker.rb,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** bt-tracker.rb 10 Sep 2004 00:01:57 -0000 1.5
--- bt-tracker.rb 10 Sep 2004 00:32:39 -0000 1.6
***************
*** 154,170 ****
require 'application-base'
module Aversa
! module Track < ApplicationBase
! DEFAULT_PORT = 6969
!
! def define_options(opt)
! super
! opt.on('-p [VAL]', '--port [VAL]', 'tracker port'){|v| @port = v }
! end
!
! def main(port=DEFAULT_PORT, *argv)
! @port ||= port
!
! tracker = BitTorrent::Tracker.new( :Port => @port )
! tracker.start
end
end
--- 154,171 ----
require 'application-base'
module Aversa
! class Track < ApplicationBase
! DEFAULT_PORT = 6969
!
! def define_options(opt)
! super
! opt.on('-p [VAL]', '--port [VAL]', 'tracker port'){|v| @port = v }
! end
!
! def main(port=DEFAULT_PORT, *argv)
! @port ||= port
!
! tracker = BitTorrent::Tracker.new( :Port => @port )
! tracker.start
! end
end
end
Index: bt-rename.rb
===================================================================
RCS file: /var/cvs/aversa/aversa/bin/bt-rename.rb,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** bt-rename.rb 10 Sep 2004 00:01:57 -0000 1.3
--- bt-rename.rb 10 Sep 2004 00:32:39 -0000 1.4
***************
*** 13,38 ****
module Aversa
! class MetaInfoRename < ApplicationBase
! def define_options(opt)
! super
! opt.on('-f [VAL]', '--file [VAL]', 'metainfo file'){ |v| @file = v }
! opt.on('-n [VAL]', '--name [VAL]', 'new name') {|v| @name = n }
! end
! def main(file=nil, name=nil)
! @file ||= file
! @name ||= name
!
! if @file and @name and File.exists? @file
! metainfo = MetaInfo.new(@file)
! metainfo['info']['name'] = @name
! metainfo.save(@file)
! else
! puts @opt.help
end
end
end
- end
-
Aversa::MetaInfoRename.main(*ARGV) if $0 == __FILE__
--- 13,37 ----
module Aversa
! class MetaInfoRename < ApplicationBase
! def define_options(opt)
! super
! opt.on('-f [VAL]', '--file [VAL]', 'metainfo file'){ |v| @file = v }
! opt.on('-n [VAL]', '--name [VAL]', 'new name') {|v| @name = n }
! end
! def main(file=nil, name=nil)
! @file ||= file
! @name ||= name
!
! if @file and @name and File.exists? @file
! metainfo = MetaInfo.new(@file)
! metainfo['info']['name'] = @name
! metainfo.save(@file)
! else
! puts @opt.help
! end
end
end
end
Aversa::MetaInfoRename.main(*ARGV) if $0 == __FILE__
Index: bt-metainfo-viewer.rb
===================================================================
RCS file: /var/cvs/aversa/aversa/bin/bt-metainfo-viewer.rb,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** bt-metainfo-viewer.rb 10 Sep 2004 00:01:57 -0000 1.4
--- bt-metainfo-viewer.rb 10 Sep 2004 00:32:39 -0000 1.5
***************
*** 19,49 ****
module Aversa
! class MetaInfoView < ApplicationBase
! def define_options(opt)
! super
! opt.on('-f [VAL]', '--file [VAL]', 'metainfo file'){|v| @file = v }
! end
! def main(file)
! @file ||= file
!
! metainfo = MetaInfo.new( @file )
! puts "-------------------" * 4
! puts "creation date : %s" % Time.at(metainfo.date) # ['creation date']
! puts "comment : %s" % metainfo['comment']
! puts "announce list : "
! metainfo.announces.each do |announce|
! puts " %s" % announce
end
- puts
- puts "[Info]"
- puts " name : %s " % metainfo["info"]["name"]
- puts " length : %d bytes" % metainfo.get_file_length
- puts " piece length : %d " % metainfo["info"]["piece length"]
- puts "-------------------" * 4
end
end
- end
Aversa::MetaInfoView.new.main(*ARGV) if $0 == __FILE__
--- 19,49 ----
module Aversa
! class MetaInfoView < ApplicationBase
! def define_options(opt)
! super
! opt.on('-f [VAL]', '--file [VAL]', 'metainfo file'){|v| @file = v }
! end
! def main(file)
! @file ||= file
!
! metainfo = MetaInfo.new( @file )
! puts "-------------------" * 4
! puts "creation date : %s" % Time.at(metainfo.date) # ['creation date']
! puts "comment : %s" % metainfo['comment']
! puts "announce list : "
! metainfo.announces.each do |announce|
! puts " %s" % announce
! end
! puts
! puts "[Info]"
! puts " name : %s " % metainfo["info"]["name"]
! puts " length : %d bytes" % metainfo.get_file_length
! puts " piece length : %d " % metainfo["info"]["piece length"]
! puts "-------------------" * 4
end
end
end
Aversa::MetaInfoView.new.main(*ARGV) if $0 == __FILE__
More information about the Aversa-commits
mailing list