mirror of
https://github.com/clearlinux/autospec.git
synced 2026-08-20 05:55:52 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8bc25eebe3 | |||
| 4004cffc23 | |||
| a3589e1a70 |
+30
-2
@@ -315,7 +315,7 @@ class Specfile(object):
|
||||
self._write("%defattr(-,root,root,-)\n")
|
||||
if "main" in self.packages:
|
||||
for filename in sorted(self.packages["main"]):
|
||||
self._write("{}\n".format(filename))
|
||||
self._write("{}\n".format(self.quote_filename(filename)))
|
||||
|
||||
for pkg in sorted(self.packages):
|
||||
if pkg in ["ignore", "main", "locales"]:
|
||||
@@ -324,7 +324,7 @@ class Specfile(object):
|
||||
self._write("\n%files {}\n".format(pkg))
|
||||
self._write("%defattr(-,root,root,-)\n")
|
||||
for filename in sorted(self.packages[pkg]):
|
||||
self._write("{}\n".format(filename))
|
||||
self._write("{}\n".format(self.quote_filename(filename)))
|
||||
|
||||
def write_lang_files(self):
|
||||
"""
|
||||
@@ -1162,3 +1162,31 @@ class Specfile(object):
|
||||
|
||||
def _write_strip(self, string):
|
||||
self.specfile.write_strip(string)
|
||||
|
||||
def quote_filename(self, filename):
|
||||
"""
|
||||
Quotes the filename, if necessary. Identifies and skips any RPM directive prefix.
|
||||
"""
|
||||
# Characters that require quoting -- only those with special
|
||||
# meaning in specfiles
|
||||
special_chars = set(" \t")
|
||||
# Build up the output as a string
|
||||
quoted = ''
|
||||
# Capture any directive prefix separately from actual filename
|
||||
# (1 )(3 )
|
||||
directive_re = re.compile("(%\w+(\([^\)]*\))?\s+)(.*)")
|
||||
parts = directive_re.match(filename)
|
||||
if parts:
|
||||
# Add prefix to the output
|
||||
quoted += parts.group(1)
|
||||
# Set the filename to the remaining portion
|
||||
filename = parts.group(3)
|
||||
|
||||
# Now check for special characters
|
||||
if any(c in filename for c in special_chars):
|
||||
# Quote the filename
|
||||
quoted += '"{}"'.format(filename)
|
||||
else:
|
||||
# Add the filename as-is
|
||||
quoted += filename
|
||||
return quoted
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
import sys, os
|
||||
version = "1.1.0"
|
||||
version = "1.1.1"
|
||||
|
||||
def readme():
|
||||
with open("README.rst") as f:
|
||||
|
||||
@@ -343,15 +343,21 @@ class TestSpecfileWrite(unittest.TestCase):
|
||||
"""
|
||||
test write_files base test.
|
||||
"""
|
||||
self.specfile.packages["main"] = ["mainfile1", "mainfile2", "mainfile3"]
|
||||
self.specfile.packages["main"] = ["mainfile1", "/mainfile2", "/mainfile3",
|
||||
"/mainfile 4", "mainfile\t5", "%foo /mainfile6", "%bar /mainfile 7"]
|
||||
self.specfile.packages["ignore"] = ["ignorepkg"]
|
||||
self.specfile.packages["other"] = ["other2", "other1"]
|
||||
self.specfile.write_files()
|
||||
# Note the special sorting
|
||||
expect = ["\n%files\n",
|
||||
"%defattr(-,root,root,-)\n",
|
||||
'%bar "/mainfile 7"\n',
|
||||
"%foo /mainfile6\n",
|
||||
'"/mainfile 4"\n',
|
||||
"/mainfile2\n",
|
||||
"/mainfile3\n",
|
||||
'"mainfile\t5"\n',
|
||||
"mainfile1\n",
|
||||
"mainfile2\n",
|
||||
"mainfile3\n",
|
||||
"\n%files other\n",
|
||||
"%defattr(-,root,root,-)\n",
|
||||
"other1\n",
|
||||
|
||||
Reference in New Issue
Block a user