<commit_before>package lib

import (
	"archive/tar"
	"bytes"
	"context"
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"sync"

	da "github.com/cvmfs/ducc/docker-api"

	"github.com/docker/docker/api/types"
	"github.com/docker/docker/client"
	log "github.com/sirupsen/logrus"
)

var NoPasswordError = 101

type ConversionResult int

const (
	ConversionNotFound = iota
	ConversionMatch    = iota
	ConversionNotMatch = iota
)

var subDirInsideRepo = ".layers"

func ConvertWishSingularity(wish WishFriendly) (err error) {<commit_msg>check singularity version<commit_after>package lib

import (
	"archive/tar"
	"bytes"
	"context"
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strconv"
	"strings"
	"sync"

	da "github.com/cvmfs/ducc/docker-api"

	"github.com/docker/docker/api/types"
	"github.com/docker/docker/client"
	log "github.com/sirupsen/logrus"
)

var NoPasswordError = 101

type ConversionResult int

const (
	ConversionNotFound = iota
	ConversionMatch    = iota
	ConversionNotMatch = iota
)

var subDirInsideRepo = ".layers"

func assureValidSingularity() error {
	err, stdout, _ := ExecCommand("singularity", "--version").StartWithOutput()
	if err != nil {
		err := fmt.Errorf("No working version of Singularity: %s", err)
		LogE(err).Error("No working version of Singularity")
		return err
	}
	version := stdout.String()
	sems := strings.Split(version, ".")
	if len(sems) < 2 {
		err := fmt.Errorf("Singularity version returned an unexpected format, unable to find Major and Minor number")
		LogE(err).WithFields(log.Fields{"version": version}).Error("Not valid singularity")
		return err
	}
	majorS := sems[0]
	majorI, err := strconv.Atoi(majorS)
	if err != nil {
		errF := fmt.Errorf("Singularity version returned an unexpected format, unable to parse Major number: %s", err)
		LogE(errF).WithFields(log.Fields{"version": version, "major number": majorS}).Error("Not valid singularity")
		return errF
	}
	if majorI >= 4 {
		return nil
	}
	minorS := sems[1]
	minorI, err := strconv.Atoi(minorS)
	if err != nil {
		errF := fmt.Errorf("Singularity version returned an unexpected format, unable to parse Minor number: %s", err)
		LogE(errF).WithFields(log.Fields{"version": version, "minor number": minorS}).Error("Not valid singularity")
		return errF
	}
	if majorI >= 3 && minorI >= 5 {
		return nil
	}
	errF := fmt.Errorf("Installed singularity is too old, we need at least 3.5: Installed version: %s", version)
	LogE(errF).WithFields(log.Fields{"version": version}).Error("Too old singularity")
	return errF
}

func ConvertWishSingularity(wish WishFriendly) (err error) {
	err := assureValidSingularity()
	if err != nil {
		return err
	}
{'fraction_non_alphanumeric': 0.1354625550660793, 'fraction_numerical': 0.006607929515418502, 'mean_word_length': 4.606995884773663, 'pattern_counts': {'":': 6, '<': 4, '<?xml version=': 0, '>': 6, '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': '5965619', 'n_tokens_mistral': 1025, 'n_tokens_neox': 968, 'n_words': 239}