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?

#16 User is offline   Steve Scrimpshire 

  • This is a dark ride
  • Group: OTW
  • Posts: 3,590
  • Joined: 13-December 02

Posted 15 November 2004 - 04:31 AM

Cleaned up and fixed some missing things:

#!/usr/bin/python

import os
import sys
import locale
import time # test purposes only

import yum
import yum.Errors as Errors

repos = {}

def use_repository():
       while True:
               var = raw_input("Enable freshrpms? y/n: ")
               if var in ('y', 'ye', 'yes'):
                       repos['fresh'] = "--enablerepo=freshrpms"
                       return False
               if var in ('n', 'no', 'nop', 'nope'):
                       repos['fresh'] = "--disablerepo=freshrpms"
                       return False

use_repository()

print repos["fresh"]

def use_repository():
       while True:
               var1 = raw_input("Enable fedora-us? y/n: ")
               if var1 in ('y', 'ye', 'yes'):
                       repos['fedoraus'] = "--enablerepo=fedora-us"
                       return False
               if var1 in ('n', 'no', 'nop', 'nope'):
                       repos['fedoraus'] = "--disablerepo=fedora-us"
                       return False

use_repository()

print repos["fedoraus"]

def use_repository():
       while True:
               var2 = raw_input("Enable livna-stable? y/n: ")
               if var2 in ('y', 'ye', 'yes'):
                       repos['livnastable'] = "--enablerepo=livna-stable"
                       return False
               if var2 in ('n', 'no', 'nop', 'nope'):
                       repos['livnastable'] = "--disablerepo=livna-stable"
                       return False

use_repository()

print repos["livnastable"]

def use_repository():
       while True:
               var3 = raw_input("Enable livna-testing? y/n: ")
               if var3 in ('y', 'ye', 'yes'):
                       repos['livnatesting'] = "--enablerepo=livna-testing"
                       return False
        if var3 in ('n', 'no', 'nope'):
                       repos['livnatesting'] = "--disablerepo=livna-testing"
                       return False

use_repository()

print repos["livnatesting"]

def use_repository():
       while True:
               var4 = raw_input("Enable livna-unstable? y/n: ")
               if var4 in ('y', 'ye', 'yes'):
                       repos['livnaunstable'] = "--enablerepo=livna-unstable"
                       return False
               if var4 in ('n', 'no', 'nop', 'nope'):
                       repos['livnaunstable'] = "--disablerepo=livna-unstable" 
                       return False

use_repository()

print repos["livnaunstable"]

def use_repository():
       while True:
               var5 = raw_input("Enable dag? y/n: ")
               if var5 in ('y', 'ye', 'yes'):
                       repos['dag'] = "--enablerepo=dag"
                       return False
               if var5 in ('n', 'no', 'nop', 'nope'):
                       repos['dag'] = "--disablerepo=dag"
                       return False

use_repository()

print repos["dag"]

def use_repository():
       while True:
               var6 = raw_input("Enable dries? y/n: ")
               if var6 in ('y', 'ye', 'yes'):
                       repos['dries'] = "--enablerepo=dries"
                       return False
               if var6 in ('n', 'no', 'nop', 'nope'):
                       repos['dries'] = "--disablerepo=dries"
                       return False

use_repository()

print repos["dries"]

def use_repository():
       while True:
               var7 = raw_input("Enable newsrpms? y/n: ")
               if var7 in ('y', 'ye', 'yes'):
                       repos['newsrpms'] = "--enablerepo=newsrpms"
                       return False
               if var7 in ('n', 'no', 'nop', 'nope'):
                       repos['newsrpms'] = "--disablerepo=newsrpms"
                       return False

use_repository()

print repos["newsrpms"]

def use_repository():
       while True:
               var8 = raw_input("Enable atrpms-good? y/n: ")
               if var8 in ('y', 'ye', 'yes'):
                       repos['atrpmsgood'] = "--enablerepo=atrpms-good"
                       return False
               if var8 in ('n', 'no', 'nop', 'nope'):
                       repos['atrpmsgood'] = "--disablerepo=atrpms-good"
                       return False

use_repository()

print repos["atrpmsgood"]

def use_repository():
       while True:
               var9 = raw_input("Enable atrpms-stable? y/n: ")
               if var9 in ('y', 'ye', 'yes'):
                       repos['atrpmsstable'] = "--enablerepo=atrpms-stable"
                       return False
               if var9 in ('n', 'no', 'nop', 'nope'):
                       repos['atrpmsstable'] = "--disablerepo=atrpms-stable"
                       return False

use_repository()


print repos["atrpmsstable"]

def use_repository():
       while True:
               var10 = raw_input("Enable atrpms-testing? y/n: ")
               if var10 in ('y', 'ye', 'yes'):
                       repos['atrpmstesting'] = "--enablerepo=atrpms-testing"
                       return False
               if var10 in ('n', 'no', 'nop', 'nope'):
                       repos['atrpmstesting'] = "--disablerepo=atrpms-testing"
                       return False

use_repository()

print repos["atrpmstesting"]

def use_repository():
       while True:
               var11 = raw_input("Enable atrpms-bleeding? y/n: ")
               if var11 in ('y', 'ye', 'yes'):
                      repos['atrpmsbleeding'] = "--enablerepo=atrpms-bleeding" 
                      return False
               if var11 in ('n', 'no', 'nop', 'nope'):
                     repos['atrpmsbleeding'] = "--disablerepo=atrpms-bleeding"
                     return False

use_repository()

print repos["atrpmsbleeding"]

This post has been edited by Steve Scrimpshire: 15 November 2004 - 04:32 AM

Posted Image
0

#17 User is offline   jlc 

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

Posted 15 November 2004 - 04:36 AM

:oops:/> the script on my box is right, just didn't cp it over good :)/>
0

#18 User is offline   jlc 

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

Posted 15 November 2004 - 05:56 AM

Latest

#!/usr/bin/python

import os
import sys
# if not root...kick out
if not os.geteuid()==0:
    sys.exit("\nOnly root can run this script\n")

import locale
import time # test purposes only

import yum
import yum.Errors as Errors

repos = {}

def use_repository():
	while True:
  var = raw_input("Enable freshrpms? y/n: ")
  if var in ('y', 'ye', 'yes'): 
 	 repos['freshrpms'] = "--enablerepo=freshrpms" 
 	 return False
  if var in ('n', 'no', 'nop', 'nope'): 
 	 repos['freshrpms'] = "--disablerepo=freshrpms" 
 	 return False

use_repository()

print repos["freshrpms"]

def use_repository():
        while True:
                var1 = raw_input("Enable fedora-us? y/n: ")
                if var1 in ('y', 'ye', 'yes'):
                        repos['fedora-us'] = "--enablerepo=fedora-us"
                        return False
                if var1 in ('n', 'no', 'nop', 'nope'):
                        repos['fedora-us'] = "--disablerepo=fedora-us"
                        return False

use_repository()

print repos["fedora-us"]

def use_repository():
        while True:
                var2 = raw_input("Enable livna-stable? y/n: ")
                if var2 in ('y', 'ye', 'yes'):
                        repos['livna-stable'] = "--enablerepo=livna-stable"
                        return False
                if var2 in ('n', 'no', 'nop', 'nope'):
                        repos['livna-stable'] = "--disablerepo=livna-stable"
                        return False

use_repository()

print repos["livna-stable"]

def use_repository():
        while True:
                var3 = raw_input("Enable livna-testing? y/n: ")
                if var3 in ('y', 'ye', 'yes'):
                        repos['livna-testing'] = "--enablerepo=livna-testing"
                        return False
                if var3 in ('n', 'no', 'nop', 'nope'):
                        repos['livna-testing'] = "--disablerepo=testing"
                        return False

use_repository()

print repos["livna-testing"]

def use_repository():
        while True:
                var4 = raw_input("Enable livna-unstable? y/n: ")
                if var4 in ('y', 'ye', 'yes'):
                        repos['livna-unstable'] = "--enablerepo=livna-unstable"
                        return False
                if var4 in ('n', 'no', 'nop', 'nope'):
                        repos['livna-unstable'] = "--disablerepo=livna-unstable"
                        return False

use_repository()

print repos["livna-unstable"]

def use_repository():
        while True:
                var5 = raw_input("Enable dag? y/n: ")
                if var5 in ('y', 'ye', 'yes'):
                        repos['dag'] = "--enablerepo=dag"
                        return False
                if var5 in ('n', 'no', 'nop', 'nope'):
                        repos['dag'] = "--disablerepo=dag"
                        return False

use_repository()

print repos["dag"]

def use_repository():
        while True:
                var6 = raw_input("Enable dries? y/n: ")
                if var6 in ('y', 'ye', 'yes'):
                        repos['dries'] = "--enablerepo=dries"
                        return False
                if var6 in ('n', 'no', 'nop', 'nope'):
                        repos['dries'] = "--disablerepo=dries"
                        return False

use_repository()

print repos["dries"]

def use_repository():
        while True:
                var7 = raw_input("Enable newsrpms? y/n: ")
                if var7 in ('y', 'ye', 'yes'):
                        repos['newsrpms'] = "--enablerepo=newsrpms"
                        return False
                if var7 in ('n', 'no', 'nop', 'nope'):
                        repos['newsrpms'] = "--disablerepo=newsrpms"
                        return False

use_repository()

print repos["newsrpms"]

def use_repository():
        while True:
                var8 = raw_input("Enable atrpms-good? y/n: ")
                if var8 in ('y', 'ye', 'yes'):
                        repos['atrpms-good'] = "--enablerepo=atrpms-good"
                        return False
                if var8 in ('n', 'no', 'nop', 'nope'):
                        repos['atrpms-good'] = "--disablerepo=atrpms-good"
                        return False

use_repository()

print repos["atrpms-good"]

def use_repository():
        while True:
                var9 = raw_input("Enable atrpms-stable? y/n: ")
                if var9 in ('y', 'ye', 'yes'):
                        repos['atrpms-stable'] = "--enablerepo=atrpms-stable"
                        return False
                if var9 in ('n', 'no', 'nop', 'nope'):
                        repos['atrpms-stable'] = "--disablerepo=atrpms-stable"
                        return False

use_repository()

print repos["atrpms-stable"]

def use_repository():
        while True:
                var10 = raw_input("Enable atrpms-testing? y/n: ")
                if var10 in ('y', 'ye', 'yes'):
                        repos['atrpms-testing'] = "--enablerepo=atrpms-testing"
                        return False
                if var10 in ('n', 'no', 'nop', 'nope'):
                        repos['atrpms-testing'] = "--disablerepo=atrpms-testing"
                        return False

use_repository()

print repos["atrpms-testing"]

def use_repository():
        while True:
                var11 = raw_input("Enable atrpms-bleeding? y/n: ")
                if var11 in ('y', 'ye', 'yes'):
                       repos['atrpms-bleeding'] = "--enablerepo=atrpms-bleeding"
                       return False
                if var11 in ('n', 'no', 'nop', 'nope'):
                      repos['atrpms-bleeding'] = "--disablerepo=atrpms-bleeding"
                      return False

use_repository()

print repos["atrpms-bleeding"]

su_do={}

def use_su():
	while True:
  var12 = raw_input("Use su or sudo? su/sudo: ")
  if var12 in ('su'):
 	 su_do['enable']="su"
 	 return False
  if var12 in ('sudo'):
 	 su_do['enable']="sudo"
 	 return False

use_su()

print su_do['enable']

var13 = raw_input("What pkg do you want to install? ")
if su_do['enable'] is "su":
	os.system('su')
	os.system('yum "' + 
repos["freshrpms"] + 
repos["fedora-us"] + repos["livna-stable"] + 
repos["livna-testing"] + repos["livna-unstable"] + 
repos["dag"] + repos["dries"] + repos["newsrpms"] + 
repos["atrpms-good"] + repos["atrpms-stable"] + 
repos["atrpms-testing"] + repos["atrpms-bleeding"] + '"install ' + 'var13') 

if su_do['enable'] is "sudo":
	os.system('sudo yum "' + 
repos["freshrpms"] + 
repos["fedora-us"] + repos["livna-stable"] + 
repos["livna-testing"] + repos["livna-unstable"] + 
repos["dag"] + repos["dries"] + repos["newsrpms"] + 
repos["atrpms-good"] + repos["atrpms-stable"] + 
repos["atrpms-testing"] + repos["atrpms-bleeding"] + '"install "var13"')

This post has been edited by cybrjackle: 15 November 2004 - 06:05 AM

0

#19 User is offline   Steve Scrimpshire 

  • This is a dark ride
  • Group: OTW
  • Posts: 3,590
  • Joined: 13-December 02

Posted 15 November 2004 - 06:06 AM

Try replacing everything after:
var13 = raw_input("What pkg do you want to install? ")

with:
fullcmd = "yum " + repos["fresh"] + " " + repos["fedoraus"] + " "  + repos["livnastable"] + " " + repos["livnatesting"] + " " + repos["livnaunstable"] + " " + repos["dag"] + " " + repos["dries"] + " " + repos["newsrpms"] + " " + repos["atrpmsgood"] + " " + repos["atrpmsstable"] + " " + repos["atrpmstesting"] + " " + repos["atrpmsbleeding"] + " install " + var13

sudocmd =  "sudo yum " + repos["fresh"] + " " + repos["fedoraus"] + " "  + repos["livnastable"] + " " + repos["livnatesting"] + " " + repos["livnaunstable"] + " " + repos["dag"] + " " + repos["dries"] + " " + repos["newsrpms"] + " " + repos["atrpmsgood"] + " " + repos["atrpmsstable"] + " " + repos["atrpmstesting"] + " " + repos["atrpmsbleeding"] + " install " + var13

if su_do['enable'] is "su":
   os.system('su')
   os.system('"fullcmd"') 
   
if su_do['enable'] is "sudo":
      os.system('"sudocmd"')

Posted Image
0

#20 User is offline   jlc 

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

Posted 15 November 2004 - 06:42 AM

Thanks to Steve, we have a working script and I learned a thing or more about python! ;-)

#!/usr/bin/python

import os
import sys
# if not root...kick out
if not os.geteuid()==0:
    sys.exit("\nOnly root can run this script\n")

import locale
import time # test purposes only

import yum
import yum.Errors as Errors

repos = {}

def use_repository():
	while True:
  var = raw_input("Enable freshrpms? y/n: ")
  if var in ('y', 'ye', 'yes'): 
 	 repos['freshrpms'] = "--enablerepo=freshrpms" 
 	 return False
  if var in ('n', 'no', 'nop', 'nope'): 
 	 repos['freshrpms'] = "--disablerepo=freshrpms" 
 	 return False

use_repository()

print repos["freshrpms"]

def use_repository():
        while True:
                var1 = raw_input("Enable fedora-us? y/n: ")
                if var1 in ('y', 'ye', 'yes'):
                        repos['fedora-us'] = "--enablerepo=fedora-us"
                        return False
                if var1 in ('n', 'no', 'nop', 'nope'):
                        repos['fedora-us'] = "--disablerepo=fedora-us"
                        return False

use_repository()

print repos["fedora-us"]

def use_repository():
        while True:
                var2 = raw_input("Enable livna-stable? y/n: ")
                if var2 in ('y', 'ye', 'yes'):
                        repos['livna-stable'] = "--enablerepo=livna-stable"
                        return False
                if var2 in ('n', 'no', 'nop', 'nope'):
                        repos['livna-stable'] = "--disablerepo=livna-stable"
                        return False

use_repository()

print repos["livna-stable"]

def use_repository():
        while True:
                var3 = raw_input("Enable livna-testing? y/n: ")
                if var3 in ('y', 'ye', 'yes'):
                        repos['livna-testing'] = "--enablerepo=livna-testing"
                        return False
                if var3 in ('n', 'no', 'nop', 'nope'):
                        repos['livna-testing'] = "--disablerepo=livna-testing"
                        return False

use_repository()

print repos["livna-testing"]

def use_repository():
        while True:
                var4 = raw_input("Enable livna-unstable? y/n: ")
                if var4 in ('y', 'ye', 'yes'):
                        repos['livna-unstable'] = "--enablerepo=livna-unstable"
                        return False
                if var4 in ('n', 'no', 'nop', 'nope'):
                        repos['livna-unstable'] = "--disablerepo=livna-unstable"
                        return False

use_repository()

print repos["livna-unstable"]

def use_repository():
        while True:
                var5 = raw_input("Enable dag? y/n: ")
                if var5 in ('y', 'ye', 'yes'):
                        repos['dag'] = "--enablerepo=dag"
                        return False
                if var5 in ('n', 'no', 'nop', 'nope'):
                        repos['dag'] = "--disablerepo=dag"
                        return False

use_repository()

print repos["dag"]

def use_repository():
        while True:
                var6 = raw_input("Enable dries? y/n: ")
                if var6 in ('y', 'ye', 'yes'):
                        repos['dries'] = "--enablerepo=dries"
                        return False
                if var6 in ('n', 'no', 'nop', 'nope'):
                        repos['dries'] = "--disablerepo=dries"
                        return False

use_repository()

print repos["dries"]

def use_repository():
        while True:
                var7 = raw_input("Enable newsrpms? y/n: ")
                if var7 in ('y', 'ye', 'yes'):
                        repos['newsrpms'] = "--enablerepo=newsrpms"
                        return False
                if var7 in ('n', 'no', 'nop', 'nope'):
                        repos['newsrpms'] = "--disablerepo=newsrpms"
                        return False

use_repository()

print repos["newsrpms"]

def use_repository():
        while True:
                var8 = raw_input("Enable atrpms-good? y/n: ")
                if var8 in ('y', 'ye', 'yes'):
                        repos['atrpms-good'] = "--enablerepo=atrpms-good"
                        return False
                if var8 in ('n', 'no', 'nop', 'nope'):
                        repos['atrpms-good'] = "--disablerepo=atrpms-good"
                        return False

use_repository()

print repos["atrpms-good"]

def use_repository():
        while True:
                var9 = raw_input("Enable atrpms-stable? y/n: ")
                if var9 in ('y', 'ye', 'yes'):
                        repos['atrpms-stable'] = "--enablerepo=atrpms-stable"
                        return False
                if var9 in ('n', 'no', 'nop', 'nope'):
                        repos['atrpms-stable'] = "--disablerepo=atrpms-stable"
                        return False

use_repository()

print repos["atrpms-stable"]

def use_repository():
        while True:
                var10 = raw_input("Enable atrpms-testing? y/n: ")
                if var10 in ('y', 'ye', 'yes'):
                        repos['atrpms-testing'] = "--enablerepo=atrpms-testing"
                        return False
                if var10 in ('n', 'no', 'nop', 'nope'):
                        repos['atrpms-testing'] = "--disablerepo=atrpms-testing"
                        return False

use_repository()

print repos["atrpms-testing"]

def use_repository():
        while True:
                var11 = raw_input("Enable atrpms-bleeding? y/n: ")
                if var11 in ('y', 'ye', 'yes'):
                       repos['atrpms-bleeding'] = "--enablerepo=atrpms-bleeding"
                       return False
                if var11 in ('n', 'no', 'nop', 'nope'):
                      repos['atrpms-bleeding'] = "--disablerepo=atrpms-bleeding"
                      return False

use_repository()

print repos["atrpms-bleeding"]

su_do={}

def use_su():
	while True:
  var12 = raw_input("Use su or sudo? su/sudo: ")
  if var12 in ('su'):
 	 su_do['enable']="su"
 	 return False
  if var12 in ('sudo'):
 	 su_do['enable']="sudo"
 	 return False

use_su()

print su_do['enable']

fullcmd = {}
sudocmd = {}

var13 = raw_input("What pkg do you want to install? ")
fullcmd['test'] = "yum " + repos["freshrpms"] + " " + repos["fedora-us"] + " "  + repos["livna-stable"] + " " + repos["livna-testing"] + " " + repos["livna-unstable"] + " " + repos["dag"] + " " + repos["dries"] + " " + repos["newsrpms"] + " " + repos["atrpms-good"] + " " + repos["atrpms-stable"] + " " + repos["atrpms-testing"] + " " + repos["atrpms-bleeding"] + " install " + var13

sudocmd['test'] =  "sudo yum " + repos["freshrpms"] + " " + repos["fedora-us"] + " "  + repos["livna-stable"] + " " + repos["livna-testing"] + " " + repos["livna-unstable"] + " " + repos["dag"] + " " + repos["dries"] + " " + repos["newsrpms"] + " " + repos["atrpms-good"] + " " + repos["atrpms-stable"] + " " + repos["atrpms-testing"] + " " + repos["atrpms-bleeding"] + " install " + var13

if su_do['enable'] is "su":
  os.system('su')
  os.system(fullcmd['test'])
 
if su_do['enable'] is "sudo":
     os.system(sudocmd['test'])


$ rpm -qa |grep unrar


$ sudo ./yum-repos.py
Password:
Enable freshrpms? y/n: y
--enablerepo=freshrpms
Enable fedora-us? y/n: n
--disablerepo=fedora-us
Enable livna-stable? y/n: n
--disablerepo=livna-stable
Enable livna-testing? y/n: n
--disablerepo=livna-testing
Enable livna-unstable? y/n: n
--disablerepo=livna-unstable
Enable dag? y/n: n
--disablerepo=dag
Enable dries? y/n: n
--disablerepo=dries
Enable newsrpms? y/n: n
--disablerepo=newsrpms
Enable atrpms-good? y/n: n
--disablerepo=atrpms-good
Enable atrpms-stable? y/n: n
--disablerepo=atrpms-stable
Enable atrpms-testing? y/n: n
--disablerepo=atrpms-testing
Enable atrpms-bleeding? y/n: n
--disablerepo=atrpms-bleeding
Use su or sudo? su/sudo:sudo
sudo
What pkg do you want to install? unrar


Setting up Install Process
Setting up Repo:  updates-released
repomd.xml                100% |=========================|  951 B    00:00
Setting up Repo:  base
repomd.xml                100% |=========================| 1.1 kB    00:00
Setting up Repo:  freshrpms
repomd.xml                100% |=========================|  843 B    00:00
Reading repository metadata in from local files
updates-re: ################################################## 169/169
base      : ################################################## 2622/2622
freshrpms : ################################################## 422/422
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for unrar to pack into transaction set.
unrar-3.4.3-1.1.fc3.fr.i3 100% |=========================| 3.5 kB    00:01
---> Package unrar.i386 0:3.4.3-1.1.fc3.fr set to be installed
--> Running transaction check

Dependencies Resolved
Transaction Listing:
  Install: unrar.i386 0:3.4.3-1.1.fc3.fr
Is this ok [y/N]:

Is this ok [y/N]: y
Downloading Packages:
unrar-3.4.3-1.1.fc3.fr.i3 100% |=========================|  86 kB    00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: unrar 100 % done 1/1

Installed: unrar.i386 0:3.4.3-1.1.fc3.fr
Complete!


:drum:/> :headbang:/>

SWEET!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1

thx so much Ohms!
0

#21 User is offline   bvc 

  • root
  • Group: Platinum
  • Posts: 8,682
  • Joined: 19-September 02

Posted 15 November 2004 - 07:33 AM

nice work!
:woot:/>
0

#22 User is offline   iphitus 

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

Posted 15 November 2004 - 11:32 AM

Awww mann!!! I wrote one too!!

Heres mine :)/>

Name it 'yumrepo' stick it somewhere in your path (/usr/bin is all good), chmod +x it, then run "yumrepo install bob" or put any other yum commands after it. All commands after 'yumrepo' except -l, --list-repos, -h, --help are passed to yum itself.

It gets a list of repos from /etc/yum.repos.d/ so the repos are not hard coded into it, meaning the script doesnt have to be edited if you add/remove repos.

You can also do 'yumrepo -l' to list the available repos.

This command, if run by a user, will ask for root password, then start itself up as root using su -c, perform it's command and you will be returned to a user command line

Hope you like it..

Either way whether you use it or not, i improved my python skills substantially, so it was all worth it :D/> It's only 69 lines too :P/>

To make life simpler, you can download it here: http://aslan.no-ip.c...rograms/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 + "--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()

0

#23 User is offline   jlc 

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

Posted 15 November 2004 - 02:32 PM

$ sudo yumrepo install ifupdown
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)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
Setting up Install Process
Setting up Repo:  updates-released
repomd.xml                100% |=========================|  951 B    00:00
Setting up Repo:  fedora-us
http://download.fedora.us/fedora/fedora/3/i386/RPMS.extras/repodata/repomd.xml: [Errno 4] IOError: HTTP Error 404: Not Found
Trying other mirror.
Cannot open/read repomd.xml file for repository: fedora-us
failure: repodata/repomd.xml from fedora-us: [Errno 256] No more mirrors to try.


iphitus That error right there means that it is still looking into other repositorys, in this case "fedora-us" which they don't have created yet. Besides it shouldn't even be looking at it since I said "N" it should only be looking in "dag" and the default "Fedora" channels for updates and base packages?
0

#24 User is offline   Steve Scrimpshire 

  • This is a dark ride
  • Group: OTW
  • Posts: 3,590
  • Joined: 13-December 02

Posted 15 November 2004 - 06:26 PM

I think:
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] + " "


should be:
if response is "y" or response is "Y":
   yum = yum + "--enablerepo=" + f[:-5] + " "
 elif response is "n" or response is "N":
   yum = yum + "--disablerepo=" + f[:-5] + " "
 else:
   yum = yum + "--enablerepo=" + f[:-5] + " "

Posted Image
0

#25 User is offline   jlc 

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

Posted 15 November 2004 - 06:32 PM

getroot = raw_input("This program requires root access, run as root? (Y/n)")
   if getroot is "n" or getroot is "N":
     exit()


and that
0

#26 User is offline   jlc 

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

Posted 15 November 2004 - 06:36 PM

Let's see what happens, I don't have ifplugd installed from Dag's repo and I need it since this is my laptop.

[$ rpm -qa |grep ifplugd
$

Not here, move on to install

$ yumrepo install ifplugd
This program requires root access, run as root? (Y/n)n
$

That works, now, didn't on the last one.

$ yumrepo install ifplugd
This program requires root access, run as root? (Y/n)y
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)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
Setting up Install Process
Setting up Repo:  updates-released
repomd.xml                100% |=========================|  951 B    00:00
Setting up Repo:  fedora-us
http://download.fedora.us/fedora/fedora/3/i386/RPMS.extras/repodata/repomd.xml: [Errno 4] IOError: HTTP Error 404: Not Found
Trying other mirror.
Cannot open/read repomd.xml file for repository: fedora-us
failure: repodata/repomd.xml from fedora-us: [Errno 256] No more mirrors to try.[

0

#27 User is offline   iphitus 

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

Posted 15 November 2004 - 09:26 PM

i dont get why it's not workin, add a "print yum" before system(yum) and it will show you the command it's passing. If should be passing --disable-repo=fedora-us

and the command seemed fine here.
0

#28 User is offline   iphitus 

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

Posted 15 November 2004 - 10:17 PM

Ohms: == and is are equivalent, changing them does nothing.

It isnt working because I made an indentation mistake, this:

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] + " "


the if clauses within the for, should be indented further.

Anyway, i modified it to use execvp instead of system.

#! /usr/bin/env python

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

from sys import argv,exit
from os import listdir,getuid,execvp
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=[" "," "]
  for f in repolist:      
    response = raw_input("Use repository: " + f[:-5] + "? (Y/n)")
    if response == "y" or response == "Y":
      yum.append("--enablerepo=" + f[:-5])
    elif response == "n" or response == "N":
      yum.append("--disablerepo=" + f[:-5])
    else:
      yum.append("--disablerepo=" + f[:-5])

  ## Add other yum arguments    
  for a in arguments:
    if a[0] != "-" and a != "":
      yum.append(a)

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

  main()


it'll work now, because it wasnt indented, only the first option was being read.

iphitus
0

#29 User is offline   Steve Scrimpshire 

  • This is a dark ride
  • Group: OTW
  • Posts: 3,590
  • Joined: 13-December 02

Posted 15 November 2004 - 10:20 PM

Those crazy indentions.
Posted Image
0

#30 User is offline   jlc 

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

Posted 15 November 2004 - 11:57 PM

$ $ 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)y
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)y
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

    Usage:  yum [options] < update | install | info | remove | list |
            clean | provides | search | check-update | groupinstall |
            groupupdate | grouplist | groupinfo | groupremove | generate-rss |
            makecache | localinstall >

        Options:
        -c [config file] - specify the config file to use
        -e [error level] - set the error logging level
        -d [debug level] - set the debugging level
        -y - answer yes to all questions
        -R [time in minutes] - set the max amount of time to randomly run in
        -C run from cache only - do not update the cache
        --installroot=[path] - set the install root (default '/')
        --version - output the version of yum
        --rss-filename=[path/filename] - set the filename to generate rss to
        --exclude=package to exclude
        --disablerepo=repository id to disable (overrides config file)
        --enablerepo=repository id to enable (overrides config file)

        -h, --help  - this screen


It's not executing the "install" option.
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