<commit_before>#!/usr/bin/env/python

import sys
import os.path
import subprocess


# Read in a pml file and save to an xml file
def translate_pml_file(xml_file, pml_file):

    pml_path = os.path.abspath(pml_file.name)
    xml_path = os.path.abspath(xml_file.name)

    # Call XML generator
    # TODO: Remove abs-path
    return_code = subprocess.call("/opt/pml-bnfc/xml/Pmlxml %s %s" % (xml_path, pml_path), shell=True)
    if return_code != 0:
        print "Error occured reading PML file, exiting."
        sys.exit(1)


def main():
    import argparse
    parser = argparse.ArgumentParser(description="Program to output the ast of a PML program in XML format")
    parser.add_argument('-x', '--xml', required=True, type=file, help="Output abstract syntax tree in XML format")
    parser.add_argument('-p', '--pml', required=True, type=file, help="Input PML file")

    try:
        args = parser.parse_args()
        translate_pml_file(args.xml, args.pml)
    except IOError, msg:
        parser.error(str(msg))


if __name__ == "__main__":
    main()<commit_msg>Change arg from file to path<commit_after>#!/usr/bin/env/python

import sys
from os.path import isdir, split, abspath
import subprocess


# Read in a pml file and save to an xml file
def translate_pml_file(xml_file, pml_file):

    pml_path = abspath(pml_file.name)
    xml_path = abspath(xml_file)

    # Call XML generator
    # TODO: Remove abs-path
    return_code = subprocess.call("/opt/pml-bnfc/xml/Pmlxml %s %s" % (xml_path, pml_path), shell=True)
    if return_code != 0:
        print "Error occured reading PML file, exiting."
        sys.exit(1)


def valid_xml_path(xml_path):
    path, _ = split(xml_path)
    return isdir(path)


def main():
    import argparse
    parser = argparse.ArgumentParser(description="Program to output the ast of a PML program in XML format")
    parser.add_argument('-x', '--xml', required=True, type=str, help="Output abstract syntax tree in XML format")
    parser.add_argument('-p', '--pml', required=True, type=file, help="Input PML file")

    try:
        args = parser.parse_args()
        if valid_xml_path(abspath(args.xml)):
            translate_pml_file(args.xml, args.pml)
        else:
            print "XML path is invalid."
            sys.exit(1)
    except IOError, msg:
        parser.error(str(msg))


if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.11920808761583825, 'fraction_numerical': 0.0021061499578770007, 'mean_word_length': 3.2184724689165187, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 23}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4023297', 'n_tokens_mistral': 815, 'n_tokens_neox': 797, 'n_words': 217}