Esempio n. 1
0
func main() {
	appName := path.Base(os.Args[0])
	flag.Parse()
	args := flag.Args()

	cfg := cli.New(appName, "CAIT", fmt.Sprintf(license, appName, cait.Version), cait.Version)
	cfg.UsageText = fmt.Sprintf(usage, appName)
	cfg.DescriptionText = fmt.Sprintf(description, appName, appName)
	cfg.OptionsText = "OPTIONS\n"

	if showHelp == true {
		fmt.Println(cfg.Usage())
		os.Exit(0)
	}
	if showVersion == true {
		fmt.Println(cfg.Version())
		os.Exit(0)
	}
	if showLicense == true {
		fmt.Println(cfg.License())
		os.Exit(0)
	}

	if len(args) > 0 {
		bleveNames = strings.Join(args, ":")
	}

	htdocs = cfg.CheckOption("htdocs", cfg.MergeEnv("htdocs", htdocs), true)
	names := cfg.CheckOption("bleve", cfg.MergeEnv("bleve", bleveNames), true)

	handleSignals()

	for _, indexName := range strings.Split(names, ":") {
		index, err := getIndex(indexName)
		if err != nil {
			log.Printf("Skipping %s, ", indexName, err)
		} else {
			defer index.Close()

			// Walk our data import tree and index things
			log.Printf("Start indexing of %s in %s\n", htdocs, indexName)
			err = indexSite(index, 1000)
			if err != nil {
				log.Fatal(err)
			}
		}
	}
	log.Printf("Finished")
}
Esempio n. 2
0
func main() {
	appName := path.Base(os.Args[0])
	flag.Parse()
	args := flag.Args()

	cfg := cli.New(appName, "CAIT", fmt.Sprintf(license, appName, cait.Version), cait.Version)
	cfg.UsageText = fmt.Sprintf(usage, appName)
	cfg.DescriptionText = fmt.Sprintf(description, appName, appName, appName, appName)
	cfg.ExampleText = fmt.Sprintf(examples, appName, appName, appName)
	cfg.OptionsText = "OPTIONS\n"

	if showHelp == true {
		fmt.Println(cfg.Usage())
		os.Exit(0)
	}

	if showVersion == true {
		fmt.Println(cfg.Version())
		os.Exit(0)
	}

	if showLicense == true {
		fmt.Println(cfg.License())
		os.Exit(0)
	}

	caitAPIURL = cfg.CheckOption("api_url", cfg.MergeEnv("api_url", caitAPIURL), true)
	caitUsername = cfg.CheckOption("username", cfg.MergeEnv("username", caitUsername), true)
	caitPassword = cfg.CheckOption("password", cfg.MergeEnv("password", caitPassword), true)
	caitDataset = cfg.CheckOption("dataset", cfg.MergeEnv("dataset", caitDataset), true)

	if len(args) < 2 {
		log.Fatalf("Missing commands options. For more info try: cait -h")
	}

	cmd, err := parseCmd(args)
	if err != nil {
		log.Fatalf("%s\n", err)
	}

	if payload != "" {
		src, err := ioutil.ReadFile(payload)
		if err != nil {
			log.Fatalf("Cannot read %s", payload)
		}
		cmd.Payload = fmt.Sprintf("%s", src)
	}

	if cmd.Subject == "agent" && len(args) > 2 {
		cmd.Options = []string{args[2]}
	}

	//NOTE: if we have no errors we can switch the log statement to os.Stdout here.
	log.SetOutput(os.Stdout)

	api := cait.New(caitAPIURL, caitUsername, caitPassword)
	src, err := runCmd(api, cmd)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println(src)
	os.Exit(0)
}
Esempio n. 3
0
func main() {
	appName := path.Base(os.Args[0])
	flag.Parse()
	//args := flag.Args()

	cfg := cli.New(appName, "CAIT", fmt.Sprintf(license, appName, cait.Version), cait.Version)
	cfg.UsageText = fmt.Sprintf(usage, appName)
	cfg.DescriptionText = fmt.Sprintf(description, appName, appName)
	//cfg.ExampleText = fmt.Sprintf(examples, appName)
	cfg.OptionsText = "OPTIONS\n"

	if showHelp == true {
		fmt.Println(cfg.Usage())
		os.Exit(0)
	}

	if showVersion == true {
		fmt.Println(cfg.Version())
		os.Exit(0)
	}

	if showLicense == true {
		fmt.Println(cfg.License())
		os.Exit(0)
	}

	datasetDir = cfg.CheckOption("dataset", cfg.MergeEnv("dataset", datasetDir), true)
	templateDir = cfg.CheckOption("templates", cfg.MergeEnv("templates", templateDir), true)
	htdocsDir = cfg.CheckOption("htdocs", cfg.MergeEnv("htdocs", htdocsDir), true)

	if htdocsDir != "" {
		if _, err := os.Stat(htdocsDir); os.IsNotExist(err) {
			os.MkdirAll(htdocsDir, 0775)
		}
	}

	//
	// Setup directories relationships
	//
	digitalObjectDir := ""
	filepath.Walk(datasetDir, func(p string, info os.FileInfo, err error) error {
		if err == nil && info.IsDir() == true && strings.HasSuffix(p, "digital_objects") {
			digitalObjectDir = p
			return nil
		}
		return err
	})
	if digitalObjectDir == "" {
		log.Fatalf("Can't find the digital object directory in %s", datasetDir)
	}
	subjectDir := path.Join(datasetDir, "subjects")
	agentsDir := path.Join(datasetDir, "agents", "people")

	//
	// Setup Maps and generate the accessions pages
	//
	log.Printf("Reading Subjects from %s", subjectDir)
	subjectsMap, err := cait.MakeSubjectMap(subjectDir)
	if err != nil {
		log.Fatalf("%s", err)
	}

	log.Printf("Reading Digital Objects from %s", digitalObjectDir)
	digitalObjectsMap, err := cait.MakeDigitalObjectMap(digitalObjectDir)
	if err != nil {
		log.Fatalf("%s", err)
	}

	log.Printf("Reading Agents/People from %s", agentsDir)
	agentsList, err := cait.MakeAgentList(agentsDir)
	if err != nil {
		log.Fatalf("%s", err)
	}
	log.Printf("Processing Agents/People in %s\n", agentsDir)
	err = processAgentsPeople(templateDir, "agents-people.html", "agents-people.include")

	log.Printf("Processing accessions in %s\n", datasetDir)
	err = processAccessions(templateDir, "accession.html", "accession.include", agentsList, subjectsMap, digitalObjectsMap)
	if err != nil {
		log.Fatalf("%s", err)
	}
}
Esempio n. 4
0
func main() {
	var err error

	appName := path.Base(os.Args[0])
	cfg := cli.New(appName, "CAIT", fmt.Sprintf(license, appName, cait.Version), cait.Version)
	cfg.UsageText = fmt.Sprintf(usage, appName)
	cfg.DescriptionText = fmt.Sprintf(description, appName, appName)
	cfg.OptionsText = "OPTIONS\n"

	flag.Parse()
	if showHelp == true {
		fmt.Println(cfg.Usage())
		os.Exit(0)
	}
	if showVersion == true {
		fmt.Println(cfg.Version())
		os.Exit(0)
	}

	if showLicense == true {
		fmt.Println(cfg.License())
		os.Exit(0)
	}

	siteURL = check(cfg, "site_url", cfg.MergeEnv("site_url", siteURL))
	serviceURL, err := url.Parse(siteURL)
	if err != nil {
		log.Fatal(err)
	}
	htdocsDir = check(cfg, "htdocs", cfg.MergeEnv("htdocs", htdocsDir))
	bleveNames = check(cfg, "bleve", cfg.MergeEnv("bleve", bleveNames))
	templatesDir = check(cfg, "templates", cfg.MergeEnv("templates", templatesDir))
	webhookPath = cfg.MergeEnv("webhook_path", webhookPath)
	webhookSecret = cfg.MergeEnv("webhook_secret", webhookSecret)
	webhookCommand = cfg.MergeEnv("webhook_command", webhookCommand)

	templateName := path.Join(templatesDir, "advanced-search.html")
	advancedPage, err = ioutil.ReadFile(templateName)
	if err != nil {
		log.Fatalf("Can't read templates, e.g. %s, %s", templateName, err)
	}
	templateName = path.Join(templatesDir, "basic-search.html")
	basicPage, err = ioutil.ReadFile(templateName)
	if err != nil {
		log.Fatalf("Can't read %s, %s", templateName, err)
	}

	handleSignals()

	// Wake up our search engine
	indexList := strings.Split(bleveNames, ":")
	availableIndex := false
	if enableSearch == true {
		for i := 0; i < len(indexList) && availableIndex == false; i++ {
			indexName := indexList[i]
			log.Printf("Opening %q", indexName)
			index, err = bleve.OpenUsing(indexName, map[string]interface{}{
				"read_only": true,
			})
			if err != nil {
				log.Printf("Can't open Bleve index %q, %s, trying next index", indexName, err)
			} else {
				indexAlias = bleve.NewIndexAlias(index)
				availableIndex = true
			}
		}
		if availableIndex == false {
			log.Fatalf("No index available %s", bleveNames)
		}
		defer index.Close()
	}

	// Send static file request to the default handler,
	// search routes are handled by middleware customRoutes()
	http.Handle("/", http.FileServer(http.Dir(htdocsDir)))

	log.Printf("%s %s\n", appName, cait.Version)
	log.Printf("Listening on %s\n", serviceURL.String())
	err = http.ListenAndServe(serviceURL.Host, requestLogger(customRoutes(http.DefaultServeMux)))
	if err != nil {
		log.Fatal(err)
	}
}
Esempio n. 5
0
func main() {
	appName := path.Base(os.Args[0])
	flag.Parse()

	cfg := cli.New(appName, "CAIT", fmt.Sprintf(license, appName, cait.Version), cait.Version)
	cfg.UsageText = fmt.Sprintf(usage, appName)
	cfg.DescriptionText = fmt.Sprintf(description, appName)
	cfg.OptionsText = "OPTIONS\n"
	cfg.ExampleText = fmt.Sprintf(examples, appName)

	args := flag.Args()
	if showHelp == true {
		fmt.Println(cfg.Usage())
		os.Exit(0)
	}
	if showVersion == true {
		fmt.Println(cfg.Version())
		os.Exit(0)
	}
	if showLicense == true {
		fmt.Println(cfg.License())
		os.Exit(0)
	}

	if len(args) > 0 {
		sitemap = args[0]
	}

	if changefreq == "" {
		changefreq = "daily"
	}

	excludeDirs := new(ExcludeList)
	if len(excludeList) > 0 {
		excludeDirs.Set(excludeList)
	}

	// Required
	htdocs = cfg.CheckOption("htdocs", cfg.MergeEnv("htdocs", htdocs), true)
	siteURL = cfg.CheckOption("site_url", cfg.MergeEnv("site_url", siteURL), true)
	sitemap = cfg.CheckOption("sitemap", cfg.MergeEnv("sitemap", sitemap), true)

	log.Printf("Starting map of %s\n", htdocs)
	filepath.Walk(htdocs, func(p string, info os.FileInfo, err error) error {
		if strings.HasSuffix(p, ".html") {
			fname := path.Base(p)
			//NOTE: You can skip the eror pages, and excluded directories in the sitemap
			if strings.HasPrefix(fname, "50") == false && strings.HasPrefix(p, "40") == false && excludeDirs.IsExcluded(p) == false {
				finfo := new(locInfo)
				finfo.Loc = fmt.Sprintf("%s%s", siteURL, strings.TrimPrefix(p, htdocs))
				yr, mn, dy := info.ModTime().Date()
				finfo.LastMod = fmt.Sprintf("%d-%0.2d-%0.2d", yr, mn, dy)
				log.Printf("Adding %s\n", finfo.Loc)
				locList = append(locList, finfo)
			}
		}
		return nil
	})
	fmt.Printf("Writing %s\n", sitemap)
	fp, err := os.OpenFile(sitemap, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0664)
	if err != nil {
		log.Fatalf("Can't create %s, %s\n", sitemap, err)
	}
	defer fp.Close()
	fp.Write([]byte(`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
`))
	for _, item := range locList {
		fp.WriteString(fmt.Sprintf(`
    <url>
            <loc>%s</loc>
            <lastmod>%s</lastmod>
            <changefreq>%s</changefreq>
    </url>
`, item.Loc, item.LastMod, changefreq))
	}
	fp.Write([]byte(`
</urlset>
`))
}