<commit_before>#!/usr/bin/env python3
# Performs a local backup of SaaS data

import argparse
import json
import os
import subprocess
import platform
import urllib.request

BACKUPS_LOCATION = os.path.expanduser("~/Backups")


def arch() -> str:
    if platform.machine() == "x86_64":
        return "amd64"

    if "arm" in platform.machine():
        if "64" in platform.architecture()[0]:
            return "arm64"
        else:
            return "arm"


def system() -> str:
    return platform.system().lower()


def install():
    subprocess.run(["python3", "-m", "pip", "install", "github-backup"], shell=True, check=True)

    with urllib.request.urlopen(
        "https://api.github.com/repos/mlcdf/sc-backup/releases/latest"
    ) as response:
        release = json.load(response)

    for asset in release["assets"]:
        if f"{system()}-{arch()}" in asset["name"]:
            url = asset["browser_download_url"]

    urllib.request.urlretrieve(url, "sc-backup")


def github():
    if "GITHUB_TOKEN" not in os.environ:
        print("Missing GITHUB_TOKEN in environment")
        exit(1)

    subprocess.run(
        [
            "github-backup",
            "mlcdf",
            "-t",
            os.environ["GITHUB_TOKEN"],
            "--starred",
            "--repositories",
            "--gists",
            "--private",
            "-o",
            os.path.join(BACKUPS_LOCATION, "GitHub"),
        ],
        shell=True,
        check=True,
    )
<commit_msg>backup(saas): put binaries in ~/.local/bin<commit_after>#!/usr/bin/env python3
# Performs a local backup of SaaS data

import argparse
import json
import os
import subprocess
import platform
import urllib.request

BACKUPS_LOCATION = os.path.expanduser("~/Backups")
BINARIES_LOCATION = os.path.expanduser("~/.local/bin")


def arch() -> str:
    if platform.machine() == "x86_64":
        return "amd64"

    if "arm" in platform.machine():
        if "64" in platform.architecture()[0]:
            return "arm64"
        else:
            return "arm"


def system() -> str:
    return platform.system().lower()


def install():
    subprocess.run(["python3", "-m", "pip", "install", "github-backup"], shell=True, check=True)

    with urllib.request.urlopen(
        "https://api.github.com/repos/mlcdf/sc-backup/releases/latest"
    ) as response:
        release = json.load(response)

    for asset in release["assets"]:
        if f"{system()}-{arch()}" in asset["name"]:
            url = asset["browser_download_url"]

    urllib.request.urlretrieve(url, os.path.join(BINARIES_LOCATION, "sc-backup"))


def github():
    if "GITHUB_TOKEN" not in os.environ:
        print("Missing GITHUB_TOKEN in environment")
        exit(1)

    subprocess.run(
        [
            "github-backup",
            "mlcdf",
            "-t",
            os.environ["GITHUB_TOKEN"],
            "--starred",
            "--repositories",
            "--gists",
            "--private",
            "-o",
            os.path.join(BACKUPS_LOCATION, "GitHub"),
        ],
        shell=True,
        check=True,
    )

{'fraction_non_alphanumeric': 0.1495961227786753, 'fraction_numerical': 0.009046849757673668, 'mean_word_length': 2.195046439628483, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3273630', 'n_tokens_mistral': 1016, 'n_tokens_neox': 976, 'n_words': 213}