Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #45 from deadc0de6/features-42
Browse files Browse the repository at this point in the history
add features for #42
  • Loading branch information
deadc0de6 authored Jan 28, 2024
2 parents 3cf3031 + 6b9e00f commit 06a36c4
Show file tree
Hide file tree
Showing 33 changed files with 973 additions and 512 deletions.
7 changes: 7 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
coverage:
status:
project:
default:
target: 90%
threshold: 1%
patch: off
16 changes: 8 additions & 8 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: tests
on: [push, pull_request]
on: [push, pull_request, workflow_dispatch]
jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -21,9 +21,9 @@ jobs:
- name: Run tests
run: |
./tests.sh
- name: Coveralls
run: |
pip install coveralls
coveralls --service=github
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
files: coverage.xml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.pyc
.coverage
.coverage*
coverages/
coverage.xml
dist/
build/
*.egg-info/
Expand All @@ -9,3 +11,5 @@ build/
.mypy_cache
.pytest_cache
__pycache__
.pyre
.pytype
5 changes: 5 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[mypy]
strict = true
disable_error_code = import-untyped,import-not-found
ignore_missing_imports = True
warn_unused_ignores = False
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Tests Status](https://github.com/deadc0de6/catcli/workflows/tests/badge.svg?branch=master)](https://github.com/deadc0de6/catcli/actions)
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)
[![Coveralls](https://img.shields.io/coveralls/github/deadc0de6/catcli)](https://coveralls.io/github/deadc0de6/catcli?branch=master)
[![Coverage](https://codecov.io/gh/deadc0de6/catcli/graph/badge.svg?token=t5dF7UL7K1)](https://codecov.io/gh/deadc0de6/catcli)

[![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)
Expand Down Expand Up @@ -50,6 +50,8 @@ catcli ls -r
catcli ls log
# find files/directories named '*log*'
catcli find log
# show directories sizes
catcli du log
```

see [usage](#usage) for specific info
Expand All @@ -76,6 +78,7 @@ See the [examples](#examples) for an overview of the available features.
* [Find files](#find-files)
* [Mount catalog](#mount-catalog)
* [Display entire hierarchy](#display-entire-hierarchy)
* [Disk usage](#disk-usage)
* [Catalog graph](#catalog-graph)
* [Edit storage](#edit-storage)
* [Update catalog](#update-catalog)
Expand Down Expand Up @@ -148,9 +151,6 @@ 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`.

Catcli will calculate and store the total size of each node (directories, storages, etc)
unless the `-n --no-subsize` switch is used.

Using the `-a --archive` switch allows to also index archive files as explained
[below](#index-archive-files).

Expand Down Expand Up @@ -215,6 +215,11 @@ Resulting files can be sorted by size using the `-S --sortsize` switch.

See the [examples](#examples) for more.

## Disk usage

You can get the disk usage with the `du` command.
Resulting files can be sorted by size using the `-S --sortsize` switch.

## Catalog graph

The catalog can be exported in a dot file that can be used to
Expand Down
21 changes: 9 additions & 12 deletions catcli/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import os
from typing import Optional, List, Dict, Tuple, Union, Any
from anytree.exporter import JsonExporter, DictExporter # type: ignore
from anytree.importer import JsonImporter # type: ignore
from anytree import AnyNode # type: ignore
from anytree.exporter import JsonExporter, DictExporter
from anytree.importer import JsonImporter
from anytree import AnyNode

# local imports
from catcli import nodes
Expand Down Expand Up @@ -96,14 +96,13 @@ def _save_json(self, top: NodeTop) -> bool:
def _restore_json(self, string: str) -> Optional[NodeTop]:
"""restore the tree from json"""
imp = JsonImporter(dictimporter=_DictImporter(debug=self.debug))
self._debug('import from string...')
root = imp.import_(string)
self._debug(f'Catalog imported from json \"{self.path}\"')
self._debug(f'root imported: {root}')
if root.type != nodes.TYPE_TOP:
return None
top = NodeTop(root.name, children=root.children)
self._debug(f'top imported: {top}')
self._debug(f'top imported: {top.name}')
return top


Expand All @@ -126,24 +125,22 @@ def __import(self, data: Union[str, Any],
assert "parent" not in data
attrs = dict(data)
# replace attr
attrs = back_attriter(attrs, debug=self.debug)
attrs = back_attriter(attrs)
children: Union[str, Any] = attrs.pop("children", [])
node = self.nodecls(parent=parent, **attrs)
for child in children:
self.__import(child, parent=node)
return node


def back_attriter(adict: Dict[str, str],
debug: bool = False) -> Dict[str, str]:
def back_attriter(adict: Dict[str, str]) -> Dict[str, str]:
"""replace attribute on json restore"""
attrs = {}
for k, val in adict.items():
newk = k
if k == 'size':
if debug:
Logger.debug(f'changing {k}={val}')
k = 'nodesize'
attrs[k] = val
newk = 'nodesize'
attrs[newk] = val
return attrs


Expand Down
Loading

0 comments on commit 06a36c4

Please sign in to comment.