forked from openhome/ohdevtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.py
More file actions
38 lines (30 loc) · 1.44 KB
/
version.py
File metadata and controls
38 lines (30 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json
import os
import sys
# The version number of the API. Incremented whenever there
# are new features or bug fixes.
VERSION = 146
# The earliest API version that we're still compatible with.
# Changed only when a change breaks an existing API.
BACKWARD_VERSION = 22
class BadVersionException(Exception):
def __init__(self, message="Aborted due to error."):
Exception.__init__(self, message)
self.usermessage = message
def require_version(required_version):
'''Fail if the version of ohDevTools is too old.'''
if VERSION < required_version:
raise BadVersionException("FAIL: This project requires a newer version of ohDevTools. You have version {0}, but need version {1}.".format(VERSION, required_version))
if required_version < BACKWARD_VERSION:
raise BadVersionException("FAIL: This project requires an older version of ohDevTools. You have version {0}, but need version {1}.".format(VERSION, required_version))
def check_version():
if os.path.isfile('projectdata/ohdevtools.json'):
with open('projectdata/ohdevtools.json', 'r') as configfile:
config = json.load(configfile)
required_version = config.get('requires-version', None)
if required_version is not None:
try:
require_version(required_version)
except BadVersionException as e:
print(e.usermessage)
sys.exit(32)