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

Side by Side Diff: grit/format/policy_templates/writers/reg_writer.py

Issue 227073006: Added a policy writer for iOS Plists. (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: rebase Created 6 years, 8 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 unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 6
7 import json
8
7 from grit.format.policy_templates.writers import template_writer 9 from grit.format.policy_templates.writers import template_writer
8 10
9 11
10 def GetWriter(config): 12 def GetWriter(config):
11 '''Factory method for creating RegWriter objects. 13 '''Factory method for creating RegWriter objects.
12 See the constructor of TemplateWriter for description of 14 See the constructor of TemplateWriter for description of
13 arguments. 15 arguments.
14 ''' 16 '''
15 return RegWriter(['win'], config) 17 return RegWriter(['win'], config)
16 18
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 return 59 return
58 elif policy['type'] == 'list': 60 elif policy['type'] == 'list':
59 self._StartBlock(key, policy['name'], list) 61 self._StartBlock(key, policy['name'], list)
60 i = 1 62 i = 1
61 for item in example_value: 63 for item in example_value:
62 escaped_str = self._EscapeRegString(item) 64 escaped_str = self._EscapeRegString(item)
63 list.append('"%d"="%s"' % (i, escaped_str)) 65 list.append('"%d"="%s"' % (i, escaped_str))
64 i = i + 1 66 i = i + 1
65 else: 67 else:
66 self._StartBlock(key, None, list) 68 self._StartBlock(key, None, list)
67 if policy['type'] in ('string', 'dict'): 69 if policy['type'] in ('string', 'string-enum', 'dict'):
68 escaped_str = self._EscapeRegString(str(example_value)) 70 example_value_str = json.dumps(example_value, sort_keys=True)
69 example_value_str = '"' + escaped_str + '"' 71 if policy['type'] == 'dict':
72 example_value_str = '"%s"' % example_value_str
70 elif policy['type'] == 'main': 73 elif policy['type'] == 'main':
71 if example_value == True: 74 if example_value == True:
72 example_value_str = 'dword:00000001' 75 example_value_str = 'dword:00000001'
73 else: 76 else:
74 example_value_str = 'dword:00000000' 77 example_value_str = 'dword:00000000'
75 elif policy['type'] in ('int', 'int-enum'): 78 elif policy['type'] in ('int', 'int-enum'):
76 example_value_str = 'dword:%08x' % example_value 79 example_value_str = 'dword:%08x' % example_value
77 elif policy['type'] == 'string-enum':
78 example_value_str = '"%s"' % example_value
79 else: 80 else:
80 raise Exception('unknown policy type %s:' % policy['type']) 81 raise Exception('unknown policy type %s:' % policy['type'])
81 82
82 list.append('"%s"=%s' % (policy['name'], example_value_str)) 83 list.append('"%s"=%s' % (policy['name'], example_value_str))
83 84
84 def WritePolicy(self, policy): 85 def WritePolicy(self, policy):
85 self._WritePolicy(policy, 86 self._WritePolicy(policy,
86 self.config['win_reg_mandatory_key_name'], 87 self.config['win_reg_mandatory_key_name'],
87 self._mandatory) 88 self._mandatory)
88 89
(...skipping 10 matching lines...) Expand all
99 100
100 def Init(self): 101 def Init(self):
101 self._mandatory = [] 102 self._mandatory = []
102 self._recommended = [] 103 self._recommended = []
103 self._last_key = {} 104 self._last_key = {}
104 105
105 def GetTemplateText(self): 106 def GetTemplateText(self):
106 prefix = ['Windows Registry Editor Version 5.00'] 107 prefix = ['Windows Registry Editor Version 5.00']
107 all = prefix + self._mandatory + self._recommended 108 all = prefix + self._mandatory + self._recommended
108 return self.NEWLINE.join(all) 109 return self.NEWLINE.join(all)
OLDNEW
« no previous file with comments | « grit/format/policy_templates/writers/plist_writer.py ('k') | grit/format/policy_templates/writers/reg_writer_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698