<commit_before>/*
   Copyright 2014 Outbrain Inc.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

// zk provides with higher level commands over the lower level zookeeper connector
package zk

import (
	"bytes"
	"errors"
	"fmt"
	"github.com/outbrain/golib/log"
	"github.com/samuel/go-zookeeper/zk"
	"math"
	gopath "path"
	"sort"
	"strconv"
	"strings"
	"time"
)

var servers []string
var authScheme string
var authExpression []byte

// We assume complete access to all
var flags int32 = int32(0)
var acl []zk.ACL = zk.WorldACL(zk.PermAll)

// SetServers sets the list of servers for the zookeeper client to connect to.
// Each element in the array should be in either of following forms:
// - "servername"
// - "servername:port"
func SetServers(serversArray []string) {
	servers = serversArray
}

func SetAuth(scheme string, auth []byte) {
	log.Debug("Setting Auth ")
	authScheme = scheme
	authExpression = auth
}

// Returns acls
func BuildACL(authScheme string, user string, pwd string, acls string) (perms []zk.ACL, err error) {
	aclsList := strings.Split(acls, ",")
	for _, elem := range aclsList {
		acl, err := strconv.ParseInt(elem, 10, 32)
		if err != nil {
			break
		}
		perm := zk.DigestACL(int32(acl), user, pwd)
		perms = append(perms, perm[0])
	}
	return perms, err
}

// connect
func connect() (*zk.Conn, error) {
	conn, _, err := zk.Connect(servers, time.Second)
	if err == nil && authScheme != "" {
		log.Debugf("Add Auth %s %s", authScheme, authExpression)
		err = conn.AddAuth(authScheme, authExpression)
	}

	return conn, err
}

// Exists returns true when the given path exists
func Exists(path string) (bool, error) {<commit_msg>show go-zookeeper logs only if -verbose provided<commit_after>/*
   Copyright 2014 Outbrain Inc.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

// zk provides with higher level commands over the lower level zookeeper connector
package zk

import (
	"bytes"
	"errors"
	"fmt"
	"github.com/outbrain/golib/log"
	"github.com/samuel/go-zookeeper/zk"
	"math"
	gopath "path"
	"sort"
	"strconv"
	"strings"
	"time"
)

var servers []string
var authScheme string
var authExpression []byte

// We assume complete access to all
var flags int32 = int32(0)
var acl []zk.ACL = zk.WorldACL(zk.PermAll)

// SetServers sets the list of servers for the zookeeper client to connect to.
// Each element in the array should be in either of following forms:
// - "servername"
// - "servername:port"
func SetServers(serversArray []string) {
	servers = serversArray
}

func SetAuth(scheme string, auth []byte) {
	log.Debug("Setting Auth ")
	authScheme = scheme
	authExpression = auth
}

// Returns acls
func BuildACL(authScheme string, user string, pwd string, acls string) (perms []zk.ACL, err error) {
	aclsList := strings.Split(acls, ",")
	for _, elem := range aclsList {
		acl, err := strconv.ParseInt(elem, 10, 32)
		if err != nil {
			break
		}
		perm := zk.DigestACL(int32(acl), user, pwd)
		perms = append(perms, perm[0])
	}
	return perms, err
}

type infoLogger struct{}

func (_ infoLogger) Printf(format string, a ...interface{}) {
	log.Infof(format, a...)
}

// connect
func connect() (*zk.Conn, error) {
	zk.DefaultLogger = &infoLogger{}
	conn, _, err := zk.Connect(servers, time.Second)
	if err == nil && authScheme != "" {
		log.Debugf("Add Auth %s %s", authScheme, authExpression)
		err = conn.AddAuth(authScheme, authExpression)
	}

	return conn, err
}

// Exists returns true when the given path exists
func Exists(path string) (bool, error) {
{'fraction_non_alphanumeric': 0.10930904243501444, 'fraction_numerical': 0.008886914019106865, 'mean_word_length': 3.8201284796573876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1100124', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1438, 'n_words': 527}