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 Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
man in the hill
Veteran
Veteran


Joined: 15 Dec 2005
Posts: 1551
Location: Madinina

PostPosted: Mon Sep 11, 2006 6:16 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 disable it with the option -w ...



I.) Source Code


_-_ The script name's : 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 asked once and for all...
#
# == Usage
#
# kmikaze [OPTION]
#
# -n, --new :
# To redefine a new directory by default .
#
# -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})")
   
      # Remove the file  "/tmp/emerge_9999" !
      
      puts "********************* File                   removed ! *********************"
      puts(                                            rm("#{$temp_9999}").to_s.center(@marge)                       )                                   
      puts "****************************************************************************"
      puts "\nGood Bye !\n\n"
       exit
   end
   
   
   
   def   donotexist()
      
      
      # Ask the user to enter the root directory of the overlays ...
      puts"*******************************************************"
      puts "Enter the way of the directory managing your overlays :"
      puts "*******************************************************\n\n"
      $dir_parent = $stdin::gets.chomp
      
      # Save  the default directory ...
      
      puts "\n*************************************************"
      puts "Want you to keep this directory by default!:[Y/n]"
      puts "*************************************************\n\n"
      $choice_default = $stdin::gets.chomp
      
      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 !
      whoisit = Process::uid
      
   if    whoisit != 0
      puts "\nYou must be the root to use this script ! Thank you .\n\n"
        exit
   end
   
      
      # What Time is it ?
      
      t= Time.now.asctime
      puts "\n#{t}\n\n"
      
      
      # 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(['--help','-h', GetoptLong::NO_ARGUMENT],
                     ['--new', '-n', GetoptLong::NO_ARGUMENT],
                     ['--without-av', '-w', GetoptLong::NO_ARGUMENT])
      
      # Treatment of the options ...
      opts.each do |opt, arg|
      
   case  opt
      
      
      when "--help", "-h"
   
      puts"\n== Synopsis ==\n"
      puts "\nSearch for files ebuild cvs, svn, git in a directory (and under directories) in an iterative way !\n"
      puts "\nLaunch kmikaze and two small questions will be asked once and for all ...\n"
      puts "\n== Usage ==\n"
      puts "\nkmikaze [OPTION]\n"
      puts "\n-n, --new :\n"
      puts "\nTo redefine a new directory by default.\n"
      puts "\n-w, --without-av :\n"
      puts "\nLaunch emerge without -av.\n"
      puts "\n== End ==\n\n"
      exit
      
      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 "\nTry --help or -h , please ! Thank you !..\n\n"
   end
               end

      # Checking the file "/tmp/kmikaze.default" ....
      $e_9999::charge
      
   case  $choice.downcase!
      
      when   "y", "yes"
      
      # 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", ""
      
      # "e_9999" calls method "donotexist" ...
      $e_9999::donotexist()
   

      when  nil
      
      # "e_9999" calls  methode"donotexist" ...
      $e_9999::donotexist()
      
      else
      puts "\nFailed ! Sorry ! Try --help or -h, please .\n\n"
   end

exit







II.) Installation and usage



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



b.) 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



c.) 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 enable automatique emerge (without -av) and finally option --help or -h for help. 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 have write this script for the french forum at the first time and now it for you :lol: ...
_________________
Get Up and Go !


Last edited by man in the hill on Wed Sep 13, 2006 1:19 am; edited 3 times in total
Back to top
View user's profile Send private message
ChrisWhite
Retired Dev
Retired Dev


Joined: 08 Jul 2004
Posts: 399
Location: Stockton, CA

PostPosted: Tue Sep 12, 2006 5:26 am    Post subject: Reply with quote

tab_ebuild = %x( ls -R )::grep(/-9999.ebuild$/)::uniq

well, considering the format of portage overlays, you could do this:

tab_ebuild = %x( ls */*/*9999.ebuild)

not sure about the uniq. This however assumes the directory structure of

current_directory/category/package/whatever-9999.ebuild
Back to top
View user's profile Send private message
Meqif
Tux's lil' helper
Tux's lil' helper


Joined: 09 Mar 2003
Posts: 103
Location: Portugal

PostPosted: Tue Sep 12, 2006 4:10 pm    Post subject: Reply with quote

Nice script.

Two suggestions:

1) Get rid of all those 'puts ""'. It's ugly. Use '\n' instead. I understand you may want to have the same look in both the source and the output, but it doesn't look nice, imho.

2) You could use
Code:
case $choice.downcase!

when "y", "yes"

...

when "n", "no", ""

instead of:
Code:
case  $choice
     
when  "Y", "Yes", "YEs", "YES", "yes", "yEs", "yES", "y"
     
 ...
   
when  "n", "no", "nO",  "N", "No", "NO", ""


It's a lot cleaner and does the same job. One may argue against downcase! because it replaces in place. Use downcase if you're concerned, I think in this case it's not relevant.

Keep up the good job! 8)
Back to top
View user's profile Send private message
man in the hill
Veteran
Veteran


Joined: 15 Dec 2005
Posts: 1551
Location: Madinina

PostPosted: Tue Sep 12, 2006 8:58 pm    Post subject: Reply with quote

ChrisWhite wrote:
tab_ebuild = %x( ls -R )::grep(/-9999.ebuild$/)::uniq

well, considering the format of portage overlays, you could do this:

tab_ebuild = %x( ls */*/*9999.ebuild)

not sure about the uniq. This however assumes the directory structure of

current_directory/category/package/whatever-9999.ebuild


Hello,

Well I understand, but the goal is to manage differents portage overlays with their own "current_directory" (like me :
Code:

 crazy_gentoo  %
 kmikaze

Tue Sep 12 16:14:12 2006


These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] media-video/mplayer-9999  USE="(-3dfx) (-3dnow) (-3dnowext) X aac aalib alsa (-altivec) -amr -arts bidi -bindist -bl cdparanoia -cpudetection -custom-cflags -debug -dga -directfb -doc dts dv -dvb dvd dvdread -enca encode esd -fbcon -ggi gif gtk iconv ipv6 -jack joystick jpeg libcaca -lirc live -livecd -lzo mad -matrox (-mmx) (-mmxext) -musepack -nas -openal opengl oss png (-real) -rtc -samba sdl -speex (-sse) (-sse2) (-svga) -tga theora truetype -unicode -v4l -v4l2 vorbis (-win32codecs) -x264 -xanim -xinerama xmms xv xvid -xvmc" 0 kB [2]
[ebuild   R   ] net-misc/wget-9999  USE="-build -debug ipv6 nls -socks5 ssl -static" 0 kB [2]
[ebuild   R   ] x11-misc/cgwd-themes-9999  0 kB [1]
[ebuild   R   ] x11-misc/cgwd-themes-extra-0.3  0 kB [1]
[ebuild   R   ] x11-misc/compiz-manager-0.5  0 kB [1]
[ebuild   R   ] x11-misc/compiz-quinnstorm-plugins-0.20.1  0 kB [1]
[ebuild   R   ] x11-misc/csm-0.9  0 kB [1]
[ebuild   R   ] x11-misc/gset-compiz-9999  USE="-debug" 0 kB [1]
[ebuild   R   ] x11-wm/cgwd-9999  USE="-debug" 0 kB [1]
[ebuild   R   ] x11-wm/compiz-quinnstorm-9999  USE="-debug gnome svg" 0 kB [1]

Total size of downloads: 0 kB
Portage overlays:
 [1] /usr/local/overlays/xgl-coffee
 [2] /usr/local/overlays/faya-gentoo
 [3] /usr/local/overlays/gkrellm-overlay

Would you like to merge these packages? [Yes/No]
and if it is not the case, that work too ...



To Meqif:

1.) It's not ugly for me ! I will make some tests and I would see ...

2.) Good idea ! and thanks for your explanation ...


I made well write here because I did not have any suggestion in the French forum ...

I can come on the English forum to put some questions about ruby :D ...


Thanks a lot both !


Bye .
_________________
Get Up and Go !
Back to top
View user's profile Send private message
Meqif
Tux's lil' helper
Tux's lil' helper


Joined: 09 Mar 2003
Posts: 103
Location: Portugal

PostPosted: Tue Sep 12, 2006 10:08 pm    Post subject: Reply with quote

man in the hill wrote:
To Meqif:

1.) It's not ugly for me ! I will make some tests and I would see ...

2.) Good idea ! and thanks for your explanation ...


I made well write here because I did not have any suggestion in the French forum ...

I can come on the English forum to put some questions about ruby :D ...


Thanks a lot both !


Bye .


Heh, I'm just used to write code as cleanly and with as few lines as possible, as long as I don't obfuscate the code (which I think it wouldn't in this case). Meh, a few lines more don't matter much, and each to his own. :)

No problem. I suggest you get the "Pickaxe" (aka "Programming Ruby - The Pragmatic Programmers' Guide") if you don't have it already. I've got the PDF version and it's quite handy. Pretty good when you're looking for a better way to do something.

Sure, there are a lot more people reading your post here than on the French subforum, which is understandable.

Cheers 8)
Back to top
View user's profile Send private message
man in the hill
Veteran
Veteran


Joined: 15 Dec 2005
Posts: 1551
Location: Madinina

PostPosted: Tue Sep 12, 2006 11:33 pm    Post subject: Reply with quote

Meqif wrote:
Heh, I'm just used to write code as cleanly and with as few lines as possible, as long as I don't obfuscate the code (which I think it wouldn't in this case). Meh, a few lines more don't matter much, and each to his own. :)


I understand, I also want to write a readable code ... I'm new rubiyste and I always search a style ... I will work on this side for make a compact code readable also ...

Meqif wrote:
No problem. I suggest you get the "Pickaxe" (aka "Programming Ruby - The Pragmatic Programmers' Guide") if you don't have it already. I've got the PDF version and it's quite handy. Pretty good when you're looking for a better way to do something.

I read somes pages on ruby-doc.org ... not enouth of course !

Meqif wrote:
Sure, there are a lot more people reading your post here than on the French subforum, which is understandable.

Cheers 8)

This code was write in French first of all, because I'm naturaly french (from the caraïbe of course =martinique= !) after I have translate it in english and post here where there are more people :) ! I know them all on the French forum and there are no rubiyste !!!!!


Bye

[EDIT] I remove all puts "", that's a good idea :D ! While I am there, can you help me here http://forums.gentoo.org/viewtopic-t-497762.html , thanks ! [/EDIT]
_________________
Get Up and Go !
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks 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