Coverage for aiocoap/cli/defaults.py: 94%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

31 statements  

1# This file is part of the Python aiocoap library project. 

2# 

3# Copyright (c) 2012-2014 Maciej Wasilak <http://sixpinetrees.blogspot.com/>, 

4# 2013-2014 Christian Amsüss <c.amsuess@energyharvesting.at> 

5# 

6# aiocoap is free software, this file is published under the MIT license as 

7# described in the accompanying LICENSE file. 

8 

9"""This helper script can be used to easily inspect aiocoap's environment 

10autodetection (ie. whether all modules required for particular subsystems are 

11available, losely corresponding to the "features" made available through 

12setup.py); run it as `python3 -m aiocoap.cli.defaults`.""" 

13 

14import sys 

15from aiocoap.meta import version 

16from aiocoap.defaults import dtls_missing_modules, oscore_missing_modules, \ 

17 linkheader_missing_modules, prettyprint_missing_modules, has_reuse_port, \ 

18 get_default_clienttransports, get_default_servertransports 

19import argparse 

20import os 

21 

22if __name__ == "__main__": 

23 p = argparse.ArgumentParser(description=__doc__) 

24 # Allow passing this in as AIOCOAP_DEFAULTS_EXPECT_ALL=1 via the 

25 # environment, as that's easier to set in tox 

26 p.add_argument("--expect-all", help="Exit with an error unless all subsystems are available", 

27 action='store_true', default=os.environ.get('AIOCOAP_DEFAULTS_EXPECT_ALL') == '1') 

28 p.add_argument('--version', action='version', version=version) 

29 args = p.parse_args() 

30 

31 error = 0 

32 

33 print("Python version: %s" % sys.version) 

34 print("aiocoap version: %s" % version) 

35 print("Modules missing for subsystems:") 

36 missmods = [dtls_missing_modules, oscore_missing_modules, linkheader_missing_modules, prettyprint_missing_modules] 

37 for m in missmods: 

38 name = m.__name__[:-len("_missing_modules")] 

39 missing = m() 

40 if missing and args.expect_all: 

41 error = 1 

42 print(" %s: %s" % (name, "everything there" if not missing else "missing " + ", ".join(missing))) 

43 print("Python platform: %s" % sys.platform) 

44 print("Default server transports: %s" % ":".join(get_default_servertransports(use_env=False))) 

45 print("Selected server transports: %s" % ":".join(get_default_servertransports())) 

46 print("Default client transports: %s" % ":".join(get_default_clienttransports(use_env=False))) 

47 print("Selected client transports: %s" % ":".join(get_default_clienttransports())) 

48 print("SO_REUSEPORT available (default, selected): %s, %s" % (has_reuse_port(use_env=False), has_reuse_port())) 

49 

50 if error: 

51 print("Exiting unsuccessfully because --expect-all was set and not all extras are available.") 

52 sys.exit(error)