<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""PyLNP main library."""
from __future__ import print_function, unicode_literals

import sys
from tkgui import TkGui

import fnmatch, glob, os, re, shutil, subprocess, tempfile, webbrowser
import distutils.dir_util as dir_util
from datetime import datetime

from settings import DFConfiguration

BASEDIR = '.'
VERSION = '0.1'

class PyLNP(object):
    """
    PyLNP library class.

    Acts as an abstraction layer between the UI and the Dwarf Fortress
    instance.
    """
    def __init__(self):
        """Constructor for the PyLNP library."""
        self.bundle = ''
        if hasattr(sys, 'frozen'):
            os.chdir(os.path.dirname(sys.executable))
            if sys.platform == 'win32':
                self.bundle = 'win'
            elif sys.platform.startswith('linux'):
                self.bundle = 'linux'
            elif sys.platform == 'darwin':
                self.bundle = 'osx'
                #OS X bundles start in different directory
                os.chdir('../../..')
        else:
            os.chdir(os.path.dirname(os.path.abspath(__file__)))

        self.lnp_dir = os.path.join(BASEDIR, 'LNP')
        if not os.path.isdir(self.lnp_dir):
            print('WARNING: LNP folder is missing!', file=sys.stderr)
        self.keybinds_dir = self.case_sensitive_folder('Keybinds')
        self.graphics_dir = self.case_sensitive_folder('Graphics')
        self.utils_dir = self.case_sensitive_folder('Utilities')

        self.folders = []
        self.df_dir = ''
        self.settings = None
        self.init_dir = ''
        self.save_dir = ''
        self.autorun = []

        self.load_autorun()
        self.find_df_folder()

        TkGui(self)

    def load_params(self):
        """Loads settings from the selected Dwarf Fortress instance."""
        try:
            self.settings.read_settings()
        except IOError:
            sys.excepthook(*sys.exc_info())
            msg = ("Failed to read settings, "
                   "{0} not really a DF dir?"
                  ).format(self.df_dir)
            raise IOError(msg)

    def save_params(self):
        """Saves settings to the selected Dwarf Fortress instance."""
        self.settings.write_settings()

    def restore_defaults(self):
        """Copy default settings into the selected Dwarf Fortress instance."""
        shutil.copy(
            os.path.join(self.lnp_dir, 'Defaults', 'init.txt'),
            os.path.join(self.init_dir, 'init.txt')
            )
        shutil.copy(
            os.path.join(self.lnp_dir, 'Defaults', 'd_init.txt'),
            os.path.join(self.init_dir, 'd_init.txt')
        )
        self.load_params()

    def run_df(self):
        """Launches Dwarf Fortress."""
        if sys.platform == 'win32':
            self.run_program(os.path.join(self.df_dir, 'Dwarf Fortress.exe'))
        else:
            self.run_program(os.path.join(self.df_dir, 'df'))
        for prog in self.autorun:
            if os.access(os.path.join(self.utils_dir, prog), os.F_OK):<commit_msg>Allow for DFhack under Mac OS/X and Unix platforms<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""PyLNP main library."""
from __future__ import print_function, unicode_literals

import sys
from tkgui import TkGui

import fnmatch, glob, os, re, shutil, subprocess, tempfile, webbrowser
import distutils.dir_util as dir_util
from datetime import datetime

from settings import DFConfiguration

BASEDIR = '.'
VERSION = '0.1'

class PyLNP(object):
    """
    PyLNP library class.

    Acts as an abstraction layer between the UI and the Dwarf Fortress
    instance.
    """
    def __init__(self):
        """Constructor for the PyLNP library."""
        self.bundle = ''
        if hasattr(sys, 'frozen'):
            os.chdir(os.path.dirname(sys.executable))
            if sys.platform == 'win32':
                self.bundle = 'win'
            elif sys.platform.startswith('linux'):
                self.bundle = 'linux'
            elif sys.platform == 'darwin':
                self.bundle = 'osx'
                #OS X bundles start in different directory
                os.chdir('../../..')
        else:
            os.chdir(os.path.dirname(os.path.abspath(__file__)))

        self.lnp_dir = os.path.join(BASEDIR, 'LNP')
        if not os.path.isdir(self.lnp_dir):
            print('WARNING: LNP folder is missing!', file=sys.stderr)
        self.keybinds_dir = self.case_sensitive_folder('Keybinds')
        self.graphics_dir = self.case_sensitive_folder('Graphics')
        self.utils_dir = self.case_sensitive_folder('Utilities')

        self.folders = []
        self.df_dir = ''
        self.settings = None
        self.init_dir = ''
        self.save_dir = ''
        self.autorun = []

        self.load_autorun()
        self.find_df_folder()

        TkGui(self)

    def load_params(self):
        """Loads settings from the selected Dwarf Fortress instance."""
        try:
            self.settings.read_settings()
        except IOError:
            sys.excepthook(*sys.exc_info())
            msg = ("Failed to read settings, "
                   "{0} not really a DF dir?"
                  ).format(self.df_dir)
            raise IOError(msg)

    def save_params(self):
        """Saves settings to the selected Dwarf Fortress instance."""
        self.settings.write_settings()

    def restore_defaults(self):
        """Copy default settings into the selected Dwarf Fortress instance."""
        shutil.copy(
            os.path.join(self.lnp_dir, 'Defaults', 'init.txt'),
            os.path.join(self.init_dir, 'init.txt')
            )
        shutil.copy(
            os.path.join(self.lnp_dir, 'Defaults', 'd_init.txt'),
            os.path.join(self.init_dir, 'd_init.txt')
        )
        self.load_params()

    def run_df(self):
        """Launches Dwarf Fortress."""
        if sys.platform == 'win32':
            self.run_program(os.path.join(self.df_dir, 'Dwarf Fortress.exe'))
        else:
            if os.path.isfile(os.path.join(self.df_dir, 'dfhack')):
              self.run_program(os.path.join(self.df_dir, 'dfhack'))
            else:
              self.run_program(os.path.join(self.df_dir, 'df'))
        for prog in self.autorun:
            if os.access(os.path.join(self.utils_dir, prog), os.F_OK):
{'fraction_non_alphanumeric': 0.12454788488756094, 'fraction_numerical': 0.0025161188866173927, 'mean_word_length': 2.0918813806514343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5838298', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1931, 'n_words': 433}