<commit_before>package daemondriver

import (
	"fmt"
	"os"
	"strings"

	"github.com/emccode/rexray/util"
)

var (
	driverInitFuncs map[string]InitFunc
	drivers         map[string]Driver
	debug           string
)

var Adapters map[string]Driver

type Driver interface {
	// Starts the daemon
	Start(string) error
}

type InitFunc func() (Driver, error)

func Register(name string, initFunc InitFunc) error {
	driverInitFuncs[name] = initFunc
	return nil
}

func init() {
	driverInitFuncs = make(map[string]InitFunc)
	drivers = make(map[string]Driver)
	debug = strings.ToUpper(os.Getenv("REXRAY_DEBUG"))
}

func GetDrivers(osDrivers string) (map[string]Driver, error) {
	var err error
	var osDriversArr []string
	if osDrivers != "" {
		osDriversArr = strings.Split(osDrivers, ",")
	}

	if debug == "TRUE" {
		fmt.Println(driverInitFuncs)
	}

	for name, initFunc := range driverInitFuncs {
		if len(osDriversArr) > 0 && !util.StringInSlice(name, osDriversArr) {
			continue
		}
		drivers[name], err = initFunc()
		if err != nil {
			if debug == "TRUE" {
				fmt.Println(fmt.Sprintf("Info (%s): %s", name, err))
			}
			delete(drivers, name)
		}
	}

	return drivers, nil
}<commit_msg>added prioritization of daemon driver start<commit_after>package daemondriver

import (
	"fmt"
	"os"
	"strings"

	"github.com/emccode/rexray/util"
)

var (
	driverInitFuncs map[string]InitFunc
	drivers         map[string]Driver
	debug           string
)

var Adapters map[string]Driver

type Driver interface {
	// Starts the daemon
	Start(string) error
}

type InitFunc func() (Driver, error)

func Register(name string, initFunc InitFunc) error {
	driverInitFuncs[name] = initFunc
	return nil
}

func init() {
	driverInitFuncs = make(map[string]InitFunc)
	drivers = make(map[string]Driver)
	debug = strings.ToUpper(os.Getenv("REXRAY_DEBUG"))
}

func GetDrivers(daemonDrivers string) (map[string]Driver, error) {
	var err error
	var daemonDriversArr []string
	if daemonDrivers != "" {
		daemonDriversArr = strings.Split(daemonDrivers, ",")
	}

	if debug == "TRUE" {
		fmt.Println(driverInitFuncs)
	}

	driverPriority := []string{
		"dockervolumedriver",
		"dockerremotevolumedriver",
	}

	for _, name := range driverPriority {

		if len(daemonDriversArr) > 0 && !util.StringInSlice(name, daemonDriversArr) {
			continue
		}

		var initFunc InitFunc
		var ok bool
		if initFunc, ok = driverInitFuncs[name]; !ok {
			continue
		}

		drivers[name], err = initFunc()
		if err != nil {
			if debug == "TRUE" {
				fmt.Println(fmt.Sprintf("Info (%s): %s", name, err))
			}
			delete(drivers, name)
		}
	}

	return drivers, nil
}
{'fraction_non_alphanumeric': 0.12524010756819054, 'fraction_numerical': 0.000768344218209758, 'mean_word_length': 4.0859375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6413490', 'n_tokens_mistral': 1029, 'n_tokens_neox': 937, 'n_words': 214}