MandrivaUsers.org : python/yum idea "SOLVED" - MandrivaUsers.org

Jump to content

  • 3 Pages +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

python/yum idea "SOLVED" need help? Any python experts out there?

#31 User is offline   iphitus 

  • Arch Linux Developer, Rocket Scientist
  • View blog
  • Group: Global Moderator
  • Posts: 3,869
  • Joined: 16-April 03

Posted 16 November 2004 - 12:13 AM

#! /usr/bin/env python

##  Yum Repository selection frontend
##  by iphitus  --  iphitus@gmail.com 

from sys import argv,exit
from os import listdir,getuid,execvp,system,wait
from optparse import OptionParser   

## Change this if this file is not named program_name
program_name = "yumrepo"
    
def main():

  arguments = argv[1:]
  
  ## Load list of repositories
  repolist = listdir("/etc/yum.repos.d")
  for f in repolist:
    if f[-5:] != ".repo":
      repolist.remove(f)

  ## Load and parse command line options
  parser = OptionParser()
  parser.add_option("-l", "--list-repos", 
            action="store_true", dest="listrepos", help="List available repositories.")
  (options,args) = parser.parse_args()

  ## Check to see if root, if not, su then execute command again
  if getuid() != 0:
    getroot = raw_input("This program requires root access, run as root? (Y/n)")
    if getroot == "n" or getroot == "N":
      exit()
    else:
      astring = " "
      for a in arguments:
        astring = astring+" "+a
      suargs = ["root","--command="+program_name+astring]
      execvp("su",suargs)
 
  ## Check command line options
  if options.listrepos:
    print "Available repositories are:"
    for r in repolist:
      print "  ",r[:-5]        
    exit()  
    
  ## Start offering repos 
  yum="yum "
  for f in repolist:      
    response = raw_input("Use repository: " + f[:-5] + "? (Y/n)")
    if response == "y" or response == "Y":
      yum = yum + "--enablerepo=" + f[:-5] + " "
    elif response == "n" or response == "N":
      yum = yum + "--disablerepo=" + f[:-5] + " "
    else:
      yum = yum + "--enablerepo=" + f[:-5] + " "

  ## Add other yum arguments    
  for a in arguments:
    if a[0] != "-" and a != "":
      yum=yum+" " + a

    ## Run Yum
  system(yum)
    
if __name__ == "__main__":

  main()


here we go...

arguments werent passed in the last one because i rewrote it to use execvp :P/> here's the fixed one using system again
0

#32 User is offline   jlc 

  • Kainos
  • Group: OTW
  • Posts: 2,574
  • Joined: 31-March 03

Posted 16 November 2004 - 02:30 PM

:oops:/>
$ yumrepo install ifplugd
This program requires root access, run as root? (Y/n)
Password:
Use repository: freshrpms? (Y/n)n
Use repository: fedora-devel? (Y/n)n
Use repository: livna-testing? (Y/n)n
Use repository: atrpms-bleeding? (Y/n)n
Use repository: newsrpms? (Y/n)n
Use repository: fedora-us? (Y/n)n
Use repository: fedora? (Y/n)
Use repository: atrpms-testing? (Y/n)n
Use repository: atrpms-stable? (Y/n)n
Use repository: fedora-updates-testing? (Y/n)n
Use repository: livna-stable? (Y/n)n
Use repository: fedora-updates? (Y/n)n
Use repository: dries? (Y/n)n
Use repository: atrpms-good? (Y/n)n
Use repository: dag? (Y/n)y
Use repository: livna-unstable? (Y/n)n
Error getting repository data for fedora-devel, repository not found


Can't find a repo that I said no to :unsure:/>

Here is another question for you, is it possible to have them all default to "N" except "fedora" and "fedora-updates" ?
0

#33 User is offline   iphitus 

  • Arch Linux Developer, Rocket Scientist
  • View blog
  • Group: Global Moderator
  • Posts: 3,869
  • Joined: 16-April 03

Posted 17 November 2004 - 04:28 AM

I quite frankly am puzzled
I made myself a script which spits out all the options passed to it to replace yum itself........

This is what it says....

~ | yumrepo
This program requires root access, run as root? (Y/n)y
Password:
Use repository: dag? (Y/n)n
Use repository: dries? (Y/n)n
Use repository: fedora-us? (Y/n)n
Use repository: freshrpms? (Y/n)n
Use repository: livna-stable? (Y/n)n
Use repository: livna-testing? (Y/n)n
Use repository: livna-unstable? (Y/n)n
Use repository: newsrpms? (Y/n)n
im yum, i do stuff
['/usr/bin/yum', '--disablerepo=dag', '--disablerepo=dries', '--disablerepo=fedora-us', '--disablerepo=freshrpms', '--disablerepo=livna-stable', '--disablerepo=livna-testing', '--disablerepo=livna-unstable', '--disablerepo=newsrpms']
done


This is the script I am using for yumrepo
#! /usr/bin/env python

##  Yum Repository selection frontend
##  by iphitus  --  iphitus@gmail.com 

from sys import argv,exit
from os import listdir,getuid,execvp,system,wait
from optparse import OptionParser   

## Change this if this file is not named program_name
program_name = "yumrepo"
    
def main():

  arguments = argv[1:]
  
  ## Load list of repositories
  repolist = listdir("/etc/yum.repos.d")
  for f in repolist:
    if f[-5:] != ".repo":
      repolist.remove(f)

  ## Load and parse command line options
  parser = OptionParser()
  parser.add_option("-l", "--list-repos", 
            action="store_true", dest="listrepos", help="List available repositories.")
  (options,args) = parser.parse_args()

  ## Check to see if root, if not, su then execute command again
  if getuid() != 0:
    getroot = raw_input("This program requires root access, run as root? (Y/n)")
    if getroot == "n" or getroot == "N":
      exit()
    else:
      astring = " "
      for a in arguments:
        astring = astring+" "+a
      suargs = ["root","--command="+program_name+astring]
      execvp("su",suargs)
 
  ## Check command line options
  if options.listrepos:
    print "Available repositories are:"
    for r in repolist:
      print "  ",r[:-5]        
    exit()  
    
  ## Start offering repos 
  yum="yum "
  for f in repolist:      
    response = raw_input("Use repository: " + f[:-5] + "? (Y/n)")
    if response == "y" or response == "Y":
      yum = yum + "--enablerepo=" + f[:-5] + " "
    elif response == "n" or response == "N":
      yum = yum + "--disablerepo=" + f[:-5] + " "
    else:
      yum = yum + "--disablerepo=" + f[:-5] + " "

  ## Add other yum arguments    
  for a in arguments:
    if a[0] != "-" and a != "":
      yum=yum+" " + a

    ## Run Yum
  system(yum)
    
if __name__ == "__main__":

  main()

0

#34 User is offline   jlc 

  • Kainos
  • Group: OTW
  • Posts: 2,574
  • Joined: 31-March 03

Posted 18 November 2004 - 01:47 AM

If I get a chance, I'll see if i can figure it out :unsure:/> :juggle:/>
0

Share this topic:


  • 3 Pages +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users