pull/30/head
deadc0de6 1 year ago
parent e39088f6cb
commit e4cda7948c

@ -15,7 +15,6 @@ from typing import Dict, Any, List
from docopt import docopt from docopt import docopt
# local imports # local imports
from catcli import nodes
from catcli.version import __version__ as VERSION from catcli.version import __version__ as VERSION
from catcli.nodes import NodeTop, NodeAny from catcli.nodes import NodeTop, NodeAny
from catcli.logger import Logger from catcli.logger import Logger
@ -23,7 +22,7 @@ from catcli.colors import Colors
from catcli.catalog import Catalog from catcli.catalog import Catalog
from catcli.walker import Walker from catcli.walker import Walker
from catcli.noder import Noder from catcli.noder import Noder
from catcli.utils import ask, edit from catcli.utils import ask, edit, path_to_search_all
from catcli.fuser import Fuser from catcli.fuser import Fuser
from catcli.exceptions import BadFormatException, CatcliException from catcli.exceptions import BadFormatException, CatcliException
@ -31,8 +30,6 @@ NAME = 'catcli'
CUR = os.path.dirname(os.path.abspath(__file__)) CUR = os.path.dirname(os.path.abspath(__file__))
CATALOGPATH = f'{NAME}.catalog' CATALOGPATH = f'{NAME}.catalog'
GRAPHPATH = f'/tmp/{NAME}.dot' GRAPHPATH = f'/tmp/{NAME}.dot'
SEPARATOR = '/'
WILD = '*'
FORMATS = ['native', 'csv', 'csv-with-header', 'fzf-native', 'fzf-csv'] FORMATS = ['native', 'csv', 'csv-with-header', 'fzf-native', 'fzf-csv']
BANNER = f""" +-+-+-+-+-+-+ BANNER = f""" +-+-+-+-+-+-+
@ -168,22 +165,7 @@ def cmd_ls(args: Dict[str, Any],
noder: Noder, noder: Noder,
top: NodeTop) -> List[NodeAny]: top: NodeTop) -> List[NodeAny]:
"""ls action""" """ls action"""
path = args['<path>'] path = path_to_search_all(args['<path>'])
if not path:
path = SEPARATOR
if not path.startswith(SEPARATOR):
path = SEPARATOR + path
# prepend with top node path
pre = f'{SEPARATOR}{nodes.NAME_TOP}'
if not path.startswith(pre):
path = pre + path
# ensure ends with a separator
if not path.endswith(SEPARATOR):
path += SEPARATOR
# add wild card
if not path.endswith(WILD):
path += WILD
fmt = args['--format'] fmt = args['--format']
if fmt.startswith('fzf'): if fmt.startswith('fzf'):
raise BadFormatException('fzf is not supported in ls, use find') raise BadFormatException('fzf is not supported in ls, use find')

@ -15,6 +15,7 @@ import fuse # type: ignore
# local imports # local imports
from catcli.noder import Noder from catcli.noder import Noder
from catcli.nodes import NodeTop, NodeAny from catcli.nodes import NodeTop, NodeAny
from catcli.utils import path_to_search_all, path_to_top
from catcli import nodes from catcli import nodes
@ -25,10 +26,6 @@ fh = logging.FileHandler('/tmp/fuse-catcli.log')
fh.setLevel(logging.DEBUG) fh.setLevel(logging.DEBUG)
logger.addHandler(fh) logger.addHandler(fh)
# globals
WILD = '*'
SEPARATOR = '/'
class Fuser: class Fuser:
"""fuse filesystem mounter""" """fuse filesystem mounter"""
@ -58,9 +55,7 @@ class CatcliFilesystem(fuse.LoggingMixIn, fuse.Operations): # type: ignore
def _get_entry(self, path: str) -> Optional[NodeAny]: def _get_entry(self, path: str) -> Optional[NodeAny]:
"""return the node pointed by path""" """return the node pointed by path"""
pre = f'{SEPARATOR}{nodes.NAME_TOP}' path = path_to_top(path)
if not path.startswith(pre):
path = pre + path
found = self.noder.list(self.top, path, found = self.noder.list(self.top, path,
rec=False, rec=False,
fmt='native', fmt='native',
@ -71,13 +66,7 @@ class CatcliFilesystem(fuse.LoggingMixIn, fuse.Operations): # type: ignore
def _get_entries(self, path: str) -> List[NodeAny]: def _get_entries(self, path: str) -> List[NodeAny]:
"""return nodes pointed by path""" """return nodes pointed by path"""
pre = f'{SEPARATOR}{nodes.NAME_TOP}' path = path_to_search_all(path)
if not path.startswith(pre):
path = pre + path
if not path.endswith(SEPARATOR):
path += SEPARATOR
if not path.endswith(WILD):
path += WILD
found = self.noder.list(self.top, path, found = self.noder.list(self.top, path,
rec=False, rec=False,
fmt='native', fmt='native',
@ -89,27 +78,36 @@ class CatcliFilesystem(fuse.LoggingMixIn, fuse.Operations): # type: ignore
if not entry: if not entry:
return {} return {}
curt = time() maccess = time()
mode: Any = S_IFREG mode: Any = S_IFREG
size: int = 0
if entry.type == nodes.TYPE_ARCHIVED: if entry.type == nodes.TYPE_ARCHIVED:
mode = S_IFREG mode = S_IFREG
size = entry.size
elif entry.type == nodes.TYPE_DIR: elif entry.type == nodes.TYPE_DIR:
mode = S_IFDIR mode = S_IFDIR
size = entry.size
maccess = entry.maccess
elif entry.type == nodes.TYPE_FILE: elif entry.type == nodes.TYPE_FILE:
mode = S_IFREG mode = S_IFREG
size = entry.size
maccess = entry.maccess
elif entry.type == nodes.TYPE_STORAGE: elif entry.type == nodes.TYPE_STORAGE:
mode = S_IFDIR mode = S_IFDIR
size = entry.size
maccess = entry.ts
elif entry.type == nodes.TYPE_META: elif entry.type == nodes.TYPE_META:
mode = S_IFREG mode = S_IFREG
elif entry.type == nodes.TYPE_TOP: elif entry.type == nodes.TYPE_TOP:
mode = S_IFREG mode = S_IFREG
mode = mode | 0o777
return { return {
'st_mode': (mode), 'st_mode': (mode), # file type
'st_nlink': 1, 'st_nlink': 1, # count hard link
'st_size': 0, 'st_size': size,
'st_ctime': curt, 'st_ctime': maccess, # attr last modified
'st_mtime': curt, 'st_mtime': maccess, # content last modified
'st_atime': curt, 'st_atime': maccess, # access time
'st_uid': os.getuid(), 'st_uid': os.getuid(),
'st_gid': os.getgid(), 'st_gid': os.getgid(),
} }
@ -122,7 +120,7 @@ class CatcliFilesystem(fuse.LoggingMixIn, fuse.Operations): # type: ignore
# mountpoint # mountpoint
curt = time() curt = time()
meta = { meta = {
'st_mode': (S_IFDIR), 'st_mode': (S_IFDIR | 0o777),
'st_nlink': 1, 'st_nlink': 1,
'st_size': 0, 'st_size': 0,
'st_ctime': curt, 'st_ctime': curt,

@ -12,10 +12,40 @@ import subprocess
import datetime import datetime
# local imports # local imports
from catcli import nodes
from catcli.exceptions import CatcliException from catcli.exceptions import CatcliException
SEPARATOR = '/' SEPARATOR = '/'
WILD = '*'
def path_to_top(path: str) -> str:
"""path pivot under top"""
pre = f'{SEPARATOR}{nodes.NAME_TOP}'
if not path.startswith(pre):
# prepend with top node path
path = pre + path
return path
def path_to_search_all(path: str) -> str:
"""path to search for all subs"""
if not path:
path = SEPARATOR
if not path.startswith(SEPARATOR):
path = SEPARATOR + path
pre = f'{SEPARATOR}{nodes.NAME_TOP}'
if not path.startswith(pre):
# prepend with top node path
path = pre + path
if not path.endswith(SEPARATOR):
# ensure ends with a separator
path += SEPARATOR
if not path.endswith(WILD):
# add wild card
path += WILD
return path
def md5sum(path: str) -> str: def md5sum(path: str) -> str:

@ -11,7 +11,7 @@ set -e
# pycodestyle # pycodestyle
echo "[+] pycodestyle" echo "[+] pycodestyle"
pycodestyle --version pycodestyle --version
pycodestyle --ignore=W605 catcli/ pycodestyle catcli/
pycodestyle tests/ pycodestyle tests/
pycodestyle setup.py pycodestyle setup.py
@ -29,7 +29,6 @@ pyflakes setup.py
# R0915: Too many statements # R0915: Too many statements
# R0911: Too many return statements # R0911: Too many return statements
# R0903: Too few public methods # R0903: Too few public methods
# R0801: Similar lines in 2 files
# R0902: Too many instance attributes # R0902: Too many instance attributes
# R0201: no-self-used # R0201: no-self-used
echo "[+] pylint" echo "[+] pylint"
@ -41,24 +40,28 @@ pylint -sn \
--disable=R0915 \ --disable=R0915 \
--disable=R0911 \ --disable=R0911 \
--disable=R0903 \ --disable=R0903 \
--disable=R0801 \
--disable=R0902 \ --disable=R0902 \
--disable=R0201 \ --disable=R0201 \
--disable=R0022 \ --disable=R0022 \
catcli/ catcli/
# R0801: Similar lines in 2 files
# W0212: Access to a protected member
# R0914: Too many local variables
# R0915: Too many statements
pylint -sn \ pylint -sn \
--disable=R0801 \
--disable=W0212 \ --disable=W0212 \
--disable=R0914 \ --disable=R0914 \
--disable=R0915 \ --disable=R0915 \
--disable=R0801 \
tests/ tests/
pylint -sn setup.py pylint -sn setup.py
# mypy # mypy
echo "[+] mypy" echo "[+] mypy"
mypy \ mypy --strict catcli/
--strict \
catcli/
# unittest # unittest
echo "[+] unittests" echo "[+] unittests"

Loading…
Cancel
Save