Skip to content

nishkumar/tree

 
 

Repository files navigation

Tree

Tree is a recursive directory listing command that produces a depth indented listing of files

This assignment is to re-create the tree command, using Python.

Functionality

To play around with the actual tree command, you will need to install it within your virtual machine:

sudo apt update
sudo apt install tree

While the actual tree command accepts a bunch of optional flags/options, we are only going to worry about the basic use cases:

  • Passing in a path as the first/only argument

    $ tree examples/simple/
    examples/simple/
    ├── another
    ├── bites
    │   ├── dust
    │   │   └── dot.jpg
    │   └── the
    └── one.txt
    
    2 directories, 4 files
    
  • Not passing in any arguments, which will display the contents of the working directory

    $ cd examples/simple/
    $ tree
    .
    ├── another
    ├── bites
    │   ├── dust
    │   │   └── dot.jpg
    │   └── the
    └── one.txt
    
    2 directories, 4 files
    

Your script should produce identical output, but run with

./pytree.py [path]
# which is equivalent to
python3 pytree.py [path]

Requirements

  • Put your code into pytree.py
  • pytest tests passing (90% total)
  • Code Climate checks passing (10%)
  • All of the logic must exist in Python. In other words, you may not use any of the following modules/functions:
    • os.popen()
    • os.spawn*()
    • os.system()
    • subprocess

Dealing with unicode

tree uses some unicode characters to create the layout and draw the lines. This includes non-breaking spaces (tested with tree v1.7.0), highlighted below:

non-breaking spaces

Working with unicode/encodings can be challenging, but in short, we recommend copying-and-pasting the special characters directly from the tree output in your terminal to strings in your Python script.

Running tests locally

Run the following from this directory:

# install dependencies
sudo apt update
sudo apt install tree
pip3 install -r requirements.txt
# run the pytests
pytest -v
# run the pep8 checks
pep8

Code Climate checks

If you want to try running these locally:

  1. Install Docker (follow the "Ubuntu Xenial 16.04 (LTS)" instructions)
  2. Run the Code Climate CLI.

Note that this is advanced, so don't worry if you have trouble getting it running.

About

Tree Assignment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%