Ejemplo n.º 1
0
Archivo: cli.go Proyecto: urmet/gdrive
func printInfo(d *gdrive.Drive, f *drive.File, sizeInBytes bool) {
	fields := map[string]string{
		"Id":          f.Id,
		"Title":       f.Title,
		"Description": f.Description,
		"Size":        util.FileSizeFormat(f.FileSize, sizeInBytes),
		"Created":     util.ISODateToLocal(f.CreatedDate),
		"Modified":    util.ISODateToLocal(f.ModifiedDate),
		"Owner":       strings.Join(f.OwnerNames, ", "),
		"Md5sum":      f.Md5Checksum,
		"Shared":      util.FormatBool(isShared(d, f.Id)),
		"Parents":     util.ParentList(f.Parents),
	}

	order := []string{
		"Id",
		"Title",
		"Description",
		"Size",
		"Created",
		"Modified",
		"Owner",
		"Md5sum",
		"Shared",
		"Parents",
	}
	util.Print(fields, order)
}
Ejemplo n.º 2
0
Archivo: cli.go Proyecto: urmet/gdrive
func List(d *gdrive.Drive, query, titleFilter string, maxResults int, sharedStatus, noHeader, includeDocs, sizeInBytes bool) error {
	caller := d.Files.List()
	queryList := []string{}

	if maxResults > 0 {
		caller.MaxResults(int64(maxResults))
	}

	if titleFilter != "" {
		q := fmt.Sprintf("title contains '%s'", titleFilter)
		queryList = append(queryList, q)
	}

	if query != "" {
		queryList = append(queryList, query)
	} else {
		// Skip trashed files
		queryList = append(queryList, "trashed = false")

		// Skip google docs
		if !includeDocs {
			for _, mime := range googleMimeTypes {
				q := fmt.Sprintf("mimeType != '%s'", mime)
				queryList = append(queryList, q)
			}
		}
	}

	if len(queryList) > 0 {
		q := strings.Join(queryList, " and ")
		caller.Q(q)
	}

	list, err := caller.Do()
	if err != nil {
		return err
	}

	files := list.Items

	for list.NextPageToken != "" {
		if maxResults > 0 && len(files) > maxResults {
			break
		}

		caller.PageToken(list.NextPageToken)
		list, err = caller.Do()
		if err != nil {
			return err
		}
		files = append(files, list.Items...)
	}

	items := make([]map[string]string, 0, 0)

	for _, f := range files {
		if maxResults > 0 && len(items) >= maxResults {
			break
		}

		items = append(items, map[string]string{
			"Id":      f.Id,
			"Title":   util.TruncateString(f.Title, 40),
			"Size":    util.FileSizeFormat(f.FileSize, sizeInBytes),
			"Created": util.ISODateToLocal(f.CreatedDate),
		})
	}

	columnOrder := []string{"Id", "Title", "Size", "Created"}

	if sharedStatus {
		addSharedStatus(d, items)
		columnOrder = append(columnOrder, "Shared")
	}

	util.PrintColumns(items, columnOrder, 3, noHeader)
	return nil
}