Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Unified Diff: tools/grit/grit/format/policy_templates/writers/adm_writer.py

Issue 6327011: Allow ADM(X) templates to manage both MACHINE and USER policies (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: " Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/grit/grit/format/policy_templates/writers/adm_writer.py
diff --git a/tools/grit/grit/format/policy_templates/writers/adm_writer.py b/tools/grit/grit/format/policy_templates/writers/adm_writer.py
index b55ede180c6633abfe19163d2309410e564aae8c..c3ccf1efec7b18b3d988c62d5710f872c8ebf2c5 100644
--- a/tools/grit/grit/format/policy_templates/writers/adm_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/adm_writer.py
@@ -31,7 +31,7 @@ class AdmWriter(template_writer.TemplateWriter):
# Escape newlines in the value.
value = value.replace('\n', '\\n')
line = '%s="%s"' % (name, value)
- self.str_list.append(line)
+ self.strings.append(line)
def _PrintLine(self, string='', indent_diff=0):
'''Prints a string with indents and a linebreak to the output.
Jakob Kummerow 2011/01/24 16:52:28 More accurate would be: "Appends a string with ind
@@ -46,9 +46,9 @@ class AdmWriter(template_writer.TemplateWriter):
if indent_diff < 0:
self.indent = self.indent[(-indent_diff):]
if string != '':
- self.policy_list.append(self.indent + string)
+ self.lines.append(self.indent + string)
else:
- self.policy_list.append('')
+ self.lines.append('')
if indent_diff > 0:
self.indent += ''.ljust(indent_diff)
@@ -121,26 +121,30 @@ class AdmWriter(template_writer.TemplateWriter):
def EndPolicyGroup(self):
if self._open_category:
self._PrintLine('END CATEGORY', -1)
+ self._PrintLine('')
- def BeginTemplate(self):
+ def _WriteTemplateForClass(self, policy_class, policies):
+ '''Writes the whole ADM template except for the [strings] section.
+ The output is self.lines.
+
+ Args:
+ policy_class: USER or MACHINE
+ policies: ADM code for all the policies in the form of list of
+ strings.
+ '''
category_path = self.config['win_category_path']
- self._AddGuiString(self.config['win_supported_os'],
- self.messages['win_supported_winxpsp2']['text'])
- self._PrintLine(
- 'CLASS ' + self.config['win_group_policy_class'].upper(),
- 1)
+
+ self._PrintLine('CLASS ' + policy_class, 1)
if self.config['build'] == 'chrome':
- self._AddGuiString(category_path[0], 'Google')
- self._AddGuiString(category_path[1], self.config['app_name'])
self._PrintLine('CATEGORY !!' + category_path[0], 1)
self._PrintLine('CATEGORY !!' + category_path[1], 1)
elif self.config['build'] == 'chromium':
- self._AddGuiString(category_path[0], self.config['app_name'])
self._PrintLine('CATEGORY !!' + category_path[0], 1)
self._PrintLine('KEYNAME "%s"' % self.config['win_reg_key_name'])
self._PrintLine()
- def EndTemplate(self):
+ self.lines += policies
+
if self.config['build'] == 'chrome':
self._PrintLine('END CATEGORY', -1)
self._PrintLine('END CATEGORY', -1)
@@ -149,11 +153,36 @@ class AdmWriter(template_writer.TemplateWriter):
self._PrintLine('END CATEGORY', -1)
self._PrintLine('', -1)
+ def BeginTemplate(self):
+ category_path = self.config['win_category_path']
+ self._AddGuiString(self.config['win_supported_os'],
+ self.messages['win_supported_winxpsp2']['text'])
+ if self.config['build'] == 'chrome':
+ self._AddGuiString(category_path[0], 'Google')
+ self._AddGuiString(category_path[1], self.config['app_name'])
+ self.indent = ' '
+ elif self.config['build'] == 'chromium':
+ self._AddGuiString(category_path[0], self.config['app_name'])
+ self.indent = ' '
+ # After this, all the policies will be written into self.lines. The header
+ # and footer of the template will be added in self.EndTemplates().
Jakob Kummerow 2011/01/24 16:52:28 nit: self.EndTemplate()
gfeher 2011/01/25 10:42:21 Done.
+
+ def EndTemplate(self):
+ # Save the list of policies.
+ policies = self.lines
+ self.lines = []
+ self.indent = ''
+ policy_class = self.config['win_group_policy_class'].upper()
+ if policy_class in ('BOTH', 'MACHINE'):
+ self._WriteTemplateForClass('MACHINE', policies)
+ if policy_class in ('BOTH', 'USER'):
+ self._WriteTemplateForClass('USER', policies)
+
def Init(self):
- self.policy_list = []
- self.str_list = ['[Strings]']
+ self.lines = []
+ self.strings = ['[Strings]']
self.indent = ''
def GetTemplateText(self):
- lines = self.policy_list + self.str_list
+ lines = self.lines + self.strings
return self.NEWLINE.join(lines)

Powered by Google App Engine
This is Rietveld 408576698