Exemple #1
0
def check_dir(d):
    if not os.path.isdir(d):
        d = resolve_dir(os.path.join(os.getcwd(), d))
        if not os.path.isdir(d):
            print(d + " needs to be an existing directory")
            return
    return resolve_dir(d)
def check_and_create(d):
    """ Turn input into an existing, absolute directory path.
    """
    if not os.path.isdir(d):
        d = resolve_dir(os.path.join(os.getcwd(), d))
        if not os.path.isdir(d):
            os.makedirs(d)
            print(f"Created directory {d}")
    return resolve_dir(d)
def write_gantt_charts(args):
    p = Parse(
        args.dir,
        paths=args.file,
        file_re=args.regex,
        exclude_re=args.exclude,
        recursive=args.nonrecursive,
        logger_cfg=dict(level=args.level),
    )
    p.parse_mscx()
    gantt_path = resolve_dir(args.out)
    ats = p.get_lists(expanded=True)
    N = len(ats)
    if N == 0:
        p.logger.info("None of the scores contains DCML harmony labels, no gantt charts created.")
        return
    else:
        p.logger.info(f"{N} files contain DCML labels.")
    for (key, i, _), at in ats.items():  # at stands for annotation table, i.e. DataFrame of expanded labels
        fname = p.fnames[key][i]
        score_obj = p._parsed_mscx[(key, i)]
        metadata = score_obj.mscx.metadata
        logger = score_obj.mscx.logger
        last_mn = metadata["last_mn"]
        try:
            globalkey = metadata["annotated_key"]
        except:
            logger.warning('Global key is missing in the metadata.')
            globalkey = '?'
        logger.debug(f"Creating Gantt data for {fname}...")
        data = make_gantt_data(at, logger=logger)
        if len(data) == 0:
            logger.debug(f"Could not create Gantt data for {fname}...")
            continue
        phrases = get_phraseends(at)
        data.sort_values(args.yaxis, ascending=False, inplace=True)
        logger.debug(f"Making and storing Gantt chart for {fname}...")
        fig = create_modulation_plan(data, title=f"{fname}", globalkey=globalkey, task_column=args.yaxis, phraseends=phrases)
        out_path = os.path.join(gantt_path, f'{fname}.html')
        plot(fig, filename=out_path)
        logger.debug(f"Stored as {out_path}")
def check_dir(d):
    if not os.path.isdir(d):
        d = resolve_dir(os.path.join(os.getcwd(), d))
        if not os.path.isdir(d):
            raise argparse.ArgumentTypeError(d + " needs to be an existing directory")
    return resolve_dir(d)