Ejemplo n.º 1
0
func filterEventJobCreated(resp *etcd.Response) *Event {
	if resp.Action != "set" || resp.Node.PrevValue != "" {
		return nil
	}

	dir, jobName := path.Split(resp.Node.Key)
	dir = strings.TrimSuffix(dir, "/")
	dir, prefix := path.Split(dir)
	if prefix != strings.Trim(schedulePrefix, "/") {
		return nil
	}

	var jp job.JobPayload
	err := unmarshal(resp.Node.Value, &jp)
	if err != nil {
		log.V(1).Infof("Failed to deserialize JobPayload: %s", err)
		return nil
	}

	j, _ := job.NewJob(jobName, nil, &jp)

	dir = strings.TrimSuffix(dir, "/")
	dir, machName := path.Split(dir)
	m := machine.New(machName)

	return &Event{"EventJobCreated", *j, m}
}
Ejemplo n.º 2
0
// for direct zk connection: vtzk://host:port/cell/keyspace/tabletType
// we always use a MetaConn, host and port are ignored.
// the driver name dictates if we use zk or zkocc, and streaming or not
//
// if user and password are specified in the URL, they will be used
// for each DB connection to the tablet's vttablet processes
func (driver *sDriver) Open(name string) (sc db.Conn, err error) {
	if !strings.HasPrefix(name, "vtzk://") {
		// add a default protocol talking to zk
		name = "vtzk://" + name
	}
	u, err := url.Parse(name)
	if err != nil {
		return nil, err
	}

	dbi, tabletType := path.Split(u.Path)
	dbi = strings.Trim(dbi, "/")
	tabletType = strings.Trim(tabletType, "/")
	cell, keyspace := path.Split(dbi)
	cell = strings.Trim(cell, "/")
	keyspace = strings.Trim(keyspace, "/")
	var user, password string
	if u.User != nil {
		user = u.User.Username()
		var ok bool
		password, ok = u.User.Password()
		if !ok {
			return nil, fmt.Errorf("vt: need a password if a user is specified")
		}
	}
	return Dial(driver.ts, cell, keyspace, topo.TabletType(tabletType), driver.stream, tablet.DefaultTimeout, user, password)
}
Ejemplo n.º 3
0
func filterEventJobUnscheduled(resp *goetcd.Response) *event.Event {
	if resp.Action != "delete" && resp.Action != "compareAndDelete" {
		return nil
	}

	dir, baseName := path.Split(resp.Node.Key)
	if baseName != "target" {
		return nil
	}

	dir = strings.TrimSuffix(dir, "/")
	dir, jobName := path.Split(dir)

	dir = strings.TrimSuffix(dir, "/")
	dir, prefixName := path.Split(dir)

	if prefixName != jobPrefix {
		return nil
	}

	if resp.PrevNode == nil {
		return nil
	}

	return &event.Event{"EventJobUnscheduled", jobName, resp.PrevNode.Value}
}
Ejemplo n.º 4
0
// statesByMUSKey returns a map of all UnitStates stored in the registry indexed by MUSKey
func (r *EtcdRegistry) statesByMUSKey() (map[MUSKey]*unit.UnitState, error) {
	mus := make(map[MUSKey]*unit.UnitState)
	req := etcd.Get{
		Key:       path.Join(r.keyPrefix, statesPrefix),
		Recursive: true,
	}
	res, err := r.etcd.Do(&req)
	if err != nil && !etcd.IsKeyNotFound(err) {
		return nil, err
	}
	if res != nil {
		for _, dir := range res.Node.Nodes {
			_, name := path.Split(dir.Key)
			for _, node := range dir.Nodes {
				_, machID := path.Split(node.Key)
				var usm unitStateModel
				if err := unmarshal(node.Value, &usm); err != nil {
					log.Errorf("Error unmarshalling UnitState(%s) from Machine(%s): %v", name, machID, err)
					continue
				}
				us := modelToUnitState(&usm, name)
				if us != nil {
					key := MUSKey{name, machID}
					mus[key] = us
				}
			}
		}
	}
	return mus, nil
}
Ejemplo n.º 5
0
// stateByMUSKey returns a single UnitState stored in the registry indexed by MUSKey
// that matches with the given unit name
func (r *EtcdRegistry) stateByMUSKey(uName string) (*unit.UnitState, error) {
	key := r.prefixed(statesPrefix)
	opts := &etcd.GetOptions{
		Recursive: true,
	}
	res, err := r.kAPI.Get(context.Background(), key, opts)
	if err != nil && !isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
		return nil, err
	}
	if res == nil {
		return nil, nil
	}

	for _, dir := range res.Node.Nodes {
		_, name := path.Split(dir.Key)
		if name != uName {
			continue
		}
		for _, node := range dir.Nodes {
			_, machID := path.Split(node.Key)
			var usm unitStateModel
			if err := unmarshal(node.Value, &usm); err != nil {
				log.Errorf("Error unmarshalling UnitState(%s) from Machine(%s): %v", name, machID, err)
				continue
			}
			us := modelToUnitState(&usm, name)
			if us != nil {
				return us, nil
			}
		}
	}
	return nil, nil
}
Ejemplo n.º 6
0
// 输出文件。
// name指定文件名,为空时默认保持原文件名不变。
func (self *Context) FileOutput(name ...string) {
	_, s := path.Split(self.GetUrl())
	n := strings.Split(s, "?")[0]

	// 初始化
	baseName := strings.Split(n, ".")[0]
	ext := path.Ext(n)

	if len(name) > 0 {
		p, n := path.Split(name[0])
		if baseName2 := strings.Split(n, ".")[0]; baseName2 != "" {
			baseName = p + baseName2
		}
		if ext == "" {
			ext = path.Ext(n)
		}
	}

	if ext == "" {
		ext = ".html"
	}
	self.Lock()
	self.files = append(self.files, data.GetFileCell(self.GetRuleName(), baseName+ext, self.Response.Body))
	self.Unlock()
}
Ejemplo n.º 7
0
// statesByMUSKey returns a map of all UnitStates stored in the registry indexed by MUSKey
func (r *EtcdRegistry) statesByMUSKey() (map[MUSKey]*unit.UnitState, error) {
	mus := make(map[MUSKey]*unit.UnitState)
	key := r.prefixed(statesPrefix)
	opts := &etcd.GetOptions{
		Recursive: true,
	}
	res, err := r.kAPI.Get(r.ctx(), key, opts)
	if err != nil && !isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
		return nil, err
	}
	if res != nil {
		for _, dir := range res.Node.Nodes {
			_, name := path.Split(dir.Key)
			for _, node := range dir.Nodes {
				_, machID := path.Split(node.Key)
				var usm unitStateModel
				if err := unmarshal(node.Value, &usm); err != nil {
					log.Errorf("Error unmarshalling UnitState(%s) from Machine(%s): %v", name, machID, err)
					continue
				}
				us := modelToUnitState(&usm, name)
				if us != nil {
					key := MUSKey{name, machID}
					mus[key] = us
				}
			}
		}
	}
	return mus, nil
}
Ejemplo n.º 8
0
// AddFile saves to Response.Files preparing for Pipeline
func (self *Response) AddFile(name ...string) {
	file := map[string]interface{}{
		"Body": self.Response.Body,
	}

	_, s := path.Split(self.GetUrl())
	n := strings.Split(s, "?")[0]

	// 初始化
	baseName := strings.Split(n, ".")[0]
	ext := path.Ext(n)

	if len(name) > 0 {
		_, n = path.Split(name[0])
		if baseName2 := strings.Split(n, ".")[0]; baseName2 != "" {
			baseName = baseName2
		}
		if ext == "" {
			ext = path.Ext(n)
		}
	}

	if ext == "" {
		ext = ".html"
	}

	file["Name"] = baseName + ext

	self.files = append(self.files, file)
}
Ejemplo n.º 9
0
func main() {
	wd, err := os.Getwd()
	if err != nil {
		panic(err)
	}

	fmt.Println("working directory: ", wd)

	fmt.Println("base: ", path.Base(wd))
	fmt.Println("dir: ", path.Dir(wd))
	fmt.Println("ext: ", path.Ext(wd+"howdy.test"))
	fmt.Println("abs: ", path.IsAbs(wd))
	fmt.Println("abs: ", path.IsAbs("howdy/../../"))

	dirty := "////howdy////lots/of//slashes//yeah/"
	fmt.Println("dirty: ", dirty)
	fmt.Println("clean: ", path.Clean(dirty))

	fmt.Println("joined: ", path.Join("one", "two", "three", "four"))

	dir, file := path.Split(wd + "/lala.txt")
	fmt.Println("dir: ", dir, " file: ", file)

	// Hmmmm, I wonder if path works with URLs.
	var base string
	url := "http://example.com/test/file.txt"
	base, file = path.Split(url)
	fmt.Printf("Got base %v and file %v\n", base, file)

	// Looks like the double slash after http: gets messed up by path.Dir.
	fmt.Printf("Base is %v\nDir is %v\n", path.Base(url), path.Dir(url))
}
Ejemplo n.º 10
0
// 输出文件。
// name指定文件名,为空时默认保持原文件名不变。
func (self *Context) FileOutput(name ...string) {
	// 读取完整文件流
	bytes, err := ioutil.ReadAll(self.Response.Body)
	self.Response.Body.Close()
	if err != nil {
		panic(err.Error())
		return
	}

	// 智能设置完整文件名
	_, s := path.Split(self.GetUrl())
	n := strings.Split(s, "?")[0]

	baseName := strings.Split(n, ".")[0]

	var ext string
	if len(name) > 0 {
		p, n := path.Split(name[0])
		if baseName2 := strings.Split(n, ".")[0]; baseName2 != "" {
			baseName = p + baseName2
		}
		ext = path.Ext(n)
	}
	if ext == "" {
		ext = path.Ext(n)
	}
	if ext == "" {
		ext = ".html"
	}

	// 保存到文件临时队列
	self.Lock()
	self.files = append(self.files, data.GetFileCell(self.GetRuleName(), baseName+ext, bytes))
	self.Unlock()
}
Ejemplo n.º 11
0
// NewReplacer makes a new replacer based on r and rr.
// Do not create a new replacer until r and rr have all
// the needed values, because this function copies those
// values into the replacer. rr may be nil if it is not
// available. emptyValue should be the string that is used
// in place of empty string (can still be empty string).
func NewReplacer(r *http.Request, rr *responseRecorder, emptyValue string) Replacer {
	rep := replacer{
		replacements: map[string]string{
			"{method}": r.Method,
			"{scheme}": func() string {
				if r.TLS != nil {
					return "https"
				}
				return "http"
			}(),
			"{host}":     r.Host,
			"{path}":     r.URL.Path,
			"{query}":    r.URL.RawQuery,
			"{fragment}": r.URL.Fragment,
			"{proto}":    r.Proto,
			"{remote}": func() string {
				if fwdFor := r.Header.Get("X-Forwarded-For"); fwdFor != "" {
					return fwdFor
				}
				host, _, err := net.SplitHostPort(r.RemoteAddr)
				if err != nil {
					return r.RemoteAddr
				}
				return host
			}(),
			"{port}": func() string {
				_, port, err := net.SplitHostPort(r.RemoteAddr)
				if err != nil {
					return ""
				}
				return port
			}(),
			"{uri}": r.URL.RequestURI(),
			"{when}": func() string {
				return time.Now().Format(timeFormat)
			}(),
			"{file}": func() string {
				_, file := path.Split(r.URL.Path)
				return file
			}(),
			"{dir}": func() string {
				dir, _ := path.Split(r.URL.Path)
				return dir
			}(),
		},
		emptyValue: emptyValue,
	}
	if rr != nil {
		rep.replacements["{status}"] = strconv.Itoa(rr.status)
		rep.replacements["{size}"] = strconv.Itoa(rr.size)
		rep.replacements["{latency}"] = time.Since(rr.start).String()
	}

	// Header placeholders
	for header, val := range r.Header {
		rep.replacements[headerReplacer+header+"}"] = strings.Join(val, ",")
	}

	return rep
}
Ejemplo n.º 12
0
Archivo: fnc.go Proyecto: essiene/efene
func getProgramPath() (string, os.Error) {
	program := os.Args[0]
	dir, _ := path.Split(program)

	if dir == "" {
		binPath, pathError := exec.LookPath(program)

		if pathError != nil {
			if syscall.Access(program, syscall.O_RDONLY) != 0 {
				return "", os.NewError("Path to " + program + " couldn't be found")
			}

			cwd, cwdError := os.Getwd()

			if cwdError != nil {
				return "", cwdError
			}

			return cwd, nil
		}

		binPath, _ = path.Split(binPath)
		return binPath, nil
	}

	dir, _ = abspath(dir)
	return dir, nil
}
Ejemplo n.º 13
0
func getProjectInfo(filename string) (projectDir string, sources map[string]string, specialPackages map[string][]string, ok bool) {
	projectDir, _ = path.Split(filename)
	projectDir = projectDir[:len(projectDir)-1]
	projectDir, _ = path.Split(projectDir)
	for {
		projectDir = projectDir[:len(projectDir)-1]
		if projectDir == "" {
			return "", nil, nil, false
		}
		//fmt.Println(projectDir)
		fd, _ := os.Open(projectDir)

		list, _ := fd.Readdir(-1)

		for i := 0; i < len(list); i++ {
			d := &list[i]
			if d.Name == "goref.cfg" {
				srcs, specialPacks, ok := getInfo(projectDir, path.Join(projectDir, d.Name))
				if !ok {
					return "", nil, nil, false
				}

				return projectDir, srcs, specialPacks, true
			}
		}
		projectDir, _ = path.Split(projectDir)
		fd.Close()
	}
	return "", nil, nil, false
}
Ejemplo n.º 14
0
// Mv moves the file or directory at 'src' to 'dst'
func Mv(r *Root, src, dst string) error {
	srcDir, srcFname := gopath.Split(src)

	var dstDirStr string
	var filename string
	if dst[len(dst)-1] == '/' {
		dstDirStr = dst
		filename = srcFname
	} else {
		dstDirStr, filename = gopath.Split(dst)
	}

	// get parent directories of both src and dest first
	dstDir, err := lookupDir(r, dstDirStr)
	if err != nil {
		return err
	}

	srcDirObj, err := lookupDir(r, srcDir)
	if err != nil {
		return err
	}

	srcObj, err := srcDirObj.Child(srcFname)
	if err != nil {
		return err
	}

	nd, err := srcObj.GetNode()
	if err != nil {
		return err
	}

	fsn, err := dstDir.Child(filename)
	if err == nil {
		switch n := fsn.(type) {
		case *File:
			_ = dstDir.Unlink(filename)
		case *Directory:
			dstDir = n
		default:
			return fmt.Errorf("unexpected type at path: %s", dst)
		}
	} else if err != os.ErrNotExist {
		return err
	}

	err = dstDir.AddChild(filename, nd)
	if err != nil {
		return err
	}

	err = srcDirObj.Unlink(srcFname)
	if err != nil {
		return err
	}

	return nil
}
Ejemplo n.º 15
0
// TrimSourceFile shortens DCCP source file names for readability
func TrimSourceFile(sfile string) string {
	sdir, sfile := path.Split(sfile)
	if len(sdir) > 0 {
		_, sdir = path.Split(sdir[:len(sdir)-1])
	}
	sfile = path.Join(sdir, sfile)
	return sfile
}
Ejemplo n.º 16
0
// statesByMUSKey returns a map of all UnitStates stored in the registry indexed by MUSKey
func (r *EtcdRegistry) statesByMUSKey() (map[MUSKey]*unit.UnitState, error) {
	mus := make(map[MUSKey]*unit.UnitState)

	// For backwards compatibility, first retrieve any states stored in the
	// old format
	req := etcd.Get{
		Key:       path.Join(r.keyPrefix, statePrefix),
		Recursive: true,
	}
	res, err := r.etcd.Do(&req)
	if err != nil && !isKeyNotFound(err) {
		return nil, err
	}
	if res != nil {
		for _, node := range res.Node.Nodes {
			_, name := path.Split(node.Key)
			var usm unitStateModel
			if err := unmarshal(node.Value, &usm); err != nil {
				log.Errorf("Error unmarshalling UnitState(%s): %v", name, err)
				continue
			}
			us := modelToUnitState(&usm, name)
			if us != nil {
				key := MUSKey{name, us.MachineID}
				mus[key] = us
			}
		}
	}

	// Now retrieve states stored in the new format and overlay them
	req = etcd.Get{
		Key:       path.Join(r.keyPrefix, statesPrefix),
		Recursive: true,
	}
	res, err = r.etcd.Do(&req)
	if err != nil && !isKeyNotFound(err) {
		return nil, err
	}
	if res != nil {
		for _, dir := range res.Node.Nodes {
			_, name := path.Split(dir.Key)
			for _, node := range dir.Nodes {
				_, machID := path.Split(node.Key)
				var usm unitStateModel
				if err := unmarshal(node.Value, &usm); err != nil {
					log.Errorf("Error unmarshalling UnitState(%s) from Machine(%s): %v", name, machID, err)
					continue
				}
				us := modelToUnitState(&usm, name)
				if us != nil {
					key := MUSKey{name, machID}
					mus[key] = us
				}
			}
		}
	}
	return mus, nil
}
Ejemplo n.º 17
0
// NewReplacer makes a new replacer based on r and rr which
// are used for request and response placeholders, respectively.
// Request placeholders are created immediately, whereas
// response placeholders are not created until Replace()
// is invoked. rr may be nil if it is not available.
// emptyValue should be the string that is used in place
// of empty string (can still be empty string).
func NewReplacer(r *http.Request, rr *ResponseRecorder, emptyValue string) Replacer {
	rep := &replacer{
		responseRecorder:   rr,
		customReplacements: make(map[string]string),
		replacements: map[string]string{
			"{method}": r.Method,
			"{scheme}": func() string {
				if r.TLS != nil {
					return "https"
				}
				return "http"
			}(),
			"{host}":          r.Host,
			"{path}":          r.URL.Path,
			"{path_escaped}":  url.QueryEscape(r.URL.Path),
			"{query}":         r.URL.RawQuery,
			"{query_escaped}": url.QueryEscape(r.URL.RawQuery),
			"{fragment}":      r.URL.Fragment,
			"{proto}":         r.Proto,
			"{remote}": func() string {
				if fwdFor := r.Header.Get("X-Forwarded-For"); fwdFor != "" {
					return fwdFor
				}
				host, _, err := net.SplitHostPort(r.RemoteAddr)
				if err != nil {
					return r.RemoteAddr
				}
				return host
			}(),
			"{port}": func() string {
				_, port, err := net.SplitHostPort(r.RemoteAddr)
				if err != nil {
					return ""
				}
				return port
			}(),
			"{uri}":         r.URL.RequestURI(),
			"{uri_escaped}": url.QueryEscape(r.URL.RequestURI()),
			"{when}":        time.Now().Format(timeFormat),
			"{file}": func() string {
				_, file := path.Split(r.URL.Path)
				return file
			}(),
			"{dir}": func() string {
				dir, _ := path.Split(r.URL.Path)
				return dir
			}(),
		},
		emptyValue: emptyValue,
	}

	// Header placeholders (case-insensitive)
	for header, values := range r.Header {
		rep.replacements[headerReplacer+strings.ToLower(header)+"}"] = strings.Join(values, ",")
	}

	return rep
}
Ejemplo n.º 18
0
func (c *hwMonCollector) hwmonName(dir string) (string, error) {
	// generate a name for a sensor path

	// sensor numbering depends on the order of linux module loading and
	// is thus unstable.
	// However the path of the device has to be stable:
	// - /sys/devices/<bus>/<device>
	// Some hardware monitors have a "name" file that exports a human
	// readbale name that can be used.

	// human readable names would be bat0 or coretemp, while a path string
	// could be platform_applesmc.768

	// preference 1: construct a name based on device name, always unique

	devicePath, devErr := filepath.EvalSymlinks(path.Join(dir, "device"))
	if devErr == nil {
		devPathPrefix, devName := path.Split(devicePath)
		_, devType := path.Split(strings.TrimRight(devPathPrefix, "/"))

		cleanDevName := cleanMetricName(devName)
		cleanDevType := cleanMetricName(devType)

		if cleanDevType != "" && cleanDevName != "" {
			return cleanDevType + "_" + cleanDevName, nil
		}

		if cleanDevName != "" {
			return cleanDevName, nil
		}
	}

	// preference 2: is there a name file
	sysnameRaw, nameErr := ioutil.ReadFile(path.Join(dir, "name"))
	if nameErr == nil && string(sysnameRaw) != "" {
		cleanName := cleanMetricName(string(sysnameRaw))
		if cleanName != "" {
			return cleanName, nil
		}
	}

	// it looks bad, name and device don't provide enough information
	// return a hwmon[0-9]* name

	realDir, err := filepath.EvalSymlinks(dir)
	if err != nil {
		return "", err
	}

	// take the last path element, this will be hwmonX
	_, name := path.Split(realDir)
	cleanName := cleanMetricName(name)
	if cleanName != "" {
		return cleanName, nil
	}
	return "", errors.New("Could not derive a monitoring name for " + dir)
}
Ejemplo n.º 19
0
// Remove function remove the node.
func (n *node) Remove(dir, recursive bool, callback func(path string)) *etcdErr.Error {

	if n.IsDir() {
		if !dir {
			// cannot delete a directory without recursive set to true
			return etcdErr.NewError(etcdErr.EcodeNotFile, n.Path, n.store.CurrentIndex)
		}

		if len(n.Children) != 0 && !recursive {
			// cannot delete a directory if it is not empty and the operation
			// is not recursive
			return etcdErr.NewError(etcdErr.EcodeDirNotEmpty, n.Path, n.store.CurrentIndex)
		}
	}

	if !n.IsDir() { // key-value pair
		_, name := path.Split(n.Path)

		// find its parent and remove the node from the map
		if n.Parent != nil && n.Parent.Children[name] == n {
			delete(n.Parent.Children, name)
		}

		if callback != nil {
			callback(n.Path)
		}

		if !n.IsPermanent() {
			n.store.ttlKeyHeap.remove(n)
		}

		return nil
	}

	for _, child := range n.Children { // delete all children
		child.Remove(true, true, callback)
	}

	// delete self
	_, name := path.Split(n.Path)
	if n.Parent != nil && n.Parent.Children[name] == n {
		delete(n.Parent.Children, name)

		if callback != nil {
			callback(n.Path)
		}

		if !n.IsPermanent() {
			n.store.ttlKeyHeap.remove(n)
		}

	}

	return nil
}
Ejemplo n.º 20
0
// Rewrite rewrites the internal location of the current request.
func (r *RegexpRule) Rewrite(req *http.Request) bool {
	rPath := req.URL.Path

	// validate base
	if !middleware.Path(rPath).Matches(r.Base) {
		return false
	}

	// validate extensions
	if !r.matchExt(rPath) {
		return false
	}

	// validate regexp
	if !r.MatchString(rPath[len(r.Base):]) {
		return false
	}

	to := r.To

	// check variables
	for _, v := range regexpVars {
		if strings.Contains(r.To, v) {
			switch v {
			case "{path}":
				to = strings.Replace(to, v, req.URL.Path[1:], -1)
			case "{query}":
				to = strings.Replace(to, v, req.URL.RawQuery, -1)
			case "{frag}":
				to = strings.Replace(to, v, req.URL.Fragment, -1)
			case "{file}":
				_, file := path.Split(req.URL.Path)
				to = strings.Replace(to, v, file, -1)
			case "{dir}":
				dir, _ := path.Split(req.URL.Path)
				to = path.Clean(strings.Replace(to, v, dir, -1))
			}
		}
	}

	// validate resulting path
	url, err := url.Parse(to)
	if err != nil {
		return false
	}

	// perform rewrite
	req.URL.Path = url.Path
	if url.RawQuery != "" {
		// overwrite query string if present
		req.URL.RawQuery = url.RawQuery
	}
	return true
}
Ejemplo n.º 21
0
Archivo: ivc.go Proyecto: namsyvo/IVC
func ReadInputInfo() *ivc.ParaInfo {
	var genome_file = flag.String("R", "", "reference genome file")
	var var_prof_file = flag.String("V", "", "variant profile file")
	var idx_dir = flag.String("I", "", "index directory")
	var read_file_1 = flag.String("1", "", "pairend read file, first end")
	var read_file_2 = flag.String("2", "", "pairend read file, second end")
	var var_call_file = flag.String("O", "", "variant call output file")
	var search_mode = flag.Int("mode", 0, "searching mode for finding seeds (1: random (default), 2: deterministic)")
	var start_pos = flag.Int("start", 0, "starting position on reads for finding seeds")
	var search_step = flag.Int("step", 0, "step for searching in deterministic mode")
	var max_snum = flag.Int("maxs", 0, "maximum number of seeds")
	var max_psnum = flag.Int("maxp", 0, "maximum number of paired-seeds")
	var min_slen = flag.Int("lmin", 0, "minimum length of seeds")
	var max_slen = flag.Int("lmax", 0, "maximum length of seeds")
	var dist_thres = flag.Float64("d", 0, "threshold of alignment distances")
	var iter_num = flag.Int("r", 0, "maximum number of iterations")
	var sub_cost = flag.Float64("s", 0, "substitution cost")
	var gap_open = flag.Float64("o", 0, "gap open cost")
	var gap_ext = flag.Float64("e", 0, "gap extension cost")
	var proc_num = flag.Int("t", 0, "maximum number of CPUs")
	var debug_mode = flag.Bool("debug", false, "turn on debug mode.")
	flag.Parse()

	_, genome_file_name := path.Split(*genome_file)
	multi_seq_file_name := path.Join(*idx_dir, genome_file_name) + ".mgf"
	rev_multi_seq_file_name := path.Join(*idx_dir, genome_file_name) + ".rev.mgf"
	_, var_prof_file_name := path.Split(*var_prof_file)
	var_prof_index_file_name := path.Join(*idx_dir, var_prof_file_name) + ".idx"

	para_info := new(ivc.ParaInfo)
	para_info.Ref_file = multi_seq_file_name
	para_info.Var_prof_file = var_prof_index_file_name
	para_info.Index_file = multi_seq_file_name + ".index/"
	para_info.Rev_index_file = rev_multi_seq_file_name + ".index/"
	para_info.Read_file_1 = *read_file_1
	para_info.Read_file_2 = *read_file_2
	para_info.Var_call_file = *var_call_file
	para_info.Search_mode = *search_mode
	para_info.Start_pos = *start_pos
	para_info.Search_step = *search_step
	para_info.Max_snum = *max_snum
	para_info.Max_psnum = *max_psnum
	para_info.Min_slen = *min_slen
	para_info.Max_slen = *max_slen
	para_info.Dist_thres = *dist_thres
	para_info.Iter_num = *iter_num
	para_info.Sub_cost = *sub_cost
	para_info.Gap_open = *gap_open
	para_info.Gap_ext = *gap_ext
	para_info.Proc_num = *proc_num
	para_info.Debug_mode = *debug_mode

	return para_info
}
Ejemplo n.º 22
0
func shipCircuit() string {
	tmpdir, err := MakeTempDir()
	if err != nil {
		Fatalf("Problem making packaging directory (%s)\n", err)
	}

	// Copy worker binary over to shipping directory
	println("--Packaging worker", x.binary)
	binpkg := workerPkgPath()
	_, workerName := path.Split(binpkg)
	shipFile := path.Join(tmpdir, x.binary) // Destination binary location and name
	if _, err = CopyFile(path.Join(binpkg, workerName), shipFile); err != nil {
		Fatalf("Problem copying circuit worker binary (%s)\n", err)
	}
	if err = os.Chmod(shipFile, 0755); err != nil {
		Fatalf("Problem chmod'ing circuit worker binary (%s)\n", err)
	}

	// Copy command-line helper tools over to shipping directory
	for _, cpkg := range cmdPkg {
		println("--Packaging helper", cpkg)
		shipHelper := path.Join(tmpdir, cpkg)
		if _, err = CopyFile(path.Join(helperPkgPath(cpkg), cpkg), shipHelper); err != nil {
			Fatalf("Problem copying circuit helper binary (%s)\n", err)
		}
		if err = os.Chmod(shipHelper, 0755); err != nil {
			Fatalf("Problem chmod'ing circuit helper binary (%s)\n", err)
		}
	}

	// Copy additional user commands to shipping directory
	for _, cmdpkg := range x.cmdPkgs {
		println("--Packaging command", cmdpkg)
		_, cmd := path.Split(cmdpkg)
		shipCommand := path.Join(tmpdir, cmd)
		if _, err = CopyFile(path.Join(cmdPkgPath(cmdpkg), cmd), shipCommand); err != nil {
			Fatalf("Problem copying command binary (%s)\n", err)
		}
		if err = os.Chmod(shipCommand, 0755); err != nil {
			Fatalf("Problem chmod'ing command binary (%s)\n", err)
		}
	}

	// Place the zookeeper dynamic libraries in the shipment
	// Shipping Zookeeper is not necessary when static linking (currently enabled).
	/*
		println("--Packaging Zookeeper libraries")
		if err = ShellCopyFile(path.Join(x.zlib, "libzookeeper*"), tmpdir+"/"); err != nil {
			Fatalf("Problem copying Zookeeper library files (%s)\n", err)
		}
	*/

	return tmpdir
}
Ejemplo n.º 23
0
func ParseParameters(url, host string) os.Error {
	View.Host = host
	View.Imprint = false
	View.Index = 0
	View.Rubric = 0
	View.Article = 0

	dir, file := path.Split(url)
	if file == "" {
		// is Index Startpage
		View.Index = 1
		return nil
	}
	i, err := strconv.Atoi(file)
	if err == nil {
		//is Index non Startpage
		View.Index = i
		if ((i - 1) * PaginatorMax) > len(View.Articles.Index()) {
			View.Index = 0
			return nil
		}
		return nil
	}
	if file == "impressum" {
		// is Impressum
		View.Imprint = true
		return nil
	}
	nextdir := path.Clean(dir)
	dir, file = path.Split(nextdir)
	i, err = strconv.Atoi(file)
	if err != nil {
		return err
	}
	if dir == "/kategorie/" {
		//is Rubricpage
		View.Rubric = i
		if View.Rubrics.Index().Current() == nil {
			View.Rubric = 0
		}
		return nil
	}
	if dir == "/artikel/" {
		//is Articlepage
		View.Article = i
		if View.Articles.Index().Current() == nil {
			View.Article = 0
		}
		return nil
	}
	return os.ENOTDIR
}
Ejemplo n.º 24
0
func (m *MemS3Fs) findParent(f afero.File) afero.File {
	dirs, _ := path.Split(f.Name())
	if len(dirs) > 1 {
		_, parent := path.Split(path.Clean(dirs))
		if len(parent) > 0 {
			pfile, err := m.Open(parent)
			if err != nil {
				return pfile
			}
		}
	}
	return nil
}
Ejemplo n.º 25
0
func getFileTime_tstat(filename string) (ft FileTime) {
	dir, _ := path.Split(filename)
	_, lastDirName := path.Split(dir[:len(dir)-1])

	t, err := time.ParseInLocation(tstat_shortForm, lastDirName, time.Now().Location())
	if err != nil {
		log.Panic(err)
	}
	ft.Timestamp = t.Unix()
	ft.Filename = filename

	return ft
}
Ejemplo n.º 26
0
func (c *Controller) RenderBytes() ([]byte, error) {
	//if the controller has set layout, then first get the tplname's content set the content to the layout
	if c.Layout != "" {
		if c.TplNames == "" {
			c.TplNames = c.ChildName + "/" + c.Ctx.Request.Method + "." + c.TplExt
		}
		if RunMode == "dev" {
			BuildTemplate(ViewsPath)
		}
		subdir := path.Dir(c.TplNames)
		_, file := path.Split(c.TplNames)
		newbytes := bytes.NewBufferString("")
		if _, ok := BeeTemplates[subdir]; !ok {
			panic("can't find templatefile in the path:" + c.TplNames)
			return []byte{}, errors.New("can't find templatefile in the path:" + c.TplNames)
		}
		BeeTemplates[subdir].ExecuteTemplate(newbytes, file, c.Data)
		tplcontent, _ := ioutil.ReadAll(newbytes)
		c.Data["LayoutContent"] = template.HTML(string(tplcontent))
		subdir = path.Dir(c.Layout)
		_, file = path.Split(c.Layout)
		ibytes := bytes.NewBufferString("")
		err := BeeTemplates[subdir].ExecuteTemplate(ibytes, file, c.Data)
		if err != nil {
			Trace("template Execute err:", err)
		}
		icontent, _ := ioutil.ReadAll(ibytes)
		return icontent, nil
	} else {
		if c.TplNames == "" {
			c.TplNames = c.ChildName + "/" + c.Ctx.Request.Method + "." + c.TplExt
		}
		if RunMode == "dev" {
			BuildTemplate(ViewsPath)
		}
		subdir := path.Dir(c.TplNames)
		_, file := path.Split(c.TplNames)
		ibytes := bytes.NewBufferString("")
		if _, ok := BeeTemplates[subdir]; !ok {
			panic("can't find templatefile in the path:" + c.TplNames)
			return []byte{}, errors.New("can't find templatefile in the path:" + c.TplNames)
		}
		err := BeeTemplates[subdir].ExecuteTemplate(ibytes, file, c.Data)
		if err != nil {
			Trace("template Execute err:", err)
		}
		icontent, _ := ioutil.ReadAll(ibytes)
		return icontent, nil
	}
	return []byte{}, nil
}
Ejemplo n.º 27
0
func (t *TestFS) Rename(oldpath, newpath string) error {

	newDir, newFile := path.Split(newpath)
	oldDir, oldFile := path.Split(oldpath)

	srcDir, err := t.find(oldDir)
	if err != nil {
		return err
	}

	if !checkPerm(srcDir, 'r', 'w', 'x') {
		return os.ErrPermission
	}

	srcDir.mu.Lock()
	defer srcDir.mu.Unlock()

	src, err := srcDir.lookup([]string{oldFile})
	if err != nil {
		return err
	}

	dstDir, err := t.find(newDir)
	if err != nil {
		return err
	}

	if !checkPerm(dstDir, 'r', 'w', 'x') {
		return os.ErrPermission
	}

	srcDir.mtime = time.Now()

	if srcDir != dstDir {
		dstDir.mu.Lock()
		defer dstDir.mu.Unlock()

		dstDir.mtime = time.Now()
	}

	_, err = dstDir.lookup([]string{newFile})
	if !os.IsNotExist(err) {
		return os.ErrExist
	}

	dstDir.children[newFile] = src
	delete(srcDir.children, oldFile)

	return nil
}
Ejemplo n.º 28
0
func filterEventJobCancelled(resp *etcd.Response) *Event {
	if resp.Action != "delete" && resp.Action != "expire" {
		return nil
	}

	dir, baseName := path.Split(resp.Node.Key)
	if baseName != "target" {
		return nil
	}

	dir = strings.TrimSuffix(dir, "/")
	dir, jobName := path.Split(dir)

	return &Event{"EventJobCancelled", jobName, nil}
}
Ejemplo n.º 29
0
func filterEventJobStopped(resp *etcd.Response) *event.Event {
	if resp.Action != "delete" && resp.Action != "expire" {
		return nil
	}

	dir, jobName := path.Split(resp.Node.Key)
	dir = strings.TrimSuffix(dir, "/")
	dir, prefixName := path.Split(dir)

	if prefixName != "job" {
		return nil
	}

	return &event.Event{"EventJobStopped", jobName, nil}
}
Ejemplo n.º 30
0
func filterEventJobDestroyed(resp *goetcd.Response) *event.Event {
	if resp.Action != "delete" {
		return nil
	}

	dir, jobName := path.Split(resp.Node.Key)
	dir = strings.TrimSuffix(dir, "/")
	dir, prefixName := path.Split(dir)

	if prefixName != jobPrefix {
		return nil
	}

	return &event.Event{"EventJobDestroyed", jobName, nil}
}