Exemple #1
0
func cmd_eggs_add(conn *scrapinghub.Connection, args []string, flags *PFlags) {
	if len(args) < 2 {
		log.Fatalf("Missing arguments: <project_id> and <egg_path>\n")
	}
	project_id := args[0]
	egg_path := args[1]
	name_version := args[2:]

	var egg_name string
	var egg_ver string

	if len(name_version) > 0 {
		name_ver_map := equality_list_to_map(name_version)
		egg_name = name_ver_map["name"]
		egg_ver = name_ver_map["version"]
	} else {
		result := re_egg_pattern.FindStringSubmatch(filepath.Base(egg_path))
		if len(result) <= 0 {
			log.Fatalf("eggs-add error: Can't guess the name and version from egg path filename, provide it using name=<name> and version=<version> as parameters.\n")
		}
		egg_name = result[1]
		egg_ver = result[2]
	}
	if egg_name == "" || egg_ver == "" {
		log.Fatalf("Error: name and version are required\n")
	}
	var eggs scrapinghub.Eggs
	eggdata, err := eggs.Add(conn, project_id, egg_name, egg_ver, egg_path)
	if err != nil {
		log.Fatalf("eggs-add error: %s\n", err)
	}
	fmt.Printf("Egg uploaded successfully! Project: %s, Egg name: %s, version: %s\n", project_id, eggdata.Name, eggdata.Version)
}
Exemple #2
0
func cmd_eggs_delete(conn *scrapinghub.Connection, args []string, flags *PFlags) {
	if len(args) < 2 {
		log.Fatalf("Missing arguments: <project_id> and <egg_name>\n")
	}
	project_id := args[0]
	egg_name := args[1]

	var eggs scrapinghub.Eggs
	err := eggs.Delete(conn, project_id, egg_name)
	if err != nil {
		log.Fatalf("eggs-delete error: %s\n", err)
	}
	fmt.Printf("Egg %s successfully deleted from project: %s\n", egg_name, project_id)
}
Exemple #3
0
func cmd_eggs_list(conn *scrapinghub.Connection, args []string, flags *PFlags) {
	if len(args) < 1 {
		log.Fatalf("Missing argument: <project_id>\n")
	}

	project_id := args[0]
	var eggs scrapinghub.Eggs
	egglist, err := eggs.List(conn, project_id)
	if err != nil {
		log.Fatalf("eggs-list error: %s\n", err)
	}

	fmt.Println(dashes(97))
	outfmt := "| %-30s | %60s |\n"
	fmt.Printf(outfmt, "Name", "Version")
	fmt.Println(dashes(97))
	for _, egg := range egglist {
		fmt.Printf(outfmt, egg.Name, egg.Version)
	}
	fmt.Println(dashes(97))
}