| |
@@ -20,17 +20,25 @@
|
| |
R packages class.
|
| |
"""
|
| |
|
| |
+ from __future__ import absolute_import, division, print_function
|
| |
|
| |
- import ConfigParser
|
| |
import os
|
| |
import re
|
| |
import shutil
|
| |
import sys
|
| |
import tarfile
|
| |
- import urllib2
|
| |
|
| |
from tarfile import TarError
|
| |
|
| |
+ try:
|
| |
+ import configparser
|
| |
+ except ImportError:
|
| |
+ import ConfigParser as configparser
|
| |
+ try:
|
| |
+ import urllib.request as urllib_request
|
| |
+ except ImportError:
|
| |
+ import urllib2 as urllib_request
|
| |
+
|
| |
from r2spec import get_logger, get_rpm_tag, R2specError
|
| |
|
| |
|
| |
@@ -44,20 +52,20 @@
|
| |
"""
|
| |
log = get_logger()
|
| |
try:
|
| |
- stream = urllib2.urlopen(url)
|
| |
- content = stream.read()
|
| |
+ stream = urllib_request.urlopen(url)
|
| |
+ content = stream.read().decode()
|
| |
stream.close()
|
| |
- sourcemotif = re.compile("Package:\s+%s\n" % name)
|
| |
+ sourcemotif = re.compile(r"Package:\s+%s\n" % name)
|
| |
result = sourcemotif.search(content)
|
| |
if result is not None:
|
| |
log.info("Package found in : %s" % url)
|
| |
- versionmotif = re.compile("Package:\s+%s\nVersion:(.*)" % name)
|
| |
+ versionmotif = re.compile(r"Package:\s+%s\nVersion:(.*)" % name)
|
| |
version = versionmotif.search(content).group(1).strip()
|
| |
return (version)
|
| |
else:
|
| |
log.info("Not Found: %s in %s" % (name, url))
|
| |
- except IOError, ex:
|
| |
- print 'Could not contact the repository at url: %s' % url
|
| |
+ except IOError as ex:
|
| |
+ print('Could not contact the repository at url: %s' % url)
|
| |
log.debug('Error: %s' % ex)
|
| |
return None
|
| |
|
| |
@@ -68,7 +76,7 @@
|
| |
def __init__(self, name=None, url=None, source0=None):
|
| |
""" Constructor. """
|
| |
self.name = name
|
| |
- parser = ConfigParser.ConfigParser()
|
| |
+ parser = configparser.RawConfigParser()
|
| |
parser.read('/etc/R2spec/repos.cfg')
|
| |
self.config = parser
|
| |
self.log = get_logger()
|
| |
@@ -129,13 +137,12 @@
|
| |
return
|
| |
|
| |
url = self.source0.rsplit('/', 1)[0]
|
| |
- url = '%s/%s' % (url,self.source)
|
| |
+ url = '%s/%s' % (url, self.source)
|
| |
self.log.info('Downloading %s' % url)
|
| |
|
| |
- remotefile = urllib2.urlopen(url)
|
| |
- localfile = open(sources, 'w')
|
| |
- localfile.write(remotefile.read())
|
| |
- localfile.close()
|
| |
+ remotefile = urllib_request.urlopen(url)
|
| |
+ with open(sources, 'wb') as localfile:
|
| |
+ localfile.write(remotefile.read())
|
| |
|
| |
def extract_sources(self):
|
| |
""" Extract the sources into the current directory. """
|
| |
@@ -146,7 +153,7 @@
|
| |
tar = tarfile.open(tarball)
|
| |
tar.extractall()
|
| |
tar.close()
|
| |
- except TarError, err:
|
| |
+ except TarError as err:
|
| |
self.log.debug("Error while extracting the tarball")
|
| |
self.log.debug("ERROR: %s" % err)
|
| |
|
| |
@@ -158,7 +165,7 @@
|
| |
:arg key, the key to retrieve from the DESCRIPTION file of the R
|
| |
package
|
| |
"""
|
| |
- if key and key in self.description.keys():
|
| |
+ if key and key in self.description:
|
| |
return self.description[key]
|
| |
else:
|
| |
return ''
|
| |
@@ -174,7 +181,7 @@
|
| |
stream = open(description, 'r')
|
| |
content = stream.read()
|
| |
stream.close()
|
| |
- except IOError, err:
|
| |
+ except IOError as err:
|
| |
self.log.info(
|
| |
'An error occured while reading the DESCRIPTION file: %s' \
|
| |
% description)
|
| |
@@ -182,7 +189,7 @@
|
| |
key = None
|
| |
for row in content.split('\n'):
|
| |
if row.strip():
|
| |
- pattern = re.compile("\w:*")
|
| |
+ pattern = re.compile(r"\w:*")
|
| |
if pattern.match(row):
|
| |
key, value = row.split(':', 1)
|
| |
self.description[key.strip()] = value.strip()
|
| |
@@ -196,7 +203,7 @@
|
| |
def read_config(self):
|
| |
""" Read the general configuration containing the repo information
|
| |
"""
|
| |
- parser = ConfigParser.ConfigParser()
|
| |
+ parser = configparser.RawConfigParser()
|
| |
configfile = '/etc/R2spec/config'
|
| |
parser.read(configfile)
|
| |
self.config = parser
|
| |
@@ -208,7 +215,7 @@
|
| |
self.log.info('Removing extracted sources: "%s"' % self.name)
|
| |
try:
|
| |
shutil.rmtree(self.name)
|
| |
- except (IOError, OSError), err:
|
| |
+ except (IOError, OSError) as err:
|
| |
self.log.info('Could not remove the extracted sources: "%s"'\
|
| |
% self.name)
|
| |
self.log.debug('ERROR: %s' % err)
|
| |
@@ -239,7 +246,7 @@
|
| |
self.source0 = self.config.get(repo, 'source')
|
| |
if self.up_version != self.down_version:
|
| |
self.source0 = self.source0.replace('%{version}', self.up_version)
|
| |
- self.source = '%s_%s.tar.gz' % (self.name,self.up_version)
|
| |
+ self.source = '%s_%s.tar.gz' % (self.name, self.up_version)
|
| |
|
| |
def set_repo(self, reponame):
|
| |
""" This function find the URL and Source0 tag for the spec file
|
| |
Pretty straightforward. All tests that were passing before continue to pass (a couple were already broken.)