3838"""
3939import copy
4040import inspect
41+ import json
4142import os
4243from collections import OrderedDict
4344from easybuild .tools import LooseVersion
7374DETAILED = 'detailed'
7475SIMPLE = 'simple'
7576
77+ FORMAT_JSON = 'json'
7678FORMAT_MD = 'md'
7779FORMAT_RST = 'rst'
7880FORMAT_TXT = 'txt'
@@ -116,6 +118,11 @@ def avail_cfgfile_constants(go_cfg_constants, output_format=FORMAT_TXT):
116118 return generate_doc ('avail_cfgfile_constants_%s' % output_format , [go_cfg_constants ])
117119
118120
121+ def avail_cfgfile_constants_json (go_cfg_constants ):
122+ """Generate documentation on constants for configuration files in json format"""
123+ raise NotImplementedError ("JSON output format not supported for avail_cfgfile_constants_json" )
124+
125+
119126def avail_cfgfile_constants_txt (go_cfg_constants ):
120127 """Generate documentation on constants for configuration files in txt format"""
121128 doc = [
@@ -185,6 +192,11 @@ def avail_easyconfig_constants(output_format=FORMAT_TXT):
185192 return generate_doc ('avail_easyconfig_constants_%s' % output_format , [])
186193
187194
195+ def avail_easyconfig_constants_json ():
196+ """Generate easyconfig constant documentation in json format"""
197+ raise NotImplementedError ("JSON output format not supported for avail_easyconfig_constants_json" )
198+
199+
188200def avail_easyconfig_constants_txt ():
189201 """Generate easyconfig constant documentation in txt format"""
190202 doc = ["Constants that can be used in easyconfigs" ]
@@ -243,6 +255,11 @@ def avail_easyconfig_licenses(output_format=FORMAT_TXT):
243255 return generate_doc ('avail_easyconfig_licenses_%s' % output_format , [])
244256
245257
258+ def avail_easyconfig_licenses_json ():
259+ """Generate easyconfig license documentation in json format"""
260+ raise NotImplementedError ("JSON output format not supported for avail_easyconfig_licenses_json" )
261+
262+
246263def avail_easyconfig_licenses_txt ():
247264 """Generate easyconfig license documentation in txt format"""
248265 doc = ["License constants that can be used in easyconfigs" ]
@@ -355,6 +372,13 @@ def avail_easyconfig_params_rst(title, grouped_params):
355372 return '\n ' .join (doc )
356373
357374
375+ def avail_easyconfig_params_json ():
376+ """
377+ Compose overview of available easyconfig parameters, in json format.
378+ """
379+ raise NotImplementedError ("JSON output format not supported for avail_easyconfig_params_json" )
380+
381+
358382def avail_easyconfig_params_txt (title , grouped_params ):
359383 """
360384 Compose overview of available easyconfig parameters, in plain text format.
@@ -427,6 +451,11 @@ def avail_easyconfig_templates(output_format=FORMAT_TXT):
427451 return generate_doc ('avail_easyconfig_templates_%s' % output_format , [])
428452
429453
454+ def avail_easyconfig_templates_json ():
455+ """ Returns template documentation in json text format """
456+ raise NotImplementedError ("JSON output format not supported for avail_easyconfig_templates" )
457+
458+
430459def avail_easyconfig_templates_txt ():
431460 """ Returns template documentation in plain text format """
432461 # This has to reflect the methods/steps used in easyconfig _generate_template_values
@@ -641,6 +670,8 @@ def avail_classes_tree(classes, class_names, locations, detailed, format_strings
641670
642671
643672def list_easyblocks (list_easyblocks = SIMPLE , output_format = FORMAT_TXT ):
673+ if output_format == FORMAT_JSON :
674+ raise NotImplementedError ("JSON output format not supported for list_easyblocks" )
644675 format_strings = {
645676 FORMAT_MD : {
646677 'det_root_templ' : "- **%s** (%s%s)" ,
@@ -1025,6 +1056,38 @@ def list_software_txt(software, detailed=False):
10251056 return '\n ' .join (lines )
10261057
10271058
1059+ def list_software_json (software , detailed = False ):
1060+ """
1061+ Return overview of supported software in json
1062+
1063+ :param software: software information (strucuted like list_software does)
1064+ :param detailed: whether or not to return detailed information (incl. version, versionsuffix, toolchain info)
1065+ :return: multi-line string presenting requested info
1066+ """
1067+ lines = ['[' ]
1068+ for key in sorted (software , key = lambda x : x .lower ()):
1069+ for entry in software [key ]:
1070+ if detailed :
1071+ # deep copy here to avoid modifying the original dict
1072+ entry = copy .deepcopy (entry )
1073+ entry ['description' ] = ' ' .join (entry ['description' ].split ('\n ' )).strip ()
1074+ else :
1075+ entry = {}
1076+ entry ['name' ] = key
1077+
1078+ lines .append (json .dumps (entry , indent = 4 , sort_keys = True , separators = (',' , ': ' )) + "," )
1079+ if not detailed :
1080+ break
1081+
1082+ # remove trailing comma on last line
1083+ if len (lines ) > 1 :
1084+ lines [- 1 ] = lines [- 1 ].rstrip (',' )
1085+
1086+ lines .append (']' )
1087+
1088+ return '\n ' .join (lines )
1089+
1090+
10281091def list_toolchains (output_format = FORMAT_TXT ):
10291092 """Show list of known toolchains."""
10301093 _ , all_tcs = search_toolchain ('' )
@@ -1173,6 +1236,11 @@ def list_toolchains_txt(tcs):
11731236 return '\n ' .join (doc )
11741237
11751238
1239+ def list_toolchains_json (tcs ):
1240+ """ Returns overview of all toolchains in json format """
1241+ raise NotImplementedError ("JSON output not implemented yet for --list-toolchains" )
1242+
1243+
11761244def avail_toolchain_opts (name , output_format = FORMAT_TXT ):
11771245 """Show list of known options for given toolchain."""
11781246 tc_class , _ = search_toolchain (name )
@@ -1226,6 +1294,11 @@ def avail_toolchain_opts_rst(name, tc_dict):
12261294 return '\n ' .join (doc )
12271295
12281296
1297+ def avail_toolchain_opts_json (name , tc_dict ):
1298+ """ Returns overview of toolchain options in jsonformat """
1299+ raise NotImplementedError ("JSON output not implemented yet for --avail-toolchain-opts" )
1300+
1301+
12291302def avail_toolchain_opts_txt (name , tc_dict ):
12301303 """ Returns overview of toolchain options in txt format """
12311304 doc = ["Available options for %s toolchain:" % name ]
@@ -1252,6 +1325,13 @@ def get_easyblock_classes(package_name):
12521325 return easyblocks
12531326
12541327
1328+ def gen_easyblocks_overview_json (package_name , path_to_examples , common_params = None , doc_functions = None ):
1329+ """
1330+ Compose overview of all easyblocks in the given package in json format
1331+ """
1332+ raise NotImplementedError ("JSON output not implemented yet for gen_easyblocks_overview" )
1333+
1334+
12551335def gen_easyblocks_overview_md (package_name , path_to_examples , common_params = None , doc_functions = None ):
12561336 """
12571337 Compose overview of all easyblocks in the given package in MarkDown format
0 commit comments