Git Product home page Git Product logo

dirman's Introduction

Introduction

A CLI DIRectory MANagement tool written in Python 3.

Implementation

Overview

The objective is to provide a simple and intuitive command line interface, similar to a bash shell.

The prompt_toolkit library is used to manage the CLI experience, with features like history and selection through up/down arrows.

For visualization, the library rich was used to render the tree and drawing tables.

Commands strings are processed using an handler function, which given a function mapping, will call the function with the supplied arguments.

Data structures

The internal data structure used to represent directories and files is an N-ary tree. Nodes (see dirman/tree/TreeNode.py) can have multiple children, which, in turn, also can have many children. Nodes are added recursively from the root, following the directory path by traversing the tree.

The motivation to use a tree structure is to have a convenient way of storing and navigating the directories to access files. Tree are common and well known in computer science, allowing us to use algorithms like depth-first search (DFS) or breadth-first search (BFS). Another advantage is the ability to reuse nodes for nested directories.

An additional Trie data structure stores a copy of all file names. The main purpose of the Trie is to quickly filter files by their name, avoiding to expand the search to the entire directory tree. In fact, the search runtime complexity of the Trie is $O(L)$ where $L$ is the length of the longest matching name.

Capabilities

  • Adding directories or files:

    # Adding a directory
    > add dataset
    
    # Adding a file
    > add dataset/file.txt
  • View:

    > view

    Image

  • View with sort:

    • -sort_by: can sort by name, time, or size.
    • -r: add this option to reverse the sort.
    > view -sort_by name -r 

    Image

  • View directory:

    > view dataset

    Image

  • Filter:

    • --prefix: filter the files by prefix name (i.e. test*).
    • --type: filter the files by type (image, video, audio, text, application).
    • -gt: greater than n bytes.
    • -lt: less than n bytes.
    > filter dataset --prefix test --type text -gt 256 -lt 16384

    Image

  • delete:

    can delete files or directories.

    delete dataset

Additional commands

Thanks to prompt_toolkit, QOL features such as command history, and clear display are easily implemented.

  • clear: clears the terminal.

    > clear
  • history: shows the command history.

    > history
  • Rerun old command: the following command will rerun the command number 8 (as shown with history).

    > ! 8
  • help: shows the list of available commands.

    > help

Install dirman

It is recommended to create a virtual environment first.

Install the setup.py:

(venv) $ pip install -e .

Running dirman

Once installed, you can run dirman as CLI tool:

(venv) $ dirmancli

Tests

Unit testing is implemented using the pytest library. To run the tests:

(venv) $ python -m pytest tests

Some known issues

  • Folder size does not update when deleting subfolders.
  • Sorting only works running view with no arguments.
  • Incorrect error message when running filter with no results.
  • Empty folders are shown in tree view when files are filtered out.

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.