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.
To play around with the actual tree command, you will need to install it within your virtual machine:
sudo apt update
sudo apt install treeWhile 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]- Put your code into
pytree.py pytesttests 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
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
pep8If you want to try running these locally:
- Install Docker (follow the "Ubuntu Xenial 16.04 (LTS)" instructions)
- Run the Code Climate CLI.
Note that this is advanced, so don't worry if you have trouble getting it running.