| |
@@ -24,25 +24,37 @@
|
| |
|
| |
import datetime
|
| |
import os
|
| |
- import re
|
| |
import sys
|
| |
import textwrap
|
| |
- from jinja2 import Template
|
| |
+ from collections import namedtuple
|
| |
+
|
| |
+ from jinja2 import Environment, FileSystemLoader
|
| |
from r2spec import get_logger, get_rpm_tag, R2specError
|
| |
|
| |
|
| |
+ class Package(namedtuple('Package', 'name version')):
|
| |
+ def __str__(self):
|
| |
+ if self.version:
|
| |
+ return self.name + ' ' + self.version
|
| |
+ else:
|
| |
+ return self.name
|
| |
+
|
| |
+ @property
|
| |
+ def rpm_version(self):
|
| |
+ if self.version:
|
| |
+ return self.name + ' ' + self.version.replace('-', '.')
|
| |
+ else:
|
| |
+ return self.name
|
| |
+
|
| |
+
|
| |
def format_dependencies(dependencies):
|
| |
""" Format the dependencies cleanning them as much as possible for rpm.
|
| |
"""
|
| |
ignorelist = ['R']
|
| |
- # Regular expression used to determine whether the string is a
|
| |
- # version number
|
| |
- versionmotif = re.compile(r'\d\.\d\.?\d?')
|
| |
char = {
|
| |
'\r': '',
|
| |
'(': ' ',
|
| |
')': ' ',
|
| |
- ',': ' ',
|
| |
' ': ' ',
|
| |
}
|
| |
|
| |
@@ -50,17 +62,19 @@
|
| |
dependencies = dependencies.replace(key, char[key])
|
| |
dep_list = []
|
| |
|
| |
- for dep in dependencies.split(' '):
|
| |
- if dep.strip():
|
| |
- if not ">" in dep \
|
| |
- and not "<" in dep \
|
| |
- and not "=" in dep \
|
| |
- and len(versionmotif.findall(dep)) == 0 \
|
| |
- and dep.strip() not in ignorelist:
|
| |
- dep = 'R-%s' % dep.strip()
|
| |
- dep_list.append(dep)
|
| |
+ for dep in dependencies.split(','):
|
| |
+ dep = dep.strip()
|
| |
+ if dep:
|
| |
+ if ' ' in dep:
|
| |
+ name, version = dep.split(' ', 1)
|
| |
+ else:
|
| |
+ name = dep
|
| |
+ version = ''
|
| |
+ if name not in ignorelist:
|
| |
+ name = 'R-%s' % name.strip()
|
| |
+ dep_list.append(Package(name, version.strip()))
|
| |
|
| |
- return ' '.join(dep_list).strip()
|
| |
+ return dep_list
|
| |
|
| |
|
| |
class Spec:
|
| |
@@ -70,16 +84,17 @@
|
| |
"""
|
| |
|
| |
def __init__(self, settings, package=None, no_check=False,
|
| |
- no_suggest=False):
|
| |
+ with_deps=False):
|
| |
""" Constructor.
|
| |
"""
|
| |
self.package = package
|
| |
self.settings = settings
|
| |
- self.__dict = {}
|
| |
+ self.__dict = {
|
| |
+ 'with_deps': with_deps
|
| |
+ }
|
| |
self.log = get_logger()
|
| |
self.spec = None
|
| |
self.no_check = no_check
|
| |
- self.no_suggest = no_suggest
|
| |
|
| |
def add_files(self, files):
|
| |
""" Add to a spec file the given files list.
|
| |
@@ -145,11 +160,8 @@
|
| |
self.package.get('Depends'))
|
| |
self.__dict['imports'] = format_dependencies(
|
| |
self.package.get('Imports'))
|
| |
- if not self.no_suggest:
|
| |
- self.__dict['suggests'] = format_dependencies(
|
| |
- self.package.get('Suggests'))
|
| |
- else:
|
| |
- self.__dict['suggests'] = ""
|
| |
+ self.__dict['suggests'] = format_dependencies(
|
| |
+ self.package.get('Suggests'))
|
| |
self.__dict['description'] = textwrap.fill(
|
| |
self.package.get('Description'),
|
| |
width=75)
|
| |
@@ -205,17 +217,15 @@
|
| |
""" Read the empty template and fills it with the information
|
| |
retrieved.
|
| |
"""
|
| |
- template = '%s/specfile.tpl' % os.path.dirname(__file__)
|
| |
self.log.info('Filling spec template')
|
| |
+ loader = FileSystemLoader(os.path.dirname(__file__))
|
| |
+ env = Environment(loader=loader, lstrip_blocks=True, trim_blocks=True)
|
| |
try:
|
| |
- stream = open(template, 'r')
|
| |
- tplfile = stream.read()
|
| |
- stream.close()
|
| |
- mytemplate = Template(tplfile)
|
| |
+ mytemplate = env.get_template('specfile.tpl')
|
| |
self.spec = mytemplate.render(self.__dict)
|
| |
except IOError as err:
|
| |
self.log.debug('ERROR: %s', err)
|
| |
- raise R2specError('Cannot read the file %s' % template)
|
| |
+ raise R2specError('Cannot read the file %s' % (err, ))
|
| |
|
| |
def get_specfile(self):
|
| |
""" Return the path to the spec file.
|
| |
This does three things:
DESCRIPTION
)Suggests
instead ofRequires
Note, this is based on #22 due to conflicts.