Example #1
0
func RunClang(args ...string) ([]byte, error) {
	cmd := exec.Command("clang", args...)
	log4go.Debug("Running clang command: %v", cmd)

	if e, err := cmd.StderrPipe(); err != nil {
		return nil, err
	} else if s, err := cmd.StdoutPipe(); err != nil {
		return nil, err
	} else if err := cmd.Start(); err != nil {
		return nil, err
	} else {
		so, serr := ioutil.ReadAll(s)
		eo, eerr := ioutil.ReadAll(e)
		// We ignore the output error here as a non-zero exit
		// code doesn't necessarily mean that the output isn't
		// useful
		cmd.Wait()

		log4go.Fine("stdout: %s\n", string(so))
		log4go.Fine("stderr: %s\n", string(eo))
		if serr != nil {
			return nil, serr
		} else if eerr != nil {
			return nil, eerr
		}
		return so, nil
	}
}
Example #2
0
func (c *Java) Complete(args *content.CompleteArgs, cmp *content.CompletionResult) error {
	log4go.Fine("%+v", args)
	var archive Archive
	session := args.Session()
	if session != nil {
		if a, ok := session.Get("java_archive").(Archive); ok {
			archive = a
		}
	}
	if archive == nil {
		cp, err := DefaultClasspath()
		if err != nil {
			// We don't really care about not being able to get the default classpath as it could be provided manually by the user
			log4go.Warn("Couldn't get the default classpath: %s", err)
		}
		settings := args.Settings()
		if cp2, ok := settings.Get("java_classpath").([]string); ok {
			// TODO: do we ever want to override rather than append to the classpath?
			cp = append(cp, cp2...)
		}
		log4go.Fine("classpath: %+v", cp)
		if archive, err = NewCompositeArchive(cp); err != nil {
			return err
		} else if session != nil {
			session.Set("java_archive", archive)
		}
	}

	className, err := fqnToClassname(args.Location)
	if err != nil {
		return err
	}

	data, err := archive.LoadClass(className)
	if err != nil {
		return err
	}

	class, err := NewClass(bytes.NewReader(data))
	if err != nil {
		return err
	}

	ct, err := class.ToContentType()
	if err != nil {
		return err
	}

	// TODO(q): Inherited fields and methods?
	// 			I see value in being able to "just" get the smaller set,
	//			but getting the full set should definitely be possible "server side"
	cmp.Fields = ct.Fields
	cmp.Types = ct.Types
	cmp.Methods = ct.Methods

	return nil
}
Example #3
0
func (qe QueryContextEvent) Call(v *View, key string, operator Op, operand interface{}, match_all bool) QueryContextReturn {
	log4go.Fine("Query context: %s, %v, %v, %v", key, operator, operand, match_all)
	for i := range qe {
		r := qe[i](v, key, operator, operand, match_all)
		if r != Unknown {
			return r
		}
	}
	log4go.Fine("Unknown context: %s", key)
	return Unknown
}
Example #4
0
func (je *JoinEngine) Yield(s *protocol.Series) (bool, error) {
	log4go.Fine("JoinEngine.Yield(): %s", s)
	idx := je.tableIdx[s.GetName()]
	state := &je.tablesState[idx]
	// If the state for this table didn't contain a point already,
	// increment the number of tables ready to emit a point by
	// incrementing `pts`
	if state.lastPoint == nil {
		je.pts++
	}
	state.lastPoint = s.Points[len(s.Points)-1]
	// update the fields for this table. the fields shouldn't change
	// after the first point, so we only need to set them once
	if state.lastFields == nil {
		for _, f := range s.Fields {
			state.lastFields = append(state.lastFields, s.GetName()+"."+f)
		}
	}

	log4go.Fine("JoinEngine: pts = %d", je.pts)
	// if the number of tables ready to emit a point isn't equal to the
	// total number of tables being joined, then return
	if je.pts != len(je.tablesState) {
		return true, nil
	}

	// we arbitrarily use the timestamp of the first table's point as
	// the timestamp of the resulting point. may be we should use the
	// smalles (or largest) timestamp.
	ts := je.tablesState[0].lastPoint.Timestamp
	newSeries := &protocol.Series{
		Name:   &je.name,
		Fields: je.fields(),
		Points: []*protocol.Point{
			{
				Timestamp: ts,
				Values:    je.values(),
			},
		},
	}

	// filter the point. the user may have a where clause with the join,
	// e.g. `select * from join(foo1, foo2) where foo1.val > 10`. we
	// can't evaluate the where clause until after join happens
	filteredSeries, err := Filter(je.query, newSeries)
	if err != nil {
		return false, err
	}

	if len(filteredSeries.Points) > 0 {
		return je.next.Yield(newSeries)
	}
	return true, nil
}
Example #5
0
func (self *ShardDatastore) ReturnShard(id uint32) {
	self.shardsLock.Lock()
	defer self.shardsLock.Unlock()
	log.Fine("Returning shard. id = %d", id)
	self.shardRefCounts[id] -= 1
	if self.shardRefCounts[id] != 0 {
		return
	}

	log.Fine("Checking if shard should be deleted. id = %d", id)
	if _, ok := self.shardsToDelete[id]; ok {
		self.deleteShard(id)
		return
	}

	log.Fine("Checking if shard should be closed. id = %d", id)
	if self.shardsToClose[id] {
		self.closeShard(id)
	}
}
Example #6
0
func (p *Pattern) Cache(data string, pos int) (pat *Pattern, ret MatchObject) {
	if p.cachedData == data {
		if p.cachedMatch == nil {
			return nil, nil
		}
		if p.cachedMatch[0] >= pos && p.cachedPat.cachedMatch != nil {
			p.hits++
			return p.cachedPat, p.cachedMatch
		}
	} else {
		p.cachedPatterns = nil
	}
	if p.cachedPatterns == nil {
		p.cachedPatterns = make([]*Pattern, len(p.Patterns))
		for i := range p.cachedPatterns {
			p.cachedPatterns[i] = &p.Patterns[i]
		}
	}
	p.misses++

	if p.Match.re != nil {
		pat, ret = p, p.Match.Find(data, pos)
	} else if p.Begin.re != nil {
		pat, ret = p, p.Begin.Find(data, pos)
	} else if p.Include != "" {
		if z := p.Include[0]; z == '#' {
			key := p.Include[1:]
			if p2, ok := p.owner.Repository[key]; ok {
				pat, ret = p2.Cache(data, pos)
			} else {
				log4go.Fine("Not found in repository: %s", p.Include)
			}
		} else if z == '$' {
			// TODO(q): Implement tmLanguage $ include directives
			log4go.Warn("Unhandled include directive: %s", p.Include)
		} else if l, err := Provider.GetLanguage(p.Include); err != nil {
			if !failed[p.Include] {
				log4go.Warn("Include directive %s failed: %s", p.Include, err)
			}
			failed[p.Include] = true
		} else {
			return l.RootPattern.Cache(data, pos)
		}
	} else {
		pat, ret = p.FirstMatch(data, pos)
	}
	p.cachedData = data
	p.cachedMatch = ret
	p.cachedPat = pat

	return
}
Example #7
0
func (td *TypeDef) Fields() (fields []content.Field, err error) {
	if td.ct.Name.Relative != "" {
		return td.ct.Fields, nil
	}

	var (
		mu               = td.index.(*ConcreteTableIndex).metadataUtil
		startRow, endRow = td.ListRange(td.index.Index(), id_TypeDef, id_Field, func(i interface{}) uint32 { return i.(*TypeDefRow).FieldList.Index() })
		idx              = ConcreteTableIndex{mu, startRow, id_Field}
	)
	cn := stripProto(td.Name().Absolute)
	for i := startRow; i < endRow; i++ {
		idx.index = i
		if rawfield, err := idx.Data(); err != nil {
			return nil, err
		} else {
			var (
				field = rawfield.(*FieldRow)
				f     content.Field
				dec   *SignatureDecoder
				sig   FieldSig
			)
			f.Name.Relative = string(field.Name)
			f.Name.Absolute = fmt.Sprintf("net://field/%s;%d", cn, i-startRow)
			if dec, err = NewSignatureDecoder(field.Signature); err != nil {
				return nil, err
			} else if err = dec.Decode(&sig); err != nil {
				return nil, err
			} else {
				f.Type = td.initContentType(td.index, &sig.Type)
			}
			if field.Flags&FieldAttributes_Static != 0 {
				f.Flags |= content.FLAG_STATIC
			}
			if field.Flags&FieldAttributes_Public != 0 {
				f.Flags |= content.FLAG_ACC_PUBLIC
			} else if field.Flags&FieldAttributes_Private != 0 {
				f.Flags |= content.FLAG_ACC_PRIVATE
			} else if field.Flags&FieldAttributes_Family != 0 {
				f.Flags |= content.FLAG_ACC_PROTECTED
			}
			if err := check(&f, f.Name); err != nil {
				log4go.Fine("Skipping field: %s, %+v, %+v", err, f, field)
				continue
			}
			fields = append(fields, f)
		}
	}
	return fields, nil
}
Example #8
0
func (ch *commandHandler) RunApplicationCommand(name string, args Args) error {
	p := Prof.Enter("ac")
	defer p.Exit()
	if ch.log {
		log4go.Info("Running application command: %s %v", name, args)
	} else {
		log4go.Fine("Running application command: %s %v", name, args)
	}
	if c := ch.ApplicationCommands[name]; c != nil {
		if err := c.Run(args); err != nil && ch.verbose {
			log4go.Debug("Command execution failed: %s", err)
		}
	}
	return nil
}
Example #9
0
func (self *ShardDatastore) DeleteShard(shardId uint32) {
	self.shardsLock.Lock()
	defer self.shardsLock.Unlock()
	// If someone has a reference to the shard we can't delete it
	// now. We have to wait until it's returned and delete
	// it. ReturnShard will take care of that as soon as the reference
	// count becomes 0.
	if refc := self.shardRefCounts[shardId]; refc > 0 {
		log.Fine("Cannot delete shard: shardId = %d, shardRefCounts[shardId] = %d", shardId, refc)
		self.shardsToDelete[shardId] = struct{}{}
		return
	}

	// otherwise, close the shard and delete it now
	self.deleteShard(shardId)
}
Example #10
0
File: view.go Project: nicecai/lime
func (v *View) EndEdit(edit *Edit) {
	if edit.invalid {
		log4go.Fine("This edit has already been invalidated: %v, %v", edit, v.editstack)
		return
	}
	i := len(v.editstack) - 1
	for i := len(v.editstack) - 1; i >= 0; i-- {
		if v.editstack[i] == edit {
			break
		}
	}
	if i == -1 {
		log4go.Error("This edit isn't even in the stack... where did it come from? %v, %v", edit, v.editstack)
		return
	}

	var selmod bool

	if l := len(v.editstack) - 1; i != l {
		log4go.Error("This edit wasn't last in the stack... %d !=  %d: %v, %v", i, l, edit, v.editstack)
	}
	for j := len(v.editstack) - 1; j >= i; j-- {
		ce := v.editstack[j]
		ce.invalid = true
		is := reflect.DeepEqual(*v.Sel(), ce.savedSel)
		ib := v.buffer.ChangeCount() == ce.savedCount
		eq := (is && ib && ce.composite.Len() == 0)
		if !eq && is {
			selmod = true
		}
		if v.scratch || ce.bypassUndo || eq {
			continue
		}
		if i == 0 || j != i {
			// Presume someone forgot to add it in the j != i case
			v.undoStack.Add(edit)
		} else {
			// This edit belongs to another edit
			v.editstack[i-1].composite.Add(ce)
		}
	}
	v.editstack = v.editstack[:i]
	if selmod {
		OnSelectionModified.Call(v)
	}
}
Example #11
0
// Saves the file to the specified filename
func (v *View) SaveAs(name string) (err error) {
	log4go.Fine("SaveAs(%s)", name)
	v.Settings().Set("lime.saving", true)
	defer v.Settings().Erase("lime.saving")
	var atomic bool
	OnPreSave.Call(v)
	if atomic, _ = v.Settings().Get("atomic_save", true).(bool); v.buffer.FileName() == "" || !atomic {
		if err := v.nonAtomicSave(name); err != nil {
			return err
		}
	} else {
		n, err := ioutil.TempDir(path.Dir(v.buffer.FileName()), "lime")
		if err != nil {
			return err
		}
		tmpf := path.Join(n, "tmp")
		if err := v.nonAtomicSave(tmpf); err != nil {
			return err
		}
		if err := os.Rename(tmpf, name); err != nil {
			// When we wan't to save as a file in another directory
			// we can't go with os.Rename so we need to force
			// not atomic saving sometimes as 4th test in TestSaveAsOpenFile
			if err := v.nonAtomicSave(name); err != nil {
				return err
			}
		}
		if err := os.RemoveAll(n); err != nil {
			return err
		}
	}

	ed := GetEditor()
	if v.buffer.FileName() != name {
		v.Buffer().SetFileName(name)
		// TODO(.): There could be multiple watchers tied to a single filename...
		ed.UnWatch(v.buffer.FileName())
		ed.Watch(NewWatchedUserFile(v))
	}

	v.buffer.Settings().Set("lime.last_save_change_count", v.buffer.ChangeCount())
	OnPostSave.Call(v)
	return nil
}
Example #12
0
func CheckForUpdatedConfigs(auto_update string, config_url string, api_key string, output_dir string, agent_bin string, out chan<- *AgentConfigType, defaults Consts) {
	for {
		config_data := ParseJsonFromHttp(config_url, api_key)
		out <- &config_data

		if auto_update == "true" && config_data.Version != defaults.Current_build {
			l4g.Debug("Upgrading agent version-%s\n", config_data.Version)
			hdata := config_data.Sha256
			if runtime.GOARCH == "amd64" {
				hdata = config_data.Sha256_amd64
			}
			Upgrade_version(config_data.Version, hdata, output_dir, agent_bin, defaults)
			l4g.Debug("Failed upgrading!\n")
		} else {
			l4g.Fine("Don't need to upgrade versions\n")
		}
		time.Sleep(10 * time.Second)
	}

}
Example #13
0
func (ds *CassandraDatastore) StoreParsedURL(u *URL, fr *FetchResults) {
	if !u.IsAbs() {
		log4go.Warn("Link should not have made it to StoreParsedURL: %v", u)
		return
	}
	dom, subdom, err := u.TLDPlusOneAndSubdomain()
	if err != nil {
		log4go.Debug("StoreParsedURL not storing %v: %v", fr.URL, err)
		return
	}

	if Config.AddNewDomains {
		ds.addDomainIfNew(dom)
	}
	log4go.Fine("Inserting parsed URL: %v", u)
	err = ds.db.Query(`INSERT INTO links (dom, subdom, path, proto, time)
						VALUES (?, ?, ?, ?, ?)`,
		dom, subdom, u.RequestURI(), u.Scheme, NotYetCrawled).Exec()
	if err != nil {
		log4go.Error("failed inserting parsed url (%v) to cassandra, %v", u, err)
	}
}
Example #14
0
func (c *ViewEventGlue) onEvent(v *backend.View) {
	l := py.NewLock()
	defer l.Unlock()
	if pv, err := toPython(v); err != nil {
		log4go.Error(err)
	} else {
		defer pv.Decref()
		log4go.Fine("onEvent: %v, %v, %v", c, c.inner, pv)
		// interrupt := true
		// defer func() { interrupt = false }()
		// go func() {
		// 	<-time.After(time.Second * 5)
		// 	if interrupt {
		// 		py.SetInterrupt()
		// 	}
		// }()

		if ret, err := c.inner.Base().CallFunctionObjArgs(pv); err != nil {
			log4go.Error(err)
		} else if ret != nil {
			ret.Decref()
		}
	}
}
Example #15
0
// start blocks until the fetcher has completed by being told to quit.
func (f *fetcher) start() {
	log4go.Debug("Starting new fetcher")
	for {
		if f.host != "" {
			//TODO: ensure that this unclaim will happen... probably want the
			//logic below in a function where the Unclaim is deferred
			log4go.Info("Finished crawling %v, unclaiming", f.host)
			f.fm.Datastore.UnclaimHost(f.host)
		}

		select {
		case <-f.quit:
			f.done <- struct{}{}
			return
		default:
		}

		f.host = f.fm.Datastore.ClaimNewHost()
		if f.host == "" {
			time.Sleep(time.Second)
			continue
		}

		if f.checkForBlacklisting(f.host) {
			continue
		}

		f.fetchRobots(f.host)
		f.crawldelay = time.Duration(Config.DefaultCrawlDelay) * time.Second
		if f.robots != nil && int(f.robots.CrawlDelay) > Config.DefaultCrawlDelay {
			f.crawldelay = f.robots.CrawlDelay
		}
		log4go.Info("Crawling host: %v with crawl delay %v", f.host, f.crawldelay)

		for link := range f.fm.Datastore.LinksForHost(f.host) {
			//TODO: check <-f.quit and clean up appropriately

			fr := &FetchResults{URL: link}

			if f.robots != nil && !f.robots.Test(link.String()) {
				log4go.Debug("Not fetching due to robots rules: %v", link)
				fr.ExcludedByRobots = true
				f.fm.Datastore.StoreURLFetchResults(fr)
				continue
			}

			time.Sleep(f.crawldelay)

			fr.FetchTime = time.Now()
			fr.Response, fr.RedirectedFrom, fr.FetchError = f.fetch(link)
			if fr.FetchError != nil {
				log4go.Debug("Error fetching %v: %v", link, fr.FetchError)
				f.fm.Datastore.StoreURLFetchResults(fr)
				continue
			}
			log4go.Debug("Fetched %v -- %v", link, fr.Response.Status)

			ctype, ctypeOk := fr.Response.Header["Content-Type"]
			if ctypeOk && len(ctype) > 0 {
				media_type, _, err := mime.ParseMediaType(ctype[0])
				if err != nil {
					log4go.Error("Failed to parse mime header %q: %v", ctype[0], err)
				} else {
					fr.MimeType = media_type
				}
			}

			canSearch := isHTML(fr.Response)
			if canSearch {
				log4go.Debug("Reading and parsing as HTML (%v)", link)

				//TODO: ReadAll is inefficient. We should use a properly sized
				//		buffer here (determined by
				//		Config.MaxHTTPContentSizeBytes or possibly
				//		Content-Length of the response)
				var body []byte
				body, fr.FetchError = ioutil.ReadAll(fr.Response.Body)
				if fr.FetchError != nil {
					log4go.Debug("Error reading body of %v: %v", link, fr.FetchError)
					f.fm.Datastore.StoreURLFetchResults(fr)
					continue
				}
				fr.Response.Body = ioutil.NopCloser(bytes.NewReader(body))

				outlinks, err := getLinks(body)
				if err != nil {
					log4go.Debug("error parsing HTML for page %v: %v", link, err)
				} else {
					for _, outlink := range outlinks {
						outlink.MakeAbsolute(link)
						log4go.Fine("Parsed link: %v", outlink)
						if shouldStore(outlink) {
							f.fm.Datastore.StoreParsedURL(outlink, fr)
						}
					}
				}
			}

			// handle any doc that we searched or that is in our AcceptFormats
			// list
			canHandle := isHandleable(fr.Response, f.fm.acceptFormats)
			if canSearch || canHandle {
				f.fm.Handler.HandleResponse(fr)
			} else {
				ctype := strings.Join(fr.Response.Header["Content-Type"], ",")
				log4go.Debug("Not handling url %v -- `Content-Type: %v`", link, ctype)
			}

			//TODO: Wrap the reader and check for read error here
			log4go.Debug("Storing fetch results for %v", link)
			f.fm.Datastore.StoreURLFetchResults(fr)
		}
	}
}
Example #16
0
func (self *Coordinator) CommitSeriesData(db string, serieses []*protocol.Series, sync bool) error {
	now := common.CurrentTime()

	shardToSerieses := map[uint32]map[string]*protocol.Series{}
	shardIdToShard := map[uint32]*cluster.ShardData{}

	for _, series := range serieses {
		if len(series.Points) == 0 {
			return fmt.Errorf("Can't write series with zero points.")
		}

		for _, point := range series.Points {
			if point.Timestamp == nil {
				point.Timestamp = &now
			}
		}

		// sort the points by timestamp
		// TODO: this isn't needed anymore
		series.SortPointsTimeDescending()

		sn := series.GetName()
		// use regular for loop since we update the iteration index `i' as
		// we batch points that have the same timestamp
		for i := 0; i < len(series.Points); {
			if len(series.GetName()) == 0 {
				return fmt.Errorf("Series name cannot be empty")
			}

			ts := series.Points[i].GetTimestamp()
			shard, err := self.clusterConfiguration.GetShardToWriteToBySeriesAndTime(db, sn, ts)
			if err != nil {
				return err
			}
			log.Fine("GetShardToWriteToBySeriesAndTime(%s, %s, %d) = (%s, %v)", db, sn, ts, shard, err)
			firstIndex := i
			for ; i < len(series.Points) && series.Points[i].GetTimestamp() == ts; i++ {
				// add all points with the same timestamp
			}

			// if shard == nil, then the points shouldn't be writte. This
			// will happen if the points had timestamps earlier than the
			// retention period
			if shard == nil {
				continue
			}
			newSeries := &protocol.Series{Name: series.Name, Fields: series.Fields, Points: series.Points[firstIndex:i:i]}

			shardIdToShard[shard.Id()] = shard
			shardSerieses := shardToSerieses[shard.Id()]
			if shardSerieses == nil {
				shardSerieses = map[string]*protocol.Series{}
				shardToSerieses[shard.Id()] = shardSerieses
			}
			seriesName := series.GetName()
			s := shardSerieses[seriesName]
			if s == nil {
				shardSerieses[seriesName] = newSeries
				continue
			}
			shardSerieses[seriesName] = common.MergeSeries(s, newSeries)
		}
	}

	for id, serieses := range shardToSerieses {
		shard := shardIdToShard[id]

		seriesesSlice := make([]*protocol.Series, 0, len(serieses))
		for _, s := range serieses {
			seriesesSlice = append(seriesesSlice, s)
		}

		err := self.write(db, seriesesSlice, shard, sync)
		if err != nil {
			log.Error("COORD error writing: ", err)
			return err
		}
	}

	return nil
}
Example #17
0
func Errplane_main(defaults econfig.Consts) {
	fmt.Printf("ERRPlane Local Agent starting, Version %s \n", defaults.Current_build)

	goopt.Description = func() string {
		return "ERRPlane Local Agent."
	}
	goopt.Version = defaults.Current_build
	goopt.Summary = "ErrPlane Log and System Monitor"
	goopt.Parse(nil)

	var fconfig_file string
	fconfig_file = *config_file

	fmt.Printf("Loading config file %s.\n", fconfig_file)

	c, err := config.ReadDefault(fconfig_file)
	if err != nil {
		log.Fatal("Can not find the Errplane Config file, please install it in /etc/ranger/ranger.conf.")
	}

	api_key, _ := c.String("DEFAULT", "api_key")

	if len(*install_api_key) > 1 {
		fmt.Printf("Saving new Config!\n")
		c.AddOption("DEFAULT", "api_key", *install_api_key)
		c.WriteFile(fconfig_file, 0644, "")

		c, err := config.ReadDefault(fconfig_file)
		if err != nil {
			log.Fatal("Can not find the Errplane Config file, please install it in /etc/ranger/ranger.conf.")
		}
		api_key, _ = c.String("DEFAULT", "api_key")
	}

	if len(api_key) < 1 {
		log.Fatal("No api key found. Please rerun this with --install-api-key <api_key_here> ")
		os.Exit(1)
	}

	if !*amForeground {
		//Daemonizing requires root
		if os.Getuid() == 0 {
			daemonize.Do_fork(os.Args[0], fconfig_file)
			l4g.Fine("Exiting parent process-%s\n", os.Args[0])
			os.Exit(0)
		} else {
			fmt.Printf("Daemoning requires root \n")
			os.Exit(1)
		}
	}

	setup_logger()

	api_url, _ := c.String("DEFAULT", "api_host")
	config_url, _ := c.String("DEFAULT", "config_host")
	output_dir, _ := c.String("DEFAULT", "agent_path")
	if len(output_dir) < 1 {
		output_dir = "/usr/local/ranger/"
	}
	agent_bin, _ := c.String("DEFAULT", "agent_bin")
	if len(agent_bin) < 1 {
		agent_bin = "/usr/local/bin/ranger-local-agent"
	}
	pid_location, _ := c.String("DEFAULT", "pid_file")
	if len(pid_location) < 1 {
		pid_location = "/var/run/ranger/ranger.pid"
	}
	auto_update, _ := c.String("DEFAULT", "auto_upgrade")

	write_pid(pid_location)

	config_data := econfig.ParseJsonFromHttp(config_url, api_key)

	l4g.Debug("Expected agent version-%s\n", config_data.Version)

	if auto_update == "true" && config_data.Version != defaults.Current_build {
		econfig.Upgrade_version(config_data.Version, config_data.Sha256, output_dir, agent_bin, defaults)
		os.Exit(1)
	} else {
		l4g.Debug("Don't need to upgrade versions\n")
	}

	_, err = exec.LookPath("tail")
	if err != nil {
		log.Fatal("installing tail is in your future")
		//        exit(1)
	}

	configChan := make(chan *econfig.AgentConfigType)

	go theBrain(configChan, api_key, api_url)

	go econfig.CheckForUpdatedConfigs(auto_update, config_url, api_key, output_dir, agent_bin, configChan, defaults)

	if err != nil {
		log.Fatal(err)
	}

	err = nil
	for err == nil {
		//TODO monitor go routines, if one exists reload it
		time.Sleep(0)
		runtime.Gosched()
	}
}
Example #18
0
// Ends the given Edit object.
func (v *View) EndEdit(edit *Edit) {
	if edit.invalid {
		// This happens when nesting Edits and the child Edit ends after the parent edit.
		log4go.Fine("This edit has already been invalidated: %v, %v", edit, v.editstack)
		return
	}

	// Find the position of this Edit object in this View's Edit stack.
	// If plugins, commands, etc are well-behaved the ended edit should be
	// last in the stack, but shit happens and we cannot count on this being the case.
	i := len(v.editstack) - 1
	for i := len(v.editstack) - 1; i >= 0; i-- {
		if v.editstack[i] == edit {
			break
		}
	}
	if i == -1 {
		// TODO(.): Under what instances does this happen again?
		log4go.Error("This edit isn't even in the stack... where did it come from? %v, %v", edit, v.editstack)
		return
	}

	var selection_modified bool

	if l := len(v.editstack) - 1; i != l {
		// TODO(.): See TODO in BeginEdit
		log4go.Error("This edit wasn't last in the stack... %d !=  %d: %v, %v", i, l, edit, v.editstack)
	}

	// Invalidate all Edits "below" and including this Edit.
	for j := len(v.editstack) - 1; j >= i; j-- {
		current_edit := v.editstack[j]
		current_edit.invalid = true
		sel_same := reflect.DeepEqual(*v.Sel(), current_edit.savedSel)
		buf_same := v.buffer.ChangeCount() == current_edit.savedCount
		eq := (sel_same && buf_same && current_edit.composite.Len() == 0)
		if !eq && !sel_same {
			selection_modified = true
		}
		if v.scratch || current_edit.bypassUndo || eq {
			continue
		}
		switch {
		case i == 0:
			// Well-behaved, no nested edits!
			fallthrough
		case j != i:
			// BOO! Someone began another Edit without finishing the first one.
			// In this instance, the parent Edit ended before the child.
			// TODO(.): What would be the correct way to handle this?
			v.undoStack.Add(edit)
		default:
			// BOO! Also poorly-behaved. This Edit object began after the parent began,
			// but was finished before the parent finished.
			//
			// Add it as a child of the parent Edit so that undoing the parent
			// will undo this edit as well.
			v.editstack[i-1].composite.Add(current_edit)
		}
	}
	// Pop this Edit and all the children off the Edit stack.
	v.editstack = v.editstack[:i]
	if selection_modified {
		OnSelectionModified.Call(v)
	}
}
Example #19
0
File: view.go Project: qcghdy/lime
// Saves the file to the specified filename
func (v *View) SaveAs(name string) (err error) {
	log4go.Fine("SaveAs(%s)", name)
	v.Settings().Set("lime.saving", true)
	defer v.Settings().Erase("lime.saving")
	var atomic bool
	OnPreSave.Call(v)
	if v.buffer.FileName() != "" {
		atomic, _ = v.Settings().Get("atomic_save", true).(bool)
	} else {
		atomic = false
	}
	var f *os.File
	if atomic {
		f, err = ioutil.TempFile(path.Dir(v.buffer.FileName()), "lime")
	} else {
		f, err = os.Create(name)
	}
	if err != nil {
		return err
	}
	data := []byte(v.buffer.Substr(Region{0, v.buffer.Size()}))
	for len(data) != 0 {
		var n int
		n, err = f.Write(data)
		if n > 0 {
			data = data[n:]
		}
		if err != nil {
			f.Close()
			if atomic {
				os.Remove(f.Name())
			}
			return err
		}
	}
	f.Close()
	if atomic {
		if err = os.Rename(f.Name(), name); err != nil {
			os.Remove(f.Name())
			// When we wan't to save as a file in another directory
			// we can not go with os.Rename so we need to force
			// not atomic saving sometimes as 4th test in TestSaveAsOpenFile
			hold, _ := v.Settings().Get("atomic_save", true).(bool)
			v.Settings().Set("atomic_save", false)
			v.SaveAs(name)
			v.Settings().Set("atomic_save", hold)
		}
	}

	ed := GetEditor()
	if v.buffer.FileName() != name {
		v.Buffer().SetFileName(name)
		// TODO(.): There could be multiple watchers tied to a single filename...
		ed.UnWatch(v.buffer.FileName())
		ed.Watch(NewWatchedUserFile(v))
	}

	v.buffer.Settings().Set("lime.last_save_change_count", v.buffer.ChangeCount())
	OnPostSave.Call(v)
	return nil
}
Example #20
0
func (td *TypeDef) Methods() (methods []content.Method, err error) {
	if td.ct.Name.Relative != "" {
		return td.ct.Methods, nil
	}

	var (
		mu               = td.index.(*ConcreteTableIndex).metadataUtil
		startRow, endRow = td.ListRange(td.index.Index(), id_TypeDef, id_MethodDef, func(i interface{}) uint32 { return i.(*TypeDefRow).MethodList.Index() })
		idx              = &ConcreteTableIndex{mu, startRow, id_MethodDef}
	)
	cn := stripProto(td.Name().Absolute)
	for i := startRow; i < endRow; i++ {
		idx.index = i
		if rawmethod, err := idx.Data(); err != nil {
			return nil, err
		} else {
			var (
				m      content.Method
				method = rawmethod.(*MethodDefRow)
				dec    *SignatureDecoder
				sig    MethodDefSig
			)
			if n := string(method.Name); n == ".cctor" {
				// Static constructor, we don't care about that one
				continue
			} else {
				m.Name.Relative = n
			}
			m.Name.Absolute = fmt.Sprintf("net://method/%s;%d", cn, i-startRow)
			if m.Parameters, err = td.Parameters(idx); err != nil {
				return nil, err
			}
			if dec, err = NewSignatureDecoder(method.Signature); err != nil {
				return nil, err
			} else if err = dec.Decode(&sig); err != nil {
				return nil, err
			} else {
				// TODO: need to figure out why this mismatch happens
				l := len(sig.Params)
				if l2 := len(m.Parameters); l2 < l {
					l = l2
				}
				for i := range sig.Params[:l] {
					m.Parameters[i].Type = td.initContentType(td.index, &sig.Params[i].Type)
				}
				if method.Flags&MethodAttributes_Final != 0 {
					m.Flags |= content.FLAG_FINAL
				}
				if method.Flags&MethodAttributes_Static != 0 {
					m.Flags |= content.FLAG_STATIC
				}
				if method.Flags&MethodAttributes_Public != 0 {
					m.Flags |= content.FLAG_ACC_PUBLIC
				} else if method.Flags&MethodAttributes_Private != 0 {
					m.Flags |= content.FLAG_ACC_PRIVATE
				} else if method.Flags&MethodAttributes_Family != 0 {
					m.Flags |= content.FLAG_ACC_PROTECTED
				}
				if m.Name.Relative == ".ctor" {
					m.Name.Relative = td.row.Name()
					m.Flags |= content.FLAG_CONSTRUCTOR
				} else {
					m.Returns = make([]content.Variable, 1)
					m.Returns[0].Type = td.initContentType(td.index, &sig.RetType.Type)
				}
			}
			if err := check(&m, m.Name); err != nil {
				log4go.Fine("Skipping method: %s, %+v, %+v", err, m, method)
				continue
			}

			methods = append(methods, m)
		}
	}
	return methods, nil
}
Example #21
0
func (td *TypeDef) ToContentType() (t *content.Type, err error) {
	if td.ct.Name.Relative != "" {
		return &td.ct, nil
	}
	t = &content.Type{}
	t.Name = td.Name()
	t.Flags = td.row.Flags.Convert()

	if ext, err := td.Extends(); err != nil && err != ErrInterface {
		return nil, err
	} else {
		t.Extends = ext
	}
	if imp, err := td.Implements(); err != nil {
		return nil, err
	} else {
		t.Implements = imp
	}
	if f, err := td.Fields(); err != nil {
		return nil, err
	} else {
		t.Fields = f
	}
	if f, err := td.Methods(); err != nil {
		return nil, err
	} else {
		t.Methods = f
	}

	idx := td.mu.Search(id_NestedClass, func(ti TableIndex) bool {
		if raw, err := ti.Data(); err == nil {
			c := raw.(*NestedClassRow)
			return c.NestedClass.Index() > td.index.Index()
		}
		return false
	})
	if idx != nil {
		ci := idx.(*ConcreteTableIndex)
		table := td.mu.Tables[idx.Table()]
		for i := idx.Index(); i < table.Rows+1; i++ {
			ci.index = i
			if raw, err := ci.Data(); err != nil {
				return nil, err
			} else {
				row := raw.(*NestedClassRow)
				if row.EnclosingClass.Index() != td.index.Index() {
					break
				} else if td2, err := TypeDefFromIndex(row.NestedClass); err != nil {
					return nil, err
				} else {
					ct := content.Type{}
					ct.Name = td2.Name()
					ct.Flags = td2.row.Flags.Convert()
					if err := check(&ct, ct.Name); err != nil {
						log4go.Fine("Skipping nested type: %s, %+v, %+v", err, ct, td2.row)
						continue
					}

					t.Types = append(t.Types, ct)
				}
			}
		}
	}
	err = content.Validate(&t)
	td.ct = *t
	return
}
func (cme *CommonMergeEngine) Yield(s *protocol.Series) (bool, error) {
	log4go.Fine("CommonMergeEngine.Yield(): %s", s)
	stream := cme.streams[s.GetShardId()]
	stream.Yield(s)
	return cme.merger.Update()
}
Example #23
0
func (c *OnQueryContextGlue) onQueryContext(v *backend.View, key string, operator backend.Op, operand interface{}, match_all bool) backend.QueryContextReturn {
	l := py.NewLock()
	defer l.Unlock()

	var (
		pv, pk, po, poa, pm, ret py.Object
		err                      error
	)
	if pv, err = toPython(v); err != nil {
		log4go.Error(err)
		return backend.Unknown
	}
	defer pv.Decref()

	if pk, err = toPython(key); err != nil {
		log4go.Error(err)
		return backend.Unknown
	}
	defer pk.Decref()

	if po, err = toPython(operator); err != nil {
		log4go.Error(err)
		return backend.Unknown
	}
	defer po.Decref()

	if poa, err = toPython(operand); err != nil {
		log4go.Error(err)
		return backend.Unknown
	}
	defer poa.Decref()

	if pm, err = toPython(match_all); err != nil {
		log4go.Error(err)
		return backend.Unknown
	}
	defer pm.Decref()
	// interrupt := true
	// defer func() { interrupt = false }()
	// go func() {
	// 	<-time.After(time.Second * 5)
	// 	if interrupt {
	// 		py.SetInterrupt()
	// 	}
	// }()

	if ret, err = c.inner.Base().CallFunctionObjArgs(pv, pk, po, poa, pm); err != nil {
		log4go.Error(err)
		return backend.Unknown
	}
	defer ret.Decref()

	//	if ret != nil {
	log4go.Fine("onQueryContext: %v, %v", pv, ret.Base())
	if r2, ok := ret.(*py.Bool); ok {
		if r2.Bool() {
			return backend.True
		} else {
			return backend.False
		}
	} else {
		log4go.Fine("other: %v", ret)
	}
	return backend.Unknown
}