diff --git a/Makefile b/Makefile index 050b9db..ccdff40 100644 --- a/Makefile +++ b/Makefile @@ -19,13 +19,13 @@ rpms: all: $(MAKE) -C qrexec-lib all $(MAKE) -C qmemman all - $(MAKE) -C core all + $(MAKE) -C imgconverter all install: $(MAKE) -C udev install $(MAKE) -C qrexec-lib install $(MAKE) -C qmemman install - $(MAKE) -C core install + $(MAKE) -C imgconverter install install-fedora-kernel-support: $(MAKE) -C dracut install @@ -41,4 +41,4 @@ install-debian-kernel-support: clean: $(MAKE) -C qrexec-lib clean $(MAKE) -C qmemman clean - $(MAKE) -C core clean + $(MAKE) -C imgconverter clean diff --git a/core/Makefile b/core/Makefile deleted file mode 100644 index 6a60d96..0000000 --- a/core/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -PYTHON = /usr/bin/python2 -PYTHON_SITEARCH = `python2 -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_lib(1)'` - -all: - $(PYTHON) -m compileall . - $(PYTHON) -O -m compileall . -.PHONY: all - -clean: - $(RM) *.py[co] -.PHONY: clean - -install: - mkdir -p $(DESTDIR)/$(PYTHON_SITEARCH)/qubes/ -ifeq (1,${DEBIANBUILD}) - cp *.py $(DESTDIR)/$(PYTHON_SITEARCH)/qubes/ -else - cp *.py* $(DESTDIR)/$(PYTHON_SITEARCH)/qubes/ -endif -.PHONY: install diff --git a/core/__init__.py b/core/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/imgconverter/Makefile b/imgconverter/Makefile new file mode 100644 index 0000000..2a1e3bf --- /dev/null +++ b/imgconverter/Makefile @@ -0,0 +1,16 @@ +all: + python setup.py build +.PHONY: all + +clean: + python setup.py clean +.PHONY: clean + +install: + python setup.py install -O1 --skip-build --root $(DESTDIR) +#ifeq (1,${DEBIANBUILD}) +# cp *.py $(DESTDIR)/$(PYTHON_SITEARCH)/qubes/ +#else +# cp *.py* $(DESTDIR)/$(PYTHON_SITEARCH)/qubes/ +#endif +.PHONY: install diff --git a/core/imgconverter.py b/imgconverter/qubesimgconverter/__init__.py old mode 100755 new mode 100644 similarity index 78% rename from core/imgconverter.py rename to imgconverter/qubesimgconverter/__init__.py index d099307..d47d8a4 --- a/core/imgconverter.py +++ b/imgconverter/qubesimgconverter/__init__.py @@ -252,72 +252,4 @@ def make_padlock(dst, colour, size=ICON_MAXSIZE): cs.write_to_png(dst) - -class TestCaseImage(unittest.TestCase): - def setUp(self): - self.rgba = \ - '\x00\x00\x00\xff' '\xff\x00\x00\xff' \ - '\x00\xff\x00\xff' '\x00\x00\x00\xff' - self.size = (2, 2) - - self.image = Image(rgba=self.rgba, size=self.size) - - def test_00_init(self): - self.assertEqual(self.image._rgba, self.rgba) - self.assertEqual(self.image._size, self.size) - - def test_01_tint(self): - image = self.image.tint('#0000ff') - - self.assertEqual(image._rgba, - '\x00\x00\x00\xff' '\x00\x00\xff\xff' - '\x00\x00\xff\xff' '\x00\x00\x00\xff') - - def test_10_get_from_stream(self): - io = StringIO.StringIO('{0[0]} {0[1]}\n{1}'.format(self.size, self.rgba)) - - image = Image.get_from_stream(io) - - self.assertEqual(image._rgba, self.rgba) - self.assertEqual(image._size, self.size) - - def test_11_get_from_stream_malformed(self): - io = StringIO.StringIO('{0[0]} {0[1]}\n{1}'.format(self.size, self.rgba[-1])) # one byte too short - - with self.assertRaises(Exception): - image = Image.get_from_stream(io) - - def test_12_get_from_stream_too_big(self): - io = StringIO.StringIO('{0[0]} {0[1]}\n{1}'.format(self.size, self.rgba)) # 2x2 - - with self.assertRaises(Exception): - image = Image.get_from_stream(io, max_width=1) - - io.seek(0) - with self.assertRaises(Exception): - image = Image.get_from_stream(io, max_height=1) - -class TestCaseFunctionsAndConstants(unittest.TestCase): - def test_00_imghdrlen(self): - self.assertEqual(imghdrlen(8, 15), len('8 15\n')) - - def test_01_re_imghdr(self): - self.assertTrue(re_imghdr.match('8 15\n')) - self.assertIsNone(re_imghdr.match('8 15')) - self.assertIsNone(re_imghdr.match('815\n')) - self.assertIsNone(re_imghdr.match('x yx\n')) - - def test_10_hex_to_float_result_00(self): - self.assertEqual(hex_to_float('#000000'), (0.0, 0.0, 0.0)) - - def test_11_hex_to_float_result_ff(self): - self.assertEqual(hex_to_float('0xffffff'), (1.0, 1.0, 1.0)) - - def test_12_hex_to_float_depth_3_not_implemented(self): - with self.assertRaises(NotImplementedError): - hex_to_float('123456', depth=3) - -if __name__ == '__main__': - unittest.main() - # vim: ft=python sw=4 ts=4 et diff --git a/imgconverter/qubesimgconverter/test.py b/imgconverter/qubesimgconverter/test.py new file mode 100644 index 0000000..4bcd0a2 --- /dev/null +++ b/imgconverter/qubesimgconverter/test.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python2 + +from __future__ import absolute_import + +import cStringIO as StringIO +import unittest + +import qubesimgconverter + +class TestCaseImage(unittest.TestCase): + def setUp(self): + self.rgba = \ + '\x00\x00\x00\xff' '\xff\x00\x00\xff' \ + '\x00\xff\x00\xff' '\x00\x00\x00\xff' + self.size = (2, 2) + + self.image = qubesimgconverter.Image(rgba=self.rgba, size=self.size) + + def test_00_init(self): + self.assertEqual(self.image._rgba, self.rgba) + self.assertEqual(self.image._size, self.size) + + def test_01_tint(self): + image = self.image.tint('#0000ff') + + self.assertEqual(image._rgba, + '\x00\x00\x00\xff' '\x00\x00\xff\xff' + '\x00\x00\xff\xff' '\x00\x00\x00\xff') + + def test_10_get_from_stream(self): + io = StringIO.StringIO('{0[0]} {0[1]}\n{1}'.format(self.size, self.rgba)) + + image = qubesimgconverter.Image.get_from_stream(io) + + self.assertEqual(image._rgba, self.rgba) + self.assertEqual(image._size, self.size) + + def test_11_get_from_stream_malformed(self): + io = StringIO.StringIO('{0[0]} {0[1]}\n{1}'.format(self.size, self.rgba[-1])) # one byte too short + + with self.assertRaises(Exception): + image = qubesimgconverter.Image.get_from_stream(io) + + def test_12_get_from_stream_too_big(self): + io = StringIO.StringIO('{0[0]} {0[1]}\n{1}'.format(self.size, self.rgba)) # 2x2 + + with self.assertRaises(Exception): + image = qubesimgconverter.Image.get_from_stream(io, max_width=1) + + io.seek(0) + with self.assertRaises(Exception): + image = qubesimgconverter.Image.get_from_stream(io, max_height=1) + +class TestCaseFunctionsAndConstants(unittest.TestCase): + def test_00_imghdrlen(self): + self.assertEqual(qubesimgconverter.imghdrlen(8, 15), len('8 15\n')) + + def test_01_re_imghdr(self): + self.assertTrue(qubesimgconverter.re_imghdr.match('8 15\n')) + self.assertIsNone(qubesimgconverter.re_imghdr.match('8 15')) + self.assertIsNone(qubesimgconverter.re_imghdr.match('815\n')) + self.assertIsNone(qubesimgconverter.re_imghdr.match('x yx\n')) + + def test_10_hex_to_float_result_00(self): + self.assertEqual(qubesimgconverter.hex_to_float('#000000'), (0.0, 0.0, 0.0)) + + def test_11_hex_to_float_result_ff(self): + self.assertEqual(qubesimgconverter.hex_to_float('0xffffff'), (1.0, 1.0, 1.0)) + + def test_12_hex_to_float_depth_3_not_implemented(self): + with self.assertRaises(NotImplementedError): + qubesimgconverter.hex_to_float('123456', depth=3) + +if __name__ == '__main__': + unittest.main() diff --git a/imgconverter/setup.py b/imgconverter/setup.py new file mode 100644 index 0000000..b4466a1 --- /dev/null +++ b/imgconverter/setup.py @@ -0,0 +1,14 @@ +import setuptools + +setuptools.setup( + name='qubesimgconverter', + version=open('../version').read().strip(), + author='Invisible Things Lab', + author_email='woju@invisiblethingslab.com', + description='Toolkit for secure transfer and conversion of images between Qubes VMs.', + license='GPL2+', + url='https://www.qubes-os.org/', + packages=['qubesimgconverter'], +) + +# vim: ts=4 sts=4 sw=4 et diff --git a/rpm_spec/qubes-utils.spec b/rpm_spec/qubes-utils.spec index 7335127..7ca627c 100644 --- a/rpm_spec/qubes-utils.spec +++ b/rpm_spec/qubes-utils.spec @@ -3,7 +3,7 @@ %define _builddir %(pwd) %endif -%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")} +%{!?python_sitepath: %define python_sitepath %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(0)")} Name: qubes-utils Version: %{version} @@ -77,12 +77,12 @@ rm -rf $RPM_BUILD_ROOT %{_sbindir}/meminfo-writer %{_unitdir}/qubes-meminfo-writer.service %{_unitdir}/qubes-meminfo-writer-dom0.service -%{python_sitearch}/qubes/__init__.py -%{python_sitearch}/qubes/__init__.pyc -%{python_sitearch}/qubes/__init__.pyo -%attr(0755,root,root) %{python_sitearch}/qubes/imgconverter.py -%{python_sitearch}/qubes/imgconverter.pyc -%{python_sitearch}/qubes/imgconverter.pyo +#%{python_sitearch}/qubes/__init__.py +#%{python_sitearch}/qubes/__init__.pyc +#%{python_sitearch}/qubes/__init__.pyo +%{python_sitepath}/qubesimgconverter/__init__.py* +%{python_sitepath}/qubesimgconverter/test.py* +%{python_sitepath}/qubesimgconverter-%{version}-py?.?.egg-info/* %files libs %{_libdir}/libqrexec-utils.so.2