2
1
mirror of https://github.com/deadc0de6/catcli synced 2024-11-15 18:14:01 +00:00
catcli/README.md

358 lines
10 KiB
Markdown
Raw Normal View History

2017-12-14 18:37:31 +00:00
# CATCLI
2017-12-14 18:48:52 +00:00
[![Build Status](https://travis-ci.org/deadc0de6/catcli.svg?branch=master)](https://travis-ci.org/deadc0de6/catcli)
2017-12-14 18:37:31 +00:00
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)
2017-12-14 18:56:46 +00:00
[![Coverage Status](https://coveralls.io/repos/github/deadc0de6/catcli/badge.svg?branch=master)](https://coveralls.io/github/deadc0de6/catcli?branch=master)
2017-12-14 21:46:49 +00:00
[![PyPI version](https://badge.fury.io/py/catcli.svg)](https://badge.fury.io/py/catcli)
2017-12-14 21:47:34 +00:00
[![Python](https://img.shields.io/pypi/pyversions/catcli.svg)](https://pypi.python.org/pypi/catcli)
2017-12-14 18:37:31 +00:00
*The command line catalog tool for your offline data*
Did you ever wanted to find back that specific file that should be on one of your
backup DVDs or one of your external hard drives ? You usually go through all
of them hoping to find the right one on the first try ?
Well [catcli](https://github.com/deadc0de6/catcli) indexes external media
in a catalog and allows to quickly find specific files or even navigate in the
catalog of indexed files while these are not connected to your host.
Features:
* Index any directories in a catalog
* Ability to search for files by name in the catalog
* Ability to navigate through indexed data à la `ls`
2017-12-22 09:36:51 +00:00
* Handle archive files (zip, tar, ...) and index their content
2017-12-14 18:37:31 +00:00
* Save catalog to json for easy versioning with git
* Command line interface FTW
* Store files and folders sizes
* Store md5 hash of files
2017-12-17 07:51:51 +00:00
<a href="https://asciinema.org/a/hRE22qbVtBGxOM1yxw2y4fBy8"><img src="https://asciinema.org/a/hRE22qbVtBGxOM1yxw2y4fBy8.png" width="50%" height="50%"></a>
2017-12-14 18:37:31 +00:00
Quick start:
```bash
2017-12-15 23:01:22 +00:00
# install catcli with pip
sudo pip3 install catcli
2017-12-14 18:37:31 +00:00
# index a directory in the catalog
catcli index -u --meta='some description' log /var/log
# display the content
catcli tree
# navigate
catcli ls log
# find files/folders named '*log*'
catcli find log
```
2017-12-17 07:52:28 +00:00
see [usage](#usage) for specific info
2017-12-14 18:37:31 +00:00
## Why catcli ?
2017-12-14 19:27:13 +00:00
[Catcli](https://github.com/deadc0de6/catcli) gives the ability to navigate,
explore and find your files that are stored on external media
(DVDs, hard drives, USB sticks, etc) when those are not connected.
2017-12-14 18:37:31 +00:00
Catcli can just as easily index any arbitrary directories.
See the [example](#example) for an overview of the available features.
---
**Table of Contents**
* [Installation](#installation)
* [Usage](#usage)
* [Index data](#index-data)
2017-12-20 08:31:40 +00:00
* [Index archive files](#index-archive-files)
2017-12-14 18:37:31 +00:00
* [Walk indexed files with ls](#walk-indexed-files-with-ls)
* [Find files](#find-files)
* [Display entire tree](#display-entire-tree)
2017-12-15 09:28:53 +00:00
* [Catalog graph](#catalog-graph)
2017-12-17 16:02:09 +00:00
* [Edit storage](#edit-storage)
2017-12-17 15:31:30 +00:00
2017-12-20 10:34:29 +00:00
* [Examples](#examples)
2017-12-14 18:37:31 +00:00
* [Contribution](#contribution)
# Installation
2017-12-14 21:32:07 +00:00
To install run:
```bash
$ sudo pip3 install catcli
```
Or from github directly
2017-12-14 18:37:31 +00:00
```bash
$ cd /tmp; git clone https://github.com/deadc0de6/catcli && cd catcli
$ sudo python3 setup.py install
$ catcli --help
```
To work with catcli without installing it, you can do the following
```bash
$ cd /tmp; git clone https://github.com/deadc0de6/catcli && cd catcli
2017-12-14 19:30:06 +00:00
$ sudo pip3 install -r requirements.txt
2017-12-14 18:37:31 +00:00
$ python3 -m catcli.catcli --help
```
or install it in a virtualenv
```bash
$ cd /tmp; git clone https://github.com/deadc0de6/catcli && cd catcli
2017-12-15 12:28:28 +00:00
$ virtualenv -p python3 env
2017-12-14 18:37:31 +00:00
$ source env/bin/activate
$ python setup.py install
$ catcli --help
```
# Usage
Each indexed directory is stored in the catalog. Multiple directories can be indexed
and they are all available through the command line interface of catcli.
2017-12-22 09:36:51 +00:00
Five different types of entry are present in a catalog:
2017-12-14 18:37:31 +00:00
* *top node*: this is the root of the tree
* *storage node*: this represents some indexed storage (a DVD, an external
hard drive, an USB drive, some arbitrary directory, ...)
* *dir node*: this is a directory
* *file node*: this is a file
2017-12-22 09:36:51 +00:00
* *archive node*: this is a file contained in an archive
2017-12-14 18:37:31 +00:00
## Index data
Let's say the DVD or external hard drive that needs to be indexed
is mounted on `/media/mnt`. The following command
will index the entire directory `/media/mnt`
and store that in your catalog under the name `<short-name>`.
```bash
$ catcli index --meta=<some-description> -u <short-name> /media/mnt
```
2017-12-15 23:01:22 +00:00
If not specified otherwise (with the switch `--catalog`), the catalog is saved in the current
2017-12-14 18:37:31 +00:00
directory under `catcli.catalog`.
The `--meta` switch allows to add any additional information to store along in
the catalog like for example `the blue disk in my office`.
2017-12-14 19:27:13 +00:00
The `-u` switch tells catcli to also store (and calculate) the total size
2017-12-22 09:36:51 +00:00
of each directory. Using the `-a` switch allows to also index archive files as explained
[below](#index-archive-files).
2017-12-14 18:37:31 +00:00
2017-12-20 08:31:40 +00:00
## Index archive files
Catcli is able to index and explore the content of archive files.
2017-12-20 10:34:29 +00:00
Following archive formats are supported: tar, tar.gz, tar.xz, lzma, tar.bz2, zip.
Also catcli is able to find files within indexed archive files.
2017-12-20 08:31:40 +00:00
See the [archive example](#archive-example) for more.
2017-12-14 18:37:31 +00:00
## Walk indexed files with ls
2017-12-14 19:27:13 +00:00
A catalog can be walked using the command `ls` as if the media
2017-12-14 18:37:31 +00:00
was mounted.
File/folder separator is `/`
```bash
$ catcli ls tmp/a/b/c
```
2017-12-17 16:02:09 +00:00
Resulting files can be sorted by size using `-S`.
2017-12-14 18:37:31 +00:00
See the [example](#example) for more.
## Find files
2017-12-14 19:27:13 +00:00
Files and directories can be found based on their names
using the `find` command.
2017-12-14 18:37:31 +00:00
See the [example](#example) for more.
## Display entire tree
The entire catalog can be shown using the `tree` command.
2017-12-17 16:02:09 +00:00
Resulting files can be sorted by size using `-S`.
2017-12-14 18:37:31 +00:00
See the [example](#example) for more.
2017-12-15 09:28:53 +00:00
## Catalog graph
The catalog can be exported in a dot file that can be used to
generate a graph of the indexed files.
```bash
$ catcli graph
dot file created under "/tmp/catcli.dot"
create graph with "dot /tmp/catcli.dot -T png -o /tmp/tree.png" (you need graphviz)
$ dot /tmp/catcli.dot -T png -o /tmp/tree.png
```
2017-12-17 16:02:09 +00:00
## Edit storage
Storage entry can be edited with
* `rename` - rename the storage
* `edit` - edit storage metadata
2017-12-20 10:34:29 +00:00
# Examples
2017-12-14 18:37:31 +00:00
2017-12-20 10:34:29 +00:00
## Example
2017-12-14 18:37:31 +00:00
Let's first create some files and directories:
```bash
$ mkdir -p /tmp/test/{a,b,c}
$ touch /tmp/test/a/{1,2,3}
$ touch /tmp/test/b/{4,5,6}
$ touch /tmp/test/c/{7,8,9}
$ ls -R /tmp/test
/tmp/test:
a b c
/tmp/test/a:
1 2 3
/tmp/test/b:
4 5 6
/tmp/test/c:
7 8 9
```
First this directory is indexed by catcli as if it was some kind of
external storage:
```bash
$ catcli index --meta='my test directory' -u tmptest /tmp/test
```
2017-12-15 23:01:22 +00:00
Catcli has created its catalog file in the current directory as `catcli.catalog`.
2017-12-14 18:37:31 +00:00
Printing the entire catalog as a tree is done with the command `tree`
2017-12-14 19:27:13 +00:00
```
2017-12-14 18:37:31 +00:00
$ catcli tree
top
└── storage: tmptest (free:183.7G, total:200.0G) (my test directory)
├── b [nbfiles:3]
│ ├── 4 [size:0]
│ ├── 5 [size:0]
│ └── 6 [size:0]
├── a [nbfiles:3]
│ ├── 1 [size:0]
│ ├── 3 [size:0]
│ └── 2 [size:0]
└── c [nbfiles:3]
├── 7 [size:0]
├── 8 [size:0]
└── 9 [size:0]
```
The catalog can be walked with `ls` as if it was a normal directory
2017-12-14 19:27:13 +00:00
```
2017-12-14 18:37:31 +00:00
$ catcli ls
top
- storage: tmptest (free:2.6G, total:2.6G) (my test directory)
$ catcli ls tmptest
storage: tmptest (free:3.7G, total:3.7G) (my test directory)
- a [nbfiles:3]
- b [nbfiles:3]
- c [nbfiles:3]
$ catcli ls tmptest/b
b [nbfiles:3]
- 4 [size:0]
- 5 [size:0]
- 6 [size:0]
```
And files can be found using the command `find`
```bash
$ catcli find 9
test/c/9 [size:0]
```
2017-12-17 15:31:30 +00:00
When using the `--script` switch, a one-liner is generated
2017-12-14 18:37:31 +00:00
that allows to handle the found file(s)
```bash
2017-12-17 15:31:30 +00:00
$ catcli find 9 --script
2017-12-14 18:37:31 +00:00
test/c/9 [size:0]
op=file; source=/media/mnt; $op ${source}/test/c/9
```
2017-12-20 10:34:29 +00:00
## Archive example
2017-12-20 08:31:40 +00:00
Let's consider a directory containing archive files:
```bash
$ ls -1 /tmp/catcli
catcli-0.3.1
v0.3.1.tar.gz
v0.3.1.zip
```
To enable the indexing of archive contents use
the `-a --archive` switch
```bash
$ catcli index -au some-name /tmp/catcli
Indexed 26 file(s) in 0:00:00.004533
```
Then any command can be used to explore the catalog as for normal
2017-12-22 09:36:51 +00:00
files but, by providing the `-a` switch, archive content are displayed.
2017-12-20 08:31:40 +00:00
```bash
2017-12-22 09:36:51 +00:00
$ catcli ls some-name
2017-12-20 08:31:40 +00:00
storage: some-name (free:800G, total:1T)
- catcli-0.3.1 [nbfiles:11, totsize:80.5K]
- v0.3.1.tar.gz [size:24.2K]
- v0.3.1.zip [size:31.2K]
$ catcli ls -r some-name/v0.3.1.zip
v0.3.1.zip [size:31.2K]
$ catcli ls -ar some-name/v0.3.1.zip
v0.3.1.zip [size:31.2K]
├── catcli-0.3.1 [archive:v0.3.1.zip]
│ ├── catcli [archive:v0.3.1.zip]
│ │ ├── __init__.py [archive:v0.3.1.zip]
│ │ ├── catalog.py [archive:v0.3.1.zip]
│ │ ├── catcli.py [archive:v0.3.1.zip]
│ │ ├── logger.py [archive:v0.3.1.zip]
│ │ ├── noder.py [archive:v0.3.1.zip]
│ │ ├── utils.py [archive:v0.3.1.zip]
│ │ └── walker.py [archive:v0.3.1.zip]
│ ├── .gitignore [archive:v0.3.1.zip]
│ ├── LICENSE [archive:v0.3.1.zip]
│ ├── MANIFEST.in [archive:v0.3.1.zip]
│ ├── README.md [archive:v0.3.1.zip]
│ ├── requirements.txt [archive:v0.3.1.zip]
│ ├── setup.cfg [archive:v0.3.1.zip]
│ ├── setup.py [archive:v0.3.1.zip]
│ ├── tests [archive:v0.3.1.zip]
│ │ ├── __init__.py [archive:v0.3.1.zip]
│ │ ├── helpers.py [archive:v0.3.1.zip]
│ │ ├── test_find.py [archive:v0.3.1.zip]
│ │ ├── test_graph.py [archive:v0.3.1.zip]
│ │ ├── test_index.py [archive:v0.3.1.zip]
│ │ ├── test_ls.py [archive:v0.3.1.zip]
│ │ ├── test_rm.py [archive:v0.3.1.zip]
│ │ └── test_tree.py [archive:v0.3.1.zip]
│ ├── tests.sh [archive:v0.3.1.zip]
│ └── .travis.yml [archive:v0.3.1.zip]
└── catcli-0.3.1/ [archive:v0.3.1.zip]
```
2017-12-22 09:36:51 +00:00
All commands can also handle archive file (like `tree` or `find`).
2017-12-14 18:37:31 +00:00
# Contribution
If you are having trouble installing or using catcli, open an issue.
If you want to contribute, feel free to do a PR (please follow PEP8).
The `tests.sh` script can be run to check the code.
# License
This project is licensed under the terms of the GPLv3 license.