def test_convert_options(self): """ Test option handling """ opts = { 'mock': [' blah'] } path = self.make_fake() output = '%s/test.mock' % (self.outdir) if os.path.exists(output): os.remove(output) resp = converters.convert('mock', path, output, options=opts) self.assertTrue(resp) with open(output) as f: v = f.read() self.assertEquals(v, 'bogus blah') os.remove(output) opts['mock'] = ' blah' resp = converters.convert('mock', path, output, options=opts) self.assertTrue(resp) with open(output) as f: v = f.read() self.assertEquals(v, 'bogus blah') os.remove(output)
def test_convert(self): """ Test convert function using a mock format """ output = '%s/test.squashfs' % (self.outdir) resp = converters.convert('mock', '', output) assert resp is True assert os.path.exists(output) path = self.make_fake() resp = converters.convert('cramfs', path, '/tmp/blah.cramfs') self.assertTrue(resp) with self.assertRaises(NotImplementedError): resp = converters.convert('ext4', path, '/tmp/blah.ext4') resp = converters.convert('squashfs', path, output) self.assertTrue(resp)
def test_convert_options(self): """ Test option handling """ opts = {'mock': [' blah']} path = self.make_fake() output = '%s/test.mock' % (self.outdir) if os.path.exists(output): os.remove(output) resp = converters.convert('mock', path, output, options=opts) self.assertTrue(resp) with open(output) as f: v = f.read() self.assertEquals(v, 'bogus blah') os.remove(output) opts['mock'] = ' blah' resp = converters.convert('mock', path, output, options=opts) self.assertTrue(resp) with open(output) as f: v = f.read() self.assertEquals(v, 'bogus blah') os.remove(output)
def test_convert(self): """ Test convert function using a mock format """ opts = dict() output = '%s/test.squashfs' % (self.outdir) resp = converters.convert('mock', '', output) assert resp is True assert os.path.exists(output) os.remove(output) path = self.make_fake() resp = converters.convert('cramfs', path, '/tmp/blah.cramfs') self.assertTrue(resp) with self.assertRaises(NotImplementedError): resp = converters.convert('ext4', path, '/tmp/blah.ext4') resp = converters.convert('squashfs', path, output, options=opts) self.assertTrue(resp) with open(output) as f: line = f.read() self.assertIn('-no-xattrs', line)
def test_convert(self): """ Test convert function using a mock format """ opts = dict() output = '%s/test.squashfs' % (self.outdir) resp = converters.convert('mock', '', output) assert resp is True assert os.path.exists(output) os.remove(output) path = self.make_fake() resp = converters.convert('cramfs', path, '/tmp/blah.cramfs') self.assertTrue(resp) with self.assertRaises(NotImplementedError): resp = converters.convert('ext4', path, '/tmp/blah.ext4') resp = converters.convert('squashfs', path, output, options=opts) self.assertTrue(resp) with open(output) as f: line = f.read() self.assertIn('-no-xattrs',line)
def convert_image(request): """ Convert the image to the required format for the target system Returns True on success """ fmt = get_image_format(request) request['format'] = fmt edir = CONFIG['ExpandDirectory'] imagefile = os.path.join(edir, '%s.%s' % (request['id'], fmt)) request['imagefile'] = imagefile status = converters.convert(fmt, request['expandedpath'], imagefile) return status