Skip to content
Browse files

Removed the /opt/virtualenvs destination in favor of using the

original path
  • Loading branch information...
1 parent ef987ce commit 1995eff4dc8ef4023e1242f5f664741fd70a4cc0 Eric Moritz committed Apr 19, 2012
View
34 package_virtualenv/backends/rpm.py
@@ -4,6 +4,24 @@
from .. import ldd
from subprocess import Popen, PIPE
+name_pat = re.compile(r"^Name\s+: ([\w_-]+)")
+
+def get_package_name(package_label):
+ p = Popen(["rpm", "-qi", package_label],
+ stdout=PIPE, stderr=PIPE)
+ returncode = p.wait()
+
+ if returncode:
+ raise Exception(p.stderr.read())
+
+ content = p.stdout.read()
+
+ match = name_pat.match(content)
+ if match:
+ return match.group(1)
+ else:
+ raise Exception("Could not find name in 'rpm -qi %' output " % (package_label, ))
+
def find_packages(file_set):
p = Popen(["rpm", "-qf"] + list(file_set),
@@ -18,7 +36,7 @@ def find_packages(file_set):
for line in p.stdout:
line = line.strip()
if line:
- result.add(line)
+ result.add(get_package_name(line))
return result
@@ -54,23 +72,21 @@ def build_spec(virtualenv_root,
lines.append(description)
+ rel_root = virtualenv_root[1:]
lines.append("")
lines.append("""%%build
-mkdir -p $RPM_BUILD_ROOT/opt/virtualenvs
-cp -r %(root)s $RPM_BUILD_ROOT/opt/virtualenvs/"""\
- % {"root": virtualenv_root})
+mkdir -p $RPM_BUILD_ROOT/%(rel_root)s
+cp -r %(root)s/* $RPM_BUILD_ROOT/%(rel_root)s/"""\
+ % {"root": virtualenv_root,
+ "rel_root": rel_root})
lines.append("")
lines.append("%files")
- root_pat = re.compile("^" + re.escape(virtualenv_root + "/"))
for filename in files:
- without_root = root_pat.sub("", filename)
- arcroot = "/opt/virtualenvs/" + os.path.basename(virtualenv_root)
- arcfile = os.path.join(arcroot , without_root)
- lines.append(arcfile)
+ lines.append(filename)
lines.append("")
View
5 package_virtualenv/backends/zip.py
@@ -8,13 +8,10 @@
def collect_filenames(root):
if root.endswith("/"): root = root[:-1]
name = os.path.basename(root)
- root_pat = re.compile("^" + re.escape(root + "/"))
# Collect the virtualenvs
for filename in utils.find_files(root):
- without_root = root_pat.sub("", filename)
- arcname = os.path.join("/virtualenvs", name, without_root)
- yield (filename, arcname)
+ yield (filename, filename)
# Collect the libraries
for library in utils.find_libraries(root):
View
14 tests/fixtures/packagelist.txt
@@ -1,7 +1,7 @@
-libgpg-error-1.7-4.el6.x86_64
-libxml2-2.7.6-4.el6_2.4.x86_64
-python-libs-2.6.6-29.el6.x86_64
-libgcrypt-1.4.5-9.el6_2.2.x86_64
-glibc-2.12-1.47.el6_2.9.x86_64
-zlib-1.2.3-27.el6.x86_64
-libxslt-1.1.26-2.el6.x86_64
+libgpg-error
+libxml2
+python-libs
+libgcrypt
+glibc
+zlib
+libxslt
View
1 tests/fixtures/test-env/lib/lib
View
13 tests/test_rpm.py
@@ -6,6 +6,13 @@
import fixtures
+class TestGetPackageName(unittest.TestCase):
+ def test(self):
+ expected = "iptables"
+ result = rpm.get_package_name("iptables-1.4.7-3.el6.x86_64")
+ self.assertEqual(expected, result)
+
+
class TestFindPackages(unittest.TestCase):
def test(self):
@@ -29,11 +36,11 @@ def test(self):
A long description
%build
-mkdir -p $RPM_BUILD_ROOT/opt/virtualenvs
-cp -r /tmp/test-env $RPM_BUILD_ROOT/opt/virtualenvs/
+mkdir -p $RPM_BUILD_ROOT/tmp/test-env
+cp -r /tmp/test-env/* $RPM_BUILD_ROOT/tmp/test-env/
%files
-/opt/virtualenvs/test-env/foo
+/tmp/test-env/foo
"""
result = rpm.build_spec("/tmp/test-env/",
View
9 tests/test_zip.py
@@ -15,16 +15,15 @@ def test(self):
def make_fixture(line):
filename = line.strip()
- if filename.startswith("/"):
- return filename, filename
- else:
- return (os.path.join(root, filename),
- os.path.join("/virtualenvs/test-env", filename))
+ if not filename.startswith("/"):
+ filename = os.path.join(root, filename)
+ return filename, filename
expected = set(imap(make_fixture,
fixtures.FILES | fixtures.LIBRARIES))
result = set(zip.collect_filenames(root))
+ print expected - result
self.assertEqual(expected, result)

0 comments on commit 1995eff

Please sign in to comment.
Something went wrong with that request. Please try again.