def main():
    global write_buffer

    profile_output_filename = None

    if len(sys.argv) >= 3:
        profile_output_filename = sys.argv[2]

        if os.path.exists(profile_output_filename):
            old_profile = open(profile_output_filename, 'r').read()
            if PROFILE_OUTPUT_FILE_HEADER_MAGIC not in old_profile:
                print "Couldn't find header in %s. Exiting." % profile_output_filename
                sys.exit(1)
            del old_profile

        # Generate header
        profile_header = PROFILE_OUTPUT_FILE_HEADER_FMT % (
            os.path.basename(profile_output_filename),
            datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            os.path.basename(__file__),
            os.path.basename(profile_xls_filename),
        )

    if profile_output_filename:
        print "Generating profile from %s" % profile_xls_filename

    types = parse_types()
    fields = parse_fields()

    autogen_python(types, fields)

    if profile_output_filename:
        print "Writing to %s" % profile_output_filename
        profile_output_file = open(profile_output_filename, 'w')
        copyright_header = open(os.path.abspath(__file__)).readlines()
        copyright_header = (''.join(copyright_header[1:copyright_header.index('\n')])).strip()
        profile_output_file.write(copyright_header + "\n\n\n")
        profile_output_file.write(profile_header)
        profile_output_file.write(write_buffer)
        profile_output_file.close()
    else:
        print write_buffer
dataset/ETHPy150Open dtcooper/python-fitparse/scripts/generate_profile.py/main/original