From 624925226ecd42998c02cdbccc57eb15dcade7d2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 10 2011 11:48:21 +0000 Subject: Clean the code a bit, add a verbose option and move the tarball to the %_sourcedir when calling R2spec with a tarball and not a url --- diff --git a/devel/r2spec/RPackage.py b/devel/r2spec/RPackage.py index 3f3000a..9f1babd 100644 --- a/devel/r2spec/RPackage.py +++ b/devel/r2spec/RPackage.py @@ -24,7 +24,7 @@ class RPackage: It contains all the information about the package that R2spec will create the spec file about. ''' - def __init__(self): + def __init__(self, verbose): ''' Initiate the object of type Package and set the attributes ''' self.name = None self.source0 = None @@ -40,10 +40,12 @@ class RPackage: self.topdir = None self.sourcedir = None self.specdir = None - + self.nocheck = False self.nosuggest = False - + + self.verbose = verbose + def setName(self): ''' Get the name of the library from the source file ''' name = self.source @@ -52,7 +54,7 @@ class RPackage: self.name=name.rsplit('/',1)[1] except IndexError, err: self.name=name - + print "* Name of the library =", self.name def setDate(self, verbose = False): @@ -61,7 +63,7 @@ class RPackage: self.date = date if verbose: print "* Date of the spec file = %s" %self.date - + def setSource(self, source): ''' From the url retrieve the name of the source ''' if source != None: @@ -88,7 +90,7 @@ class RPackage: sourcedir = self.getRPMTopDirectory('_sourcedir') if os.path.exists(sourcedir): os.chdir(sourcedir) - + if self.source0 != None: source=self.source0.rsplit('/',1)[1] # Check the presence of the source, download only if they are not already in the working directory @@ -102,7 +104,11 @@ class RPackage: if not os.path.isfile(source): print "File not downloaded" sys.exit(1) - + else: + print "Moving tarball to %s " % sourcedir + self.source = "%s/%s" % (self.path, self.source) + self.moveSource(True) + self.setSource(self.source) os.chdir(oridir) def openSource(self): @@ -120,7 +126,7 @@ class RPackage: # Go to the tmp directory os.chdir(self.getRPMTopDirectory('_sourcedir') + '/tmp/') - + # Go into the tmp folder and untar the source if self.source.endswith('tar.gz'): cmd = "tar -zxvf " + "../" + self.source + " >/dev/null" @@ -147,26 +153,26 @@ class RPackage: os.rmdir('tmp') except IOError, err: sys.exit('tmp directory can not be removed') - + def setDescription(self, verbose = False): ''' Create the object description and fill the attributes ''' description = Description() description.setDescriptionFile(self) - + description.setVersion() description.setSummary() description.setDescription() description.setLicense() description.setRequires() - + if verbose: print "* Version of the library = %s" %description.version print "* Summary of the library = %s" %description.summary print "* Description of the library =\n %s " %description.description print "* License of the library = %s" %description.license - + self.description = description - + def getArch(self, verbose = False): ''' Determine is the package is of the type Noarch or Arch ''' # Save the top directory @@ -189,10 +195,10 @@ class RPackage: print "* The package is = Arch ~ x86 or x86_64" # Remove this file os.system('rm tmp') - + # Comes back to the original directory os.chdir(original_directory) - + def setPackager(self, bioc, name, email, verbose = False): ''' Creates the object packager and fill the attributes ''' packager = Packager() @@ -220,7 +226,6 @@ class RPackage: self.source0 = "http://bioconductor.org/packages/release/bioc/src/contrib/%{packname}_%{version}.tar.gz" self.URL = "http://bioconductor.org/packages/release/bioc/html/" + self.name + ".html" - def setCranUrl(self): ''' Set the url of a standard Cran package if the option has been used ''' if self.source0 is None: @@ -270,12 +275,12 @@ class RPackage: else: text = "There are already several version of the specfile in this directory, please indiquate the name you would like to give:\n" specname = raw_input(text) - + spec = Spec(self) spec.finishName(self.arch) spec.writeSpec(specname, verbose) if todo: spec.writeOut() - + def getRPMTopDirectory(self, tag, package = None): ''' Reads the .rpmmacros and set the values accordingly Code from José Matos. @@ -293,7 +298,7 @@ class RPackage: dirname = dirname.replace("%name", specname) return dirname - + def moveSource(self, copyFile): ''' Moves the tarball to where it should be to build the RPM ''' sourcedir = self.getRPMTopDirectory("_sourcedir") @@ -306,15 +311,18 @@ class RPackage: if answer == '': answer = "y" if answer.lower() == "y" or answer.lower() == "yes": - print "cp ./" + self.source, "to", sourcedir + if self.verbose: + print "cp ./" + self.source, "to", sourcedir try: shutil.copy(self.source, sourcedir) - print "Done" + if self.verbose: + print "Done" except Exception, err: print "Can not copy the source to ",sourcedir print err else: - print "Done" + if self.verbose: + print "Done" def findSourceOfPackage(self, name): ''' For a given name find in which repository the source are and returns the corresponding url. @@ -329,7 +337,7 @@ class RPackage: 'http://www.bioconductor.org/packages/release/data/experiment/html/%s.html': 'http://www.bioconductor.org/packages/release/data/experiment/src/contrib/PACKAGES', 'http://www.bioconductor.org/packages/release/data/annotation/html/%s.html': 'http://www.bioconductor.org/packages/release/data/annotation/src/contrib/PACKAGES', } - + for repo in dicrepo.keys(): try: f = urllib.urlopen(dicrepo[repo])