Skip to content

Commit

Permalink
fix pylint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenZcience committed Sep 7, 2023
1 parent fa095d3 commit 3c5e4bf
Show file tree
Hide file tree
Showing 22 changed files with 567 additions and 211 deletions.
10 changes: 10 additions & 0 deletions cat_win/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
__main__
"""

import sys


Expand All @@ -11,9 +15,15 @@
sys.exit(1)

def shell_entry_point():
"""
run the shell.
"""
cat.shell_main()

def entry_point():
"""
run the main program.
"""
cat.main()

if __name__ == '__main__':
Expand Down
234 changes: 167 additions & 67 deletions cat_win/cat.py

Large diffs are not rendered by default.

153 changes: 102 additions & 51 deletions cat_win/const/argconstants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
argconstants
"""

class ArgConstant():
"""
Expand All @@ -22,81 +25,129 @@ def __init__(self, short_form: str, long_form: str, arg_help: str, arg_id: int,
ARGS_CONFIG, ARGS_LLENGTH, ARGS_ONELINE, ARGS_PEEK, ARGS_NOCOL = range(20, 25)
ARGS_CHR, ARGS_B64E, ARGS_B64D, ARGS_FFILES, ARGS_GREP = range(25, 30)
ARGS_NOBREAK, ARGS_ECHO, ARGS_CCOUNT, ARGS_HEXVIEW, ARGS_BINVIEW = range(30, 35)
ARGS_NOKEYWORD, ARGS_RECONFIGURE, ARGS_RECONFIGURE_IN, ARGS_RECONFIGURE_OUT, ARGS_RECONFIGURE_ERR = range(35, 40)
ARGS_NOKEYWORD, ARGS_RECONFIGURE, ARGS_RECONFIGURE_IN = range(35, 38)
ARGS_RECONFIGURE_OUT, ARGS_RECONFIGURE_ERR = range(38, 40)
ARGS_EVAL, ARGS_SORT, ARGS_GREP_ONLY, ARGS_PLAIN_ONLY, ARGS_FILE_PREFIX = range(40, 45)
ARGS_FFILE_PREFIX, ARGS_DOTFILES, ARGS_OCT, ARGS_URI, ARGS_EDITOR = range(45, 50)

DIFFERENTIABLE_ARGS = [ARGS_CUT, ARGS_REPLACE]

ALL_ARGS = [
ArgConstant('-h', '--help', 'show this help message and exit', ARGS_HELP, section=0),
ArgConstant('-v', '--version', 'output version information and exit', ARGS_VERSION, section=0),
ArgConstant('--debug', '--debug', 'show debug information', ARGS_DEBUG, show_arg=False, section=0),
ArgConstant('-h', '--help', 'show this help message and exit',
ARGS_HELP, section=0),
ArgConstant('-v', '--version', 'output version information and exit',
ARGS_VERSION, section=0),
ArgConstant('--debug', '--debug', 'show debug information',
ARGS_DEBUG, show_arg=False, section=0),

# prefix
ArgConstant('-l', '--linelength', 'display the length of each line', ARGS_LLENGTH, section=1),
ArgConstant('-n', '--number', 'number all output lines', ARGS_NUMBER, section=1),
ArgConstant('--fp', '--file-prefix', 'include the file in every line prefix', ARGS_FILE_PREFIX, show_arg_on_shell=False, section=1),
ArgConstant('--FP', '--FILE-PREFIX', 'include the file protocol in every line prefix', ARGS_FFILE_PREFIX, show_arg=False, section=1),
ArgConstant('-l', '--linelength', 'display the length of each line',
ARGS_LLENGTH, section=1),
ArgConstant('-n', '--number', 'number all output lines',
ARGS_NUMBER, section=1),
ArgConstant('--fp', '--file-prefix', 'include the file in every line prefix',
ARGS_FILE_PREFIX, show_arg_on_shell=False, section=1),
ArgConstant('--FP', '--FILE-PREFIX', 'include the file protocol in every line prefix',
ARGS_FFILE_PREFIX, show_arg=False, section=1),

# simple replacements
ArgConstant('-e', '--ends', 'display $ at the end of each line', ARGS_ENDS, section=2),
ArgConstant('--chr', '--char', 'display special characters', ARGS_CHR, section=2),
ArgConstant('-e', '--ends', 'display $ at the end of each line',
ARGS_ENDS, section=2),
ArgConstant('--chr', '--char', 'display special characters',
ARGS_CHR, section=2),

# line manipulation
ArgConstant('-b', '--blank', 'hide empty lines', ARGS_BLANK, section=3),
ArgConstant('-p', '--peek', 'only print the first and last lines', ARGS_PEEK, show_arg_on_shell=False, section=3),
ArgConstant('-r', '--reverse', 'reverse output', ARGS_REVERSE, show_arg_on_shell=False, section=3),
ArgConstant('-u', '--unique', 'suppress repeated output lines', ARGS_SQUEEZE, show_arg_on_shell=False, section=3),
ArgConstant('--sort', '--sort', 'sort all lines alphabetically', ARGS_SORT, show_arg_on_shell=False, section=3),
ArgConstant('-b', '--blank', 'hide empty lines',
ARGS_BLANK, section=3),
ArgConstant('-p', '--peek', 'only print the first and last lines',
ARGS_PEEK, show_arg_on_shell=False, section=3),
ArgConstant('-r', '--reverse', 'reverse output',
ARGS_REVERSE, show_arg_on_shell=False, section=3),
ArgConstant('-u', '--unique', 'suppress repeated output lines',
ARGS_SQUEEZE, show_arg_on_shell=False, section=3),
ArgConstant('--sort', '--sort', 'sort all lines alphabetically',
ARGS_SORT, show_arg_on_shell=False, section=3),

# different content types
ArgConstant('-E', '--echo', 'handle every following parameter as stdin', ARGS_ECHO, show_arg_on_shell=False, section=4),
ArgConstant('-i', '--interactive', 'use stdin', ARGS_INTERACTIVE, show_arg_on_shell=False, section=4),
ArgConstant('-o', '--oneline', 'take only the first stdin-line', ARGS_ONELINE, section=4),
ArgConstant('-U', '--url', 'display the contents of any provided url', ARGS_URI, show_arg_on_shell=False, section=4),
ArgConstant('-E', '--echo', 'handle every following parameter as stdin',
ARGS_ECHO, show_arg_on_shell=False, section=4),
ArgConstant('-i', '--interactive', 'use stdin',
ARGS_INTERACTIVE, show_arg_on_shell=False, section=4),
ArgConstant('-o', '--oneline', 'take only the first stdin-line',
ARGS_ONELINE, section=4),
ArgConstant('-U', '--url', 'display the contents of any provided url',
ARGS_URI, show_arg_on_shell=False, section=4),

# summary
ArgConstant('-f', '--files', 'list applied files and file sizes', ARGS_FILES, show_arg_on_shell=False, section=5),
ArgConstant('-F', '--FILES', 'ONLY list applied files and file sizes', ARGS_FFILES, show_arg=False, section=5),
ArgConstant('-s', '--sum', 'show sum of lines', ARGS_COUNT, show_arg_on_shell=False, section=5),
ArgConstant('-S', '--SUM', 'ONLY show sum of lines', ARGS_CCOUNT, show_arg=False, section=5),
ArgConstant('-f', '--files', 'list applied files and file sizes',
ARGS_FILES, show_arg_on_shell=False, section=5),
ArgConstant('-F', '--FILES', 'ONLY list applied files and file sizes',
ARGS_FFILES, show_arg=False, section=5),
ArgConstant('-s', '--sum', 'show sum of lines',
ARGS_COUNT, show_arg_on_shell=False, section=5),
ArgConstant('-S', '--SUM', 'ONLY show sum of lines',
ARGS_CCOUNT, show_arg=False, section=5),

# search and match
ArgConstant('-g', '--grep', 'only show lines containing queried keywords or patterns', ARGS_GREP, section=6),
ArgConstant('-G', '--GREP', 'only show found and matched substrings', ARGS_GREP_ONLY, show_arg=False, section=6),
ArgConstant('--nk', '--nokeyword', 'inverse the grep output', ARGS_NOKEYWORD, section=6),
ArgConstant('--nb', '--nobreak', 'do not interrupt the output', ARGS_NOBREAK, section=6),
ArgConstant('-g', '--grep', 'only show lines containing queried keywords or patterns',
ARGS_GREP, section=6),
ArgConstant('-G', '--GREP', 'only show found and matched substrings',
ARGS_GREP_ONLY, show_arg=False, section=6),
ArgConstant('--nk', '--nokeyword', 'inverse the grep output',
ARGS_NOKEYWORD, section=6),
ArgConstant('--nb', '--nobreak', 'do not interrupt the output',
ARGS_NOBREAK, section=6),

# meta information
ArgConstant('-a', '--attributes', 'show meta-information about the files', ARGS_DATA, show_arg_on_shell=False, section=7),
ArgConstant('-m', '--checksum', 'show the checksums of all files', ARGS_CHECKSUM, show_arg_on_shell=False, section=7),
ArgConstant('-a', '--attributes', 'show meta-information about the files',
ARGS_DATA, show_arg_on_shell=False, section=7),
ArgConstant('-m', '--checksum', 'show the checksums of all files',
ARGS_CHECKSUM, show_arg_on_shell=False, section=7),

# numbers
ArgConstant('--b64d', '--b64d', 'decode the input from base64', ARGS_B64D, section=8),
ArgConstant('--b64e', '--b64e', 'encode the input to base64', ARGS_B64E, section=8),
ArgConstant('--eval', '--EVAL', 'evaluate simple mathematical equations', ARGS_EVAL, section=8),
ArgConstant('--hex', '--HEX', 'convert hexadecimal numbers to binary, octal and decimal', ARGS_HEX, section=8),
ArgConstant('--dec', '--DEC', 'convert decimal numbers to binary, octal and hexadecimal', ARGS_DEC, section=8),
ArgConstant('--oct', '--OCT', 'convert octal numbers to binary, decimal and hexadecimal', ARGS_OCT, section=8),
ArgConstant('--bin', '--BIN', 'convert binary numbers to octal, decimal and hexadecimal', ARGS_BIN, section=8),
ArgConstant('--b64d', '--b64d', 'decode the input from base64',
ARGS_B64D, section=8),
ArgConstant('--b64e', '--b64e', 'encode the input to base64',
ARGS_B64E, section=8),
ArgConstant('--eval', '--EVAL', 'evaluate simple mathematical equations',
ARGS_EVAL, section=8),
ArgConstant('--hex', '--HEX', 'convert hexadecimal numbers to binary, octal and decimal',
ARGS_HEX, section=8),
ArgConstant('--dec', '--DEC', 'convert decimal numbers to binary, octal and hexadecimal',
ARGS_DEC, section=8),
ArgConstant('--oct', '--OCT', 'convert octal numbers to binary, decimal and hexadecimal',
ARGS_OCT, section=8),
ArgConstant('--bin', '--BIN', 'convert binary numbers to octal, decimal and hexadecimal',
ARGS_BIN, section=8),

# raw
ArgConstant('--binview', '--binview', 'display the raw byte representation in binary', ARGS_BINVIEW, show_arg_on_shell=False, section=9),
ArgConstant('--hexview', '--HEXVIEW', 'display the raw byte representation in hexadecimal', ARGS_HEXVIEW, show_arg_on_shell=False, section=9),

ArgConstant('-!', '--edit', 'open each file in a simple editor', ARGS_EDITOR, section=10),
ArgConstant('-c', '--clip', 'copy output to clipboard', ARGS_CLIP, section=10),
ArgConstant('--dot', '--dotfiles', 'additionally query and edit dotfiles', ARGS_DOTFILES, show_arg_on_shell=False, section=10),
ArgConstant('--plain', '--plain-only', 'ignore non-plaintext files automatically', ARGS_PLAIN_ONLY, show_arg_on_shell=False, section=10),
ArgConstant('--nc', '--nocolor', 'disable colored output', ARGS_NOCOL, section=10),

ArgConstant('--config', '--config', 'change color configuration', ARGS_CONFIG, section=11),

ArgConstant('-R', '--R', 'reconfigure the stdin and stdout with the parsed encoding', ARGS_RECONFIGURE, show_arg=False),
ArgConstant('--Rin', '--Rin', 'reconfigure the stdin with the parsed encoding', ARGS_RECONFIGURE_IN, show_arg=False),
ArgConstant('--Rout', '--Rout', 'reconfigure the stdout with the parsed encoding', ARGS_RECONFIGURE_OUT, show_arg=False),
ArgConstant('--Rerr', '--Rerr', 'reconfigure the stderr with the parsed encoding', ARGS_RECONFIGURE_ERR, show_arg=False),
ArgConstant('--binview', '--binview', 'display the raw byte representation in binary',
ARGS_BINVIEW, show_arg_on_shell=False, section=9),
ArgConstant('--hexview', '--HEXVIEW', 'display the raw byte representation in hexadecimal',
ARGS_HEXVIEW, show_arg_on_shell=False, section=9),

ArgConstant('-!', '--edit', 'open each file in a simple editor',
ARGS_EDITOR, section=10),
ArgConstant('-c', '--clip', 'copy output to clipboard',
ARGS_CLIP, section=10),
ArgConstant('--dot', '--dotfiles', 'additionally query and edit dotfiles',
ARGS_DOTFILES, show_arg_on_shell=False, section=10),
ArgConstant('--plain', '--plain-only', 'ignore non-plaintext files automatically',
ARGS_PLAIN_ONLY, show_arg_on_shell=False, section=10),
ArgConstant('--nc', '--nocolor', 'disable colored output',
ARGS_NOCOL, section=10),

ArgConstant('--config', '--config', 'change color configuration',
ARGS_CONFIG, section=11),

ArgConstant('-R', '--R', 'reconfigure the stdin and stdout with the parsed encoding',
ARGS_RECONFIGURE, show_arg=False),
ArgConstant('--Rin', '--Rin', 'reconfigure the stdin with the parsed encoding',
ARGS_RECONFIGURE_IN, show_arg=False),
ArgConstant('--Rout', '--Rout', 'reconfigure the stdout with the parsed encoding',
ARGS_RECONFIGURE_OUT, show_arg=False),
ArgConstant('--Rerr', '--Rerr', 'reconfigure the stderr with the parsed encoding',
ARGS_RECONFIGURE_ERR, show_arg=False),
]
ALL_ARGS.sort(key=lambda x:x.section)

Expand Down
9 changes: 6 additions & 3 deletions cat_win/const/colorconstants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
colorconstants
"""

ESC_CODE = '\x1b'

Expand Down Expand Up @@ -63,11 +66,11 @@ class ColorOptions:
Back = {'NONE': ''}
Style = {'NONE': ''}

for key in __Fore:
for key, _ in __Fore.items():
Fore[key] = id_to_code(__Fore[key])
for key in __Back:
for key, _ in __Back.items():
Back[key] = id_to_code(__Back[key])
for key in __Style:
for key, _ in __Style.items():
Style[key] = id_to_code(__Style[key])


Expand Down
32 changes: 21 additions & 11 deletions cat_win/persistence/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
config
"""

import configparser
import os
import sys
Expand Down Expand Up @@ -105,18 +109,20 @@ def _print_get_all_available_colors(self) -> list:
config_menu = ''
options = []

for index in range(len(fore_options)):
key, value = fore_options[index]
for index, fore_option in enumerate(fore_options):
key, value = fore_option
colored_option = f"{value}Fore.{key}{ColorOptions.Style['RESET']}"
config_menu += f"{index+1: <{index_offset}}: {colored_option: <{self.longest_char_count+len(value)}}"
config_menu += f"{index+1: <{index_offset}}: "
config_menu += f"{colored_option: <{self.longest_char_count+len(value)}}"
if index % self.rows == self.rows-1:
config_menu += '\n'
options.append('Fore.' + key)
config_menu += '\n'
for index in range(len(back_options)):
key, value = back_options[index]
for index, back_option in enumerate(back_options):
key, value = back_option
colored_option = f"{value}Back.{key}{ColorOptions.Style['RESET']}"
config_menu += f"{len(fore_options)+index+1: <{index_offset}}: {colored_option: <{self.longest_char_count+len(value)}}"
config_menu += f"{len(fore_options)+index+1: <{index_offset}}: "
config_menu += f"{colored_option: <{self.longest_char_count+len(value)}}"
if index % self.rows == self.rows-1:
config_menu += '\n'
options.append('Back.' + key)
Expand All @@ -135,10 +141,11 @@ def _print_all_available_elements(self) -> None:
index_offset = len(str(len(self.elements) + 1))

config_menu = ''
for index in range(len(self.elements)):
element = self.elements[index]
for index, element in enumerate(self.elements):
colored_element = f"{self.color_dic[element]}{element}{ColorOptions.Style['RESET']}"
config_menu += f"{index+1: <{index_offset}}: {colored_element: <{self.longest_char_count+len(self.color_dic[element])}}"
config_menu += f"{index+1: <{index_offset}}: "
offset = self.longest_char_count+len(self.color_dic[element])
config_menu += f"{colored_element: <{offset}}"
if index % self.rows == self.rows-1:
config_menu += '\n'

Expand All @@ -163,7 +170,8 @@ def save_config(self) -> None:
if keyword.isdigit():
keyword = self.elements[int(keyword)-1] if (
0 < int(keyword) <= len(self.elements)) else keyword
print(f"Successfully selected element '{self.color_dic[keyword]}{keyword}{ColorOptions.Style['RESET']}'.")
print('Successfully selected element ', end='')
print(f"'{self.color_dic[keyword]}{keyword}{ColorOptions.Style['RESET']}'.")

color_options = self._print_get_all_available_colors()
color = ''
Expand All @@ -187,7 +195,9 @@ def save_config(self) -> None:
return

color_split = color.split('.')
print(f"Successfully selected element '{getattr(ColorOptions, color_split[0])[color_split[1]]}{color}{ColorOptions.Style['RESET']}'.")
print('Successfully selected element ', end='')
print(f"'{getattr(ColorOptions, color_split[0])[color_split[1]]}", end='')
print(f"{color}{ColorOptions.Style['RESET']}'.")

self.config_parser['COLORS'][keyword] = color
try:
Expand Down
7 changes: 7 additions & 0 deletions cat_win/shell.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
shell
"""

import sys


Expand All @@ -11,6 +15,9 @@
sys.exit(1)

def entry_point():
"""
run the shell.
"""
cat.shell_main()

if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 3c5e4bf

Please sign in to comment.