#!/usr/bin/python """ Small example userdefined script for a specrepository: get the sources """ # 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 # the rpmforge subversion contains the patches and sometimes some sources import os, commands, string, shutil, tempfile, posixpath import smtplib from email.MIMEText import MIMEText from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email import Encoders def RpmforgeGetSources(command, commanddir, brr): print "RpmforgeGetSources start" brr.logDebugLine("getting the sources for command " + str(command.getId())) # get the directory of the svn checkout fullpath = command.getSpecRepositorySpecFile().getFullPath() (dir,fname) = os.path.split(fullpath) print "dir: " + dir # copy every file except the spec file dirlist = os.listdir(dir) for entry in dirlist: # make sure its not a spec file && regular file rindex = string.rfind(entry,'.spec') if os.path.isfile(os.path.join(dir,entry)) and not (rindex > 0 and rindex == len(entry) - len('.spec')): print "lets copy (specrepo->commanddir): " + entry brr.logDebugLine("copying (specrepo->commanddir)" + entry) shutil.copy(os.path.join(dir,entry), commanddir) else: print "wont copy (specrepo->commanddir): " + entry brr.logDebugLine("wont copy (specrepo->commanddir): " + str(entry)) # now download the other files with spectool or get them from a cache # first check if there is already a cache directory cacheDir = "/var/lib/pydar2/cachedsources/" + str(command.getSpecRepoId()) + "/" + str(command.getSpecFileId()) + "/" + str(command.getVersion()) + "/" print "cacheDir set to: " + cacheDir brr.logDebugLine("cacheDir: "+ str(cacheDir)) if posixpath.isdir(cacheDir): # the cacheDir exists, lets use it print "cachedir ok" brr.logDebugLine("the cachedir exists") else: # the cacheDir does not exist, create it and fill it os.makedirs(cacheDir) print "cacheDir created" brr.logDebugLine("the cachedir did not exist") defines = command.getDefines() spectoolcommand = "spectool " + defines + " -gf " + os.path.join(commanddir, fname) print "spectoolcommand: " + spectoolcommand (tempfd, tempfilepath) = tempfile.mkstemp('pydar2') print 'tempfilepath: ' + tempfilepath brr.logDebugLine("spectoolcommand: " + str(spectoolcommand) + " and tempfilepath: "+ str(tempfilepath)) os.write(tempfd, "cd " + cacheDir + "\n") os.write(tempfd, spectoolcommand + "\n") os.close(tempfd) print "tempfd ok" (status,output) = commands.getstatusoutput("/bin/bash " + tempfilepath) print "status: " + str(status) print "output: " + (output) brr.logDebugLine("status: " + str(status) + ", output: "+ str(output)) # now copy everything from the cache to the commanddir dirlist = os.listdir(cacheDir) brr.logDebugLine("before copying, the cachedir:" + str (cacheDir)) for entry in dirlist: brr.logDebugLine("entry: " + str(entry)) rindex = string.rfind(entry,'.spec') brr.logDebugLine("rindex: " + str(rindex)) if os.path.isfile(os.path.join(cacheDir,entry)) and not (rindex > 0 and rindex == len(entry) - len('.spec')): print "lets copy (cachedir->commanddir): " + entry brr.logDebugLine("lets copy (cachedir->commanddir): " + str(entry)) shutil.copy(os.path.join(cacheDir,entry), commanddir) else: print "wont copy (cachedir->commanddir): " + entry brr.logDebugLine("wont copy (cachedir->commanddir): " + str(entry))