Skip to content

Show copy progress for CopyFileToMachine on Shell Service #4918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

michaellee1019
Copy link
Member

@michaellee1019 michaellee1019 commented Apr 16, 2025

It was hard to see the progress of the two CLI operations that copy files to machines:

  • viam module reload
  • viam machine part cp

This PR adds wrappers around the CopyFileToMachine NewCopyFileToMachineFactory to print out the status of the file transfer.

The viam machine part cp command now outputs this (works for both single and multiple files):

michaellee@ROBOT-MYHLX2FTJN mcp23017 % viam machine part cp --machine "gpioflicker" --part "gpioflicker-main" face-identification-0_5_2-darwin-arm64.tar.gz meta.json test.bgcode  machine:/root/
Copying face-identification-0_5_2-darwin-arm64.tar.gz...
Progress: 100% (177516276/177516276 bytes)
Copying meta.json...
Progress: 100% (1479/1479 bytes)
Copying test.bgcode...
Progress: 100% (1287725/1287725 bytes)

And viam module reload:

michaellee@ROBOT-MYHLX2FTJN mcp23017 % viam module reload --part-id a6d97ea0-97c9-45a1-b9d4-b97608d44472
Info: Starting build
...
2025-04-16T18:47:42.178Z	INFO	reload	client/client.go:466	A WebRTC connection was made to the robot. Reconnects will disallow direct gRPC connections.
2025-04-16T18:47:42.179Z	INFO	reload	client/client.go:437	successfully (re)connected to remote at address	{"address":"gpioflicker-main.m027aso1s5.viam.cloud"}
Copying face-identification-0_5_2-darwin-arm64.tar.gz...
Progress: 38% (67108864/177516276 bytes)

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Apr 16, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 16, 2025
Copy link
Member

@abe-winter abe-winter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, see comments about newline + --no-progress

return pr.reader.Stat()
}

func (pr *progressReader) Close() error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider adding final \n somewhere (potentially in Close)

as-is, the next shell prompt appears on the same line as the progress output

~/repo/rdk$ go run ./cli/viam machine part cp --part PART README.md machine:README.md
Copying README.md...
Progress: 100% (5577/5577 bytes)~/repo/rdk$

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Good catch. I had this but then I refactored to handle multiple files.

}
uploadPercent := int(math.Ceil(100 * float64(bytes) / float64(fileSize)))
//nolint:errcheck // progress display is non-critical
_, _ = os.Stdout.WriteString(fmt.Sprintf("\rProgress: %d%% (%d/%d bytes)", uploadPercent, bytes, fileSize))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note this will work differently in headless shells

would not worry too much about it, but maybe add a --no-progress field for reload + cp, so that people can skip this behavior if it's messing with their shell?

(or assign this to me as afterwork so this PR can get merged; I feel bad that I took so long to start this review)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Was easy.

@michaellee1019 michaellee1019 requested a review from a team as a code owner May 14, 2025 22:25
@michaellee1019 michaellee1019 requested review from njooma and stuqdog May 14, 2025 22:25
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels May 14, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels May 15, 2025
@michaellee1019
Copy link
Member Author

Hey @cheukt can you give this a review?

Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good from SDK perspective, with one minor request!

cli/app.go Outdated
@@ -75,6 +75,7 @@ const (
moduleFlagForce = "force"
moduleFlagBinary = "binary"
moduleFlagLocal = "local"
moduleFlagNoProgress = "no-progress"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) can we collapse this and cpFlagNoProgress into a single flag (generalFlagNoProgress or something like that)? Would prefer to not have two identical flags.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing! I did not see the general flags above earlier. Makes total sense.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels May 16, 2025
Copy link
Member

@cheukt cheukt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@michaellee1019 michaellee1019 merged commit dfb3e00 into viamrobotics:main May 16, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants