#!/usr/bin/python """ Script which moves the result of a command (normally 1 or more rpms, a srpm and a buildlog) """ # 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Copyright 2004 Dries Verachtert # this script must move the results of one command. it gets the command and the directory where it can find the rpms and the buildlog # if the commanddir is accepted and if the rpms are moved, then it should return True, otherwise False import os,string, shutil def moveCommandResults(command, commanddir): print "moveCommandResults start, commanddir:" + commanddir webrootdir = "/var/lib/pydar2/webroot/" packagesdir = os.path.join(webrootdir, "packages") shortname = command.getNameFromSpec() print "shortname: " + str(shortname) pdir = os.path.join(packagesdir, shortname) distroarchtag = command.getDistroArchTag() pdirwithdistroarchtag = os.path.join(pdir, distroarchtag) print "pdirwithdistroarchtag: " + str(pdirwithdistroarchtag) try: os.makedirs(pdirwithdistroarchtag) except: print "exception, dir probably exists already" containsRpms = False # first check if there are new rpm files for entry in os.listdir(commanddir): if string.find(entry,".rpm") > 0: containsRpms = True # only if it contains rpms: remove the old ones and copy the new ones if containsRpms: for entry in os.listdir(pdirwithdistroarchtag): print "remove: " + os.path.join(pdirwithdistroarchtag, entry) os.remove(os.path.join(pdirwithdistroarchtag, entry)) # now move the newly created rpms for entry in os.listdir(commanddir): moveEntry = False if string.find(entry, ".rpm") > 0: moveEntry = True if moveEntry: os.rename(os.path.join(commanddir,entry), os.path.join(pdirwithdistroarchtag, entry)) print "rename: " + os.path.join(commanddir,entry) + " to " + os.path.join(pdirwithdistroarchtag, entry) # always move the buildlog suffix = "" if not containsRpms: suffix = "-failed" os.rename(os.path.join(commanddir,"buildlog.txt.gz"),os.path.join(pdirwithdistroarchtag, shortname + "-" + distroarchtag + suffix + "-buildlog.txt.gz")) print "rename: " + os.path.join(commanddir,"buildlog.txt.gz") + " to " + os.path.join(pdirwithdistroarchtag, shortname + "-" + distroarchtag + suffix + "-buildlog.txt.gz") return True