Skip to content

Commit

Permalink
Merge branch 'v0.5.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
trisongz committed Oct 17, 2023
2 parents ce8a24e + 8dd9857 commit 04aa070
Show file tree
Hide file tree
Showing 81 changed files with 6,498 additions and 1,280 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ tests/*

validation/private_*
!validation/
fileio/providers/hffs/*
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
recursive-include fileio *
recursive-exclude * __pycache__
recursive-exclude * *.py[co]
63 changes: 52 additions & 11 deletions fileio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,62 @@
from __future__ import absolute_import
# from __future__ import absolute_import

import os
from fileio import types
# from . import types
from .lib.base import pathlib
from .types import (
PathLike,
FileInfo,
PreparedFile,
ParsedFile,
)

from fileio.core.imports import pathlib
from fileio.core.generic import *
from .lib.types import (
File,
FileLike,
FileType,
FileListType,
FileSysLike,
)

from fileio.core import flavours
from fileio.core import base
from fileio.core import generic
# from .types import (
# File,
# FileLike,
# FileType,
# FileListType,
# PathLike,
# FileSysLike,
# FileInfo,
# PreparedFile,
# ParsedFile,
# )
from .utils import settings

from fileio import providers
__all__ = [
'pathlib',
'File',
'FileLike',
'FileType',
'FileListType',
'PathLike',
'FileSysLike',
'FileInfo',
'PreparedFile',
'ParsedFile',
'settings',
]
# from fileio.core.imports import pathlib
# from fileio.core.generic import *

from fileio.utils import settings
from fileio.core.types import File, FileLike, FileType, FileListType
# from fileio.core import flavours
# from fileio.core import base
# from fileio.core import generic

from fileio.types.etc import ParsedFile, PreparedFile
# from fileio import providers

# from fileio.utils import settings
# from fileio.core.types import File, FileLike, FileType, FileListType

# from fileio.types.etc import ParsedFile, PreparedFile

# from fileio.converters.base import BaseConverter
# PreparedFile.update_forward_refs()
Expand Down
152 changes: 152 additions & 0 deletions fileio/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
from __future__ import annotations

"""
FileIO CLI
"""

import typer
import asyncio

from typing import Optional

_help = """
FileIO CLI
Usage:
fileio <command> [options]
Commands:
copy: Copy a file
info: Get information about a file or directory
ls: List files in a directory
rm: Remove a file or directory
cat: Echo the file contents
"""

cmd = typer.Typer(no_args_is_help = True, help = _help)

@cmd.command('copy', help = 'Copy a file')
def copy_file(
source: str = typer.Argument(..., help = 'Path to file to copy'),
destination: str = typer.Argument(..., help = 'Path to destination file. Can be a directory or a file'),
filename: Optional[str] = typer.Option(None, help = 'Name of file to upload as. If not provided, will use the name of the source file'),
new_suffix: Optional[str] = typer.Option(None, help = 'If provided, will replace the suffix of the source file with this suffix'),
overwrite: Optional[bool] = typer.Option(False, help = 'Whether to overwrite the destination file if it exists'),
):
"""
Usage:
Upload or Download a file using FileIO backend
$ fileio get <source> <destination> [options]
"""
from .functions import fetch_file
asyncio.run(
fetch_file(
source = source,
destination = destination,
filename = filename,
new_suffix = new_suffix,
overwrite = overwrite,
)
)


@cmd.command('info', help = 'Get information about a file or directory')
def source_info_cmd(
source: str = typer.Argument(..., help = 'Path to file or directory'),
recursive: Optional[bool] = typer.Option(False, help = 'Whether to recursively list files'),
dirs_only: Optional[bool] = typer.Option(False, help = 'Whether to only dirs (default is files only)'),
):
"""
Usage:
Get information about a file or directory using FileIO backend
$ fileio info <source> [options]
"""
from .functions import source_info
asyncio.run(
source_info(
source = source,
recursive = recursive,
dirs_only = dirs_only,
)
)


@cmd.command('ls', help = 'List files in a directory')
def list_files(
source: str = typer.Argument(..., help = 'Path to directory'),
pattern: str = typer.Argument('*', help = 'Pattern to match files against'),
):
"""
Usage:
List files in a directory using FileIO backend
$ fileio ls <source> [options]
"""
from .functions import list_dir
asyncio.run(
list_dir(
source = source,
pattern = pattern,
)
)

@cmd.command('rm', help = 'Remove a file or directory')
def rm_cmd(
source: str = typer.Argument(..., help = 'Path to file or directory'),
recursive: Optional[bool] = typer.Option(False, help = 'Whether to recursively delete files'),
force: Optional[bool] = typer.Option(False, help = 'Whether to force delete without prompting'),
):
"""
Usage:
Delete a file or directory using FileIO backend
$ fileio rm <source> [options]
"""
from .functions import rm_files_or_dir
asyncio.run(
rm_files_or_dir(
source = source,
recursive = recursive,
force = force,
)
)


@cmd.command('cat', help = 'Echo the file contents')
def cat_cmd(
source: str = typer.Argument(..., help = 'Path to file'),
binary: Optional[bool] = typer.Option(False, help = 'Whether to read the file as binary'),
encode: Optional[str] = typer.Option(None, help = 'Encoding to use when reading the file'),
decode: Optional[str] = typer.Option(None, help = 'Decoding to use when writing the file'),
):
"""
Usage:
Echo the file contents using FileIO backend
$ fileio cat <source> [options]
"""
from .functions import cat_file
asyncio.run(
cat_file(
source = source,
binary = binary,
encode = encode,
decode = decode,
)
)


if __name__ == '__main__':
cmd()




Loading

0 comments on commit 04aa070

Please sign in to comment.