Checks for open network connection; get listing file in proper language

svn: r15724
This commit is contained in:
Doug Blank 2010-08-13 13:31:00 +00:00
parent e7c741a2a7
commit f3fb0b9d2e

View File

@ -201,6 +201,7 @@ UIDEFAULT = '''<ui>
WIKI_HELP_PAGE_FAQ = '%s_-_FAQ' % const.URL_MANUAL_PAGE WIKI_HELP_PAGE_FAQ = '%s_-_FAQ' % const.URL_MANUAL_PAGE
WIKI_HELP_PAGE_KEY = '%s_-_Keybindings' % const.URL_MANUAL_PAGE WIKI_HELP_PAGE_KEY = '%s_-_Keybindings' % const.URL_MANUAL_PAGE
WIKI_HELP_PAGE_MAN = '%s' % const.URL_MANUAL_PAGE WIKI_HELP_PAGE_MAN = '%s' % const.URL_MANUAL_PAGE
ADDONS_URL = "http://gramps-addons.svn.sourceforge.net/viewvc/gramps-addons/trunk"
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -292,33 +293,60 @@ class ViewManager(CLIManager):
elif howoften == 4: # always elif howoften == 4: # always
update = True update = True
if update: if update:
import urllib import urllib, locale
print("Checking for updated addons...") LOG.debug("Checking for updated addons...")
lang = 'en' lang = locale.getlocale()[0] or "en"
SOURCEFORGE = "http://gramps-addons.svn.sourceforge.net/viewvc/gramps-addons/trunk/" if "_" in lang:
URL = "%s/listings/addons-%s.txt" % (SOURCEFORGE, lang) lang, variation = lang.split("_", 1)
fp = urllib.urlopen(URL) URL = "%s/listings/addons-%s.txt" % (ADDONS_URL, lang)
for line in fp: LOG.debug(" trying: %s" % URL)
try:
fp = urllib.urlopen(URL)
except: # some error
LOG.debug(" IOError!")
fp = None
count = 0
while fp and fp.getcode() != 200: # 200 = ok
count += 1
fp.close()
URL = "%s/listings/addons-%s.txt" % (ADDONS_URL, 'en')
done = True
LOG.debug(" trying: %s" % URL)
try: try:
plugin_dict = safe_eval(line) fp = urllib.urlopen(URL)
except: except: # some error
pass LOG.debug(" IOError!")
id = plugin_dict["i"] fp = None
plugin = self._pmgr.get_plugin(id) if count > 2: # perhaps wrong code?
if plugin: fp = None
if (version_str_to_tup(plugin_dict["v"], 3) > break
version_str_to_tup(plugin.version, 3)): if fp:
print(" Downloading '%s'..." % plugin_dict["z"]) addon_update_list = []
#load_addon_file("%s/download/%s" % for line in fp:
# (SOURCEFORGE, plugin_dict["z"]), try:
# callback=print) 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)):
LOG.debug(" Downloading '%s'..." % plugin_dict["z"])
addon_update_list.append("%s/download/%s" %
(SOURCEFORGE,
plugin_dict["z"]))
else:
LOG.debug(" '%s' is ok" % plugin_dict["n"])
else: else:
print(" '%s' is ok" % plugin_dict["n"]) LOG.debug(" '%s' is not installed" % plugin_dict["n"])
else: config.set("behavior.last-check-for-updates",
print(" '%s' is not installed" % plugin_dict["n"]) datetime.date.today().strftime("%Y/%m/%d"))
config.set("behavior.last-check-for-updates", if fp:
datetime.date.today().strftime("%Y/%m/%d")) fp.close()
print("Done!") #for plugin_url in addon_update_list:
# load_addon_file(plugin_url, callback=print)
LOG.debug("Done updating!")
def _errordialog(title, errormessage): def _errordialog(title, errormessage):
""" """