diff --git a/client/djrandom_client/client.py b/client/djrandom_client/client.py index d99fe036a8afb4786a2962f4edd0bc42b5e297bd..0baee71c3ee486df81479e705b0cdbf2eb6a137c 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 5efa285596b3b57dc273e73799eb71e1f20631f0..e9fd9d046aa607c899a8afded1be57c6e5d14c81 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 0000000000000000000000000000000000000000..68c0733348c65f5f45bd043f1e94bc7b1bd30d48 --- /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 aad077744a396a69b9386489b50c30ad581863cb..60cd80bfc16b4648b368844c62d207606ed8baee 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",