Commit 6ee1378d authored by Luke Champine's avatar Luke Champine

Merge branch 'siac-renter-ls' into 'master'

Change siac renter list to siac renter ls [path]

See merge request !3591
parents 7eeef97e bd8210fb
Pipeline #57484397 passed with stages
in 30 minutes and 50 seconds
......@@ -242,8 +242,8 @@ RPC Stats:
es.Version,
yesNo(is.AcceptingContracts), periodUnits(is.MaxDuration),
filesizeUnits(int64(is.MaxDownloadBatchSize)),
filesizeUnits(int64(is.MaxReviseBatchSize)), netaddr,
filesizeUnits(is.MaxDownloadBatchSize),
filesizeUnits(is.MaxReviseBatchSize), netaddr,
is.WindowSize/6,
currencyUnits(is.Collateral.Mul(modules.BlockBytesPerMonthTerabyte)),
......@@ -289,8 +289,8 @@ RPC Stats:
`,
connectabilityString,
filesizeUnits(int64(totalstorage)),
filesizeUnits(int64(totalstorage-storageremaining)), price,
filesizeUnits(totalstorage),
filesizeUnits(totalstorage-storageremaining), price,
periodUnits(is.MaxDuration),
yesNo(is.AcceptingContracts), currencyUnits(totalPotentialRevenue),
......@@ -322,7 +322,7 @@ RPC Stats:
for _, folder := range sg.Folders {
curSize := int64(folder.Capacity - folder.CapacityRemaining)
pctUsed := 100 * (float64(curSize) / float64(folder.Capacity))
fmt.Fprintf(w, "\t%s\t%s\t%.2f\t%s\n", filesizeUnits(curSize), filesizeUnits(int64(folder.Capacity)), pctUsed, folder.Path)
fmt.Fprintf(w, "\t%s\t%s\t%.2f\t%s\n", filesizeUnits(uint64(curSize)), filesizeUnits(folder.Capacity), pctUsed, folder.Path)
}
w.Flush()
}
......
......@@ -18,7 +18,7 @@ import (
var errUnableToParseSize = errors.New("unable to parse size")
// filesize returns a string that displays a filesize in human-readable units.
func filesizeUnits(size int64) string {
func filesizeUnits(size uint64) string {
if size == 0 {
return "0 B"
}
......
......@@ -104,11 +104,10 @@ var (
}
renterFilesListCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List the status of all files",
Long: "List the status of all files known to the renter on the Sia network.",
Run: wrap(renterfileslistcmd),
Use: "ls [path]",
Short: "List the status of all files within specified dir",
Long: "List the status of all files known to the renter within the specified folder on the Sia network. To query the root dir either '\"\"', '/' or '.' can be supplied",
Run: wrap(renterfileslistcmd),
}
renterFilesRenameCmd = &cobra.Command{
......@@ -207,9 +206,6 @@ func rentercmd() {
`, currencyUnits(rg.Settings.Allowance.Funds),
currencyUnits(totalSpent), currencyUnits(fm.Unspent))
}
// also list files
renterfileslistcmd()
}
// renteruploadscmd is the handler for the command `siac renter uploads`.
......@@ -238,7 +234,7 @@ func renteruploadscmd() {
}
fmt.Println("Uploading", len(filteredFiles), "files:")
for _, file := range filteredFiles {
fmt.Printf("%13s %s (uploading, %0.2f%%)\n", filesizeUnits(int64(file.Filesize)), file.SiaPath, file.UploadProgress)
fmt.Printf("%13s %s (uploading, %0.2f%%)\n", filesizeUnits(file.Filesize), file.SiaPath, file.UploadProgress)
}
}
......@@ -311,8 +307,8 @@ Expectations for period:
Expected Upload: %v
Expected Download: %v
Expected Redundancy: %v
`, currencyUnits(allowance.Funds), allowance.Period, allowance.RenewWindow, allowance.Hosts, filesizeUnits(int64(allowance.ExpectedStorage)),
filesizeUnits(int64(allowance.ExpectedUpload)), filesizeUnits(int64(allowance.ExpectedDownload)), allowance.ExpectedRedundancy)
`, currencyUnits(allowance.Funds), allowance.Period, allowance.RenewWindow, allowance.Hosts, filesizeUnits(allowance.ExpectedStorage),
filesizeUnits(allowance.ExpectedUpload), filesizeUnits(allowance.ExpectedDownload), allowance.ExpectedRedundancy)
// Show spending detail
fm := rg.FinancialMetrics
......@@ -582,7 +578,7 @@ func rentercontractscmd() {
Total Spent: %v
Total Fees: %v
`, len(rc.ActiveContracts), filesizeUnits(int64(activeTotalStored)),
`, len(rc.ActiveContracts), filesizeUnits(activeTotalStored),
currencyUnits(activeTotalRemaining), currencyUnits(activeTotalSpent), currencyUnits(activeTotalFees))
w := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)
fmt.Fprintln(w, " Host\tHost Version\tRemaining Funds\tSpent Funds\tSpent Fees\tData\tEnd Height\tID\tGoodForUpload\tGoodForRenew")
......@@ -599,7 +595,7 @@ func rentercontractscmd() {
currencyUnits(c.RenterFunds),
currencyUnits(c.TotalCost.Sub(c.RenterFunds).Sub(c.Fees)),
currencyUnits(c.Fees),
filesizeUnits(int64(c.Size)),
filesizeUnits(c.Size),
c.EndHeight,
c.ID,
c.GoodForUpload,
......@@ -630,7 +626,7 @@ func rentercontractscmd() {
Total Spent: %v
Total Fees: %v
`, len(rc.InactiveContracts), filesizeUnits(int64(inactiveTotalStored)), currencyUnits(inactiveTotalRemaining), currencyUnits(inactiveTotalSpent), currencyUnits(inactiveTotalFees))
`, len(rc.InactiveContracts), filesizeUnits(inactiveTotalStored), currencyUnits(inactiveTotalRemaining), currencyUnits(inactiveTotalSpent), currencyUnits(inactiveTotalFees))
w := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)
fmt.Fprintln(w, " Host\tHost Version\tRemaining Funds\tSpent Funds\tSpent Fees\tData\tEnd Height\tID\tGoodForUpload\tGoodForRenew")
for _, c := range rc.InactiveContracts {
......@@ -646,7 +642,7 @@ func rentercontractscmd() {
currencyUnits(c.RenterFunds),
currencyUnits(c.TotalCost.Sub(c.RenterFunds).Sub(c.Fees)),
currencyUnits(c.Fees),
filesizeUnits(int64(c.Size)),
filesizeUnits(c.Size),
c.EndHeight,
c.ID,
c.GoodForUpload,
......@@ -680,7 +676,7 @@ func rentercontractscmd() {
Total Spent: %v
Total Fees: %v
`, len(rce.ExpiredContracts), filesizeUnits(int64(expiredTotalStored)), currencyUnits(expiredTotalWithheld), currencyUnits(expiredTotalSpent), currencyUnits(expiredTotalFees))
`, len(rce.ExpiredContracts), filesizeUnits(expiredTotalStored), currencyUnits(expiredTotalWithheld), currencyUnits(expiredTotalSpent), currencyUnits(expiredTotalFees))
w := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)
fmt.Fprintln(w, " Host\tHost Version\tWithheld Funds\tSpent Funds\tSpent Fees\tData\tEnd Height\tID\tGoodForUpload\tGoodForRenew")
for _, c := range rce.ExpiredContracts {
......@@ -696,7 +692,7 @@ func rentercontractscmd() {
currencyUnits(c.RenterFunds),
currencyUnits(c.TotalCost.Sub(c.RenterFunds).Sub(c.Fees)),
currencyUnits(c.Fees),
filesizeUnits(int64(c.Size)),
filesizeUnits(c.Size),
c.EndHeight,
c.ID,
c.GoodForUpload,
......@@ -752,7 +748,7 @@ Contract %v
currencyUnits(rc.StorageSpending),
currencyUnits(rc.DownloadSpending),
currencyUnits(rc.RenterFunds),
filesizeUnits(int64(rc.Size)))
filesizeUnits(rc.Size))
printScoreBreakdown(&hostInfo)
return
......@@ -1066,7 +1062,7 @@ func downloadprogress(tfs []trackedFile) []api.DownloadInfo {
elapsed := time.Since(d.StartTime)
elapsed -= elapsed % time.Second // round to nearest second
progressStr := fmt.Sprintf("Downloading %v... %5.1f%% of %v, %v elapsed, %s ", tf.siaPath.String(), pct, filesizeUnits(int64(d.Filesize)), elapsed, speed)
progressStr := fmt.Sprintf("Downloading %v... %5.1f%% of %v, %v elapsed, %s ", tf.siaPath.String(), pct, filesizeUnits(d.Filesize), elapsed, speed)
if tfIdx < len(tfs)-1 {
fmt.Println(progressStr)
} else {
......@@ -1088,29 +1084,48 @@ func (s bySiaPath) Less(i, j int) bool { return s[i].SiaPath.String() < s[j].Sia
// renterfileslistcmd is the handler for the command `siac renter list`.
// Lists files known to the renter on the network.
func renterfileslistcmd() {
var rf api.RenterFiles
rf, err := httpClient.RenterFilesGet()
func renterfileslistcmd(path string) {
var sp modules.SiaPath
var err error
if path == "." || path == "" || path == "/" {
sp = modules.RootSiaPath()
} else {
sp, err = modules.NewSiaPath(path)
if err != nil {
die("could not parse siapath:", err)
}
}
rgd, err := httpClient.RenterGetDir(sp)
if err != nil {
die("Could not get file list:", err)
}
if len(rf.Files) == 0 {
fmt.Println("No files have been uploaded.")
if len(rgd.Files)+len(rgd.Directories) <= 1 {
fmt.Println("No files/dirs have been uploaded.")
return
}
fmt.Print("\nTracking ", len(rf.Files), " files:")
fmt.Printf("\nListing %v files/dirs:", len(rgd.Files)+len(rgd.Directories)-1)
var totalStored uint64
for _, file := range rf.Files {
for _, file := range rgd.Files {
totalStored += file.Filesize
}
fmt.Printf(" %9s\n", filesizeUnits(int64(totalStored)))
fmt.Printf(" %9s\n", filesizeUnits(totalStored))
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
if renterListVerbose {
fmt.Fprintln(w, " File size\tAvailable\tUploaded\tProgress\tRedundancy\tHealth\tStuck\tRenewing\tOn Disk\tRecoverable\tSia path")
}
sort.Sort(bySiaPath(rf.Files))
for _, file := range rf.Files {
fmt.Fprintf(w, " %9s", filesizeUnits(int64(file.Filesize)))
fmt.Fprintln(w, " Name\tFile size\tAvailable\tUploaded\tProgress\tRedundancy\tHealth\tStuck\tRenewing\tOn Disk\tRecoverable")
}
sort.Sort(bySiaPath(rgd.Files))
// Print root dir.
fmt.Fprintf(w, "%v/\n", rgd.Directories[0].SiaPath)
// Print dirs.
for i := 1; i < len(rgd.Directories); i++ {
name := rgd.Directories[i].SiaPath.Name()
fmt.Fprintf(w, " %v/\n", name)
}
// Print files.
for _, file := range rgd.Files {
name := file.SiaPath.Name()
fmt.Fprintf(w, " %s", name)
fmt.Fprintf(w, "\t%9s", filesizeUnits(file.Filesize))
if renterListVerbose {
availableStr := yesNo(file.Available)
renewingStr := yesNo(file.Renewing)
......@@ -1126,9 +1141,8 @@ func renterfileslistcmd() {
onDiskStr := yesNo(file.OnDisk)
recoverableStr := yesNo(file.Recoverable)
stuckStr := yesNo(file.Stuck)
fmt.Fprintf(w, "\t%s\t%9s\t%8s\t%10s\t%6s\t%s\t%s\t%s\t%s", availableStr, filesizeUnits(int64(file.UploadedBytes)), uploadProgressStr, redundancyStr, healthStr, stuckStr, renewingStr, onDiskStr, recoverableStr)
fmt.Fprintf(w, "\t%s\t%9s\t%8s\t%10s\t%6s\t%s\t%s\t%s\t%s", availableStr, filesizeUnits(file.UploadedBytes), uploadProgressStr, redundancyStr, healthStr, stuckStr, renewingStr, onDiskStr, recoverableStr)
}
fmt.Fprintf(w, "\t%s", file.SiaPath)
if !renterListVerbose && !file.Available {
fmt.Fprintf(w, " (uploading, %0.2f%%)", file.UploadProgress)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment