@@ -32,12 +32,27 @@ def hasmethod(obj, name):
32
32
return hasattr (obj , name ) and type (getattr (obj , name )) == types .MethodType
33
33
34
34
35
- def update_all (obj , config ):
35
+ def set_all (obj , config ):
36
36
for path , value in config .items ():
37
- update (obj , path , value )
37
+ setter (obj , path , value )
38
38
39
39
40
- def update (obj , path , val ):
40
+ def getter (obj , path ):
41
+ if len (path ) == 0 :
42
+ return obj
43
+ key = path [0 ]
44
+ if hasmethod (obj , key ):
45
+ import pdb
46
+ pdb .set_trace ()
47
+ return getattr (obj , key )(* path [1 ])
48
+ if isinstance (key , str ) and hasattr (obj , key ):
49
+ return getter (getattr (obj , key ), path [1 :])
50
+ if isinstance (obj , (list , dict , tuple , TTFont )):
51
+ return getter (obj [key ], path [1 :])
52
+ return obj
53
+
54
+
55
+ def setter (obj , path , val ):
41
56
if len (path ) == 0 :
42
57
return
43
58
key = path [0 ]
@@ -52,7 +67,7 @@ def update(obj, path, val):
52
67
return
53
68
54
69
if isinstance (key , str ) and hasattr (obj , key ):
55
- update (getattr (obj , key ), path [1 :])
70
+ setter (getattr (obj , key ), path [1 :], val )
56
71
elif isinstance (obj , (list , dict , tuple , TTFont )):
57
72
is_tuple = False
58
73
# convert numeric keys if needed
@@ -65,7 +80,7 @@ def update(obj, path, val):
65
80
if isinstance (obj [key ], tuple ):
66
81
is_tuple = True
67
82
obj [key ] = list (obj [key ])
68
- update (obj [key ], path [1 :], val )
83
+ setter (obj [key ], path [1 :], val )
69
84
if is_tuple :
70
85
obj [key ] = tuple (obj [key ])
71
86
@@ -78,7 +93,7 @@ def main(args=None):
78
93
args = parser .parse_args (args )
79
94
80
95
config = load_config (args .config )
81
- update_all (args .font , config )
96
+ set_all (args .font , config )
82
97
83
98
if not args .out :
84
99
args .out = makeOutputFileName (args .font .reader .file .name )
0 commit comments