Chromium Code Reviews| 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) |