Sfoglia il codice sorgente

Add version checker

 * Most bug reports in pwman are in Older versions
   adding this so in the future users are notified about newer
   versions
Oz N Tiram 8 anni fa
parent
commit
b0d36a1c85
2 ha cambiato i file con 19 aggiunte e 4 eliminazioni
  1. 1 1
      pwman/__init__.py
  2. 18 3
      pwman/ui/cli.py

+ 1 - 1
pwman/__init__.py

@@ -38,7 +38,7 @@ appname = "pwman3"
 try:
 try:
     version = pkg_resources.get_distribution('pwman3').version
     version = pkg_resources.get_distribution('pwman3').version
 except pkg_resources.DistributionNotFound:  # pragma: no cover
 except pkg_resources.DistributionNotFound:  # pragma: no cover
-        version = "0.8.1"
+    version = "0.8.1"
 
 
 
 
 class PkgMetadata(object):
 class PkgMetadata(object):

+ 18 - 3
pwman/ui/cli.py

@@ -14,13 +14,13 @@
 # along with Pwman3; if not, write to the Free Software
 # along with Pwman3; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 # ============================================================================
 # ============================================================================
-# Copyright (C) 2012, 2013, 2014, 2015 Oz Nahum <nahumoz@gmail.com>
+# Copyright (C) 2012-2016 Oz N Tiram <oz.tiram@gmail.com>
 # ============================================================================
 # ============================================================================
 # pylint: disable=I0011
 # pylint: disable=I0011
 
 
-from __future__ import print_function
 
 
 import cmd
 import cmd
+import http.client
 import sys
 import sys
 
 
 
 
@@ -34,7 +34,6 @@ except ImportError as e:  # pragma: no cover
     import pyreadline as readline
     import pyreadline as readline
     _readline_available = True
     _readline_available = True
 
 
-
 from pwman.ui.baseui import BaseCommands
 from pwman.ui.baseui import BaseCommands
 from pwman import (get_conf_options, get_db_version, version, website,
 from pwman import (get_conf_options, get_db_version, version, website,
                    parser_options, has_cryptography)
                    parser_options, has_cryptography)
@@ -94,12 +93,28 @@ def get_ui_platform(platform):  # pragma: no cover
     return PwmanCli, OSX
     return PwmanCli, OSX
 
 
 
 
+def is_latest_version():  # pragma: no cover
+    """check current version againt latest version"""
+    conn = http.client.HTTPConnection("pwman.tiram.it", timeout=0.5)
+    conn.request("GET", "/")
+    r = conn.getresponse()
+    data = r.read()  # This will return entire content.
+    if data.decode().split(".") > version.split("."):
+        return False
+    else:
+        return True
+
+
 def main():
 def main():
     args = parser_options().parse_args()
     args = parser_options().parse_args()
     PwmanCli, OSX = get_ui_platform(sys.platform)
     PwmanCli, OSX = get_ui_platform(sys.platform)
     xselpath, dbtype, config = get_conf_options(args, OSX)
     xselpath, dbtype, config = get_conf_options(args, OSX)
     dburi = config.get_value('Database', 'dburi')
     dburi = config.get_value('Database', 'dburi')
 
 
+    if config.get_value('Global', 'supress_version').lower() != 'yes':  # pragma: no cover
+        if not is_latest_version():
+            print("A newer version of Pwman3 was release, you should consider updating")  # noqa
+
     if not has_cryptography:
     if not has_cryptography:
         import colorama
         import colorama
         if config.get_value('Crypto', 'supress_warning').lower() != 'yes':
         if config.get_value('Crypto', 'supress_warning').lower() != 'yes':