Perference for checking (and currently updates) addons

svn: r15720
This commit is contained in:
Doug Blank 2010-08-13 06:18:11 +00:00
parent 506f9dc643
commit f9af188191
2 changed files with 75 additions and 8 deletions

View File

@ -970,15 +970,16 @@ class GrampsPreferences(ConfigureDialog):
self.old_format = the_list.get_value(the_iter, COL_FMT) self.old_format = the_list.get_value(the_iter, COL_FMT)
win = DisplayNameEditor(self.uistate, self.dbstate, self.track, self) win = DisplayNameEditor(self.uistate, self.dbstate, self.track, self)
def date_format_changed(self, obj): def check_for_updates_changed(self, obj):
config.set('behavior.check-for-updates', obj.get_active())
def date_format_changed(self, obj):
config.set('preferences.date-format', obj.get_active()) config.set('preferences.date-format', obj.get_active())
OkDialog(_('Change is not immediate'), OkDialog(_('Change is not immediate'),
_('Changing the data format will not take ' _('Changing the data format will not take '
'effect until the next time Gramps is started.')) 'effect until the next time Gramps is started.'))
def date_calendar_changed(self, obj): def date_calendar_changed(self, obj):
config.set('preferences.calendar-format-report', obj.get_active()) config.set('preferences.calendar-format-report', obj.get_active())
def add_date_panel(self, configdialog): def add_date_panel(self, configdialog):
@ -1041,6 +1042,21 @@ class GrampsPreferences(ConfigureDialog):
5, self.path_entry, self.dbstate.db.get_mediapath(), 5, self.path_entry, self.dbstate.db.get_mediapath(),
self.set_mediapath, self.select_mediapath) self.set_mediapath, self.select_mediapath)
# Check for updates:
obox = gtk.combo_box_new_text()
formats = [_("Never"),
_("Once a month"),
_("Once a week"),
_("Once a day"),
_("Always"), ]
map(obox.append_text, formats)
active = config.get('behavior.check-for-updates')
obox.set_active(active)
obox.connect('changed', self.check_for_updates_changed)
lwidget = BasicLabel("%s: " % _('Check for updates'))
table.attach(lwidget, 1, 2, 6, 7, yoptions=0)
table.attach(obox, 2, 4, 6, 7, yoptions=0)
return _('General'), table return _('General'), table
def add_database_panel(self, configdialog): def add_database_panel(self, configdialog):

View File

@ -33,8 +33,10 @@ Manages the main window and the pluggable views
# Standard python modules # Standard python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from __future__ import print_function
import os import os
import time import time
import datetime
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
from cStringIO import StringIO from cStringIO import StringIO
from collections import defaultdict from collections import defaultdict
@ -64,9 +66,9 @@ from gui.plug import tool
from gen.plug import (START, END) from gen.plug import (START, END)
from gen.plug import REPORT from gen.plug import REPORT
from gen.plug.report._constants import standalone_categories from gen.plug.report._constants import standalone_categories
from gui.plug import PluginWindows, \ from gui.plug import (PluginWindows, ReportPluginDialog, ToolPluginDialog)
ReportPluginDialog, ToolPluginDialog
from gui.plug.report import report from gui.plug.report import report
from gen.plug.utils import version_str_to_tup, load_addon_file
from gui.pluginmanager import GuiPluginManager from gui.pluginmanager import GuiPluginManager
import Relationship import Relationship
import DisplayState import DisplayState
@ -86,6 +88,7 @@ from gen.db.backup import backup
from gen.db.exceptions import DbException from gen.db.exceptions import DbException
from GrampsAboutDialog import GrampsAboutDialog from GrampsAboutDialog import GrampsAboutDialog
from gui.sidebar import Sidebar from gui.sidebar import Sidebar
from gen.utils.configmanager import safe_eval
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -268,6 +271,54 @@ class ViewManager(CLIManager):
#plugins loaded now set relationship class #plugins loaded now set relationship class
self.rel_class = Relationship.get_relationship_calculator() self.rel_class = Relationship.get_relationship_calculator()
self.uistate.set_relationship_class() self.uistate.set_relationship_class()
# Need to call after plugins have been registered
self.check_for_updates()
def check_for_updates(self):
"""
"""
howoften = config.get("behavior.check-for-updates")
update = False
if howoften != 0: # update never if zero
y,m,d = map(int,
config.get("behavior.last-check-for-updates").split("/"))
days = (datetime.date.today() - datetime.date(y, m, d)).days
if howoften == 1 and days >= 30: # once a month
update = True
elif howoften == 2 and days >= 7: # once a week
update = True
elif howoften == 3 and days >= 1: # once a day
update = True
elif howoften == 4: # always
update = True
if update:
import urllib
print("Checking for updated addons...")
lang = 'en'
SOURCEFORGE = "http://gramps-addons.svn.sourceforge.net/viewvc/gramps-addons/trunk/"
URL = "%s/listings/addons-%s.txt" % (SOURCEFORGE, lang)
fp = urllib.urlopen(URL)
for line in fp:
try:
plugin_dict = safe_eval(line)
except:
pass
id = plugin_dict["i"]
plugin = self._pmgr.get_plugin(id)
if plugin:
if (version_str_to_tup(plugin_dict["v"], 3) >
version_str_to_tup(plugin.version, 3)):
print(" Downloading '%s'..." % plugin_dict["z"])
load_addon_file("%s/download/%s" %
(SOURCEFORGE, plugin_dict["z"]),
callback=print)
else:
print(" '%s' is ok" % plugin_dict["n"])
else:
print(" '%s' is not installed" % plugin_dict["n"])
config.set("behavior.last-check-for-updates",
datetime.date.today().strftime("%Y/%m/%d"))
print("Done!")
def _errordialog(title, errormessage): def _errordialog(title, errormessage):
""" """
@ -361,8 +412,8 @@ class ViewManager(CLIManager):
for pdata in self._pmgr.get_reg_sidebars(): for pdata in self._pmgr.get_reg_sidebars():
module = self._pmgr.load_plugin(pdata) module = self._pmgr.load_plugin(pdata)
if not module: if not module:
print "Error loading sidebar '%s': skipping content" \ print("Error loading sidebar '%s': skipping content"
% pdata.name % pdata.name)
continue continue
sidebar_class = getattr(module, pdata.sidebarclass) sidebar_class = getattr(module, pdata.sidebarclass)
@ -860,7 +911,7 @@ class ViewManager(CLIManager):
page_display = page.get_display() page_display = page.get_display()
except: except:
import traceback import traceback
print "ERROR: '%s' failed to create view" % pdata.name print("ERROR: '%s' failed to create view" % pdata.name)
traceback.print_exc() traceback.print_exc()
return return
page_display.show_all() page_display.show_all()