victordomingos / Count-files

A CLI utility written in Python to help you count files, grouped by extension, in a directory. By default, it will count files recursively in current working directory and all of its subdirectories, and will display a table showing the frequency for each file extension (e.g.: .txt, .py, .html, .css) and the total number of files found.
https://no-title.victordomingos.com/projects/count-files/
MIT License
23 stars 9 forks source link

Ideas for Count Files v1.5 #84

Open victordomingos opened 6 years ago

victordomingos commented 6 years ago

Lets gather a few ideas of what kind of improvements we could consider to include in the next Count Files release. For now, this issue will function as simple brainstorming place in order to help us define priorities and plan ahead about where we should focus our working efforts.

To get things started, let me introduce some possible ideas:

NataliaBondarenko commented 6 years ago

Argparse and help system. make text blocks a bit shorter, if possible: I do not know if this is possible, complex parsers have a pretty large help text. maybe implement sub-parsers: This can be done, for example, the git has a sub-parser help and also the usual --help. git --help git help <command> (Launching default browser to display HTML-file), git help -a, git help -g I do not know how it is implemented there, but with a parser you can do something like this:

from argparse import ArgumentParser
import os
from textwrap import fill

# handlers
def foo(args):
    print('ext:', args.file_extension, 'path:', args.path, 'preview:', args.preview)
    # print start_message
    """print(fill(show_start_message(args.extension, args.case_sensitive,
                                  recursive, include_hidden, location),
               width=START_TEXT_WIDTH), end="\n\n")"""
    print('the process of getting the list here')

def bar(args):
    # here you can write anything and even make a responsive help text
    # key-values may be stored in settings
    arg_help = {
        'desc': 'usage: test help <command>',
        'path': 'path help',
        'fe': 'file-extension help',
        'file-extension': 'file-extension help'
    }
    print(fill(arg_help.get(args.argument, 'not implemented'), width=5))

parser = ArgumentParser(
    prog='test',
    description='desc'
)
# common arguments
parser.add_argument('path', nargs='?', default=os.getcwd(), type=str,
                    help='The path to the folder containing the files to be counted.')
parser.add_argument('-st', '--supported-types', action='store_true',
                    help='The list of currently supported file types for preview.')

subparsers = parser.add_subparsers(help='Usual sub-command help')

parser_bar = subparsers.add_parser('help', help='Help by certain argument name')
parser_bar.add_argument('-a', '--argument', type=str, default='desc',
                        choices=('desc', 'path', 'fe', 'file-extension'))
parser_bar.set_defaults(func=bar)

# special arguments
parser_search = subparsers.add_parser('search', help='File searching by extension help')
parser_search.add_argument('-fe', '--file-extension', type=str, required=True,  # or set default='py',
                           help="Search files by file extension ...")
parser_search.add_argument('-p', '--preview', action='store_true', default=False,
                           help='Display a short preview (only available for text files.')
# parser_search.add_argument(...)
parser_search.set_defaults(func=foo)

def main(*args):

    args = parser.parse_args(*args)

    if args.supported_types:
        parser.exit(status=0, message='supported_type_info_message')

    if os.path.abspath(args.path) == os.getcwd():
        location = os.getcwd()
        loc_text = ' the current directory'
    else:
        location = os.path.expanduser(args.path)
        loc_text = ':\n' + os.path.normpath(location)

    if not os.path.exists(location):
        parser.exit(status=1, message=f'The path {location} '
                                      f'does not exist, or there may be a typo in it.')

    # if not include_hidden and is_hidden_file_or_dir(location): ... parser.exit
    args.path = location
    args.func(args)

if __name__ == "__main__":
    main()

it looks like this: ex1 ex2 consider if we should move from argparse to other similar 3rd. party package: this is possible if there is some especially important functional that is not present in the ArgumentParser.

NataliaBondarenko commented 6 years ago

Add file search by other criteria it will be difficult - many filters. can be used: os.stat, glob or pathlib usually operating systems have tools for searching and sorting files and folders according to the pattern. here need to think about what tasks we can solve without duplication.

NataliaBondarenko commented 6 years ago

Add some new preview systems for common file types: In the standard library, there are tools for working with common file types. Text files can be read. and what kind of data can be used for the preview images or PDF?

NataliaBondarenko commented 6 years ago

And one more thing:

Example with symbolic link link_img

Example with Windows shortcut win_sh

Should I pay attention to such files or count them on a par with others?

NataliaBondarenko commented 6 years ago

suggestions:

NataliaBondarenko commented 5 years ago

Summary before new release:

Added the ability to search in help text (help system extension) with more detailed text about arguments and groups. Currently built-in parser help is also available(--help). Theoretically, this can be replaced with own text or with --help-cmd totally.

parser = argparse.ArgumentParser(description='Does some important things.', add_help=False)
parser.add_argument('-h', '--help', action='store_true', default=False)
if args.help:
    print(parser.description)
    print(parser.print_usage())
    print('My own short text')

But perhaps such changes may be unusual for user.

What about sub-parsers or other similar 3rd. party CLI packages? If you split parser in two executable entrypoints, then it probably does not make sense.

name starts with (name prefix); name ends with (name suffix); name contains; extension starts with (extension prefix); extension ends with (extension suffix); extension contains This can be done. Search with * are under development. What about the order of the search arguments and total? https://github.com/victordomingos/Count-files/pull/105#issuecomment-476788651

file size bigger than; file size smaller than This can be added to the def show_result_for_search_files. But we will need to add another argument for this.

This can be postponed until release 2.x. Nothing is done here at all :) Maybe it's time to expand the list of supported text types for previews. Here we can also add this https://github.com/victordomingos/Count-files/issues/91#issuecomment-448409774.

This can be postponed until release 2.x.

This can be postponed until release 2.x.

This can be added to count, search -fe .. and total -t ..