<commit_before>from __future__ import print_function

print("Welcome to the LightSweeper installer!")

import sys

def bail(mess):
    print("\n{:s}".format(mess))
    sys.exit()
    
if __name__ != "__main__":
    print("Oh no! Something went terribly wrong!")
    bail("Please run installer.py directly.")

if sys.hexversion < 0x030200a1:
    print("LightSweeper requires python 3.2 or higher but your current python version is:")
    print(sys.version)
    bail("Please upgrade your python interpreter and try again.")

import os
import shutil
import tempfile

from urllib.request import urlopen
from zipfile import ZipFile

def main():

    print("Checking for LightSweeper API... ", end="")
    try:
        import lightsweeper
    except:
        print("not installed.")
        print("The LightSweeper API is not installed.")
        if YESno("Would you like me to fetch it from the internet and install it?"):
            try:
                lsApiArchive = fetch_ls_api()
            except Exception as e:
                print("Failed to fetch archive.")
                bail("Please ensure you have an active internet connection and try again.")
            install_ls_api(lsApiArchive)
            lsApiArchive.close()
            restarter()
        else:
            bail("Please install the LightSweeper API then try again.")
    print("installed.")


    from lightsweeper import lsconfig

    sysPath = os.path.abspath("/LightSweeper")
    localPath = os.path.abspath(os.path.expanduser("~/.lightsweeper"))

    scopes = ["System-wide", "For the local user only"]
    installScope = lsconfig.userSelect(scopes, "\nHow would you like to install the LightSweeper environment?")

    if (installScope == scopes[0]):
        configDir = sysPath
        local=False
    else:
        configDir = localPath
        local=True

    basePath = os.path.expanduser("~") if local else sysPath

    gamesDir = chooseDir("Where would you like to store your games?", os.path.join(basePath, "lightsweeper-games" if local else "games"))

    if local:
        utilsDir = chooseDir("Where would you like to store the LightSweeper utilities?", os.path.join(basePath, "lightsweeper-utilities"))
    else:
        utilsDir = os.path.join(basePath, "util")

    examplesDir = os.path.join(os.path.join(basePath, ".lightsweeper") if local else basePath, "examples")
    
    sysSoundsDir = os.path.join(lightsweeper.lsconfig.lsSysPath, "sounds")

    entryPoint = chooseFile("Where should I put the LightSweeper entry point?", os.path.join(basePath, "LightSweeper.py"))

    check_dir(configDir, "configuration")
    check_dir(gamesDir, "games")
    check_dir(utilsDir, "utilities")
    check_dir(examplesDir, "examples")
    
    print("Copying some data... ", end="")

    try:
        shutil.copyfile(sane_root("LightSweeper.py"), entryPoint)
        copy_directory(sane_root("util"), utilsDir)
        copy_directory(sane_root("examples"), examplesDir)
        copy_directory(sane_root("sounds"), sysSoundsDir)
    except Exception as e:
        bail("Error copying data: {:s}".format(e))

    print("done.")
    
    config = os.path.join(configDir, "lightsweeper.conf")
    print("Generating lightsweeper.conf... ", end="")
    if os.path.exists(config):
        shutil.copy2(config, "{:s}.bak".format(config))

    f = open(config, "w")
    f.write("GAMESDIR = {:s}\n".format(gamesDir))
    
    f.close()
    print("okay.")
    
    if len(os.listdir(gamesDir)) == 0:
        print("It appears your LightSweeper games folder is empty.")
        if YESno("Would you like me to fetch the official game pack from the internet?"):
            try:
                lsGamesArchive = fetch_games()
            except Exception as e:
                try:
                    lsGamesArchive = fetch_games()
                except Exception as e:
                    print("Failed to fetch games, sorry :(")
            with tempfile.TemporaryDirectory() as td:
                archive = ZipFile(lsGamesArchive)
                archive.extractall(td)
                setupPath = os.path.join(td, "games-master")
                copy_directory(setupPath, gamesDir)
        else:
            print("So be it, jedi.")
            shutil.copy2(os.path.join(examplesDir, "HelloWorld.py"), gamesDir)
    
    print("Okay have fun!")

def check_dir(path, name):
    from lightsweeper import lsconfig
    if not os.path.exists(path):
        print("Creating {:s} directory... ".format(name), end="")
        try:
            os.mkdir(path)
        except PermissionError:
            print("failed.")
            print("Could not create folder: {:s}".format(path))
            bail("Please check your permissions and try again.")
        print(path)
    else:
        if os.path.isdir(path):
            if not lsconfig.yesNO("{:s} already exists, would you like to install anyway? (This may clobber data)".format(path)):
                bail("Please move the folder at {:s} and try again.".format(path))
        else:
            print("{:s} already exists.".format(path))
            bail("Please move or rename the file at {:s} and try again.".format(path))

def copy_directory(sourceDir, destDir):
    for fileName in os.listdir(sourceDir):
        source = os.path.join(sourceDir, fileName)
        dest = os.path.join(destDir, fileName)
        if os.path.isdir(source):
          #  copy_directory(source, dest)
            try:<commit_msg>Installer now recursively creates directories if you specified a deep non-existant subdirectory for anything<commit_after>from __future__ import print_function

print("Welcome to the LightSweeper installer!")

import sys

def bail(mess):
    print("\n{:s}".format(mess))
    sys.exit()
    
if __name__ != "__main__":
    print("Oh no! Something went terribly wrong!")
    bail("Please run installer.py directly.")

if sys.hexversion < 0x030200a1:
    print("LightSweeper requires python 3.2 or higher but your current python version is:")
    print(sys.version)
    bail("Please upgrade your python interpreter and try again.")

import os
import shutil
import tempfile

from urllib.request import urlopen
from zipfile import ZipFile

def main():

    print("Checking for LightSweeper API... ", end="")
    try:
        import lightsweeper
    except:
        print("not installed.")
        print("The LightSweeper API is not installed.")
        if YESno("Would you like me to fetch it from the internet and install it?"):
            try:
                lsApiArchive = fetch_ls_api()
            except Exception as e:
                print("Failed to fetch archive.")
                bail("Please ensure you have an active internet connection and try again.")
            install_ls_api(lsApiArchive)
            lsApiArchive.close()
            restarter()
        else:
            bail("Please install the LightSweeper API then try again.")
    print("installed.")


    from lightsweeper import lsconfig

    sysPath = os.path.abspath("/LightSweeper")
    localPath = os.path.abspath(os.path.expanduser("~/.lightsweeper"))

    scopes = ["System-wide", "For the local user only"]
    installScope = lsconfig.userSelect(scopes, "\nHow would you like to install the LightSweeper environment?")

    if (installScope == scopes[0]):
        configDir = sysPath
        local=False
    else:
        configDir = localPath
        local=True

    basePath = os.path.expanduser("~") if local else sysPath

    gamesDir = chooseDir("Where would you like to store your games?", os.path.join(basePath, "lightsweeper-games" if local else "games"))

    gamesDir = os.path.abspath(gamesDir)

    if local:
        utilsDir = chooseDir("Where would you like to store the LightSweeper utilities?", os.path.join(basePath, "lightsweeper-utilities"))
    else:
        utilsDir = os.path.join(basePath, "util")

    utilsDir = os.path.abspath(utilsDir)

    examplesDir = os.path.join(os.path.join(basePath, ".lightsweeper") if local else basePath, "examples")

    sysSoundsDir = os.path.join(lightsweeper.lsconfig.lsSysPath, "sounds")

    entryPoint = chooseFile("Where should I put the LightSweeper entry point?", os.path.join(basePath, "LightSweeper.py"))

    entryPoint = os.path.abspath(entryPoint)

    check_dir(configDir, "configuration")
    check_dir(gamesDir, "games")
    check_dir(utilsDir, "utilities")
    check_dir(examplesDir, "examples")

    if not os.path.exists(os.path.dirname(entryPoint)):
        os.makedirs(os.path.dirname(entryPoint))
    
    print("Copying some data... ", end="")

    try:
        shutil.copyfile(sane_root("LightSweeper.py"), entryPoint)
        copy_directory(sane_root("util"), utilsDir)
        copy_directory(sane_root("examples"), examplesDir)
        copy_directory(sane_root("sounds"), sysSoundsDir)
    except Exception as e:
        bail("Error copying data: {:s}".format(e))

    print("done.")
    
    config = os.path.join(configDir, "lightsweeper.conf")
    print("Generating lightsweeper.conf... ", end="")
    if os.path.exists(config):
        shutil.copy2(config, "{:s}.bak".format(config))

    f = open(config, "w")
    f.write("GAMESDIR = {:s}\n".format(gamesDir))
    
    f.close()
    print("okay.")
    
    if len(os.listdir(gamesDir)) == 0:
        print("It appears your LightSweeper games folder is empty.")
        if YESno("Would you like me to fetch the official game pack from the internet?"):
            try:
                lsGamesArchive = fetch_games()
            except Exception as e:
                try:
                    lsGamesArchive = fetch_games()
                except Exception as e:
                    print("Failed to fetch games, sorry :(")
            with tempfile.TemporaryDirectory() as td:
                archive = ZipFile(lsGamesArchive)
                archive.extractall(td)
                setupPath = os.path.join(td, "games-master")
                copy_directory(setupPath, gamesDir)
        else:
            print("So be it, jedi.")
            shutil.copy2(os.path.join(examplesDir, "HelloWorld.py"), gamesDir)
    
    print("Okay have fun!")

def check_dir(path, name):
    from lightsweeper import lsconfig
    if not os.path.exists(path):
        print("Creating {:s} directory... ".format(name), end="")
        try:
            os.makedirs(path)
        except PermissionError:
            print("failed.")
            print("Could not create folder: {:s}".format(path))
            bail("Please check your permissions and try again.")
        print(path)
    else:
        if os.path.isdir(path):
            if not lsconfig.yesNO("{:s} already exists, would you like to install anyway? (This may clobber data)".format(path)):
                bail("Please move the folder at {:s} and try again.".format(path))
        else:
            print("{:s} already exists.".format(path))
            bail("Please move or rename the file at {:s} and try again.".format(path))

def copy_directory(sourceDir, destDir):
    for fileName in os.listdir(sourceDir):
        source = os.path.join(sourceDir, fileName)
        dest = os.path.join(destDir, fileName)
        if os.path.isdir(source):
          #  copy_directory(source, dest)
            try:
{'fraction_non_alphanumeric': 0.11629153269024652, 'fraction_numerical': 0.002500893176134334, 'mean_word_length': 2.6154342912495965, 'pattern_counts': {'":': 2, '<': 5, '<?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': '3567499', 'n_tokens_mistral': 3396, 'n_tokens_neox': 3225, 'n_words': 898}