[Abtlinux-svn] SF.net SVN: abtlinux: [203] src/trunk/AbtQueueManager.rb
Status: Alpha
Brought to you by:
eschabell
From: <esc...@us...> - 2006-11-18 15:23:16
|
Revision: 203 http://svn.sourceforge.net/abtlinux/?rev=203&view=rev Author: eschabell Date: 2006-11-18 07:23:11 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Constructor now constains a log directory check. Implemented addPackageToQueue method. Modified Paths: -------------- src/trunk/AbtQueueManager.rb Modified: src/trunk/AbtQueueManager.rb =================================================================== --- src/trunk/AbtQueueManager.rb 2006-11-18 15:21:40 UTC (rev 202) +++ src/trunk/AbtQueueManager.rb 2006-11-18 15:23:11 UTC (rev 203) @@ -38,6 +38,51 @@ # <b>RETURN</b> <i>AbtQueueManager</i> - an initialized AbtQueueManager object. ## def initialize + if ( !File.directory?( $ABT_LOGS ) ) + FileUtils.mkdir_p( $ABT_LOGS ) # initialize logs. + end end -end \ No newline at end of file + ## + # Add a given package to the given queue. If package already in + # the queue then it will not be added twice and return a positive + # answer. + # + # <b>PARAM</b> <i>String</i> - the package to be added to the queue. + # <b>PARAM</b> <i>String</i> - the queue to add the package to. + # + # <b>RETURN</b> <i>boolean</i> - true if package added/exists to/in install + # queue, otherwise false. + ## + def addPackageToQueue( package, queue ) + queueFile = "#{$ABT_LOGS}/#{queue}.log" + logger = AbtLogManager.new + + if ( log = File.new( queueFile, File::WRONLY|File::APPEND|File::CREAT, 0644 ) ) + # pickup queue contents to ensure no duplicates. + checkingQueue = IO.readlines( queueFile ) + + # endsure no duplicates. + matched = false + checkingQueue.each do |entry| + entryName = entry.split( '|' ) + if ( entryName[0] == package ) + matched = true + end + end + + # check if package exists, otherwise add. + if ( !matched ) + log.puts "#{package}|#{$TIMESTAMP}" + logger.logToJournal( "Added #{package} to #{queue} queue." ) + else + logger.logToJournal( "Did not add #{package} to #{queue}, already exists." ) + end + + log.close + return true + end + + return false + end +end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |