Ejemplo n.º 1
0
 def _main():
     p = ArgumentParser(description=descr, formatter_class=RawTextHelpFormatter, add_help=False)
     p.format_help = MethodType(lambda s: s.description, p)
     p.add_argument("file", nargs="?")
     p.add_argument("-d", "--decode", action="store_true")
     p.add_argument("-i", "--ignore-garbage", action="store_true")
     if inv:
         p.add_argument("-I", "--invert", action="store_true")
     if swap:
         p.add_argument("-s", "--swapcase", action="store_true")
     if wrap:
         p.add_argument("-w", "--wrap", type=int, default=76)
     p.add_argument("--help", action="help")
     p.add_argument("--version", action="version")
     p.version = "CodExt " + __version__
     args = p.parse_args()
     if args.decode:
         args.wrap = 0
     args.invert = getattr(args, "invert", False)
     c, f = _input(args.file), [encode, decode][args.decode]
     if swap and args.swapcase and args.decode:
         c = codecs.decode(c, "swapcase")
     c = b(c).rstrip(b"\r\n")
     try:
         c = f(c, "base" + base + ["", "-inv"][getattr(args, "invert", False)],
               ["strict", "ignore"][args.ignore_garbage])
     except Exception as err:
         print("%sbase%s: invalid input" % (getattr(err, "output", ""), base))
         return 1
     c = ensure_str(c)
     if swap and args.swapcase and not args.decode:
         c = codecs.encode(c, "swapcase")
     for l in (wraptext(c, args.wrap) if args.wrap > 0 else [c]) if wrap else c.split("\n"):
         print(l)
     return 0
Ejemplo n.º 2
0
def get_options():
    parser = ArgumentParser(description='CMD Option Demo.', epilog="best practice opt parser by pete312")
    parser.version = str(1)
    parser.add_argument('--version', action='version', help='print the version and exit')    
    parser.add_argument('--test', '-t', action='store_true', default=False, help='run test()')
  
    return parser.parse_args()
Ejemplo n.º 3
0
def main():
    descr = """Usage: unbase [OPTION]... [FILE]
Decode multi-layer base encoded FILE, or standard input, to standard output.

With no FILE, or when FILE is -, read standard input.

Optional arguments:
  -E, --extended        also consider generic base codecs while guess-decoding
  -f, --stop-function   set the result chceking function (default: text)
                         format: printables|text|flag|lang_[bigram]
  -M, --max-depth       maximum codec search depth (default: 5)
  -m, --min-depth       minimum codec search depth (default: 0)
  -p, --pattern         pattern to be matched while searching
  -s, --show            show the decoding chain

      --help     display this help and exit
      --verbose  show guessing information and steps
      --version  output version information and exit

Report unbase bugs to <https://github.com/dhondta/python-codext/issues/new>
Full documentation at: <https://python-codext.readthedocs.io/en/latest/enc/base.html>
"""
    parser = ArgumentParser(description=descr,
                            formatter_class=RawTextHelpFormatter,
                            add_help=False)
    parser.format_help = MethodType(lambda s: s.description, parser)
    group = parser.add_mutually_exclusive_group()
    parser.add_argument("file", nargs="?")
    parser.add_argument("-E", "--extended", action="store_true")
    group.add_argument("-f", "--stop-function", default="text")
    parser.add_argument("-M", "--max-depth", type=int, default=10)
    parser.add_argument("-m", "--min-depth", type=int, default=0)
    group.add_argument("-p", "--pattern")
    parser.add_argument("-s", "--show", action="store_true")
    parser.add_argument("--help", action="help")
    parser.add_argument("--version", action="version")
    parser.add_argument("--verbose", action="store_true")
    parser.version = "CodExt " + __version__
    args = parser.parse_args()
    c, e = _input(args.file), [["base%d-generic" % i for i in range(2, 256)],
                               []][args.extended]
    c = c.rstrip("\r\n") if isinstance(c, str) else c.rstrip(b"\r\n")
    r = codecs.guess(c,
                     stopfunc._validate(args.stop_function),
                     0,
                     args.max_depth,
                     "base",
                     tuple(e),
                     stop=False,
                     show=args.verbose,
                     debug=args.verbose)
    if len(r) == 0:
        print("Could not decode :-(")
        return 0
    ans = max(r.items(), key=lambda x: len(x[0]))
    if args.show:
        print(" - ".join(ans[0]))
    print(ensure_str(ans[1]))
    return 0
Ejemplo n.º 4
0
def main():  # pragma: no cover
    from argparse import ArgumentParser
    from myrich import __description__, __package_name__, __version__

    retuncode = 0

    # Argument Parser
    my_parser = ArgumentParser(
        prog=__package_name__,
        allow_abbrev=False,
        usage="%(prog)s [options] [commands ...]",
        description=__description__,
    )
    # Add arguments
    my_parser.version = __version__
    my_parser.add_argument(
        "commands",
        action="store",
        nargs="*",
        default=None,
        help="Commands to be executed",
    )
    my_parser.add_argument(
        "-c",
        "--force-color",
        dest="force_color",
        action="store_true",
        default=None,
        help="force color for non-terminals",
    )
    my_parser.add_argument(
        "-w",
        "--width",
        type=int,
        dest="width",
        default=None,
        help="width of output (default will auto-detect)",
    )
    my_parser.add_argument("-V", "--version", action="version")

    args = my_parser.parse_args()
    cwd = os.getcwd()

    if args.width:
        console._width = args.width

    if args.force_color:
        console._force_terminal = args.force_color

    if args.commands:
        c = run_command(" ".join(args.commands), cwd)
        retuncode = c.return_code
    else:
        retuncode = start_shell(cwd)

    return retuncode
Ejemplo n.º 5
0
def get_options():
    parser = ArgumentParser(description='xml parse.', epilog="...")
    parser.version = str(VERSION)
    parser.add_argument('--version',
                        action='version',
                        help='print the version and exit')
    parser.add_argument('--file',
                        '-f',
                        action='store',
                        type=str,
                        required=True,
                        help="xml file")
    return parser.parse_args()
Ejemplo n.º 6
0
def get_options():
    parser = ArgumentParser(description='CMD Option Demo.',
                            epilog="best practice opt parser by pete312")
    parser.version = str(1)
    parser.add_argument('--version',
                        action='version',
                        help='print the version and exit')
    parser.add_argument('--test',
                        '-t',
                        action='store_true',
                        default=False,
                        help='run test()')

    return parser.parse_args()
Ejemplo n.º 7
0
def get_options():
    parser = ArgumentParser(description='fabric test v{}'.format(VERSION), epilog="...")
    parser.version = str(VERSION)
    parser.add_argument('--version', action='version', help='print the version and exit')
    parser.add_argument('-c', '--count', type=int, default=1, help='numebr of times operation happens remotely')
    parser.add_argument('-x', '--noof_conn_per_host', type=int, default=1, help='numebr of times operation happens remotely')
    parser.add_argument('-P', '--setpass', dest='password', default=False, help='set user password')
    parser.add_argument('-p', '--askpass', dest='password', action='store_true', default=False, help='ask for password prompt')
    parser.add_argument('-H', '--hosts', metavar='N', type=str, nargs='+',
                        help='hosts to act on (user is current user unless notation user@host is used)')
    
   
    
    return parser.parse_args()
Ejemplo n.º 8
0
def get_options():
    parser = ArgumentParser(description='CMD Option Demo.', epilog="best practice opt parser by pete312")
    parser.version = str(VERSION)
    parser.add_argument('--version', action='version', help='print the version and exit')
    parser.add_argument('--loglevel', choices=_LOGLEVELS, default='INFO', help='log to stdout')
    
    parser.add_argument('--default-false-bool', '-t', action='store_true', default=False, help='override the usually False flag')
    parser.add_argument('--default-true-bool', '-f',action='store_false', default=True, help='override the usually True flag')
    
    parser.add_argument('--intopt', action='store', type=int, default=1, help='store any int')
    parser.add_argument('--floatopt', action='store', type=float, default=1.0, help='store any float')
    parser.add_argument('--stropt', action='store', type=str, default='foo', help='store any str')
    parser.add_argument('--i-am-required','-r', action='store', type=str, required=True, help="I can't be ignored")
    return parser.parse_args()
Ejemplo n.º 9
0
def get_options():
    parser = ArgumentParser(description='CMD Option Demo.',
                            epilog="best practice opt parser by pete312")
    parser.version = str(VERSION)
    parser.add_argument('--version',
                        action='version',
                        help='print the version and exit')
    parser.add_argument('--loglevel',
                        choices=_LOGLEVELS,
                        default='INFO',
                        help='log to stdout')

    parser.add_argument('--default-false-bool',
                        '-t',
                        action='store_true',
                        default=False,
                        help='override the usually False flag')
    parser.add_argument('--default-true-bool',
                        '-f',
                        action='store_false',
                        default=True,
                        help='override the usually True flag')

    parser.add_argument('--intopt',
                        action='store',
                        type=int,
                        default=1,
                        help='store any int')
    parser.add_argument('--floatopt',
                        action='store',
                        type=float,
                        default=1.0,
                        help='store any float')
    parser.add_argument('--stropt',
                        action='store',
                        type=str,
                        default='foo',
                        help='store any str')
    parser.add_argument('--i-am-required',
                        '-r',
                        action='store',
                        type=str,
                        required=True,
                        help="I can't be ignored")
    return parser.parse_args()
Ejemplo n.º 10
0
def get_options():
    parser = ArgumentParser(description='fabric test v{}'.format(VERSION),
                            epilog="...")
    parser.version = str(VERSION)
    parser.add_argument('--version',
                        action='version',
                        help='print the version and exit')
    parser.add_argument('-c',
                        '--count',
                        type=int,
                        default=1,
                        help='numebr of times operation happens remotely')
    parser.add_argument('-x',
                        '--noof_conn_per_host',
                        type=int,
                        default=1,
                        help='numebr of times operation happens remotely')
    parser.add_argument('-P',
                        '--setpass',
                        dest='password',
                        default=False,
                        help='set user password')
    parser.add_argument('-p',
                        '--askpass',
                        dest='password',
                        action='store_true',
                        default=False,
                        help='ask for password prompt')
    parser.add_argument(
        '-H',
        '--hosts',
        metavar='N',
        type=str,
        nargs='+',
        help=
        'hosts to act on (user is current user unless notation user@host is used)'
    )

    return parser.parse_args()
Ejemplo n.º 11
0
            print("Subscribed %s to node %s" % (self.boundjid.bare, self.node))
        except:
            logging.error("Could not subscribe %s to node %s" % (self.boundjid.bare, self.node))

    def unsubscribe(self):
        try:
            self["xep_0060"].unsubscribe(self.pubsub_server, self.node)
            print("Unsubscribed %s from node %s" % (self.boundjid.bare, self.node))
        except:
            logging.error("Could not unsubscribe %s from node %s" % (self.boundjid.bare, self.node))


if __name__ == "__main__":
    # Setup the command line arguments.
    parser = ArgumentParser()
    parser.version = "%%prog 0.1"
    parser.usage = (
        "Usage: %%prog [options] <jid> "
        + "nodes|create|delete|purge|subscribe|unsubscribe|publish|retract|get"
        + " [<node> <data>]"
    )

    parser.add_argument(
        "-q",
        "--quiet",
        help="set logging to ERROR",
        action="store_const",
        dest="loglevel",
        const=logging.ERROR,
        default=logging.ERROR,
    )
Ejemplo n.º 12
0
            logging.error('Could not subscribe %s to node %s: %s', self.boundjid.bare, self.node, error.format())

    async def unsubscribe(self):
        try:
            await self['xep_0060'].unsubscribe(self.pubsub_server, self.node)
            logging.info('Unsubscribed %s from node %s', self.boundjid.bare, self.node)
        except XMPPError as error:
            logging.error('Could not unsubscribe %s from node %s: %s', self.boundjid.bare, self.node, error.format())




if __name__ == '__main__':
    # Setup the command line arguments.
    parser = ArgumentParser()
    parser.version = '%%prog 0.1'
    parser.usage = "Usage: %%prog [options] <jid> " + \
                             'nodes|create|delete|get_configure|purge|subscribe|unsubscribe|publish|retract|get' + \
                             ' [<node> <data>]'

    parser.add_argument("-q","--quiet", help="set logging to ERROR",
                        action="store_const",
                        dest="loglevel",
                        const=logging.ERROR,
                        default=logging.INFO)
    parser.add_argument("-d","--debug", help="set logging to DEBUG",
                        action="store_const",
                        dest="loglevel",
                        const=logging.DEBUG,
                        default=logging.INFO)
Ejemplo n.º 13
0
                else:
                    print("Incorrect number of items. Please enter grade,MCs:")
            else:
                if file:
                    csv.close()
                    break
        except KeyboardInterrupt:
            break
    return results


if __name__ == "__main__":
    my_parser = ArgumentParser(
        description=
        'Calculate and display the CAP of a student from the grades input.')
    my_parser.version = '1.0'
    my_parser.add_argument('-f',
                           '--file',
                           nargs='?',
                           const='nofile',
                           default=None,
                           help='read grades from CSV file',
                           action='store')
    file_arg = my_parser.parse_args().file
    if not file_arg:
        print(f"\rCAP: {round(cap(read_input()), 2)}")
    elif file_arg == 'nofile':
        files = glob("*.csv")
        if not files:
            print("No CSV files found in current directory.")
        elif len(files) == 1:
Ejemplo n.º 14
0
from argparse import ArgumentParser, RawTextHelpFormatter
from sys import exit

# initializing argument parser
parser = ArgumentParser(
    prog='SeBAz',
    description='Perform CIS Benchmark scoring on your Linux System',
    usage='# ./%(prog)s [optional arguments]',
    epilog='Enjoy Hardening your System!',
    formatter_class=RawTextHelpFormatter)

# SeBAz version
parser.version = '%(prog)s v0.5.1'

# optional arguments

# inlcude
parser.add_argument(
    '-i',
    '--include',
    type=str,
    nargs='+',
    action='store',
    help='List recommendations to be INCLUDED in score (Whitelist)'
    '\nDefault all recommendations are benchmarked'
    '\nGive recommendations seperated by space'
    '\nExample:'
    '\n --include 1.*   [Will only score Initial Setup]'
    '\n --include 2.1.* [Will only score inetd Services]')

# exclude
Ejemplo n.º 15
0
solution.cpp.
        '''),
                        usage="%(prog)s [options] problem_number",
                        prog='mkprob.py',
                        formatter_class=RawTextHelpFormatter,
                        epilog=dedent("""
Example Usage:
  Usage #1: Creating One Problem Directory
    mkprob.py 17
  
  Usage #2: Creating Multiple Problem Directories
    mkprob.py 17 18 19 20
"""))

# Version Number of the Script
parser.version = '0.1'

# Positional Argument for Problem Number
parser.add_argument(
    'problem_number',
    metavar='problem_number',
    type=int,
    help='Creates Directory or Directories with Problem Number(s) as suffix',
    action='store',
    nargs='+')

# Optional Agument for Version Number
parser.add_argument('-v', '--version', action='version')

# Parse Aruguments
args = parser.parse_args()
Ejemplo n.º 16
0
# -*- coding: UTF-8 -*-

from BulkEmails import *

from argparse import ArgumentParser

if __name__ == '__main__':
    #####

    # parameters management
    args_parser = ArgumentParser(
        description=
        "Send Custom Bulk Emails by Yacine YADDADEN [ https://github.com/yyaddaden ]"
    )
    args_parser.version = "1.0"

    group = args_parser.add_argument_group("send test email")
    group.add_argument("-t",
                       "--test",
                       help="send test email",
                       action="store_true")
    group.add_argument("-e",
                       "--email",
                       metavar="",
                       help="email address for testing",
                       action="store")

    group = args_parser.add_argument_group("send bulk emails")
    group.add_argument("-b",
                       "--bulk",
                       help="send bulk emails",
Ejemplo n.º 17
0
def get_options():
    parser = ArgumentParser(description='xml parse.', epilog="...")
    parser.version = str(VERSION)
    parser.add_argument('--version', action='version', help='print the version and exit')
    parser.add_argument('--file','-f', action='store', type=str, required=True, help="xml file")
    return parser.parse_args()
Ejemplo n.º 18
0
def main():
    retuncode = 0

    # Argument Parser
    my_parser = ArgumentParser(
        prog=__package_name__,
        allow_abbrev=False,
        usage="%(prog)s [options] [commands ...]",
        description=__description__,
    )

    # Add arguments
    my_parser.version = __version__
    my_parser.add_argument(
        "commands",
        action="store",
        nargs="*",
        default=None,
        help="Commands to be executed",
    )
    my_parser.add_argument(
        "-c",
        "--force-color",
        dest="force_color",
        action="store_true",
        default=None,
        help="force color for non-terminals",
    )
    my_parser.add_argument(
        "-M",
        "--markdown",
        action="store_true",
        default=None,
        help="Render Markdown to the console with Rich",
    )
    my_parser.add_argument(
        "-w",
        "--width",
        type=int,
        dest="width",
        default=None,
        help="width of output (default will auto-detect)",
    )
    my_parser.add_argument(
        "-i",
        "--inline-code-lexer",
        dest="inline_code_lexer",
        default=None,
        help="inline_code_lexer",
    )
    my_parser.add_argument(
        "-t",
        "--code-theme",
        dest="code_theme",
        default="monokai",
        help="pygments code theme",
    )
    my_parser.add_argument(
        "-y",
        "--hyperlinks",
        dest="hyperlinks",
        action="store_true",
        help="enable hyperlinks",
    )
    my_parser.add_argument(
        "-j",
        "--justify",
        dest="justify",
        action="store_true",
        help="enable full text justify",
    )
    my_parser.add_argument(
        "-p",
        "--page",
        dest="page",
        action="store_true",
        help="use pager to scroll output",
    )
    my_parser.add_argument(
        "-S",
        "--syntax",
        action="store_true",
        default=None,
        help="Render Syntax from file",
    )
    my_parser.add_argument("--path", metavar="PATH", default=None, help="path to file")
    my_parser.add_argument(
        "-l",
        "--line-numbers",
        dest="line_numbers",
        action="store_true",
        help="render line numbers",
    )
    my_parser.add_argument(
        "-r",
        "--wrap",
        dest="word_wrap",
        action="store_true",
        default=False,
        help="word wrap long lines",
    )
    my_parser.add_argument(
        "-s",
        "--soft-wrap",
        action="store_true",
        dest="soft_wrap",
        default=False,
        help="enable soft wrapping mode",
    )
    my_parser.add_argument(
        "-b",
        "--background-color",
        dest="background_color",
        default=None,
        help="Overide background color",
    )
    my_parser.add_argument("-V", "--version", action="version")

    args = my_parser.parse_args()
    cwd = os.getcwd()

    if args.width:
        console._width = args.width

    if args.force_color:
        console._force_terminal = args.force_color

    if args.syntax:
        if args.path:
            try:
                render2syntax(args.path, vars(args))
            except ColorParseError as err:
                print_error(str(err))
        else:
            print_error("Syntax require --path to fille")
            sys.exit(1)
    elif args.markdown:
        render2markdown(" ".join(args.commands), vars(args))
    elif args.commands:
        c = run_command(" ".join(args.commands), cwd)
        retuncode = c.return_code
    else:
        retuncode = start_shell(cwd)

    return retuncode
Ejemplo n.º 19
0
Archivo: arg.py Proyecto: nuaays/des
'''Handle CLI args'''
from argparse import ArgumentParser
from des.__init__ import __version__

ARGPARSER = ArgumentParser(
    description='Run scripts in response to Docker events')

ARGPARSER.version = __version__

ARGPARSER.add_argument('-c',
                       '--create',
                       dest='create',
                       action='store_true',
                       help='Create script dir structure and exit')

ARGPARSER.add_argument(
    '-e',
    dest='docker_url',
    action='store',
    default="unix:///var/run/docker.sock",
    help='Docker endpoint (Default: unix:///var/run/docker.sock)')

ARGPARSER.add_argument('-d',
                       dest='script_dir',
                       action='store',
                       default="/etc/docker/events.d",
                       help='Event script directory')

ARGPARSER.add_argument('-v',
                       '--verbose',
                       dest='verbose',
Ejemplo n.º 20
0
                          self.boundjid.bare, self.node, error.format())

    async def unsubscribe(self):
        try:
            await self['xep_0060'].unsubscribe(self.pubsub_server, self.node)
            logging.info('Unsubscribed %s from node %s', self.boundjid.bare,
                         self.node)
        except XMPPError as error:
            logging.error('Could not unsubscribe %s from node %s: %s',
                          self.boundjid.bare, self.node, error.format())


if __name__ == '__main__':
    # Setup the command line arguments.
    parser = ArgumentParser()
    parser.version = '%%prog 0.1'
    parser.usage = "Usage: %%prog [options] <jid> " + \
                             'nodes|create|delete|get_configure|purge|subscribe|unsubscribe|publish|retract|get' + \
                             ' [<node> <data>]'

    parser.add_argument("-q",
                        "--quiet",
                        help="set logging to ERROR",
                        action="store_const",
                        dest="loglevel",
                        const=logging.ERROR,
                        default=logging.INFO)
    parser.add_argument("-d",
                        "--debug",
                        help="set logging to DEBUG",
                        action="store_const",
Ejemplo n.º 21
0
'''Handle CLI args'''
from argparse import ArgumentParser
from des.__init__ import __version__

ARGPARSER = ArgumentParser(
    description='Run scripts in response to Docker events'
)

ARGPARSER.version = __version__

ARGPARSER.add_argument(
    '-c',
    '--create',
    dest='create',
    action='store_true',
    help='Create script dir structure and exit')

ARGPARSER.add_argument(
    '-e',
    dest='docker_url',
    action='store',
    default="unix:///var/run/docker.sock",
    help='Docker endpoint (Default: unix:///var/run/docker.sock)')

ARGPARSER.add_argument(
    '-d',
    dest='script_dir',
    action='store',
    default="/etc/docker/events.d",
    help='Event script directory')