You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
catcli/README.md

457 lines
14 KiB
Markdown

6 years ago
# CATCLI
1 year ago
[![Tests Status](https://github.com/deadc0de6/catcli/workflows/tests/badge.svg?branch=master)](https://github.com/deadc0de6/catcli/actions)
6 years ago
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)
4 months ago
[![Coverage](https://codecov.io/gh/deadc0de6/catcli/graph/badge.svg?token=t5dF7UL7K1)](https://codecov.io/gh/deadc0de6/catcli)
2 years ago
6 years ago
[![PyPI version](https://badge.fury.io/py/catcli.svg)](https://badge.fury.io/py/catcli)
[![AUR](https://img.shields.io/aur/version/catcli-git.svg)](https://aur.archlinux.org/packages/catcli-git)
6 years ago
[![Python](https://img.shields.io/pypi/pyversions/catcli.svg)](https://pypi.python.org/pypi/catcli)
6 years ago
3 years ago
[![Donate](https://img.shields.io/badge/donate-KoFi-blue.svg)](https://ko-fi.com/deadc0de6)
6 years ago
*The command line catalog tool for your offline data*
2 months ago
> [!WARNING]
> catcli has been superseded by [gocatcli](https://github.com/deadc0de6/gocatcli/)
> which provides all features of catcli and more...
6 years ago
Did you ever wanted to find back that specific file that should be on one of your
5 years ago
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?
[Catcli](https://github.com/deadc0de6/catcli) indexes external media
in a catalog file and allows to quickly find specific files or even navigate in the
6 years ago
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`
1 year ago
* Support for fuse to mount the indexed data as a virtual filesystem
6 years ago
* Handle archive files (zip, tar, ...) and index their content
6 years ago
* Save catalog to json for easy versioning with git
* Command line interface FTW
5 years ago
* Store files and directories sizes
6 years ago
* Store md5 hash of files
5 years ago
* Ability to update the catalog
* Support for `fzf` for finding files
5 years ago
* Tag your different storages with additional information
2 years ago
* Export catalog to CSV
6 years ago
6 years ago
<a href="https://asciinema.org/a/hRE22qbVtBGxOM1yxw2y4fBy8"><img src="https://asciinema.org/a/hRE22qbVtBGxOM1yxw2y4fBy8.png" width="50%" height="50%"></a>
6 years ago
Quick start:
```bash
6 years ago
# install catcli with pip
pip3 install catcli --user
6 years ago
# index a directory in the catalog
4 years ago
catcli index --meta='some description' log /var/log
6 years ago
# display the content
2 years ago
catcli ls -r
6 years ago
# navigate
catcli ls log
5 years ago
# find files/directories named '*log*'
6 years ago
catcli find log
4 months ago
# show directories sizes
catcli du log
6 years ago
```
6 years ago
see [usage](#usage) for specific info
6 years ago
5 years ago
## Why catcli?
6 years ago
[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.
6 years ago
Catcli can just as easily index any arbitrary directories.
5 years ago
See the [examples](#examples) for an overview of the available features.
6 years ago
---
**Table of Contents**
* [Installation](#installation)
* [Usage](#usage)
* [Index data](#index-data)
* [Index archive files](#index-archive-files)
6 years ago
* [Walk indexed files with ls](#walk-indexed-files-with-ls)
* [Find files](#find-files)
1 year ago
* [Mount catalog](#mount-catalog)
2 years ago
* [Display entire hierarchy](#display-entire-hierarchy)
4 months ago
* [Disk usage](#disk-usage)
6 years ago
* [Catalog graph](#catalog-graph)
6 years ago
* [Edit storage](#edit-storage)
6 years ago
* [Update catalog](#update-catalog)
* [CSV format](#csv-format)
6 years ago
* [Examples](#examples)
6 years ago
* [Contribution](#contribution)
2 years ago
* [Thank you](#thank-you)
6 years ago
# Installation
2 years ago
Install from Pypi
```bash
$ pip3 install catcli --user
```
Or from github directly
6 years ago
```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
$ pip3 install -r requirements.txt --user
6 years ago
$ python3 -m catcli.catcli --help
```
or install it in a virtualenv
```bash
$ cd /tmp; git clone https://github.com/deadc0de6/catcli && cd catcli
$ virtualenv -p python3 env
6 years ago
$ source env/bin/activate
$ python setup.py install
$ catcli --help
```
Catcli is also available on aur: https://aur.archlinux.org/packages/catcli-git/
6 years ago
# 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.
6 years ago
Five different types of entry are present in a catalog:
6 years ago
2 years ago
* **top node**: this is the root of the hierarchy
5 years ago
* **storage node**: this represents an indexed storage (a DVD, an external
hard drive, an USB drive, some arbitrary directory, etc).
* **dir node**: this is a directory
* **file node**: this is a file
* **archive node**: this is a file contained in an archive (tar, zip, etc)
6 years ago
3 months ago
Following environment variables are supported:
* `CATCLI_CATALOG_PATH`: define the catalog path (`--catalog=<path>`)
* `CATCLI_NO_BANNER`: disable the banner (`--no-banner`)
* `CATCLI_VERBOSE`: enable verbose mode (`--verbose`)
* `CATCLI_FORMAT`: define the output format (`-F --format=<fmt>`)
6 years ago
## 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
4 years ago
$ catcli index --meta=<some-description> <short-name> /media/mnt
6 years ago
```
6 years ago
If not specified otherwise (with the switch `--catalog`), the catalog is saved in the current
6 years ago
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`.
Using the `-a --archive` switch allows to also index archive files as explained
6 years ago
[below](#index-archive-files).
6 years ago
## Index archive files
Catcli is able to index and explore the content of archive files.
5 years ago
Following archive formats are supported: *tar*, *tar.gz*, *tar.xz*, *lzma*, *tar.bz2*, *zip*.
Catcli is also able to find files within indexed archive files.
See the [archive example](#archive-example) for more.
6 years ago
## Walk indexed files with ls
A catalog can be walked using the command `ls` as if the media
5 years ago
is mounted (File/directories separator is `/`).
6 years ago
```bash
$ catcli ls tmp/a/b/c
```
5 years ago
Resulting files can be sorted by size using `-S --sortsize`.
See the [examples](#examples) for more.
6 years ago
## Find files
Files and directories can be found based on their names
using the `find` command.
`Find` support two formats that allow to use `fzf` for
searching:
* `--format=fzf-native`: display the result in native format
* `--format=fzf-csv`: display the result in csv
5 years ago
See the [examples](#examples) for more.
6 years ago
1 year ago
## Mount catalog
The catalog can be mounted with [fuse](https://www.kernel.org/doc/html/next/filesystems/fuse.html)
and navigate like any filesystem.
```bash
$ mkdir /tmp/mnt
$ catcli index -c github .github
$ catcli mount /tmp/mnt
$ ls -laR /tmp/mnt
drwxrwxrwx - user 8 Mar 22:08 github
mnt/github:
.rwxrwxrwx 17 user 19 Oct 2022 FUNDING.yml
drwxrwxrwx - user 2 Mar 10:15 workflows
mnt/github/workflows:
.rwxrwxrwx 691 user 19 Oct 2022 pypi-release.yml
.rwxrwxrwx 635 user 8 Mar 21:08 testing.yml
```
2 years ago
## Display entire hierarchy
6 years ago
2 years ago
The entire catalog can be shown using the `ls -r` command.
5 years ago
Resulting files can be sorted by size using the `-S --sortsize` switch.
6 years ago
5 years ago
See the [examples](#examples) for more.
6 years ago
4 months ago
## Disk usage
You can get the disk usage with the `du` command.
Resulting files can be sorted by size using the `-S --sortsize` switch.
6 years ago
## 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
```
6 years ago
## Edit storage
5 years ago
Storage entry can be edited with following catcli commands:
6 years ago
* `rename` - rename the storage
* `edit` - edit storage metadata
6 years ago
## Update catalog
The catalog can be updated with the `update` command.
Updates are based on the access time of each of the files and on the
hash checksum if present (catalog was indexed with `-c --hash` and
`update` is called with the switch `-c --hash`).
6 years ago
## CSV format
2 years ago
Results can be printed to CSV using `--format=csv`.
2 years ago
Fields are separated by a comma (`,`) and are quoted with double quotes (`"`).
2 years ago
Each line contains the following fields:
2 years ago
* **name**: the entry name
2 years ago
* **type**: the entry type (file, directory, storage, etc)
2 years ago
* **path**: the entry path
* **size**: the entry size
* **indexed_at**: when this entry was indexed
* **maccess**: the entry modification date/time
* **md5**: the entry checksum (if any)
1 year ago
* **nbfiles**: the number of children (empty for nodes that are not storage or directory)
2 years ago
* **free_space**: free space (empty for not storage nodes)
* **total_space**: total space (empty for not storage nodes)
* **meta**: meta information (empty for not storage nodes)
2 years ago
6 years ago
# Examples
6 years ago
5 years ago
## Simple example
6 years ago
Let's first create some files and directories:
5 years ago
6 years ago
```bash
$ mkdir -p /tmp/test/{a,b,c}
5 years ago
$ echo 'something in files in a' > /tmp/test/a/{1,2,3}
$ echo 'something else in files in b' > /tmp/test/b/{4,5,6}
$ echo 'some bytes' > /tmp/test/c/{7,8,9}
$ tree /tmp/test
/tmp/test
├── a
│   ├── 1
│   ├── 2
│   └── 3
├── b
│   ├── 4
│   ├── 5
│   └── 6
└── c
├── 7
├── 8
└── 9
3 directories, 9 files
6 years ago
```
5 years ago
First this directory is indexed with `catcli` as if it was some kind of
6 years ago
external storage:
5 years ago
6 years ago
```bash
$ catcli index --meta='my test directory' tmptest /tmp/test
6 years ago
```
5 years ago
Catcli creates its catalog file in the current directory as `catcli.catalog`.
6 years ago
2 years ago
Printing the entire catalog as a tree is done with the command `ls -r`
5 years ago
```
2 years ago
$ catcli ls -r
6 years ago
top
5 years ago
└── storage: tmptest (my test directory) (nbfiles:3, free:3.7G/3.7G, date:2019-01-26 19:59:47)
├── a [nbfiles:3, totsize:72]
│ ├── 1 [size:24]
│ ├── 2 [size:24]
│ └── 3 [size:24]
├── b [nbfiles:3, totsize:87]
│ ├── 4 [size:29]
│ ├── 5 [size:29]
│ └── 6 [size:29]
└── c [nbfiles:3, totsize:33]
├── 7 [size:11]
├── 8 [size:11]
└── 9 [size:11]
6 years ago
```
The catalog can be walked with `ls` as if it was a normal directory
5 years ago
```
6 years ago
$ catcli ls
top
5 years ago
- storage: tmptest (my test directory) (nbfiles:3, free:3.7G/3.7G, date:2019-01-26 19:59:47)
6 years ago
$ catcli ls tmptest
5 years ago
storage: tmptest (my test directory) (nbfiles:3, free:3.7G/3.7G, date:2019-01-26 19:59:47)
- a [nbfiles:3, totsize:72]
- b [nbfiles:3, totsize:87]
- c [nbfiles:3, totsize:33]
6 years ago
$ catcli ls tmptest/b
5 years ago
b [nbfiles:3, totsize:87]
- 4 [size:29]
- 5 [size:29]
- 6 [size:29]
6 years ago
```
And files can be found using the command `find`
5 years ago
6 years ago
```bash
$ catcli find 9
5 years ago
c/9 [size:11, storage:tmptest]
6 years ago
```
5 years ago
When using the `-b --script` switch, a one-liner is generated
6 years ago
that allows to handle the found file(s)
5 years ago
```
$ catcli find 9 --script
5 years ago
c/9 [size:11, storage:tmptest]
op=file; source=/media/mnt; $op ${source}/c/9
6 years ago
```
6 years ago
## Archive example
Let's consider a directory containing archive files:
5 years ago
```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
5 years ago
```bash
$ catcli index -au some-name /tmp/catcli
```
Then any command can be used to explore the catalog as for normal
5 years ago
files but, by providing the `-a --archive` switch, archive content are displayed.
```bash
6 years ago
$ catcli ls some-name
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]
```
6 years ago
# 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.
3 years ago
# Thank you
If you like catcli, [buy me a coffee](https://ko-fi.com/deadc0de6).
6 years ago
# License
This project is licensed under the terms of the GPLv3 license.