70
77
values = self._items.get(key)
71
78
return values[-1][0] if values else None
73
def __init__(self, input_pathes, output_path):
74
self._input_pathes = tuple(input_pathes)
75
self._output_path = output_path
81
self._output_path = helpers.get_config_path()
76
82
self._groups = OrderedDict()
88
pathes += GLib.get_system_data_dirs()
89
pathes += GLib.get_system_config_dirs()
90
pathes.append(os.path.dirname(os.path.dirname(self._output_path)))
80
for path in self._input_pathes:
81
if os.path.isdir(path):
82
files.extend(sorted(iglob(os.path.join(path, '*.conf'))))
83
elif os.path.exists(path):
85
if self._output_path not in files:
86
files.append(self._output_path)
94
files += sorted(iglob(os.path.join(path, 'lightdm',
95
'lightdm-gtk-greeter.conf.d', '*.conf')))
96
files.append(os.path.join(path, 'lightdm', 'lightdm-gtk-greeter.conf'))
90
config_file = configparser.RawConfigParser(strict=False, allow_no_value=True)
91
config_file.read(path)
98
for path in filter(os.path.isfile, files):
99
config_file = configparser.RawConfigParser(strict=False)
100
if not config_file.read(path):
93
103
for groupname, values in config_file.items():
94
104
if groupname == 'DEFAULT':
99
109
group = self._groups[groupname]
101
111
for key, value in values.items():
112
if key.startswith('-'):
102
116
if key in group._items:
103
117
values = group._items[key]
104
118
if value is not None or values:
107
121
group._items[key] = [(path, value)]
110
config_file = configparser.RawConfigParser(strict=False, allow_no_value=True)
124
config_file = configparser.RawConfigParser(strict=False)
112
126
for groupname, group in self._groups.items():
113
config_file.add_section(groupname)
114
config_section = config_file[groupname]
127
config_section = None
116
128
for key, values in group._items.items():
117
129
if not values or values[-1][0] != self._output_path:
119
132
if values[-1][1] is not None or len(values) > 1:
120
config_section[key] = values[-1][1]
133
if not config_section:
134
config_file.add_section(groupname)
135
config_section = config_file[groupname]
136
if values[-1][1] is None:
137
config_section['-' + key] = ''
139
config_section[key] = values[-1][1]
122
141
with open(self._output_path, 'w') as file:
123
142
config_file.write(file)
144
def is_writable(self):
145
if os.path.exists(self._output_path) and os.access(self._output_path, os.W_OK):
147
return os.access(os.path.dirname(self._output_path), os.W_OK | os.X_OK)
126
150
return self._groups.items()