<commit_before>#!/usr/bin/env python3
import os, glob, re, json, urllib, sys, subprocess, base64

if sys.version_info[0] != 3:
    print("This program requires Python 3.")
    print("You can get it from https://www.python.org/downloads/")
    exit(1)

try:
    import requests
except ImportError:
    print("It looks like requests is not installed.")
    print("Try this: pip3 install requests")
    exit(1)

# Helpers
def open_file_gui(filename):
    if sys.platform == "win32":
        os.startfile(filename)
    else:
        opener = "open" if sys.platform == "darwin" else "xdg-open"
        subprocess.call([opener, filename])

def get_relative_path(fname):
    return os.path.join(os.path.split(os.path.realpath(__file__))[0], fname)

def get_factorio_folder():
    with open(get_relative_path("modman.conf")) as f:
        ret = [i for i in f.readlines() if i[0] != "#" and i != ""][0].strip()

        if not ret.endswith(os.sep):
            ret += os.sep
    return ret

def get_saves():
    saves = {}
    for fname in glob.glob(get_relative_path("modpacks") + "/*"):
        with open(fname) as f:
            saves[os.path.split(fname)[-1][:-4]] = [i.strip() for i in f.readlines() if i != "" and i[0] != "#"]
    return saves

def download_file(url, folder):
    local_filename = url.split('/')[-1]
    r = requests.get(url, stream=True)
    with open(folder + local_filename, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024):
            if chunk: # filter out keep-alive new chunks
                f.write(chunk)
    return local_filename


# Help function
def get_help(subj):
    if subj == [] or subj == ["help"]:
        print ("""Usage: ./modman.py [action]

Actions:
    'help' <action> : If action is present, prints detailed information of the action, otherwise this help message is printed
    'list' or 'listpacks': Lists all available
    'edit' <modpack name> : Opens the specified pack in default text editor<commit_msg>Check that the factorio folder exists when trying to use it<commit_after>#!/usr/bin/env python3
import os, glob, re, json, urllib, sys, subprocess, base64

if sys.version_info[0] != 3:
    print("This program requires Python 3.")
    print("You can get it from https://www.python.org/downloads/")
    exit(1)

try:
    import requests
except ImportError:
    print("It looks like requests is not installed.")
    print("Try this: pip3 install requests")
    exit(1)

# Helpers
def open_file_gui(filename):
    if sys.platform == "win32":
        os.startfile(filename)
    else:
        opener = "open" if sys.platform == "darwin" else "xdg-open"
        subprocess.call([opener, filename])

def get_relative_path(fname):
    return os.path.join(os.path.split(os.path.realpath(__file__))[0], fname)

def get_factorio_folder():
    with open(get_relative_path("modman.conf")) as f:
        ret = [i for i in f.readlines() if i[0] != "#" and i != ""][0].strip()

        if not ret.endswith(os.sep):
            ret += os.sep

    if not os.path.isdir(ret):
        print("Could not find your factorio directory!")
        print("Remember to set it on modman.conf")
        exit(1)

    return ret

def get_saves():
    saves = {}
    for fname in glob.glob(get_relative_path("modpacks") + "/*"):
        with open(fname) as f:
            saves[os.path.split(fname)[-1][:-4]] = [i.strip() for i in f.readlines() if i != "" and i[0] != "#"]
    return saves

def download_file(url, folder):
    local_filename = url.split('/')[-1]
    r = requests.get(url, stream=True)
    with open(folder + local_filename, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024):
            if chunk: # filter out keep-alive new chunks
                f.write(chunk)
    return local_filename


# Help function
def get_help(subj):
    if subj == [] or subj == ["help"]:
        print ("""Usage: ./modman.py [action]

Actions:
    'help' <action> : If action is present, prints detailed information of the action, otherwise this help message is printed
    'list' or 'listpacks': Lists all available
    'edit' <modpack name> : Opens the specified pack in default text editor
{'fraction_non_alphanumeric': 0.13912412291313817, 'fraction_numerical': 0.010887974836680378, 'mean_word_length': 3.0214007782101167, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2420347', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1347, 'n_words': 405}