[Scodoc-devel] [SVN] Scolar : [1213] Oups: fichier source oublie dans le commit precedent !

eviennet at lipn.univ-paris13.fr eviennet at lipn.univ-paris13.fr
Mer 20 Mar 11:05:42 CET 2013


Une pièce jointe HTML a été nettoyée...
URL: <https://www-rt.iutv.univ-paris13.fr/pipermail/scodoc-devel/attachments/20130320/0cdd296c/attachment-0001.html>
-------------- section suivante --------------
Added: trunk/sco_up_to_date.py
===================================================================
--- trunk/sco_up_to_date.py	                        (rev 0)
+++ trunk/sco_up_to_date.py	2013-03-20 10:05:42 UTC (rev 1213)
@@ -0,0 +1,109 @@
+# -*- mode: python -*-
+# -*- coding: iso8859-15 -*-
+
+##############################################################################
+#
+# Gestion scolarite IUT
+#
+# Copyright (c) 2001 - 2013 Emmanuel Viennet.  All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+#   Emmanuel Viennet      emmanuel.viennet at viennet.net
+#
+##############################################################################
+
+
+""" Verification version logiciel vs version "stable" sur serveur
+    N'effectue pas la mise \xE0 jour automatiquement, mais permet un affichage d'avertissement.
+"""
+
+from sco_utils import *
+
+# Appel renvoyant la subversion "stable"
+# La notion de "stable" est juste l\xE0 pour \xE9viter d'afficher trop frequemment
+# des avertissements de mise \xE0 jour: on veut pouvoir inciter \xE0 mettre \xE0 jour lors de
+# correctifs majeurs.
+
+GET_VER_URL = 'http://notes.iutv.univ-paris13.fr/scodoc-installmgr/last_stable_version'
+
+def get_last_stable_version():
+    """request last stable version number from server
+    (returns string as given by server, empty if failure)
+    (do not wait server answer more than 3 seconds)
+    """
+    global _LAST_UP_TO_DATE_REQUEST
+    ans = query_portal(GET_VER_URL, msg='ScoDoc version server', timeout=3) # sco_utils
+    if ans:
+        ans = ans.strip()
+    _LAST_UP_TO_DATE_REQUEST = datetime.datetime.now()
+    log('get_last_stable_version: updated at %s, answer="%s"' % (_LAST_UP_TO_DATE_REQUEST, ans))
+    return ans
+
+_LAST_UP_TO_DATE_REQUEST = None # datetime of last request to server
+_UP_TO_DATE = True # cached result (limit requests to 1 per day)
+_UP_TO_DATE_MSG = ''
+
+def is_up_to_date(context):
+    """True if up_to_date
+    Returns status, message
+    """
+    global _LAST_UP_TO_DATE_REQUEST, _UP_TO_DATE, _UP_TO_DATE_MSG
+    if (_LAST_UP_TO_DATE_REQUEST
+        and (datetime.datetime.now() - _LAST_UP_TO_DATE_REQUEST) < datetime.timedelta(1)):
+        # requete deja effectuee aujourd'hui:
+        return _UP_TO_DATE, _UP_TO_DATE_MSG
+    
+    last_stable_ver = get_last_stable_version()
+    cur_ver = get_svn_version(context.file_path) # in sco_utils
+    # Convert versions to integers:
+    try:
+        # cur_ver can be "1234" or "1234M' or '1234:1245M'...
+        m = re.match( r'([0-9]*)', cur_ver )
+        if not m:
+            raise ValueError('invalid svn version') # should never occur, regexp always (maybe empty) match
+        cur_ver_num = int(m.group(1))
+    except:
+        log('Warning: no numeric subversion !')
+        return _UP_TO_DATE, _UP_TO_DATE_MSG # silently ignore misconfiguration ?
+    try:
+        last_stable_ver_num = int(last_stable_ver)
+    except:
+        log('Warning: last_stable_version returned by server is invalid !')
+        return  _UP_TO_DATE, _UP_TO_DATE_MSG # should ignore this error (maybe server is unreachable)
+    #
+    if cur_ver_num < last_stable_ver_num:
+        _UP_TO_DATE = False
+        _UP_TO_DATE_MSG = 'Version %s disponible (version %s install\xE9e)' % (last_stable_ver, cur_ver_num)
+        log('Warning: ScoDoc installation is not up-to-date, should upgrade\n%s' % _UP_TO_DATE_MSG)
+    else:
+        _UP_TO_DATE = True
+        _UP_TO_DATE_MSG = ''
+        log('ScoDoc is up-to-date (cur_ver: %s)' % cur_ver)
+    
+    return _UP_TO_DATE, _UP_TO_DATE_MSG
+
+def html_up_to_date_box(context):
+    """
+    """
+    status, msg = is_up_to_date(context)
+    if status:
+        return ''
+    return """<div class="update_warning">
+    <span>Attention: cette installation de ScoDoc n'est pas \xE0 jour.</span>
+    <div class="update_warning_sub">Contactez votre administrateur. %s</div>
+    </div>""" % msg
+
+


Plus d'informations sur la liste de diffusion Scodoc-devel