From: Yoann G. <jj...@us...> - 2004-09-03 10:43:10
|
Update of /cvsroot/ngetsuite/ngetsuite/ngetsuite In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25191/ngetsuite Modified Files: core.rb db.rb downloader.rb group.rb nfo.rb queue.rb Log Message: code cleanup in core, more to come added -M option to change the value for the regex of a queue Index: downloader.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/ngetsuite/downloader.rb,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** downloader.rb 6 Jul 2004 10:41:21 -0000 1.35 --- downloader.rb 3 Sep 2004 10:42:59 -0000 1.36 *************** *** 199,203 **** parent.stop rescue Object => e ! puts 'Exception while parsing nget output: '+e.class.to_s + "\n" + e.backtrace.join("\n") parent.stop raise --- 199,203 ---- parent.stop rescue Object => e ! puts 'Exception while parsing nget output: '+e.class.to_s, e.backtrace parent.stop raise Index: group.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/ngetsuite/group.rb,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** group.rb 3 Sep 2004 09:12:03 -0000 1.49 --- group.rb 3 Sep 2004 10:42:59 -0000 1.50 *************** *** 6,10 **** module NgetSuite ! class NoSuchGroupException < Exception attr_reader :groupindex --- 6,10 ---- module NgetSuite ! class NoSuchGroupException < NgetsuiteException attr_reader :groupindex Index: core.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/ngetsuite/core.rb,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** core.rb 19 Jun 2004 13:27:49 -0000 1.41 --- core.rb 3 Sep 2004 10:42:59 -0000 1.42 *************** *** 1,3 **** ! # todo: move requires in the blocks needing them (move exception handling as well) require 'ngetsuite/utils' require 'ngetsuite/queue' --- 1,4 ---- ! class NgetSuite::NgetsuiteException < Exception ! end require 'ngetsuite/utils' require 'ngetsuite/queue' *************** *** 10,14 **** module NgetSuite ! class ManagerNotFoundException < Exception attr_reader :address --- 11,15 ---- module NgetSuite ! class ManagerNotFoundException < NgetsuiteException attr_reader :address *************** *** 22,26 **** end ! class NoSuchArticleException < Exception attr_reader :number --- 23,27 ---- end ! class NoSuchArticleException < NgetsuiteException attr_reader :number *************** *** 35,39 **** ! class NoSuchNfoException < Exception attr_reader :number --- 36,40 ---- ! class NoSuchNfoException < NgetsuiteException attr_reader :number *************** *** 63,67 **** end ! def search_group(groupindex, filter) Group.getgroup(groupindex).search(filter) end --- 64,68 ---- end ! def search(groupindex, filter) Group.getgroup(groupindex).search(filter) end *************** *** 173,177 **** end ! def printusage print "Usage: #{$0} command [options]\n\n" puts 'List of options:' --- 174,191 ---- end ! def help(topic = nil) ! if (topic) ! item = $args.find{ |a| a[0] == '--'+topic if a } ! arg = "#{item[0]}, #{item[1]}" ! if item.length == 5 ! arg += " #{item[3]}" ! desc = item[4] ! else ! desc = item[3] ! end ! puts "#{arg}\t#{desc}" ! return ! end ! print "Usage: #{$0} command [options]\n\n" puts 'List of options:' *************** *** 192,309 **** end ! # TODO : faudrait généraliser le split des arguments des options a coup de yield ! # en fait on doit meme pouvoir appeler la fonction qui a le meme nom que ! # l'argument de ligne de commande (faudra filtrer pour éviter '--Dir.rmdir /':) def handle_opts $opts.each do |opt, arg| begin ! case opt ! when 'debug' ! $config['debug']=true ! when 'no-debug' ! $config['debug']=false ! when 'write-config' ! $config.save(arg) ! when 'test' ! test(arg) ! when 'show-groups' ! Group.show ! when 'add-group' ! args = arg.split(',') ! add_group(*args); ! when 'delete-group' ! delete_group(arg) ! when 'update-group' ! update_group(arg) ! when 'update-all-groups' ! update_group ! when 'set-group-category' ! args = arg.split(',') ! group_set_category(*args) ! when 'set-ignore-regexp' ! args = arg.split(',') ! group_set_ignore_regexp(*args) ! when 'list-nfos' ! list_nfos(arg) ! when 'list-releases' ! list_releases(arg) ! when 'show-nfo' ! args = arg.split(',') ! show_nfo(*args) ! when 'queue-article' ! args = arg.split(',') ! queue_article(*args) ! when 'queue-regexp' ! args = arg.split(',') ! queue_regexp(*args) ! when 'delete-queue' ! arg.split(',').each{ |q| Queue.delete(q, true) } ! when 'show-queue' ! args = arg.split(',') ! Queue.show(*args) ! when 'start-manager' ! start_manager ! when 'show-status' ! show_status ! when 'search' ! args = arg.split(',') ! search_group(*args) ! when 'search-releases' ! args = arg.split(',') ! search_releases(*args) ! when 'set-period' ! args = arg.split(',') ! set_period(*args) ! when 'set-priority' ! args = arg.split(',') ! set_priority(*args) ! when 'set-status' ! args = arg.split(',') ! set_status(*args) ! when 'set-limit' ! begin ! n = Integer(arg) ! rescue ArgumentError ! raise ArgumentError.new("Incorrect args : #{arg}") ! end ! get_manager.max_dlers = n ! when 'set-poll-interval' ! begin ! n = Integer(arg) ! rescue ArgumentError ! raise ArgumentError.new("Incorrect args : #{arg}") ! end ! get_manager.poll_interval = n ! when 'stop-download' ! q = Queue.getqueue(arg) ! # Simple check on the status of the queue ! if q._status == 'PROCESSING' ! get_manager.stop_downloader(arg) ! else ! puts "No current download for this queue" ! end ! when 'show-next-queueitem' ! q = Queue.nextqueue ! if q != nil ! puts q ! else ! puts "Nothing available to download" ! end ! when 'help' ! printusage ! end # end of case ! rescue NoSuchQueueException => e ! puts e.message ! rescue NoSuchGroupException => e ! puts e.message ! rescue NoSuchNfoException => e ! puts e.message ! rescue Exception => e puts e.message - print e.backtrace.join("\n") rescue ArgumentError => e puts e.message ! print e.backtrace.join("\n") ! printusage rescue DBI::DatabaseError => e puts "An error occurred" --- 206,286 ---- end ! def debug ! $config['debug'] = true ! end ! ! def no_debug ! $config['debug'] = false ! end ! ! def write_config(fname) ! $config.save(fname) ! end ! ! def show_groups ! Group.show ! end ! ! def update_all_groups ! update_group ! end ! ! def delete_queue(*list) ! list.each { |q| Queue.delete(q, true) } ! end ! ! def show_queue(*args) ! Queue.show(*args) ! end ! ! def set_limit(l) ! getmanager.max_dlers = l.to_i ! end ! ! def set_poll_interval(i) ! getmanager.poll_interval = i.to_i ! end ! ! def stop_download(q) ! q = Queue.getqueue(q) ! # Simple check on the status of the queue ! if q._status == 'PROCESSING' ! get_manager.stop_downloader(arg) ! else ! puts "No current download for this queue" ! end ! end ! ! def show_next_queueitem ! q = Queue.nextqueue ! if q != nil ! puts q ! else ! puts "Nothing available to download" ! end ! end ! ! def set_regex(q, r) ! q = Queue.getqueue(q) ! q._value = r ! q.sync_to_db ! end ! ! # Go! def handle_opts $opts.each do |opt, arg| begin ! # Call the method which name is opt.s/-/_/g, ! # with arg.split(',') as args ! args = nil ! args = arg.split(',') if arg ! fn = opt.gsub('-', '_') ! send(fn, *args) if self.respond_to? fn ! ! rescue NgetsuiteException => e puts e.message rescue ArgumentError => e puts e.message ! help(opt) rescue DBI::DatabaseError => e puts "An error occurred" *************** *** 313,319 **** puts "Problem connecting to the manager" puts e ! ensure ! # Nothing ! end #end of begin .. rescue .. ensure end # end $opts.each do end #end handle_opts --- 290,299 ---- puts "Problem connecting to the manager" puts e ! rescue Object => e ! puts "An unknown error Occured !" ! puts e.class.ancestors ! puts "#{e}" ! raise ! end end # end $opts.each do end #end handle_opts Index: nfo.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/ngetsuite/nfo.rb,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** nfo.rb 19 Jun 2004 13:27:49 -0000 1.7 --- nfo.rb 3 Sep 2004 10:42:59 -0000 1.8 *************** *** 13,17 **** groupindex = Group.getindex(groupid) if (n > 1000) ! return Nfo.new(n, groupindex, true) end --- 13,21 ---- groupindex = Group.getindex(groupid) if (n > 1000) ! begin ! v = Nfo.new(n, groupindex, true) ! rescue NoSuchTupleException ! raise NoSuchNfoException.new(n) ! end end Index: queue.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/ngetsuite/queue.rb,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** queue.rb 19 Jun 2004 13:27:49 -0000 1.27 --- queue.rb 3 Sep 2004 10:42:59 -0000 1.28 *************** *** 14,18 **** REGEXP = 'REGEXP' ! class NoSuchQueueException < Exception attr_reader :queueid --- 14,18 ---- REGEXP = 'REGEXP' ! class NoSuchQueueException < NgetsuiteException attr_reader :queueid *************** *** 26,30 **** end ! class UnknownQueueTypeException < Exception attr_reader :type --- 26,30 ---- end ! class UnknownQueueTypeException < NgetsuiteException attr_reader :type Index: db.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/ngetsuite/db.rb,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** db.rb 20 Feb 2004 16:44:39 -0000 1.24 --- db.rb 3 Sep 2004 10:42:59 -0000 1.25 *************** *** 5,9 **** ## Exceptions ! class TableNotFoundException < Exception def initialize(klass) @klass = klass --- 5,9 ---- ## Exceptions ! class TableNotFoundException < NgetsuiteException def initialize(klass) @klass = klass *************** *** 15,19 **** end ! class MissingValue < Exception def initialize(c, missing_value) --- 15,19 ---- end ! class MissingValue < NgetsuiteException def initialize(c, missing_value) *************** *** 27,31 **** end ! class NotImplemented < Exception end --- 27,41 ---- end ! class NoSuchTupleException < NgetsuiteException ! def initialize(m) ! @m = m ! end ! ! def message ! "No such data in database: #{@m}" ! end ! end ! ! class NotImplemented < NgetsuiteException end *************** *** 223,234 **** # debug 'DB: '+ req sth = Db.dbh.execute req ! hash = sth.fetch_hash ! fields(self.class).each { |name,field| ! next if field.key? ! if hash.has_key?(name) && hash[name] ! value = field.fromdb(hash[name]) ! m = method('_'+name+'=').call(value) ! end ! } sth.finish end --- 233,247 ---- # debug 'DB: '+ req sth = Db.dbh.execute req ! if (hash = sth.fetch_hash) ! fields(self.class).each { |name,field| ! next if field.key? ! if hash.has_key?(name) && hash[name] ! value = field.fromdb(hash[name]) ! m = method('_'+name+'=').call(value) ! end ! } ! else ! raise NoSuchTupleException.new(req) ! end sth.finish end |