Mailinglist Archive: opensuse-buildservice (314 mails)

< Previous Next >
[opensuse-buildservice] script to update existing .repo files
  • From: "Dr. Peter Poeml" <poeml@xxxxxxx>
  • Date: Wed, 23 Jan 2008 01:27:57 +0100
  • Message-id: <20080123002756.GY8989@xxxxxxx>
Hi,

I hacked up a script which adapts .repo files, which are stored in
/etc/yum.repos.d, for the new key URLs.

It may be useful for other package managers, too -- I don't know.

Peter
--
"WARNING: This bug is visible to non-employees. Please be respectful!"

SUSE LINUX Products GmbH
Research & Development
#!/usr/bin/python

# Copyright (C) 2008 Peter Poeml / Novell Inc. All rights reserved.
# This program is free software; it may be used, copied, modified
# and distributed under the terms of the GNU General Public Licence,
# either version 2, or (at your option) any later version.


import os

os.chdir('/etc/yum.repos.d')
repofiles = os.listdir('.')
print repofiles

for repofile in repofiles:
if not repofile.endswith('.repo'):
continue
print
print 'file:', repofile
baseurl = None
gpgkey = None
changed = False

lines = [ line.rstrip('\n') for line in open(repofile).readlines() ]


for lineno, line in enumerate(lines):

if line.startswith('baseurl'):
baseurl = line.split('=')[1]
baseurl = baseurl.rstrip('/')
#print ' ', line

if line.startswith('gpgkey') and baseurl:
gpgkey = baseurl + '/' + 'repodata/repomd.xml.key'
lines[lineno] = 'gpgkey=%s' % gpgkey

print 'old:', line
print 'new:', lines[lineno]

if line != lines[lineno]:
changed = True


if changed:
repl = raw_input('Write? (y/N) ')
if repl == 'y':
f = open(repofile, 'w')
f.write('\n'.join(lines))
f.write('\n')
f.close()

else:
print 'unchanged'

< Previous Next >
This Thread
  • No further messages