This is a repository of first test "Write a Python program, that takes a json file (which contains the information of a directory in nested structure) and prints out its content in the console in the style of ls (linux utility)"
This module or program takes json (which contains the information of a directory in nested structure) file data as input and gives the output in the console as per the command form or pass by the user in the style of ls (linux utility) Here user has to type different commands and program will give output as per the command. Let's take an examples if user types "pyls", it will list out the top level (in the directory interpreter) directories and files. Notice it does not list .gitignore, because that is the default behaviour of ls, i.e. files and directories whose names start with . are omitted by default. it is as follows: LICENSE README.md ast go.mod lexer main.go parser token
- Installation
- Usage - Commands
- Functions
- Test Functions -Pytes
- Python 3.x
- Pytest
- Clone the repository: "https://github.com/dattachitale/Zuru_Test_One"
- Open Pycharm and load the script
- run the scrip by using Pycharm runner (form neccessary command) or using terminal type "python -m pyls"
- Form neccessary command combination which is explained in "Usage" section
for all the command, use "pyls" at the beginning and the flags if you are using it in terminal e.g "pyls -l" if you are running using Pycharm "run" button then in "Edit configuaration -> Parameters add your flags (-l -r) but no need to add "pyls"
python -m pyls : gives list of top level (in the directory interpreter) directories and files. Notice it does not list .gitignore,
LICENSE README.md ast go.mod lexer main.go parser token
.gitignore LICENSE README.md ast go.mod lexer main.go parser token
-rw-r--r-- 1071 Nov 14 11:27 LICENSE -rw-r--r-- 83 Nov 14 11:27 README.md drwxr-xr-x 4096 Nov 14 15:58 ast -rw-r--r-- 60 Nov 14 13:51 go.mod drwxr-xr-x 4096 Nov 14 15:21 lexer -rw-r--r-- 74 Nov 14 13:57 main.go drwxr-xr-x 4096 Nov 17 12:51 parser drwxr-xr-x 4096 Nov 14 14:57 token
python -m pyls -l -r: list out all top level directories and files with detail information in reverse order
drwxr-xr-x 4096 Nov 14 14:57 token drwxr-xr-x 4096 Nov 17 12:51 parser -rw-r--r-- 74 Nov 14 13:57 main.go drwxr-xr-x 4096 Nov 14 15:21 lexer -rw-r--r-- 60 Nov 14 13:51 go.mod drwxr-xr-x 4096 Nov 14 15:58 ast -rw-r--r-- 83 Nov 14 11:27 README.md -rw-r--r-- 1071 Nov 14 11:27 LICENSE
python -m pyls -l -r -t: list out all top level directories and files with detail information in reverse order of reverse order of "time_modified" filter
drwxr-xr-x 4096 Nov 17 12:51 parser drwxr-xr-x 4096 Nov 14 15:58 ast drwxr-xr-x 4096 Nov 14 15:21 lexer drwxr-xr-x 4096 Nov 14 14:57 token -rw-r--r-- 74 Nov 14 13:57 main.go -rw-r--r-- 60 Nov 14 13:51 go.mod -rw-r--r-- 1071 Nov 14 11:27 LICENSE -rw-r--r-- 83 Nov 14 11:27 README.md
python -m pyls -l -r -t --filter=dir drwxr-xr-x 4.0 KB Nov 17 12:51 parser drwxr-xr-x 4.0 KB Nov 14 15:21 lexer drwxr-xr-x 60.0 B Nov 14 13:51 go.mod drwxr-xr-x 1.0 KB Nov 14 11:27 LICENSE drwxr-xr-x 83.0 B Nov 14 11:27 README.md
python -m pyls -l -r -t --filter=file -rw-r--r-- 4.0 KB Nov 14 15:58 ast -rw-r--r-- 4.0 KB Nov 14 14:57 token -rw-r--r-- 74.0 B Nov 14 13:57 main.go
python -m pyls -l -r -t --filter=folder error: 'folder' is not a valid filter criteria. Available filters are 'dir' and 'file'
python -m pyls -l (file/dir name): this will handle file/dir path properly and gives all sub files if it is dir and file itself if it is a file
python -m pyls -l parser drwxr-xr-x 1342 Nov 17 12:51 parser_test.go -rw-r--r-- 1622 Nov 17 12:05 parser.go drwxr-xr-x 533 Nov 14 16:03 go.mod
python -m pyls -l parser/parser.go -rw-r--r-- 1622 Nov 17 12:05 parser/parser.go
python -m pyls -l lexer drwxr-xr-x 1729 Nov 14 15:15 lexer_test.go -rw-r--r-- 227 Nov 14 12:23 go.mod drwxr-xr-x 2886 Nov 14 15:21 lexer.go
python -m pyls -l non_existent_path error: cannot access 'non_existent_path': No such file or directory
python -H (file/dir name): this is new -H flag which I implemented along with file name, so you have to pass "pyls -H " only. This does not work with pyls -l -H
This command will give "Size" parameter in human-readable form as below
python -m pyls -H lexer (use only like pyls -H ) drwxr-xr-x 1.7 KB Nov 14 15:15 lexer_test.go -rw-r--r-- 227.0 B Nov 14 12:23 go.mod drwxr-xr-x 2.8 KB Nov 14 15:21 lexer.go
python -m pyls --help (-h): this is a help flag which will show you all help related to all flags. This is in-build function of argparser class
usage: pyls.py [-h] [-l [LIST]] [-A] [-r] [-t] [-filter FILTER_OPTION] [-p PATH] [-H [HUMAN]]
options: -h, --help show this help message and exit -l [LIST], --list [LIST] list ot directories with additional information -A, --all list all the files and directories (including files starting with .) -r, --reverse Reverse list of directories with additional information -t, --time_modify Show directories on time modified filter but in reversed order -filter FILTER_OPTION, --filter FILTER_OPTION filter the output on the basis of (file or dir) -p PATH, --path PATH Handle Paths - it gives detail info about subfiles if filter-option is dir and file itself of the filter-option is file -H [HUMAN], --human [HUMAN] Human readable format for Size parameter of the file or dir provided by user
This checks which all flags are set to true and calls decision_function() or top_directory() accordingly