<commit_before>package schroot

import (
	"fmt"
	"strings"

	"os/exec"
)

func getOutputLine(cmd *exec.Cmd) (string, error) {
	out, err := cmd.Output()
	if err != nil {
		return "", err
	}
	return strings.Trim(string(out), " \n\t\r"), nil
}

type Schroot struct {
	location string
	name     string
	session  string
	active   bool
}

func (schroot *Schroot) End() error {
	return exec.Command("schroot", "-e", "-c", schroot.session).Run()
}

func (schroot *Schroot) Run(cmd string, args ...string) *exec.Cmd {
	/* The semantics of foo(bar, baz, quix...) are so fucked up here
	 * it's not even funny. Let's do an append and unpack that. Sorry
	 * this looks like garbage, but it's either explicitly passing the
	 * elements into the call site, or use a foo... with nothing prefixing
	 * it. Sooo. Yeah.
	 *    -- PRT */
	return exec.Command(
		"schroot",
		append(
			[]string{
				"-r",
				"-c", schroot.session,
				"--directory", "/",
				"--",
				cmd,
			}, args...)...,
	)
}

func NewSchroot(name string) (*Schroot, error) {
	schroot := Schroot{}
	out, err := getOutputLine(exec.Command("schroot", "-b", "-c", name))
	if err != nil {
		return nil, err
	}
	schroot.session = out

	out, err = getOutputLine(exec.Command(
		"schroot", "--location",
		"-c", fmt.Sprintf("session:%s", schroot.session),
	))
	if err != nil {
		return nil, err
	}
	schroot.location = out

	return &schroot, nil
}<commit_msg>revise the interface, add active<commit_after>package schroot

import (
	"fmt"
	"strings"

	"os/exec"
)

func getOutputLine(cmd *exec.Cmd) (string, error) {
	out, err := cmd.Output()
	if err != nil {
		return "", err
	}
	return strings.Trim(string(out), " \n\t\r"), nil
}

type Schroot struct {
	location string
	name     string
	session  string
	active   bool
}

func (schroot *Schroot) End() error {
	err := exec.Command("schroot", "-e", "-c", schroot.session).Run()
	schroot.active = false
	return err
}

func (schroot *Schroot) Command(cmd string, args ...string) (*exec.Cmd, error) {
	/* The semantics of foo(bar, baz, quix...) are so fucked up here
	 * it's not even funny. Let's do an append and unpack that. Sorry
	 * this looks like garbage, but it's either explicitly passing the
	 * elements into the call site, or use a foo... with nothing prefixing
	 * it. Sooo. Yeah.
	 *    -- PRT */
	if !schroot.active {
		return nil, fmt.Errorf("Error: Schroot is not online")
	}
	return exec.Command(
		"schroot",
		append(
			[]string{
				"-r",
				"-c", schroot.session,
				"--directory", "/",
				"--",
				cmd,
			}, args...)...,
	), nil
}

func NewSchroot(name string) (*Schroot, error) {
	schroot := Schroot{
		name:   name,
		active: false,
	}
	out, err := getOutputLine(exec.Command("schroot", "-b", "-c", name))
	if err != nil {
		return nil, err
	}
	schroot.session = out
	schroot.active = true

	out, err = getOutputLine(exec.Command(
		"schroot", "--location",
		"-c", fmt.Sprintf("session:%s", schroot.session),
	))
	if err != nil {
		return nil, err
	}
	schroot.location = out

	return &schroot, nil
}
{'fraction_non_alphanumeric': 0.1659504132231405, 'fraction_numerical': 0.0, 'mean_word_length': 3.0891891891891894, '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': '3647536', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1061, 'n_words': 329}