Beispiel #1
0
func init() {
	glog.SetToStderr(true)
	cfg := config.ParseConfigFromFile("cayley_appengine.cfg")
	qs, _ := graph.NewQuadStore("memstore", "", nil)
	glog.Errorln(cfg)
	db.Load(qs, cfg, cfg.DatabasePath)
	http.SetupRoutes(qs, cfg)
}
Beispiel #2
0
func decompressAndLoad(qw graph.QuadWriter, cfg *config.Config, path, typ string, loadFn func(graph.QuadWriter, *config.Config, quad.Unmarshaler) error) error {
	var r io.Reader

	if path == "" {
		path = cfg.DatabasePath
	}
	if path == "" {
		return nil
	}
	u, err := url.Parse(path)
	if err != nil || u.Scheme == "file" || u.Scheme == "" {
		// Don't alter relative URL path or non-URL path parameter.
		if u.Scheme != "" && err == nil {
			// Recovery heuristic for mistyping "file://path/to/file".
			path = filepath.Join(u.Host, u.Path)
		}
		f, err := os.Open(path)
		if err != nil {
			return fmt.Errorf("could not open file %q: %v", path, err)
		}
		defer f.Close()
		r = f
	} else {
		res, err := client.Get(path)
		if err != nil {
			return fmt.Errorf("could not get resource <%s>: %v", u, err)
		}
		defer res.Body.Close()
		r = res.Body
	}

	r, err = decompressor(r)
	if err != nil {
		return err
	}

	var dec quad.Unmarshaler
	switch typ {
	case "cquad":
		dec = cquads.NewDecoder(r)
	case "nquad":
		dec = nquads.NewDecoder(r)
	default:
		return fmt.Errorf("unknown quad format %q", typ)
	}

	return db.Load(qw, cfg, dec)
}
Beispiel #3
0
func main() {
	// No command? It's time for usage.
	if len(os.Args) == 1 {
		Usage()
		os.Exit(1)
	}
	cmd := os.Args[1]
	newargs := make([]string, 0)
	newargs = append(newargs, os.Args[0])
	newargs = append(newargs, os.Args[2:]...)
	os.Args = newargs
	flag.Parse()
	var ts graph.TripleStore
	cfg := config.ParseConfigFromFlagsAndFile(*configFile)
	if os.Getenv("GOMAXPROCS") == "" {
		runtime.GOMAXPROCS(runtime.NumCPU())
		glog.Infoln("Setting GOMAXPROCS to", runtime.NumCPU())
	} else {
		glog.Infoln("GOMAXPROCS currently", os.Getenv("GOMAXPROCS"), " -- not adjusting")
	}
	switch cmd {
	case "init":
		db.Init(cfg, *tripleFile)
	case "load":
		ts = db.Open(cfg)
		db.Load(ts, cfg, *tripleFile, false)
		ts.Close()
	case "repl":
		ts = db.Open(cfg)
		db.Repl(ts, *queryLanguage, cfg)
		ts.Close()
	case "http":
		ts = db.Open(cfg)
		http.Serve(ts, cfg)
		ts.Close()
	default:
		fmt.Println("No command", cmd)
		flag.Usage()
	}
}
Beispiel #4
0
func main() {
	// No command? It's time for usage.
	if len(os.Args) == 1 {
		Usage()
		os.Exit(1)
	}

	cmd := os.Args[1]
	var newargs []string
	newargs = append(newargs, os.Args[0])
	newargs = append(newargs, os.Args[2:]...)
	os.Args = newargs
	flag.Parse()

	var buildString string
	if VERSION != "" {
		buildString = fmt.Sprint("Cayley ", VERSION, " built ", BUILD_DATE)
		glog.Infoln(buildString)
	}

	cfg := config.ParseConfigFromFlagsAndFile(*configFile)

	if os.Getenv("GOMAXPROCS") == "" {
		runtime.GOMAXPROCS(runtime.NumCPU())
		glog.Infoln("Setting GOMAXPROCS to", runtime.NumCPU())
	} else {
		glog.Infoln("GOMAXPROCS currently", os.Getenv("GOMAXPROCS"), " -- not adjusting")
	}

	var (
		ts  graph.TripleStore
		err error
	)
	switch cmd {
	case "version":
		if VERSION != "" {
			fmt.Println(buildString)
		} else {
			fmt.Println("Cayley snapshot")
		}
		os.Exit(0)
	case "init":
		err = db.Init(cfg, *tripleFile)
	case "load":
		ts, err = db.Open(cfg)
		if err != nil {
			break
		}
		err = db.Load(ts, cfg, *tripleFile)
		if err != nil {
			break
		}
		ts.Close()
	case "repl":
		ts, err = db.Open(cfg)
		if err != nil {
			break
		}
		err = db.Repl(ts, *queryLanguage, cfg)
		if err != nil {
			break
		}
		ts.Close()
	case "http":
		ts, err = db.Open(cfg)
		if err != nil {
			break
		}
		http.Serve(ts, cfg)
		ts.Close()
	default:
		fmt.Println("No command", cmd)
		flag.Usage()
	}
	if err != nil {
		glog.Fatalln(err)
	}
}