Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ideas for Count Files v1.5 #84

Open
victordomingos opened this issue Sep 10, 2018 · 6 comments
Open

Ideas for Count Files v1.5 #84

victordomingos opened this issue Sep 10, 2018 · 6 comments
Labels
question Further information is requested
Milestone

Comments

@victordomingos
Copy link
Owner

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:

  • Find out ways to simplify the help system:

    • make text blocks a bit shorter, if possible;
    • maybe implement sub-parsers as a way to hide some of the complexity and allow for more clear visualization of each of the available arguments and their meaning.
    • consider if we should move from argparse to other similar 3rd. party package without sacrificing portability.
  • Add file search by other criteria:

    • date last modified;
    • name starts with (name prefix);
    • name ends with (name suffix);
    • name contains;
    • extension starts with (extension prefix);
    • extension ends with (extension suffix);
    • extension contains;
    • file size bigger than;
    • file size smaller than.
  • Add some new preview systems for common file types:

    • List more usual extensions that correspond in fact to text files;
    • Images supported by Pillow (keeping external dependencies optional - only show preview if required library is available, else display a simple message);
    • PDF files.
@victordomingos victordomingos added this to the 1.5 milestone Sep 10, 2018
@victordomingos victordomingos added the question Further information is requested label Sep 10, 2018
@NataliaBondarenko
Copy link
Collaborator

NataliaBondarenko commented Sep 15, 2018

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
Copy link
Collaborator

NataliaBondarenko commented Sep 15, 2018

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

suggestions:

  • include/exclude some dirs count-files --exclude folder1 folder2
  • include/exclude some types count-files --exclude ini (system files or those for which there is no preview)
  • search or count for multiple extensions: count-files --multi-exensions txt py

@NataliaBondarenko
Copy link
Collaborator

Summary before new release:

  • Find out ways to simplify the help system:

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.

  • Add file search by other criteria:

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?
#105 (comment)

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.

  • Add some new preview systems for common file types:

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 #91 (comment).

  • Search or count for multiple extensions:

This can be postponed until release 2.x.

  • Excluding folders or file extensions:

This can be postponed until release 2.x.

  • Optimize the search with skipping root hidden folders:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants