23 class Output(object): |
23 class Output(object): |
24 """ |
24 """ |
25 Class representing an ExampleML output element. |
25 Class representing an ExampleML output element. |
26 """ |
26 """ |
27 |
27 |
28 def __init__(self, file, encoding, text): |
28 def __init__(self, file, encoding, text, lineno=None): |
29 self.file = file |
29 self.file = file |
30 self.encoding = encoding |
30 self.encoding = encoding |
31 self.text = text |
31 self.text = text |
|
32 self.lineno = lineno |
32 |
33 |
33 def get_refs(self): |
34 def get_refs(self): |
34 """ |
35 """ |
35 Return a list of all ConfML refs used in this output object. |
36 Return a list of all ConfML refs used in this output object. |
36 """ |
37 """ |
42 """ |
43 """ |
43 # Expand ConfML references |
44 # Expand ConfML references |
44 file = utils.expand_refs_by_default_view(self.file, config.get_default_view()) |
45 file = utils.expand_refs_by_default_view(self.file, config.get_default_view()) |
45 return os.path.normpath(os.path.join(output_dir, file)) |
46 return os.path.normpath(os.path.join(output_dir, file)) |
46 |
47 |
47 def write_to_file(self, output_dir, config): |
48 def write_to_file(self, output_dir, context): |
48 """ |
49 """ |
49 Write the text file specified by this output object to the |
50 Write the text file specified by this output object to the |
50 given output directory. |
51 given output directory. |
51 """ |
52 """ |
52 # Get the actual output path and encoding |
53 # Get the actual output path and encoding |
53 file_path = self.get_output_file(output_dir, config) |
54 file_path = self.get_output_file(output_dir, context.configuration) |
54 encoding = utils.expand_refs_by_default_view(self.encoding, config.get_default_view()) |
55 encoding = utils.expand_refs_by_default_view(self.encoding, context.configuration.get_default_view()) |
55 |
56 |
56 # Generate the binary data to write |
57 # Generate the binary data to write |
57 text = utils.expand_refs_by_default_view(self.text, config.get_default_view()) |
58 text = utils.expand_refs_by_default_view(self.text, context.configuration.get_default_view()) |
58 data = text.encode(encoding) |
59 data = text.encode(encoding) |
59 |
60 |
60 # Make sure that the output directory exists |
|
61 dir = os.path.dirname(file_path) |
|
62 if dir != '' and not os.path.exists(dir): |
|
63 os.makedirs(dir) |
|
64 |
61 |
65 # Write the file. |
62 # Write the file. |
66 f = open(file_path, "wb") |
63 f = context.create_file(file_path, mode="wb") |
67 try: f.write(data) |
64 try: f.write(data) |
68 finally: f.close() |
65 finally: f.close() |
69 |
66 |
70 def __eq__(self, other): |
67 def __eq__(self, other): |
71 if type(self) is type(other): |
68 if type(self) is type(other): |