Handle registry timestamps as ints or floats

This commit is contained in:
Mathieu Comandon 2016-10-25 12:38:01 -07:00
parent c01f2c9ccc
commit 63347be383
3 changed files with 15 additions and 6 deletions

View file

@ -113,16 +113,21 @@ class WineRegistry(object):
class WineRegistryKey(object):
def __init__(self, key_def):
key, timestamp = key_def.strip().rsplit(' ', 1)
self.timestamp = int(timestamp)
self.raw_name = key_def[:key_def.index(']') + 1]
self.raw_timestamp = key_def[key_def.index(']') + 1:]
ts_parts = self.raw_timestamp.strip().split()
if len(ts_parts) == 1:
self.timestamp = int(ts_parts[0])
else:
self.timestamp = float("{}.{}".format(ts_parts[0], ts_parts[1]))
self.values = {}
self.name = key.replace('\\\\', '/').strip("[]")
self.name = self.raw_name.replace('\\\\', '/').strip("[]")
def set_key(self, name, value):
self.values[name.strip("\"")] = value.strip()
def __str__(self):
return "[{0}] {1}".format(self.winname, self.timestamp)
return "{0} {1}".format(self.raw_name, self.raw_timestamp)
@property
def winname(self):

View file

@ -130,8 +130,8 @@ WINE REGISTRY Version 2
"SnapToDefaultButton"="0"
"SwapMouseButtons"="0"
[Control Panel\\Sound] 1477412318
#time=1d22edb718040d6
[Control Panel\\Sound] 1475423303 7943190
#time=1d21cc468677196
"Beep"="Yes"
[Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders] 1477412318

View file

@ -20,3 +20,7 @@ class TestWineRegistry(TestCase):
def test_can_get_timestamp_as_int(self):
key = self.registry.get_key('Control Panel/Keyboard')
self.assertEqual(key.timestamp, 1477412318)
def test_can_get_timestamp_as_float(self):
key = self.registry.get_key('Control Panel/Sound')
self.assertEqual(key.timestamp, 1475423303.7943190)