From 2cde741b316064f613fe540da030177c72e240ef Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Sun, 12 Sep 2010 01:36:38 -0700 Subject: [PATCH] Utility methods for unpacking a source tree from a single file. --- Cython/TestUtils.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Cython/TestUtils.py b/Cython/TestUtils.py index 6d62114c..094bc1a2 100644 --- a/Cython/TestUtils.py +++ b/Cython/TestUtils.py @@ -7,7 +7,8 @@ from Cython.Compiler.Visitor import TreeVisitor, VisitorTransform from Cython.Compiler import TreePath import unittest -import sys +import os, sys +import tempfile class NodeTypeWriter(TreeVisitor): def __init__(self): @@ -166,3 +167,19 @@ class TreeAssertVisitor(VisitorTransform): return node visit_Node = VisitorTransform.recurse_to_children + +def unpack_source_tree(tree_file): + dir = tempfile.mkdtemp() + cur_file = None + for line in open(tree_file).readlines(): + if line[:5] == '#####': + filename = line.strip().strip('#').strip() + path = os.path.join(dir, filename) + print os.path.dirname(path) + if not os.path.exists(os.path.dirname(path)): + print " ...creating" + os.makedirs(os.path.dirname(path)) + cur_file = open(path, 'w') + elif cur_file is not None: + cur_file.write(line) + return dir -- 2.26.2