1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-19 00:17:51 +02:00

formatting of quotation marks and docstrings

This commit is contained in:
Kelly Brazil
2020-07-09 10:54:49 -07:00
parent cedf603f12
commit c29ed3fd69

View File

@ -101,7 +101,7 @@ if os.path.isdir(local_parsers_dir):
# We only support 2.3.0+, pygments changed color names in 2.4.0.
# startswith is sufficient and avoids potential exceptions from split and int.
if pygments.__version__.startswith("2.3."):
if pygments.__version__.startswith('2.3.'):
PYGMENT_COLOR = {
'black': '#ansiblack',
'red': '#ansidarkred',
@ -188,7 +188,7 @@ def set_env_colors():
def piped_output():
"""returns False if stdout is a TTY. True if output is being piped to another program"""
"""Returns False if stdout is a TTY. True if output is being piped to another program"""
if sys.stdout.isatty():
return False
else:
@ -196,34 +196,34 @@ def piped_output():
def ctrlc(signum, frame):
"""exit with error on SIGINT"""
"""Exit with error on SIGINT"""
sys.exit(1)
def parser_shortname(parser_argument):
"""short name of the parser with dashes and no -- prefix"""
"""Short name of the parser with dashes and no -- prefix"""
return parser_argument[2:]
def parser_argument(parser):
"""short name of the parser with dashes and with -- prefix"""
"""Short name of the parser with dashes and with -- prefix"""
return f'--{parser}'
def parser_mod_shortname(parser):
"""short name of the parser's module name (no -- prefix and dashes converted to underscores)"""
"""Short name of the parser's module name (no -- prefix and dashes converted to underscores)"""
return parser.replace('--', '').replace('-', '_')
def parser_module(parser):
"""import the module just in time and return the module object"""
"""Import the module just in time and return the module object"""
shortname = parser_mod_shortname(parser)
path = ('jcparsers.' if shortname in local_parsers else 'jc.parsers.')
return importlib.import_module(path + shortname)
def parsers_text(indent=0, pad=0):
"""return the argument and description information from each parser"""
"""Return the argument and description information from each parser"""
ptext = ''
for parser in parsers:
parser_arg = parser_argument(parser)
@ -241,7 +241,7 @@ def parsers_text(indent=0, pad=0):
def about_jc():
"""return jc info and the contents of each parser.info as a dictionary"""
"""Return jc info and the contents of each parser.info as a dictionary"""
parser_list = []
for parser in parsers:
@ -271,7 +271,7 @@ def about_jc():
def helptext(message):
"""return the help text with the list of parsers"""
"""Return the help text with the list of parsers"""
parsers_string = parsers_text(indent=12, pad=17)
helptext_string = f'''
@ -304,7 +304,7 @@ def helptext(message):
def json_out(data, pretty=False, mono=False, piped_out=False):
"""Returns a JSON formatted string. String may include color codes or be pretty printed."""
if not mono and not piped_out:
# set colors
class JcStyle(Style):
@ -356,7 +356,7 @@ def generate_magic_command(args):
magic_dict = {}
parser_info = about_jc()['parsers']
# Create a dictionary of magic_commands to their respective parsers.
# create a dictionary of magic_commands to their respective parsers.
for entry in parser_info:
# Update the dict with all of the magic commands for this parser, if they exist.
magic_dict.update({mc: entry['argument'] for mc in entry.get('magic_commands', [])})
@ -365,7 +365,7 @@ def generate_magic_command(args):
one_word_command = args_given[0]
two_word_command = ' '.join(args_given[0:2])
# Try to get a parser for two_word_command, otherwise get one for one_word_command
# try to get a parser for two_word_command, otherwise get one for one_word_command
found_parser = magic_dict.get(two_word_command, magic_dict.get(one_word_command))
# construct a new command line using the standard syntax: COMMAND | jc --PARSER -OPTIONS
@ -378,6 +378,7 @@ def generate_magic_command(args):
def magic():
"""Runs the command generated by generate_magic_command() to support magic syntax"""
valid_command, run_command = generate_magic_command(sys.argv)
if valid_command:
os.system(run_command)