<commit_before>#    Copyright 2012, SIL International
#    All rights reserved.
#
#    This library is free software; you can redistribute it and/or modify
#    it under the terms of the GNU Lesser General Public License as published
#    by the Free Software Foundation; either version 2.1 of License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#    Lesser General Public License for more details.
#
#    You should also have received a copy of the GNU Lesser General Public
#    License along with this library in the file named "LICENSE".
#    If not, write to the Free Software Foundation, 51 Franklin Street,
#    suite 500, Boston, MA 02110-1335, USA or visit their web page on the 
#    internet at http://www.fsf.org/licenses/lgpl.html.

import os, subprocess, re, sys
from tempfile import mktemp
from shutil import copyfile

mainapp = None
pendingErrors = []

class DataObj(object) :
    
    def attribModel(self) :
        return None

class ModelSuper(object) :
    pass

def configval(config, section, option) :
    if config.has_option(section, option) :
        return config.get(section, option)
    else :
        return None

def configintval(config, section, option) :
    if config.has_option(section, option) :
        txt = config.get(section, option)
        if not txt : return 0
        if txt.isdigit() :
            return int(txt)
        elif txt.lower() == 'true' :
            return 1
        else :
            return 0
    else :
        return 0

def copyobj(src, dest) :
    for x in dir(src) :
        y = getattr(src, x)
        if not callable(y) and not x.startswith('__') :
            setattr(dest, x, y)

grcompiler = None
def findgrcompiler() :
    global grcompiler
    if sys.platform == 'win32' :
        if getattr(sys, 'frozen', None) :
            grcompiler = os.path.join(sys._MEIPASS, 'grcompiler.exe')
            return grcompiler
        try :
            from _winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE
            node = "Microsoft\\Windows\\CurrentVersion\\Uninstall\\Graphite Compiler_is1"
            if sys.maxsize > 1 << 32 :
                r = OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\" + node)
            else:
                r = OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\" + node)
            p = QueryValue(r, "InstallLocation")
            grcompiler = os.path.join(p, "GrCompiler.exe")
        except WindowsError :
            for p in os.environ['PATH'].split(';') :
                a = os.path.join(p, 'grcompiler.exe')
                if os.path.exists(a) :
                    grcompiler = a
                    break
    elif sys.platform == 'darwin' and getattr(sys, 'frozen', None) :
        grcompiler = os.path.join(sys._MEIPASS, 'grcompiler')
        return grcompiler
    else :
        for p in os.environ['PATH'].split(':') :
            a = os.path.join(p, "grcompiler")
            if os.path.exists(a) :
                grcompiler = a
                break
    return grcompiler

def buildGraphite(config, app, font, fontfile, errfile = None) :
    global grcompiler
    if configintval(config, 'build', 'usemakegdl') :
        gdlfile = configval(config, 'build', 'makegdlfile')
        if config.has_option('main', 'ap') :
            font.saveAP(config.get('main', 'ap'), gdlfile)<commit_msg>After building, update the tab with the AP file, if it is open.<commit_after>#    Copyright 2012, SIL International
#    All rights reserved.
#
#    This library is free software; you can redistribute it and/or modify
#    it under the terms of the GNU Lesser General Public License as published
#    by the Free Software Foundation; either version 2.1 of License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#    Lesser General Public License for more details.
#
#    You should also have received a copy of the GNU Lesser General Public
#    License along with this library in the file named "LICENSE".
#    If not, write to the Free Software Foundation, 51 Franklin Street,
#    suite 500, Boston, MA 02110-1335, USA or visit their web page on the 
#    internet at http://www.fsf.org/licenses/lgpl.html.

import os, subprocess, re, sys
from tempfile import mktemp
from shutil import copyfile

mainapp = None
pendingErrors = []

class DataObj(object) :
    
    def attribModel(self) :
        return None

class ModelSuper(object) :
    pass

def configval(config, section, option) :
    if config.has_option(section, option) :
        return config.get(section, option)
    else :
        return None

def configintval(config, section, option) :
    if config.has_option(section, option) :
        txt = config.get(section, option)
        if not txt : return 0
        if txt.isdigit() :
            return int(txt)
        elif txt.lower() == 'true' :
            return 1
        else :
            return 0
    else :
        return 0

def copyobj(src, dest) :
    for x in dir(src) :
        y = getattr(src, x)
        if not callable(y) and not x.startswith('__') :
            setattr(dest, x, y)

grcompiler = None
def findgrcompiler() :
    global grcompiler
    if sys.platform == 'win32' :
        if getattr(sys, 'frozen', None) :
            grcompiler = os.path.join(sys._MEIPASS, 'grcompiler.exe')
            return grcompiler
        try :
            from _winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE
            node = "Microsoft\\Windows\\CurrentVersion\\Uninstall\\Graphite Compiler_is1"
            if sys.maxsize > 1 << 32 :
                r = OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\" + node)
            else:
                r = OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\" + node)
            p = QueryValue(r, "InstallLocation")
            grcompiler = os.path.join(p, "GrCompiler.exe")
        except WindowsError :
            for p in os.environ['PATH'].split(';') :
                a = os.path.join(p, 'grcompiler.exe')
                if os.path.exists(a) :
                    grcompiler = a
                    break
    elif sys.platform == 'darwin' and getattr(sys, 'frozen', None) :
        grcompiler = os.path.join(sys._MEIPASS, 'grcompiler')
        return grcompiler
    else :
        for p in os.environ['PATH'].split(':') :
            a = os.path.join(p, "grcompiler")
            if os.path.exists(a) :
                grcompiler = a
                break
    return grcompiler

def buildGraphite(config, app, font, fontfile, errfile = None) :
    global grcompiler
    if configintval(config, 'build', 'usemakegdl') :
        gdlfile = configval(config, 'build', 'makegdlfile')
        if config.has_option('main', 'ap') :
            apFilename = config.get('main', 'ap')
            font.saveAP(apFilename, gdlfile)
            if app : app.updateFileEdit(apFilename)
{'fraction_non_alphanumeric': 0.09737723214285714, 'fraction_numerical': 0.009486607142857142, 'mean_word_length': 2.27351598173516, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '3581614', 'n_tokens_mistral': 2151, 'n_tokens_neox': 2079, 'n_words': 688}