Skip to content

Instantly share code, notes, and snippets.

@pydanny
Created June 15, 2011 18:38
Show Gist options
  • Select an option

  • Save pydanny/1027781 to your computer and use it in GitHub Desktop.

Select an option

Save pydanny/1027781 to your computer and use it in GitHub Desktop.
The eggshell code sample
""" 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