From: <jj...@us...> - 2004-02-06 23:50:01
|
Update of /cvsroot/ngetsuite/ngetsuite In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11482 Modified Files: HOWTO daemon.rb ngetsuite.rb resetdb.rb sampleconfig testngetcache.rb Log Message: config: defaults are in config.rb (no need to .fetch), added 'daemon_debug', 'daemon_host', 'dbhost' ; changed 'autostart_httpd' to 'httpd_autostart', 'extern_nfo_update' to 'extern_nfos_update', 'port' to 'daemon_port' ; reqesting a config keyword inexisting raises an exception group: somewhat gives a success status, fixed shortname, *sexy* headers update global: removed some global variables ($dbh->Db.dbh..) Index: HOWTO =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/HOWTO,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** HOWTO 4 Feb 2004 07:13:04 -0000 1.3 --- HOWTO 6 Feb 2004 23:46:58 -0000 1.4 *************** *** 5,8 **** --- 5,10 ---- Set up the config file cp sampleconfig ~/.ngetsuite + or + ./ngetsuite.rb -C ~/.ngetsuite vim ~/.ngetsuite the most important is the login/pass for the database. Index: daemon.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/daemon.rb,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** daemon.rb 3 Feb 2004 21:29:38 -0000 1.11 --- daemon.rb 6 Feb 2004 23:46:59 -0000 1.12 *************** *** 2,8 **** require 'drb' ! require 'dbi' require 'ngetsuite/config' homedir = ENV['HOME'] + File::Separator conf_file = homedir + '.ngetsuite' --- 2,10 ---- require 'drb' ! require 'ngetsuite/utils' require 'ngetsuite/config' + include NgetSuite::Utils + # TODO handle_opts -d -c homedir = ENV['HOME'] + File::Separator conf_file = homedir + '.ngetsuite' *************** *** 11,53 **** require 'ngetsuite/downloadmanager' ! dbuser = $config.fetch('dbuser', 'nget') ! dbname = $config.fetch('dbname', 'ngetcache') ! ! if not $config.include? 'dbpass' ! puts 'Missing required value in config file : dbpass' ! exit 1 ! end ! $dbh = DBI.connect("DBI:Mysql:#{dbname}", dbuser, $config['dbpass']) ! $nget = $config.fetch('nget', '/usr/bin/nget') ! basedir = $config.fetch('basedir', homedir + 'ngetsuite') ! max_dls = $config.fetch('max_dls', 2) ! port = $config.fetch('port', 12345) ! logfile = $config.fetch('daemon_log', basedir + 'daemon.log') $logger = File.new(logfile, 'a') - $debug = $config.fetch('debug', false) def log(msg=nil) ! $logger.puts "[#{Time.now.localtime}] #{msg}" if (msg) $logger.flush end ! puts "Starting daemon with log file '#{logfile}'" ! $manager = NgetSuite::DownloadManager.new(max_dls, basedir) drburl = 'druby://localhost:' + port.to_s ! DRb.start_service(drburl, $manager) ! $thingsrunning = [$manager] ! trap('INT') { $thingsrunning.each{ |t| t.shutdown }; DRb.stop_service } ! trap('TERM') { $thingsrunning.each{ |t| t.shutdown }; DRb.stop_service } ! if $config.fetch('autostart_httpd', false) or $config.fetch('httpd_autostart', false) require 'webrick' include WEBrick ! port = $config.fetch('httpd_port', 2000) puts "Starting web server on port #{port}" log 'Web server start' --- 13,51 ---- require 'ngetsuite/downloadmanager' ! dbuser = $config['dbuser'] ! dbname = $config['dbname'] ! $config['debug'] = true if $config['daemon_debug'] ! $nget = $config['nget'] ! basedir = $config['basedir'] ! max_dls = $config['max_dls'] ! port = $config['daemon_port'] ! logfile = $config['daemon_log'] $logger = File.new(logfile, 'a') def log(msg=nil) ! $logger.puts "[#{Time.now.localtime.strftime('%d/%m %H:%M:%S')}] #{msg}" if (msg) $logger.flush end ! puts "Starting daemon with log file '#{green logfile}'" ! manager = NgetSuite::DownloadManager.new(max_dls, basedir) ! ! manager.start if $config['daemon_autostart'] drburl = 'druby://localhost:' + port.to_s ! DRb.start_service(drburl, manager) ! $thingsrunning = [manager] ! trap('INT') { debug red('Ok, ok, i die') ; $thingsrunning.each{ |t| t.shutdown }; DRb.stop_service } ! trap('TERM') { debug red('Ok, ok, i die') ; $thingsrunning.each{ |t| t.shutdown }; DRb.stop_service } ! if $config['httpd_autostart'] require 'webrick' include WEBrick ! port = $config['httpd_port'] puts "Starting web server on port #{port}" log 'Web server start' Index: ngetsuite.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/ngetsuite.rb,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** ngetsuite.rb 4 Feb 2004 01:45:38 -0000 1.15 --- ngetsuite.rb 6 Feb 2004 23:46:59 -0000 1.16 *************** *** 1,22 **** #!/usr/bin/env ruby ! Dir.chdir(__FILE__.sub(/\/[^\/]*$/, '')) ! ! $opts = Hash.new ! $opts['config-file'] = ENV['HOME'] + File::Separator + '.ngetsuite' unless $opts['config-file'] ! ! require 'ngetsuite/config' ! $config = NgetSuite::Config.new($opts['config-file']) require 'getoptlong' - require 'dbi' - require 'ngetsuite/core' - - # reste -p, -w, -y $args = Array[ [ '--debug', '-d', GetoptLong::NO_ARGUMENT, 'Enable debug mode'], [ '--help', '-h', GetoptLong::NO_ARGUMENT, 'Shows this message'], [ '--config-file', '-c', GetoptLong::REQUIRED_ARGUMENT, 'file', 'Use another config file (def: $HOME/.ngetsuite)' ], [ '--show-groups', '-s', GetoptLong::NO_ARGUMENT, 'List all known groups'], [ '--add-group', '-a', GetoptLong::REQUIRED_ARGUMENT, 'fullname[,alias,dir,desc]', 'Add a group'], --- 1,17 ---- #!/usr/bin/env ruby ! wd = __FILE__.sub(/\/[^\/]*$/, '') ! Dir.chdir(wd) if FileTest.directory? wd require 'getoptlong' $args = Array[ [ '--debug', '-d', GetoptLong::NO_ARGUMENT, 'Enable debug mode'], + [ '--no-debug', '-D', GetoptLong::NO_ARGUMENT, 'Disable debug mode'], [ '--help', '-h', GetoptLong::NO_ARGUMENT, 'Shows this message'], [ '--config-file', '-c', GetoptLong::REQUIRED_ARGUMENT, 'file', 'Use another config file (def: $HOME/.ngetsuite)' ], + ['--write-config', '-C', GetoptLong::REQUIRED_ARGUMENT, 'file', 'Write a defaut config file'], + # end of options, begin of actions + nil, [ '--show-groups', '-s', GetoptLong::NO_ARGUMENT, 'List all known groups'], [ '--add-group', '-a', GetoptLong::REQUIRED_ARGUMENT, 'fullname[,alias,dir,desc]', 'Add a group'], *************** *** 27,32 **** [ '--show-nfo', '-n', GetoptLong::REQUIRED_ARGUMENT, 'nb_nfo[,groupid]', 'Prints the specified nfo' ], [ '--queue-article', '-q', GetoptLong::REQUIRED_ARGUMENT, 'groupid,articleid', 'Adds an article to the download queue'], ! [ '--queue-regexp', '-r', GetoptLong::REQUIRED_ARGUMENT, 'groupid,regexp[,prio,period]', 'Adds a regexp to the download queue' ], ! [ '--show-queue', '-t', GetoptLong::OPTIONAL_ARGUMENT, 'groupid', 'Shows the current download queue'], [ '--start-manager', '-m', GetoptLong::NO_ARGUMENT, 'Launches the download manager'], [ '--show-status', '-z', GetoptLong::NO_ARGUMENT, 'Prints the manager status'], --- 22,27 ---- [ '--show-nfo', '-n', GetoptLong::REQUIRED_ARGUMENT, 'nb_nfo[,groupid]', 'Prints the specified nfo' ], [ '--queue-article', '-q', GetoptLong::REQUIRED_ARGUMENT, 'groupid,articleid', 'Adds an article to the download queue'], ! [ '--queue-regexp', '-r', GetoptLong::REQUIRED_ARGUMENT, 'gid,regexp[,prio,period]', 'Adds a regexp to the download queue' ], ! [ '--show-queue', '-t', GetoptLong::OPTIONAL_ARGUMENT, '[groupid]', 'Shows the current download queue'], [ '--start-manager', '-m', GetoptLong::NO_ARGUMENT, 'Launches the download manager'], [ '--show-status', '-z', GetoptLong::NO_ARGUMENT, 'Prints the manager status'], *************** *** 34,38 **** [ '--set-priority', '-f', GetoptLong::REQUIRED_ARGUMENT, 'queueid,prio', 'Changes the priority of the specified queue' ], [ '--set-status', '-i', GetoptLong::REQUIRED_ARGUMENT, 'queueid,status', 'Changes the status of the specified queue'], ! [ '--delete-queue', '-x', GetoptLong::REQUIRED_ARGUMENT, 'queueid', 'Changes the status of the specified queue'], [ '--set-limit', '-j', GetoptLong::REQUIRED_ARGUMENT, 'limit', 'Sets the maximum limit of parallel downloads'], [ '--set-poll-interval', '-o', GetoptLong::REQUIRED_ARGUMENT, 'intervall', 'Sets the polling intervall of the download manager'], --- 29,33 ---- [ '--set-priority', '-f', GetoptLong::REQUIRED_ARGUMENT, 'queueid,prio', 'Changes the priority of the specified queue' ], [ '--set-status', '-i', GetoptLong::REQUIRED_ARGUMENT, 'queueid,status', 'Changes the status of the specified queue'], ! [ '--delete-queue', '-x', GetoptLong::REQUIRED_ARGUMENT, 'queueid', 'Delete the specified queue'], [ '--set-limit', '-j', GetoptLong::REQUIRED_ARGUMENT, 'limit', 'Sets the maximum limit of parallel downloads'], [ '--set-poll-interval', '-o', GetoptLong::REQUIRED_ARGUMENT, 'intervall', 'Sets the polling intervall of the download manager'], *************** *** 41,67 **** ] ! opts = GetoptLong.new(*($args.collect { |c| c[0..2] })) opts.each {|opt, arg| $opts[opt.sub(/^-+/, '')] = arg } ! $tempdir = "/tmp/ngetupdate.#{Process.pid}" ! Dir.mkdir $tempdir ! ! begin ! Dir.mkdir $config['basedir'] ! rescue Errno::EEXIST ! # puts "#{$config['basedir']} already exists" ! end ! ! $dbh = DBI.connect("DBI:Mysql:#{$config['dbname']}", $config['dbuser'], $config['dbpass']) ! begin ! core = NgetSuite::Core.new() ! core.handle_opts() if core ! ensure ! $dbh.disconnect if $dbh ! `rm -rf #{$tempdir}` ! end --- 36,52 ---- ] ! opts = GetoptLong.new(*($args.compact.collect { |c| c[0..2] })) + $opts = Hash.new opts.each {|opt, arg| $opts[opt.sub(/^-+/, '')] = arg } + require 'ngetsuite/config' + $config = NgetSuite::Config.new($opts.fetch('config-file', ENV['HOME'] + File::Separator + '.ngetsuite')) ! basedir = $config['basedir'] ! Dir.mkdir basedir unless FileTest.directory? basedir ! require 'ngetsuite/core' ! NgetSuite::Core.new().handle_opts() Index: resetdb.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/resetdb.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** resetdb.rb 4 Feb 2004 05:56:49 -0000 1.1 --- resetdb.rb 6 Feb 2004 23:46:59 -0000 1.2 *************** *** 6,13 **** require 'dbi' ! sql = File.open('ngetcache.sql') dbh = DBI.connect("DBI:Mysql:#{config['dbname']}", config['dbuser'], config['dbpass']) cmd = '' ! sql.each { |l| next if l =~ /^(#|\s*$)/ if l=~/CREATE TABLE (`.*`)/ --- 6,13 ---- require 'dbi' ! sqlfile = File.open('ngetcache.sql') dbh = DBI.connect("DBI:Mysql:#{config['dbname']}", config['dbuser'], config['dbpass']) cmd = '' ! sqlfile.each { |l| next if l =~ /^(#|\s*$)/ if l=~/CREATE TABLE (`.*`)/ *************** *** 21,25 **** end } ! dbh.disconnect if $dbh ! sql.close puts 'done' --- 21,25 ---- end } ! dbh.disconnect ! sqlfile.close puts 'done' Index: sampleconfig =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/sampleconfig,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** sampleconfig 4 Feb 2004 07:13:04 -0000 1.9 --- sampleconfig 6 Feb 2004 23:46:59 -0000 1.10 *************** *** 1,5 **** --- 1,10 ---- + # file to copy to ~/.ngetsuite after customisation + # for windows users, use '\' in pathes instead of '/', and use -c to specify this file path + # ngetsuite.rb --write-config gives this file without the comments + ######################### # Database parameters # + dbhost = 'localhost' dbuser = 'nget' dbpass = 'cache4pdv' *************** *** 21,24 **** --- 26,31 ---- # where to download unless otherwise specified basedir = '/home/nget/testdl' + # ngetsuite will create subdirectories here + tempdir = '/tmp' *************** *** 29,38 **** max_dls = 3 # the port for communication with the daemon ! port = 12345 daemon_log = '/tmp/nget-daemon.log' # should we automatically restart downloads in state STOPPED ? resume_downloads = false # should the daemon look for eligible queues on startup or wait for -m ! autostart = true --- 36,47 ---- max_dls = 3 # the port for communication with the daemon ! daemon_port = 12345 daemon_log = '/tmp/nget-daemon.log' # should we automatically restart downloads in state STOPPED ? resume_downloads = false # should the daemon look for eligible queues on startup or wait for -m ! daemon_autostart = true ! # you can view informative messages with this on ! daemon_debug = false *************** *** 43,46 **** --- 52,56 ---- # coma-separated list of the shortnames of the groups for which the program will not try to update the headers (but will still parse them and dl nfos) extern_headers_update = '' + extern_nfos_fetch = '' Index: testngetcache.rb =================================================================== RCS file: /cvsroot/ngetsuite/ngetsuite/testngetcache.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** testngetcache.rb 4 Feb 2004 03:07:56 -0000 1.2 --- testngetcache.rb 6 Feb 2004 23:46:59 -0000 1.3 *************** *** 7,17 **** end puts 'Testing cache for ' + ARGV[0] ! cache = NgetCache.new(ARGV[0], NgetSuite::Config.new(ENV['HOME']+'/'+'.ngetsuite')['cachedir']) - cache.files.sort! { |x,y| - x.subject <=> y.subject - }.each { |file| - puts file.subject - } puts 'Done.' --- 7,15 ---- end puts 'Testing cache for ' + ARGV[0] ! cache = NgetCache.new(ARGV[0], NgetSuite::Config.new(ENV['HOME']+'/'+'.ngetsuite')['cachedir'], 100) ! puts 'read' ! cache.writeoldformat = true ! cache.save_tofile puts 'Done.' |