Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SCRIPT RUBY] Manage your packages *-9999.ebuild !
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Duplicate Threads
View previous topic :: View next topic  
Author Message
man in the hill
Veteran
Veteran


Joined: 15 Dec 2005
Posts: 1552
Location: Madinina

PostPosted: Mon Sep 11, 2006 6:12 am    Post subject: [SCRIPT RUBY] Manage your packages *-9999.ebuild ! Reply with quote

Hello everybody :D ,



Having some packages marked 9999 (cvs, svn, git) to manage, I have create a small script in ruby to recover the names of these packages thanks to the ebuilds being in a directory (and its under directory ) given (mine is: /usr/local/overlays or I manage three overlays but each one indicates the directory of its choice so that the script is faster...), to remove duplicate packages, and to present them to emerge with the option -av but you can desactivate it with the option -w ...



I.) Source Code


_-_ The name of this script is : kmikaze (** for those which like to take risks by installing packages cvs, svn, git 8) )


_-_ This Code


Code:

#!/usr/bin/ruby   -w







###  Distributed under the terms of the GNU General Public License v2
#
###  kmikaze comes with ABSOLUTELY  NO WARRANTY ..!
#
###  Author :   Man in the Hill .
#
###  Great thanks to  Mr Professor X  !
   




# == Synopsis
#
# Search for files ebuild cvs, svn, git in a directory (and under directories) in an iterative way !
# Launch kmikaze and two small questions will be put once and for all...
#
# == Usage
#
# kmikaze [OPTION]
#
# -n, --new
# To redefine a new directory by defaultt.
#
# -w, --without-av
# Launch emerge without -av .

   






require  'getoptlong'   
require  'fileutils'
require  'pstore'

include   FileUtils
   


class Ebuild

   def initialize()
      
      @marge = 70
   
   end
   
   
   def cvssvngit()
   
   
   # Check  in the form of table files containing motif "-9999.ebuild" .
   tab_ebuild = %x( ls -R )::grep(/-9999.ebuild$/)::uniq
   
   # Name of the file or the names of the packages will be write!
   $temp_9999 = "/tmp/emerge_9999"
   
   # Creation and opening of the output file !
   begin
   new_file = File::open("#{$temp_9999}",'w')
   
   rescue SystemCallError
   $stderr.puts "Failed ! Sorry !!!"
   ensure
       
   # Treatment of the table...
   tab_ebuild.each { |i|
      
      # Remove the "\n"!
      file_with_ext_ebuild = i.chomp
      
      # Recover the extension "ebuild"!
      ext_ebuild = File::extname(file_with_ext_ebuild)
      
      # Remove the extension "ebuild"!
      file_without_ext_ebuild = File::basename(file_with_ext_ebuild, ext_ebuild)
      
      # Remove the number of version "9999" + the indent "-". !
      # and to write the name of the packages in the file!
      new_file.puts((file_without_ext_ebuild.split(/\d/).to_s.sub(/[-]$/,'')) + ' ')
      }
      
      # Close the file !
      new_file.close
      end
   end

   
   
   def  withorwithoutav(withorwithoutav)
      
      # Update by the manager of packages of gentoo Gnu/Linux !
      puts system("emerge  #{withorwithoutav} $(< #{$temp_9999})")
      puts ""
      puts ""
      
      # Remove the file  "/tmp/emerge_9999" !
      
      puts "********************* File                   removed ! *********************"
      puts                                            rm("#{$temp_9999}").to_s.center(@marge)                                                           
      puts "******************************************************************************"
      puts ""
      puts "Good Bye !"
      puts ""
       exit
   end
   
   
   
   def   donotexist()
      
      
      # Ask the user to enter the root directory of the overlays ...
      puts ""
      puts"*******************************************************"
      puts "Enter the way of the directory managing your overlays :"
      puts "*******************************************************"
      puts ""
      $dir_parent = $stdin::gets.chomp
      puts ""
      
      # Save  the default repertory ...
      
      puts ""
      puts "*************************************************"
      puts "Want you to keep this directory by default!:[Y/n]"
      puts "*************************************************"
      puts ""
      $choice_default = $stdin::gets.chomp
      puts ""
      
      stocker
      
      # Move to the working directory ...
      Dir::chdir("#{$dir_parent}")
   
      # The object "e_9999" calls the method "cvssvngit" !
      $e_9999::cvssvngit()
      
      # The object "e_9999" calls the method "avecousansav" !
      $e_9999::withorwithoutav("-av")
   
   end



   def   stocker()
      
      # Store the way of the directory ...
      $dir_overlay = "#{$dir_parent}"
      store = PStore.new("/tmp/kmikaze.default")
      store.transaction {
         store["memo"] = $dir_overlay
         }
      
      # Store .. the choice "Y" or "n" ...
      $choice = "#{$choice_default}"
      store = PStore.new("/tmp/kmikaze.default")
      store.transaction {
         store["memoire"] = $choice
         }
      
   end

   
   def  charge()
      
      # Checking of the existence of the directory by default ...
      store = PStore.new("/tmp/kmikaze.default")
      $dir_overlay = nil
      store.transaction{$dir_overlay = store["memo"]}
      
      # Checking of the choice by default ...
      store = PStore.new("/tmp/kmikaze.default")
      $choice = nil
      store.transaction{$choice = store["memoire"]}
         
   end

   public :cvssvngit, :donotexist, :stocker, :charge, :withorwithoutav

end      
      
      
      
                                                         
                           
                           
                           
                           
                           
                           
                           
                            # KMIKAZE #
      
      
      
      
      
      
      # Know  the user uid !
      whois = Process::uid
      
   if    whois != 0
      puts ""
      puts "You must be the root to use this script ! Thank you ."
      puts ""
      exit
   end
   
      
      # What Time is it ?
      puts ""
      t= Time.now.asctime
      puts t
      puts ""
      
      # Creation of the objet "e_9999" !
      $e_9999 = Ebuild.new()
   
      # Pass an argument to redefine the directory by default and  remove the option  -av  to emerge ...
      opts = GetoptLong::new(['--new', '-n', GetoptLong::NO_ARGUMENT],
                     ['--without-av', '-w', GetoptLong::NO_ARGUMENT])
      
      # Treatment of the options ...
      opts.each do |opt, arg|
      
   case  opt
      
      when  "--new", "-n" 
      
      # Call method "donotexist" !
      $e_9999::donotexist()
         
   
      when "--without-av", "-w"
      
      # Test of file to recover the directory ...
      $e_9999::charge
      
      # Move to the working directory ...
      Dir::chdir("#{$dir_overlay}")
      
      # Call method "cvssvngit" !
      $e_9999::cvssvngit()
      
      # Call method "withorwithoutav" !
      $e_9999::withorwithoutav("-v")
      
      else
      puts ""
      puts "Try options --new or -n, please ! Thank you !.."
      puts ""
      end
   
   end
      
      
      
      # Checking the file "/tmp/kmikaze.default" ....
      $e_9999::charge
      
      case  $choice
      
   when  "Y", "Yes", "YEs", "YES", "yes", "yEs", "yES", "y"
      
      # Move to the working directory  ...
      Dir::chdir("#{$dir_overlay}")
      
      # "e_9999" calls the method "cvssvngit" ...
      $e_9999::cvssvngit()
      
      # "e_9999" calls the method "avecousansav" !
      $e_9999::withorwithoutav("-av")
   
   when  "n", "no", "nO",  "N", "No", "NO", ""
      
      # "e_9999" calls method "donotexist" ...
      $e_9999::donotexist()
   

   when  nil
      
      # "e_9999" calls  methode"donotexist" ...
      $e_9999::donotexist()
      
   else
      puts ""
      puts "Failed ! Sorry ! Re-launch with options -n or --new , please ."
      puts ""
   end

exit




II.) Installation and usage



(=). Copy it into your text edit and do it executable :
Code:
chmod +x kmikaze



(=). Put it in a directory of the PATH ,

example : /usr/bin :
Code:
mv kmikaze  /usr/bin

or
go to the same dirctory of the script and launch it with this command line :
Code:
./kmikaze



(=). With the first launching in root, of course, kmikaze tell you to choice a default directory that it will save ! After, if you want to change it , you call kmikaze with options --new or -n and you will be able to indicate a new repertory to him ! After having chosen a directory by default, you can use the option --without-av or -w for activate automatique emerge (without -av) . This script is transparent and creates a file /tmp/kmikaze.default for save your choice !... I hope that this script will be useful for you ...



Enjoy !



Bye .

ps : I'm not sure for my english, excuse me , I write this script for the french forum at the first time and now it for you ...
_________________
Get Up and Go !
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 33401
Location: 56N 3W

PostPosted: Mon Sep 11, 2006 11:13 am    Post subject: Reply with quote

Moved from Unsupported Software to Duplicate Threads.

man in the hill,

No cross posting please.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Duplicate Threads All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum