#!/usr/bin/python -t # Copyright (C) 2005 Adalbert Prokop, adalbert.prokop(%)web.de # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import sys sys.path.append("/usr/share/yum") import rpmUtils import os import os.path haveOldModules = False ts = None try: ts = rpmUtils.oldUtils.Rpm_Ts_Work() except AttributeError: print "Using old modules..." haveOldModules = True if haveOldModules: ts = rpmUtils.Rpm_Ts_Work() rpmUtils.ts = ts if not haveOldModules: rpmUtils.oldUtils.ts = ts def printhelp(): print "Usage:",os.path.basename(sys.argv[0]),"{rpmfiles}" print "Renames files to produce canonical RPM names, as this:" print "[:]--..rpm" print "" sys.exit(1) if len(sys.argv) < 2 or sys.argv[1] == "-h": printhelp() for rpmfn in sys.argv[1:]: if os.path.isfile(rpmfn): headerobj = rpmUtils.oldUtils.RPM_Work(rpmfn) else: print rpmfn, "does not exist. Ignoring." continue if headerobj.hdr is None: print "Bad rpm:", rpmfn else: (name, epoch, ver, rel, arch) = headerobj.nevra() if epoch is None: epoch = '0' else: epoch = str(epoch) isSource = headerobj.isSource() canonical=name if epoch != '0': canonical=canonical+":"+epoch canonical=canonical+"-"+ver+"-"+rel if isSource: canonical=canonical+".src.rpm" else: canonical=canonical+"."+arch+".rpm" if os.path.basename(rpmfn) == canonical: continue else: canonicalfn=os.path.join(os.path.dirname(rpmfn),canonical) if os.path.isfile(canonicalfn): i=2 while os.path.isfile(canonicalfn+"."+str(i)): i=i+1 os.rename(rpmfn,canonicalfn+"."+str(i)) else: os.rename(rpmfn,canonicalfn)