Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Flags #17

Merged
merged 1 commit into from
Mar 2, 2016
Merged

Flags #17

merged 1 commit into from
Mar 2, 2016

Conversation

maruel
Copy link
Contributor

@maruel maruel commented Feb 18, 2016

If you want, you can merge this one instead of #16, as this merge request includes both.

Please try it locally first. I tried almost all commands on adb_debug.py and a few commands on fastboot_debug.py; getvar all and continue, as I didn't want to flash the device I was playing it. At least I confirmed I can access the device via --port_path in fastboot_debug.py.

This PR will remove the conflict in luci/python-adb about stripping gflags; this will ease the upstreaming process.

I made "./adb_debug.py list /path" output in a nice way as a bonus. I removed 'stat' since it was not very user-friendly.

The subparsers are still a bit too clever to my taste but if I hadn't done that, the code length would have exploded. At least the proposed design makes the help pages much more pleasant to read.

@fahhem
Copy link
Contributor

fahhem commented Feb 18, 2016

Can you remove the 'Revert doc change ...' commit from this?

maxsize = max(len(str(f.size)) for f in files)
for f in files:
mode = (
('d' if stat.S_ISDIR(f.mode) else '-') +
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a stat.filemode function in Python 3.3+ :(

@maruel maruel force-pushed the flags branch 2 times, most recently from f85d3ed to 397b762 Compare February 19, 2016 00:29
@maruel
Copy link
Contributor Author

maruel commented Feb 19, 2016

I made it magical. I hope I get bonus points! :)

Please test before merging. I did test it (and fixed adb_test.py) but I'd prefer to have a second check before getting this committed.

@maruel
Copy link
Contributor Author

maruel commented Feb 23, 2016

Ping, as I have another PR immediately following but I want to base the other PR on this one.



def Logcat(self, *options):
return adb_commands.AdbCommands.StreamingShell(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this quoting absolutely necessary? If they put such characters into the shell interface, they're ruining their own system. If someone is taking raw inputs and passing it to adb or python-adb, they're in trouble with or without this

Copy link
Contributor

Choose a reason for hiding this comment

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

Same with Shell

Copy link
Contributor

Choose a reason for hiding this comment

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

If you want it to stay, replace the doc line with functools.wraps

@fahhem
Copy link
Contributor

fahhem commented Feb 23, 2016

Sorry, I'm OOO at the moment so I can't do a more thorough review. I'm most interested in the arg parsing and if it's too complicated or not, so I'll be looking at that on Wednesday when I get back in

@maruel
Copy link
Contributor Author

maruel commented Feb 23, 2016

Ok thanks, I'll wait for your review.


@functools.wraps(adb_commands.AdbCommands.Logcat)
def Logcat(self, *options):
return adb_commands.AdbCommands.StreamingShell(
Copy link
Contributor

Choose a reason for hiding this comment

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

This and Shell don't do anything. Shell just renames StreamingShell, but that can be done in MakeSubparser

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are needed.
Shell() exists to adjust the docstring as it has to be different, there's no 'yield' concept at the CLI.
Logcat() -> it's really just to merge the outputs.

I looked at modifying MakeSubparser() to be smarter about merging remaining arguments but it's not trivial, at least not in a way that makes the code more opaque than doing the two functions.

The point here is that by doing too much magic, we're making the code less readable and less maintainable. Having these few adaptor functions actually helps readability compared to adding more magic inside common_cli.py, IMHO.

Copy link
Contributor

Choose a reason for hiding this comment

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

If shell just changes the docstring, then it should just call the other function directly so it's simpler. Logcat should also call to the existing Logcat, but with the joined options. I meant to only renamed StreamingShell to Shell in MakeSubparser, but if it's doing other things then never mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LogCat() is still needed because the *options makes MakeSubparser use argparse.REMAINDER. That's why I don't want to make the code too magical, it makes it much header to reason about it.

I did replace the StreamingShell() to Logcat() call. I also fixed it in adb_commands.py.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I meant to replace the inside of the function with a simpler call, not to remove it.

@fahhem
Copy link
Contributor

fahhem commented Feb 26, 2016

Almost there, sorry about all the changes. Thanks for the docstring stuff, though. It's hacky, but a lot less copied code. Maybe in the future we can remove docstring-parsing for something else?

@maruel
Copy link
Contributor Author

maruel commented Feb 26, 2016

Pushed new patchset

@fahhem
Copy link
Contributor

fahhem commented Mar 1, 2016

One last comment, sorry about the delay!

It is more appropriate for open source projects to use argparse.

Keep the 'clever' approach and uses the docstring on methods on
AdbCommands/FastbootCommands to generate the arguments on the parser. Override
the documentation only when it doesn't make sense, like when an argument can be
"object-like".

Update default fastboot packet size from 4kb to 1Mb.

Fix tests (adb_test.py was broken). Make them executable.
@fahhem
Copy link
Contributor

fahhem commented Mar 2, 2016

Sorry about the back-and-forth! Thank you!

fahhem added a commit that referenced this pull request Mar 2, 2016
Switch use of google-flags (gflags) to more standard argparse.

Keep the 'clever' approach and use the docstring on methods on
AdbCommands/FastbootCommands to generate the arguments on the parser. Override
the documentation only when it doesn't make sense, like when an argument can be
"object-like".

Update default fastboot packet size from 4kb to 1Mb.

Fix tests (adb_test.py was broken). Make them executable.
@fahhem fahhem merged commit f4bad87 into google:master Mar 2, 2016
@maruel maruel deleted the flags branch March 2, 2016 02:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants