OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
gab
2013/07/26 20:39:48
2013
| |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import _winreg | |
6 | |
7 def Verify(config): | |
8 for verifier_name, value in config.iteritems(): | |
9 if verifier_name == "RegistryEntries": | |
gab
2013/07/26 20:39:48
Is there some kind of switch statement for strings
sukolsak
2013/07/30 15:40:32
Python doesn't have a switch statement.
| |
10 VerifyRegistryEntries(value) | |
11 else: | |
12 # TODO: implement other verifiers | |
robertshield
2013/07/26 19:32:23
TODOs should be attributed:
# TODO(sukolsak): impl
| |
13 pass | |
14 | |
15 def VerifyRegistryEntries(entries): | |
gab
2013/07/26 20:39:48
I would put individual verifiers in their own modu
| |
16 for key, entry in entries.iteritems(): | |
17 if VerifyRegistryEntry(key, entry): | |
18 print "Passed" | |
19 else: | |
20 print "Failed" | |
21 | |
22 def RootKeyConstant(key): | |
23 if key == "HKEY_CLASSES_ROOT": | |
24 return _winreg.HKEY_CLASSES_ROOT | |
25 if key == "HKEY_CURRENT_USER": | |
26 return _winreg.HKEY_CURRENT_USER | |
27 if key == "HKEY_LOCAL_MACHINE": | |
28 return _winreg.HKEY_LOCAL_MACHINE | |
29 if key == "HKEY_USERS": | |
30 return _winreg.HKEY_USERS | |
31 raise Exception("Unknown registry key") | |
32 | |
33 def VerifyRegistryEntry(key, entry): | |
34 expected = entry["expected"] | |
35 print " - " + key | |
gab
2013/07/26 20:39:48
Constantify/document arbitrary formatting spaces
| |
36 if expected: | |
37 print " exists..." | |
38 else: | |
39 print " doesn't exist..." | |
40 try: | |
41 root_key, sub_key = key.split("\\", 1) | |
42 reg_key = _winreg.OpenKey(RootKeyConstant(root_key), \ | |
gab
2013/07/26 20:39:48
Why do you need a backslash here? (Sorry if this i
| |
43 sub_key, 0, _winreg.KEY_READ) | |
44 if expected == False: | |
45 return False | |
46 if "value" in entry: | |
47 # TODO: implement value | |
gab
2013/07/26 20:39:48
Name your TODO, i.e., TODO(sukolsak)
| |
48 pass | |
49 return True | |
50 except WindowsError: | |
51 return expected == False | |
OLD | NEW |