introducing settings support
This commit is contained in:
@@ -60,7 +60,8 @@ SINGLE_OPTIONS = (
|
||||
'CleanMethod',
|
||||
'SigLevel',
|
||||
'LocalFileSigLevel',
|
||||
'RemoteFileSigLevel'
|
||||
'RemoteFileSigLevel',
|
||||
'RefreshPeriod'
|
||||
)
|
||||
|
||||
BOOLEAN_OPTIONS = (
|
||||
@@ -69,7 +70,9 @@ BOOLEAN_OPTIONS = (
|
||||
'CheckSpace',
|
||||
'VerbosePkgLists',
|
||||
'ILoveCandy',
|
||||
'Color'
|
||||
'Color',
|
||||
'EnableAUR',
|
||||
'RemoveUnrequiredDeps'
|
||||
)
|
||||
|
||||
def define_siglevel(default_level, conf_string):
|
||||
@@ -186,7 +189,7 @@ def pacman_conf_enumerator(path):
|
||||
else:
|
||||
warnings.warn(InvalidSyntax(f.name, 'unrecognized option', key))
|
||||
|
||||
class PacmanConfig:
|
||||
class PacmanConfig():
|
||||
def __init__(self, conf = None, options = None):
|
||||
self.options = {}
|
||||
self.repos = collections.OrderedDict()
|
||||
@@ -292,8 +295,79 @@ class PacmanConfig:
|
||||
def __str__(self):
|
||||
return("PacmanConfig(options={}, repos={})".format(self.options, self.repos))
|
||||
|
||||
def pamac_conf_enumerator(path):
|
||||
filestack = []
|
||||
current_section = None
|
||||
filestack.append(open(path))
|
||||
while len(filestack) > 0:
|
||||
f = filestack[-1]
|
||||
line = f.readline()
|
||||
if len(line) == 0:
|
||||
# end of file
|
||||
filestack.pop()
|
||||
continue
|
||||
|
||||
line = line.strip()
|
||||
if len(line) == 0:
|
||||
continue
|
||||
if line[0] == '#':
|
||||
continue
|
||||
# read key, value
|
||||
key, equal, value = [x.strip() for x in line.partition('=')]
|
||||
|
||||
if equal == '=':
|
||||
if key in LIST_OPTIONS:
|
||||
for val in value.split():
|
||||
yield (current_section, key, val)
|
||||
elif key in SINGLE_OPTIONS:
|
||||
if key == 'RefreshPeriod':
|
||||
yield (current_section, key, int(value))
|
||||
else:
|
||||
yield (current_section, key, value)
|
||||
else:
|
||||
warnings.warn(InvalidSyntax(f.name, 'unrecognized option', key))
|
||||
else:
|
||||
if key in BOOLEAN_OPTIONS:
|
||||
yield (current_section, key, True)
|
||||
else:
|
||||
warnings.warn(InvalidSyntax(f.name, 'unrecognized option', key))
|
||||
|
||||
class PamacConfig():
|
||||
def __init__(self, conf = None):
|
||||
self.options = {}
|
||||
self.options["RefreshPeriod"] = 3600*3
|
||||
self.options["EnableAUR"] = False
|
||||
self.options["RemoveUnrequiredDeps"] = False
|
||||
if conf:
|
||||
self.load_from_file(conf)
|
||||
|
||||
def load_from_file(self, filename):
|
||||
for section, key, value in pamac_conf_enumerator(filename):
|
||||
if key in LIST_OPTIONS:
|
||||
self.options.setdefault(key, []).append(value)
|
||||
else:
|
||||
self.options[key] = value
|
||||
self.set_global_variables()
|
||||
|
||||
def set_global_variables(self):
|
||||
global refresh_period
|
||||
global enable_aur
|
||||
global recurse
|
||||
refresh_period = self.options['RefreshPeriod']
|
||||
enable_aur = self.options['EnableAUR']
|
||||
recurse = self.options['RemoveUnrequiredDeps']
|
||||
|
||||
def reload(self):
|
||||
self.options["EnableAUR"] = False
|
||||
self.options["RemoveUnrequiredDeps"] = False
|
||||
self.load_from_file("/etc/pamac.conf")
|
||||
|
||||
def __str__(self):
|
||||
return("PamacConfig(options={})".format(self.options))
|
||||
|
||||
pacman_conf = PacmanConfig(conf = "/etc/pacman.conf")
|
||||
handle = pacman_conf.initialize_alpm
|
||||
pamac_conf = PamacConfig(conf = "/etc/pamac.conf")
|
||||
holdpkg = []
|
||||
syncfirst = []
|
||||
if 'HoldPkg' in pacman_conf.options:
|
||||
|
@@ -67,7 +67,7 @@ interface.add_from_file('/usr/share/pamac/gui/dialogs.ui')
|
||||
ErrorDialog = interface.get_object('ErrorDialog')
|
||||
WarningDialog = interface.get_object('WarningDialog')
|
||||
#InfoDialog = interface.get_object('InfoDialog')
|
||||
#QuestionDialog = interface.get_object('QuestionDialog')
|
||||
QuestionDialog = interface.get_object('QuestionDialog')
|
||||
ConfDialog = interface.get_object('ConfDialog')
|
||||
transaction_sum = interface.get_object('transaction_sum')
|
||||
sum_top_label = interface.get_object('sum_top_label')
|
||||
@@ -84,6 +84,10 @@ ProgressCancelButton = interface.get_object('ProgressCancelButton')
|
||||
ProgressCloseButton = interface.get_object('ProgressCloseButton')
|
||||
progress_expander = interface.get_object('progress_expander')
|
||||
progress_textview = interface.get_object('progress_textview')
|
||||
PreferencesWindow = interface.get_object('PreferencesWindow')
|
||||
EnableAURButton = interface.get_object('EnableAURButton')
|
||||
RemoveUnrequiredDepsButton = interface.get_object('RemoveUnrequiredDepsButton')
|
||||
RefreshPeriodSpinButton = interface.get_object('RefreshPeriodSpinButton')
|
||||
|
||||
progress_buffer = progress_textview.get_buffer()
|
||||
|
||||
@@ -107,6 +111,7 @@ def get_dbus_methods():
|
||||
global Release
|
||||
global StopDaemon
|
||||
global SetPkgReason
|
||||
global WriteConfig
|
||||
SetPkgReason = proxy.get_dbus_method('SetPkgReason','org.manjaro.pamac')
|
||||
Refresh = proxy.get_dbus_method('Refresh','org.manjaro.pamac')
|
||||
CheckUpdates = proxy.get_dbus_method('CheckUpdates','org.manjaro.pamac')
|
||||
@@ -122,6 +127,7 @@ def get_dbus_methods():
|
||||
Interrupt = proxy.get_dbus_method('Interrupt','org.manjaro.pamac')
|
||||
Release = proxy.get_dbus_method('Release','org.manjaro.pamac')
|
||||
StopDaemon = proxy.get_dbus_method('StopDaemon','org.manjaro.pamac')
|
||||
WriteConfig = proxy.get_dbus_method('WriteConfig','org.manjaro.pamac')
|
||||
|
||||
def config_dbus_signals():
|
||||
bus.add_signal_receiver(action_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitAction")
|
||||
@@ -200,7 +206,7 @@ def choose_provides(data):
|
||||
def on_choose_renderertoggle_toggled(widget, line):
|
||||
choose_list[line][0] = not choose_list[line][0]
|
||||
|
||||
def on_ChooseButton_clicked(*arg):
|
||||
def on_ChooseButton_clicked(*args):
|
||||
ChooseDialog.hide()
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
@@ -208,11 +214,26 @@ def on_ChooseButton_clicked(*arg):
|
||||
if row[0] is True:
|
||||
to_add.add(row[1].split(':')[0]) # split done in case of optdep choice
|
||||
|
||||
def on_progress_textview_size_allocate(*arg):
|
||||
def on_progress_textview_size_allocate(*args):
|
||||
#auto-scrolling method
|
||||
adj = progress_textview.get_vadjustment()
|
||||
adj.set_value(adj.get_upper() - adj.get_page_size())
|
||||
|
||||
def on_PreferencesValidButton_clicked(*args):
|
||||
data = []
|
||||
if EnableAURButton.get_active() != config.enable_aur:
|
||||
data.append(('EnableAUR', str(EnableAURButton.get_active())))
|
||||
if RemoveUnrequiredDepsButton.get_active() != config.recurse:
|
||||
data.append(('RemoveUnrequiredDeps', str(RemoveUnrequiredDepsButton.get_active())))
|
||||
if RefreshPeriodSpinButton.get_value() != config.refresh_period:
|
||||
data.append(('RefreshPeriod', str(RefreshPeriodSpinButton.get_value_as_int())))
|
||||
if data:
|
||||
WriteConfig(data)
|
||||
PreferencesWindow.hide()
|
||||
|
||||
def on_PreferencesCloseButton_clicked(*args):
|
||||
PreferencesWindow.hide()
|
||||
|
||||
def get_handle():
|
||||
global handle
|
||||
global syncdbs
|
||||
@@ -380,7 +401,7 @@ def check_to_build():
|
||||
print('builddeps:',build_depends)
|
||||
return error
|
||||
|
||||
def run():
|
||||
def run(cascade = True, recurse = False):
|
||||
if to_add or to_remove or to_load or to_build:
|
||||
global progress_buffer
|
||||
action_handler(_('Preparing')+'...')
|
||||
@@ -404,7 +425,7 @@ def run():
|
||||
if to_add or to_remove or to_load:
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
trans_flags = {'cascade' : True}
|
||||
trans_flags = {'cascade': cascade, 'recurse': recurse}
|
||||
error += init_transaction(**trans_flags)
|
||||
if not error:
|
||||
for name in to_add:
|
||||
|
Reference in New Issue
Block a user