Created
June 15, 2011 18:38
-
-
Save pydanny/1027781 to your computer and use it in GitHub Desktop.
The eggshell code sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ Note - I make this simple because complex shell tools are hard to code | |
| and harder to document. Inspired by Kenneth Reitz's Requests library. """ | |
| from eggshell import shell | |
| # Get the location of this script | |
| shell.pwd | |
| # Get the contents of this directory | |
| directory = shell.ls(shell.pwd) | |
| # What is the absolute path of this directory? | |
| print(directory.path) | |
| # What is the return code of this command? | |
| print(directory.status_code) | |
| # Show me the contents | |
| print(directory.content) | |
| # Loop through the results | |
| for f in directory: | |
| f.name # name of the file | |
| f.path # path of the file | |
| f.permissions | |
| f.open() # Uses the file command on the object | |
| # How about grep? | |
| results = shell.grep(string='pydanny', path=shell.pwd) | |
| print(results.path) | |
| print(results.status_code) | |
| print(results.content) | |
| for result in results: | |
| f.name # name of the file | |
| f.path # path of the file | |
| f.permissions | |
| f.open() # Uses the file command on the object | |
| f.line_number # displays the line number | |
| # Lets make the sphinx docs for this project | |
| sphinx_dir = shell.join(shell.pwd, "docs") | |
| result = shell.run(sphinx_dir + "make html") | |
| print(result.status_code) | |
| print(result.content) | |
| # cd is an illegal command! | |
| # We only care about absolute paths and don't want to handle location changes | |
| # as that will add complexity to code and tests. | |
| shell.cd() # Illegal command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment