Example #1
0
func New(context *config.Context, opts *Options) *Commands {
	var r *Remote
	if context != nil {
		r = NewRemoteContext(context)
	}

	stdin, stdout, stderr := os.Stdin, os.Stdout, os.Stderr

	var logger *log.Logger = nil

	if opts == nil {
		logger = log.New(stdin, stdout, stderr)
	} else {
		if opts.Quiet {
			stdout = nil
		}

		if stdout != nil {
			opts.StdoutIsTty = isatty.IsTerminal(stdout.Fd())
		}

		if stdout == nil && opts.Piped {
			panic("piped requires stdout to be non-nil")
		}

		logger = log.New(stdin, stdout, stderr)

		// should always start with /
		opts.Path = path.Clean(path.Join("/", opts.Path))

		if !opts.Force {
			ignoresPath := filepath.Join(context.AbsPath, DriveIgnoreSuffix)
			ignorer, regErr := combineIgnores(ignoresPath)

			if regErr != nil {
				logger.LogErrf("combining ignores from path %s and internally: %v\n", ignoresPath, regErr)
			}

			opts.Ignorer = ignorer
		}
	}

	return &Commands{
		context:       context,
		rem:           r,
		opts:          opts,
		log:           logger,
		mkdirAllCache: expirableCache.New(),
	}
}
Example #2
0
func printChangeList(logy *log.Logger, changes []*Change, noPrompt bool, noClobber bool) (bool, *map[Operation]sizeCounter) {
	if len(changes) == 0 {
		logy.Logln("Everything is up-to-date.")
		return false, nil
	}
	if noPrompt {
		return true, nil
	}

	opMap := opChangeCount(changes)
	previewChanges(logy, changes, true, opMap)

	return promptForChanges(), &opMap
}
Example #3
0
func _warnChangeStopper(logy *log.Logger, items []*Change, perItemPrefix, fmt_ string, args ...interface{}) {
	logy.LogErrf(fmt_, args...)
	for _, item := range items {
		if item != nil {
			fileId := ""
			if item.Src != nil && item.Src.Id != "" {
				fileId = item.Src.Id
			} else if item.Dest != nil && item.Dest.Id != "" {
				fileId = item.Dest.Id
			}

			logy.LogErrln(perItemPrefix, item.Path, fileId)
		}
	}
}
Example #4
0
func previewChanges(logy *log.Logger, cl []*Change, reduce bool, opMap map[Operation]sizeCounter) {
	for _, c := range cl {
		op := c.Op()
		if op != OpNone {
			logy.Logln(c.Symbol(), c.Path)
		}
	}

	if reduce {
		for op, counter := range opMap {
			if counter.count < 1 {
				continue
			}
			_, name := op.description()
			logy.Logf("%s %s\n", name, counter.String())
		}
	}
}
Example #5
0
func fileSizesInfo(logy *log.Logger, about *drive.About) {
	if len(about.MaxUploadSizes) >= 1 {
		logy.Logln("\n* Maximum upload sizes per file type *")
		logy.Logf("%-50s %-20s\n", "FileType", "Size")
		for _, uploadInfo := range about.MaxUploadSizes {
			logy.Logf("%-50s %-20s\n", uploadInfo.Type, prettyBytes(uploadInfo.Size))
		}
		logy.Logln()
	}
	return
}
Example #6
0
func featuresInformation(logy *log.Logger, about *drive.About) {
	if len(about.Features) >= 1 {
		logy.Logf("%-30s %-30s\n", "Feature", "Request limit (queries/second)")
		for _, feature := range about.Features {
			if feature.FeatureName == "" {
				continue
			}
			logy.Logf("%-30s %-30f\n", feature.FeatureName, feature.FeatureRate)
		}
		logy.Logln()
	}
}
Example #7
0
func quotaInformation(logy *log.Logger, about *drive.About) {
	freeBytes := about.QuotaBytesTotal - about.QuotaBytesUsed

	logy.Logf(
		"Name: %s\nAccount type:\t%s\nBytes Used:\t%-20d (%s)\n"+
			"Bytes Free:\t%-20d (%s)\nBytes InTrash:\t%-20d (%s)\n"+
			"Total Bytes:\t%-20d (%s)\n",
		about.Name, about.QuotaType,
		about.QuotaBytesUsed, prettyBytes(about.QuotaBytesUsed),
		freeBytes, prettyBytes(freeBytes),
		about.QuotaBytesUsedInTrash, prettyBytes(about.QuotaBytesUsedInTrash),
		about.QuotaBytesTotal, prettyBytes(about.QuotaBytesTotal))

	if len(about.QuotaBytesByService) >= 1 {
		logy.Logln("\n* Space used by Google Services *")
		logy.Logf("%-36s %-36s\n", "Service", "Bytes")
		for _, quotaService := range about.QuotaBytesByService {
			logy.Logf("%-36s %-36s\n", quotaService.ServiceName, prettyBytes(quotaService.BytesUsed))
		}
		logy.Logf("%-36s %-36s\n", "Space used by all Google Apps",
			prettyBytes(about.QuotaBytesUsedAggregate))
	}
	logy.Logln()
}
Example #8
0
func (f *File) pretty(logy *log.Logger, opt attribute) {
	fmtdPath := sepJoin("/", opt.parent, f.Name)

	if opt.diskUsageOnly {
		logy.Logf("%-12v %s\n", f.Size, fmtdPath)
		return
	}

	if opt.minimal {
		logy.Logf("%s ", fmtdPath)
	} else {
		if f.IsDir {
			logy.Logf("d")
		} else {
			logy.Logf("-")
		}
		if f.Shared {
			logy.Logf("s")
		} else {
			logy.Logf("-")
		}

		if f.UserPermission != nil {
			logy.Logf(" %-10s ", f.UserPermission.Role)
		}
	}

	if owners(opt.mask) && len(f.OwnerNames) >= 1 {
		logy.Logf(" %s ", strings.Join(f.OwnerNames, " & "))
	}

	if version(opt.mask) {
		logy.Logf(" v%d", f.Version)
	}

	if !opt.minimal {
		logy.Logf(" %-10s\t%-10s\t\t%-20s\t%-50s\n", prettyBytes(f.Size), f.Id, f.ModTime, fmtdPath)
	} else {
		logy.Logln()
	}
}
Example #9
0
func warnConflictsPersist(logy *log.Logger, conflicts []*Change) {
	logy.LogErrf("These %d file(s) would be overwritten. Use -%s to override this behaviour\n", len(conflicts), CLIOptionIgnoreConflict)
	for _, conflict := range conflicts {
		logy.LogErrln(conflict.Path)
	}
}
Example #10
0
func showPromptShareChanges(logy *log.Logger, change *shareChange) Agreement {
	if len(change.files) < 1 {
		return NotApplicable
	}

	verb := "unshare"
	shareInfo := "Revoke access"
	extraShareInfo := ""
	if !change.revoke {
		shareInfo = "Provide access"
		if len(change.emails) < 1 {
			return NotApplicable
		}

		verb = "share"
		if change.notify && len(change.emailMessage) >= 1 {
			extraShareInfo = fmt.Sprintf("Message:\n\t\033[33m%s\033[00m\n", change.emailMessage)
		}
	}

	if len(change.accountTypes) >= 1 {
		logy.Logf("%s for accountType(s)\n", shareInfo)
		for _, accountType := range change.accountTypes {
			logy.Logf("\t\033[32m%s\033[00m\n", accountType.String())
		}

		logy.Logln(extraShareInfo)
	}

	if len(change.roles) >= 1 {
		logy.Logln("For roles(s)")
		for _, role := range change.roles {
			logy.Logf("\t\033[33m%s\033[00m\n", role.String())
		}
	}

	if len(change.emails) >= 1 {
		logy.Logf("\nAddressees:\n")
		for _, email := range change.emails {
			logy.Logf("\t\033[92m+\033[00m %s\n", email)
		}
	}

	logy.Logf("\nFile(s) to %s:\n", verb)
	for _, file := range change.files {
		if file == nil {
			continue
		}
		logy.Logf("\t\033[92m+\033[00m %s\n", file.Name)
	}

	logy.Logln()
	return promptForChanges()
}
Example #11
0
File: share.go Project: rghan/drive
func showPromptShareChanges(logy *log.Logger, change *shareChange) Agreement {
	if len(change.files) < 1 {
		return NotApplicable
	}
	if change.revoke {
		logy.Logf("Revoke access for accountType: \033[92m%s\033[00m for file(s):\n",
			change.accountType.String())
		for _, file := range change.files {
			logy.Logln("+ ", file.Name)
		}
		logy.Logln()
		return promptForChanges()
	}

	if len(change.emails) < 1 {
		return NotApplicable
	}

	if change.notify {
		logy.Logln("Message:\n\t", change.emailMessage)
	}

	logy.Logln("Receipients:")
	for _, email := range change.emails {
		logy.Logf("\t\033[92m+\033[00m %s\n", email)
	}

	logy.Logln("\nFile(s) to share:")
	for _, file := range change.files {
		if file == nil {
			continue
		}
		logy.Logf("\t\033[92m+\033[00m %s\n", file.Name)
	}
	return promptForChanges()
}