Giter Site home page Giter Site logo

tree's Introduction

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.

tree's People

Contributors

afeld avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

tree's Issues

handle weird unicode space issues

Basically, figure out the best way to prevent all the hassles encountered in 79f180f. Ideas:

  • Hard-code the tree output in the tests (rather than calling out to the actual tree command), but with cleaned-up spaces
  • Make the testing more flexible (e.g. check the number of characters of indentation, rather than the literal characters)
  • Have the tests normalize the spaces before doing the assertions (i.e. convert all the unicode spaces in both the expected and actual to normal spaces)

The third option sounds most promising to me, but I'm open to ideas. @AKSHAYUBHAT Mind taking a crack at it?

/cc @ebk46

Open

	d10:created by29:frostwire 2.2.8 build 100057413:creation datei1637662047e4:infod6:lengthi61197e4:name62:Add a website property - Search Console Help20211123023453.rar12:piece lengthi16384e6:pieces80:1'����(�����T�V���=�4������e"���iU�

�EK�e�n���%�T^�IT������W������������r��eed10:created by29:frostwire 2.2.8 build 100057413:creation datei1637662047e4:infod6:lengthi61197e4:name62:Add a website property - Search Console Help20211123023453.rar12:piece lengthi16384e6:pieces80:1'����(�����T�V���=�4������e"���iU�
�EK�e�n���%�T^�IT������W������������r��ee

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.