1
mirror of https://github.com/rclone/rclone synced 2024-11-26 04:07:22 +01:00

cmd: implement --stats-one-line-date and --stats-one-line-date-format

This commit is contained in:
Peter Berbec 2019-03-25 22:41:45 -04:00 committed by Nick Craig-Wood
parent bd2a7ffcf4
commit 0d511b7878
4 changed files with 87 additions and 54 deletions

View File

@ -800,6 +800,18 @@ section](#logging) for more info on log levels.
When this is specified, rclone condenses the stats into a single line When this is specified, rclone condenses the stats into a single line
showing the most important stats only. showing the most important stats only.
### --stats-one-line-date ###
When this is specified, rclone enables the single-line stats and prepends
the display with a date string. The default is `2006/01/02 15:04:05 - `
### --stats-one-line-date-format ###
When this is specified, rclone enables the single-line stats and prepends
the display with a user-supplied date string. The date string MUST be
enclosed in quotes. Follow [golang specs](https://golang.org/pkg/time/#Time.Format) for
date formatting syntax.
### --stats-unit=bits|bytes ### ### --stats-unit=bits|bytes ###
By default, data transfer rates will be printed in bytes/second. By default, data transfer rates will be printed in bytes/second.

View File

@ -216,6 +216,7 @@ func (s *StatsInfo) String() string {
currentSize = s.bytes currentSize = s.bytes
buf = &bytes.Buffer{} buf = &bytes.Buffer{}
xfrchkString = "" xfrchkString = ""
dateString = ""
) )
if !fs.Config.StatsOneLine { if !fs.Config.StatsOneLine {
@ -231,9 +232,14 @@ func (s *StatsInfo) String() string {
if len(xfrchk) > 0 { if len(xfrchk) > 0 {
xfrchkString = fmt.Sprintf(" (%s)", strings.Join(xfrchk, ", ")) xfrchkString = fmt.Sprintf(" (%s)", strings.Join(xfrchk, ", "))
} }
if fs.Config.StatsOneLineDate {
t := time.Now()
dateString = t.Format(fs.Config.StatsOneLineDateFormat) // Including the separator so people can customize it
}
} }
_, _ = fmt.Fprintf(buf, "%10s / %s, %s, %s, ETA %s%s", _, _ = fmt.Fprintf(buf, "%s%10s / %s, %s, %s, ETA %s%s",
dateString,
fs.SizeSuffix(s.bytes), fs.SizeSuffix(s.bytes),
fs.SizeSuffix(totalSize).Unit("Bytes"), fs.SizeSuffix(totalSize).Unit("Bytes"),
percent(s.bytes, totalSize), percent(s.bytes, totalSize),

View File

@ -38,59 +38,61 @@ var (
// ConfigInfo is filesystem config options // ConfigInfo is filesystem config options
type ConfigInfo struct { type ConfigInfo struct {
LogLevel LogLevel LogLevel LogLevel
StatsLogLevel LogLevel StatsLogLevel LogLevel
DryRun bool DryRun bool
CheckSum bool CheckSum bool
SizeOnly bool SizeOnly bool
IgnoreTimes bool IgnoreTimes bool
IgnoreExisting bool IgnoreExisting bool
IgnoreErrors bool IgnoreErrors bool
ModifyWindow time.Duration ModifyWindow time.Duration
Checkers int Checkers int
Transfers int Transfers int
ConnectTimeout time.Duration // Connect timeout ConnectTimeout time.Duration // Connect timeout
Timeout time.Duration // Data channel timeout Timeout time.Duration // Data channel timeout
Dump DumpFlags Dump DumpFlags
InsecureSkipVerify bool // Skip server certificate verification InsecureSkipVerify bool // Skip server certificate verification
DeleteMode DeleteMode DeleteMode DeleteMode
MaxDelete int64 MaxDelete int64
TrackRenames bool // Track file renames. TrackRenames bool // Track file renames.
LowLevelRetries int LowLevelRetries int
UpdateOlder bool // Skip files that are newer on the destination UpdateOlder bool // Skip files that are newer on the destination
NoGzip bool // Disable compression NoGzip bool // Disable compression
MaxDepth int MaxDepth int
IgnoreSize bool IgnoreSize bool
IgnoreChecksum bool IgnoreChecksum bool
NoTraverse bool NoTraverse bool
NoUpdateModTime bool NoUpdateModTime bool
DataRateUnit string DataRateUnit string
BackupDir string BackupDir string
Suffix string Suffix string
SuffixKeepExtension bool SuffixKeepExtension bool
UseListR bool UseListR bool
BufferSize SizeSuffix BufferSize SizeSuffix
BwLimit BwTimetable BwLimit BwTimetable
TPSLimit float64 TPSLimit float64
TPSLimitBurst int TPSLimitBurst int
BindAddr net.IP BindAddr net.IP
DisableFeatures []string DisableFeatures []string
UserAgent string UserAgent string
Immutable bool Immutable bool
AutoConfirm bool AutoConfirm bool
StreamingUploadCutoff SizeSuffix StreamingUploadCutoff SizeSuffix
StatsFileNameLength int StatsFileNameLength int
AskPassword bool AskPassword bool
UseServerModTime bool UseServerModTime bool
MaxTransfer SizeSuffix MaxTransfer SizeSuffix
MaxBacklog int MaxBacklog int
StatsOneLine bool StatsOneLine bool
Progress bool StatsOneLineDate bool // If we want a date prefix at all
Cookie bool StatsOneLineDateFormat string // If we want to customize the prefix
UseMmap bool Progress bool
CaCert string // Client Side CA Cookie bool
ClientCert string // Client Side Cert UseMmap bool
ClientKey string // Client Side Key CaCert string // Client Side CA
ClientCert string // Client Side Cert
ClientKey string // Client Side Key
} }
// NewConfig creates a new config with everything set to the default // NewConfig creates a new config with everything set to the default
@ -120,6 +122,8 @@ func NewConfig() *ConfigInfo {
c.TPSLimitBurst = 1 c.TPSLimitBurst = 1
c.MaxTransfer = -1 c.MaxTransfer = -1
c.MaxBacklog = 10000 c.MaxBacklog = 10000
// We do not want to set the default here. We use this variable being empty as part of the fall-through of options.
// c.StatsOneLineDateFormat = "2006/01/02 15:04:05 - "
return c return c
} }

View File

@ -87,6 +87,8 @@ func AddFlags(flagSet *pflag.FlagSet) {
flags.FVarP(flagSet, &fs.Config.MaxTransfer, "max-transfer", "", "Maximum size of data to transfer.") flags.FVarP(flagSet, &fs.Config.MaxTransfer, "max-transfer", "", "Maximum size of data to transfer.")
flags.IntVarP(flagSet, &fs.Config.MaxBacklog, "max-backlog", "", fs.Config.MaxBacklog, "Maximum number of objects in sync or check backlog.") flags.IntVarP(flagSet, &fs.Config.MaxBacklog, "max-backlog", "", fs.Config.MaxBacklog, "Maximum number of objects in sync or check backlog.")
flags.BoolVarP(flagSet, &fs.Config.StatsOneLine, "stats-one-line", "", fs.Config.StatsOneLine, "Make the stats fit on one line.") flags.BoolVarP(flagSet, &fs.Config.StatsOneLine, "stats-one-line", "", fs.Config.StatsOneLine, "Make the stats fit on one line.")
flags.BoolVarP(flagSet, &fs.Config.StatsOneLineDate, "stats-one-line-date", "", fs.Config.StatsOneLineDate, "Enables --stats-one-line and add current date/time prefix.")
flags.StringVarP(flagSet, &fs.Config.StatsOneLineDateFormat, "stats-one-line-date-format", "", fs.Config.StatsOneLineDateFormat, "Enables --stats-one-line-date and uses custom formatted date. Enclose date string in double quotes (\"). See https://golang.org/pkg/time/#Time.Format")
flags.BoolVarP(flagSet, &fs.Config.Progress, "progress", "P", fs.Config.Progress, "Show progress during transfer.") flags.BoolVarP(flagSet, &fs.Config.Progress, "progress", "P", fs.Config.Progress, "Show progress during transfer.")
flags.BoolVarP(flagSet, &fs.Config.Cookie, "use-cookies", "", fs.Config.Cookie, "Enable session cookiejar.") flags.BoolVarP(flagSet, &fs.Config.Cookie, "use-cookies", "", fs.Config.Cookie, "Enable session cookiejar.")
flags.BoolVarP(flagSet, &fs.Config.UseMmap, "use-mmap", "", fs.Config.UseMmap, "Use mmap allocator (see docs).") flags.BoolVarP(flagSet, &fs.Config.UseMmap, "use-mmap", "", fs.Config.UseMmap, "Use mmap allocator (see docs).")
@ -149,6 +151,15 @@ func SetFlags() {
log.Fatalf(`Can only use --suffix with --backup-dir.`) log.Fatalf(`Can only use --suffix with --backup-dir.`)
} }
switch {
case len(fs.Config.StatsOneLineDateFormat) > 0:
fs.Config.StatsOneLineDate = true
fs.Config.StatsOneLine = true
case fs.Config.StatsOneLineDate:
fs.Config.StatsOneLineDateFormat = "2006/01/02 15:04:05 - "
fs.Config.StatsOneLine = true
}
if bindAddr != "" { if bindAddr != "" {
addrs, err := net.LookupIP(bindAddr) addrs, err := net.LookupIP(bindAddr)
if err != nil { if err != nil {