From 8e1e8ce2f872090b673d0dc8d6f899ff9b2c36af Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Sat, 24 Sep 2011 18:23:36 +0100 Subject: [PATCH] add version check on every run of the client --- client/djrandom_client/client.py | 4 ++++ client/djrandom_client/utils.py | 31 +++++++++++++++++++++++++++++++ client/djrandom_client/version.py | 1 + client/setup.py | 7 ++++++- 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 client/djrandom_client/version.py diff --git a/client/djrandom_client/client.py b/client/djrandom_client/client.py index d99fe03..0baee71 100644 --- a/client/djrandom_client/client.py +++ b/client/djrandom_client/client.py @@ -124,6 +124,10 @@ def main(): if args: parser.error('Too many arguments') + # Perform a version check. + if utils.check_version(): + print >>sys.stderr, 'A new release is available! Please update.' + # Reading from the configuration file will set this variable to # a string, convert it back into boolean. do_realtime = not opts.no_realtime_watch diff --git a/client/djrandom_client/utils.py b/client/djrandom_client/utils.py index 5efa285..e9fd9d0 100644 --- a/client/djrandom_client/utils.py +++ b/client/djrandom_client/utils.py @@ -1,7 +1,10 @@ import hashlib import os +import urllib2 +from djrandom_client import version NESTING = 2 +VERSION_PY_URL = 'https://git.autistici.org/djrandom/plain/client/djrandom_client/version.py' def generate_path(base_dir, sha1): @@ -48,3 +51,31 @@ def read_config_defaults(parser, path): path, 1 + linenum)) var, value = map(lambda x: x.strip(), line.split('=', 1)) parser.set_default(var, _unquote(value)) + + +def _split_version_string(s): + def _toint(x): + try: + return int(x) + except: + return x + return tuple(map(_toint, s.split('.'))) + + +def check_version(): + """Returns True if we need to upgrade.""" + try: + last_version_str = urllib2.urlopen(VERSION_PY_URL).read() + except: + return False + + match = re.match(r'VERSION\s*=\s*[\'"]([0-9a-z.]+)[\'"]', + last_version_str.strip()) + if not match: + return False + last_version_t = _split_version_string(match.group(1)) + cur_version_t = _split_version_string(version.VERSION) + + return cur_version_t <= last_version_t + + diff --git a/client/djrandom_client/version.py b/client/djrandom_client/version.py new file mode 100644 index 0000000..68c0733 --- /dev/null +++ b/client/djrandom_client/version.py @@ -0,0 +1 @@ +VERSION = '0.2' diff --git a/client/setup.py b/client/setup.py index aad0777..60cd80b 100644 --- a/client/setup.py +++ b/client/setup.py @@ -1,5 +1,10 @@ #!/usr/bin/python +# Read version from version.py. +import sys, os +sys.path.insert(0, os.path.dirname(__file__)) +from djrandom_client import version + from setuptools import setup, find_packages import platform if platform.system() == 'Darwin': @@ -9,7 +14,7 @@ else: setup( name="djrandom-client", - version="0.1", + version=version.VERSION, description="DJ:Random client", author="ale", author_email="ale@incal.net", -- GitLab