# Path: tlfp/tools/common.py
# def open_json(dirpath, filename=None):
#     if filename:
#         path = os.path.join(dirpath, filename)
#     else:
#         path = dirpath
#     try:
#         with open(path, 'r') as f:
#             return json.load(f)
#     except Exception as e:
#         print(type(e), e, file=sys.stderr)
#         sys.stderr.write("ERROR: Could not open file %s" % (path,))
#         raise e
# 
# def print_json(dico, filename=None):
#     jdump = json.dumps(dico, ensure_ascii=False, sort_keys=True, indent=2)
#     if filename:
#         # create parent directories if necessary
#         dirname = os.path.dirname(filename)
#         if dirname:
#             os.makedirs(dirname, exist_ok=True)
# 
#         try:
#             with open("%s.tmp" % filename, 'w') as f:
#                 f.write(jdump)
#             if os.path.exists(filename):
#                 os.remove(filename)
#             os.rename("%s.tmp" % filename, filename)
#         except Exception as e:
#             print(type(e), e, file=sys.stderr)
#             sys.stderr.write("ERROR: Could not write in file %s" % filename)
#             raise e
#     else:
#         print(jdump)


import sys, os, random, glob
from tlfp.tools.common import open_json, print_json
# quick script to produce a DOT file of the steps from a list of dosleg
# use "python steps_as_dot.py <data_directory> | dot -Tpng > steps.png" to produce the diagram

# the XKCD font is available here: https://github.com/ipython/xkcd-font/tree/master/xkcd/build


if len(sys.argv) < 2:
    print('USAGE: "python steps_as_dot.py <data_directory> | dot -Tpng > steps.png"')
    sys.exit()

mode = "detailed" if len(sys.argv) == 3 else "simple"

procedure_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'data/valid_procedure.json')
procedure = open_json(procedure_file)

API_DIRECTORY = sys.argv[1]

# Path: tlfp/tools/common.py
# def open_json(dirpath, filename=None):
#     if filename:
#         path = os.path.join(dirpath, filename)
#     else:
#         path = dirpath
#     try:
#         with open(path, 'r') as f:
#             return json.load(f)
#     except Exception as e:
#         print(type(e), e, file=sys.stderr)
#         sys.stderr.write("ERROR: Could not open file %s" % (path,))
#         raise e
# 
# def print_json(dico, filename=None):
#     jdump = json.dumps(dico, ensure_ascii=False, sort_keys=True, indent=2)
#     if filename:
#         # create parent directories if necessary
#         dirname = os.path.dirname(filename)
#         if dirname:
#             os.makedirs(dirname, exist_ok=True)
# 
#         try:
#             with open("%s.tmp" % filename, 'w') as f:
#                 f.write(jdump)
#             if os.path.exists(filename):
#                 os.remove(filename)
#             os.rename("%s.tmp" % filename, filename)
#         except Exception as e:
#             print(type(e), e, file=sys.stderr)
#             sys.stderr.write("ERROR: Could not write in file %s" % filename)
#             raise e
#     else:
#         print(jdump)


# Path: tlfp/tools/steps_as_dot.py
import sys, os, random, glob
from tlfp.tools.common import open_json, print_json

# quick script to produce a DOT file of the steps from a list of dosleg
# use "python steps_as_dot.py <data_directory> | dot -Tpng > steps.png" to produce the diagram

# the XKCD font is available here: https://github.com/ipython/xkcd-font/tree/master/xkcd/build


if len(sys.argv) < 2:
    print('USAGE: "python steps_as_dot.py <data_directory> | dot -Tpng > steps.png"')
    sys.exit()

mode = "detailed" if len(sys.argv) == 3 else "simple"

procedure_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'data/valid_procedure.json')
procedure = open_json(procedure_file)

API_DIRECTORY = sys.argv[1]

all_senat_jo = [open_json(path) for path \