def combine_files(destination, path_list, include_imports=False): """ Combine the files in ``path_list`` to create one file at ``destination``. :param destination: The full file path of the resulting file :type destination: ``string`` :param path_list: A list of full file paths that should be combined :type path_list: ``list`` """ import cStringIO source = cStringIO.StringIO() result_file = None try: for item in path_list: content = open(item).read() if include_imports and item.endswith('.css'): content = csscompressor.remove_comments(content) content = csscompressor.include_imports(content, os.path.dirname(item)) source.write(content) source.write('\n') src_chksum = zlib.adler32(source.getvalue()) if os.path.exists(destination): func = "Replacing " dst_chksum = zlib.adler32(open(destination, 'rb').read()) else: func = "Writing " dst_chksum = 0 if src_chksum != dst_chksum: print "%s%s" % (func, destination) result_file = open(destination, 'w').write(source.getvalue()) finally: source.close() if result_file: result_file.close()
def test_remove_comments(self): css = "/*This is a \nmultiline comment */\n\n// This is a regular comment\n" self.assertEquals(csscompressor.remove_comments(css), '\n\n\n')