1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#!/usr/bin/python2.4
# Copyright (c) 2009 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Visual Studio project reader/writer."""
import common
import xml.dom
import xml.dom.minidom
#------------------------------------------------------------------------------
class Writer(object):
"""Visual Studio XML tool file writer."""
def __init__(self, tool_file_path):
"""Initializes the tool file.
Args:
tool_file_path: Path to the tool file.
"""
self.tool_file_path = tool_file_path
self.doc = None
def Create(self, name):
"""Creates the tool file document.
Args:
name: Name of the tool file.
"""
self.name = name
# Create XML doc
xml_impl = xml.dom.getDOMImplementation()
self.doc = xml_impl.createDocument(None, 'VisualStudioToolFile', None)
# Add attributes to root element
self.n_root = self.doc.documentElement
self.n_root.setAttribute('Version', '8.00')
self.n_root.setAttribute('Name', self.name)
# Add rules section
self.n_rules = self.doc.createElement('Rules')
self.n_root.appendChild(self.n_rules)
def AddCustomBuildRule(self, name, cmd, description,
additional_dependencies,
outputs, extensions):
"""Adds a rule to the tool file.
Args:
name: Name of the rule.
description: Description of the rule.
cmd: Command line of the rule.
additional_dependencies: other files which may trigger the rule.
outputs: outputs of the rule.
extensions: extensions handled by the rule.
"""
n_rule = self.doc.createElement('CustomBuildRule')
n_rule.setAttribute('Name', name)
n_rule.setAttribute('ExecutionDescription', description)
n_rule.setAttribute('CommandLine', cmd)
n_rule.setAttribute('Outputs', ';'.join(outputs))
n_rule.setAttribute('FileExtensions', ';'.join(extensions))
n_rule.setAttribute('AdditionalDependencies',
';'.join(additional_dependencies))
self.n_rules.appendChild(n_rule)
def Write(self, writer=common.WriteOnDiff):
"""Writes the tool file."""
f = writer(self.tool_file_path)
self.doc.writexml(f, encoding='Windows-1252', addindent=' ', newl='\r\n')
f.close()
#------------------------------------------------------------------------------
|