Exemplo n.º 1
0
    def run(self):
        if self.app_name == None:
            i = InfoCompiler(None)
            data_container = i.getSetupFileInfo()
        else:
            i = InfoCompiler(self.app_name)
            data_container = i.getUserInfo()

        db = DirectoryBuilder(data_container)
        db.build()
        fb = FileBuilder(data_container)
        if fb.build_and_write(): # file writes were successful
            main_script_path = make_path(data_container.app_name, 'lib', data_container.app_name, 'app.py')
            settings_path = make_path(data_container.app_name, 'lib', data_container.app_name, 'settings.py')
            command_dir = make_path(data_container.app_name, 'lib', data_container.app_name, 'commands')
            setuppy_path = make_path(data_container.app_name, 'setup.py')
            print(" ")
            print(data_container.app_name + " was successfully built.")
            print(" ")
            print("-----")
            print("Main application script:  " + main_script_path)
            print("Settings file:  " + settings_path)
            print("Commands directory:  " + command_dir)
            print("setup.py file:  " + setuppy_path)
            print("-----")
            print(" ")
            print("Use 'python setup.py develop' from the top level of your project and you can begin testing your application with the executable, " + data_container.app_name)
            exit_success()
def help():
    from Naked.toolshed.system import exit_success
    help_string = """
Naked make Command Help
=======================
The make command builds a new Naked project.  The project can be built from either responses that you give on the command line, or from a naked.yaml project settings file.

USAGE
  naked make [argument]

The command should be run in the top level of the path where you would like to create your project.  The argument to the make command is optional.  If used, this is the name of your new project.  It is not necessary to include the argument if you use a naked.yaml project settings file.

The naked.yaml settings file has the following structure:

  application:  <your project name>
  developer:    <developer name>
  license:      <license type>

Place this in the top level of an empty directory and use `naked make` in the same directory.  Naked will confirm your settings and then build the project directories and files from these settings.

SECONDARY COMMANDS
  none

OPTIONS
  none

EXAMPLES
  naked make
  naked make testapp"""
    print(help_string)
    exit_success()
Exemplo n.º 3
0
    def post_response(self):
        try:
            the_url = prepare_url(self.url)
            http = HTTP(the_url)
            http.post()
            resp = http.response()

            # confirm that a response was returned, abort if not
            if resp == None and the_url.startswith('https://'):
                stderr("Unable to connect to the requested URL. This can happen if the secure HTTP protocol is not supported at the requested URL.")
                sys.exit(1)
            elif resp == None:
                stderr("Unable to connect to the requested URL. Please confirm your URL and try again.")
                sys.exit(1)

            if len(resp.history) > 0:
                count = len(resp.history)
                for i in range(count):
                    print(str(resp.history[i].status_code) + " : " + str(resp.history[i].url))
            print(str(http.res.status_code) + " : " + the_url)
            exit_success()
        except ConnectionError as ce:
            error_string = "Unable to connect to the URL, " + self.url
            stderr(error_string, 1)
        except Exception as e:
            raise e
Exemplo n.º 4
0
def help():
    from Naked.toolshed.system import exit_success
    help_string = """
Naked make Command Help
=======================
The make command builds a new Naked project.  The project can be built from either responses that you give on the command line, or from a naked.yaml project settings file.

USAGE
  naked make [argument]

The command should be run in the top level of the path where you would like to create your project.  The argument to the make command is optional.  If used, this is the name of your new project.  It is not necessary to include the argument if you use a naked.yaml project settings file.

The naked.yaml settings file has the following structure:

  application:  <your project name>
  developer:    <developer name>
  license:      <license type>

Place this in the top level of an empty directory and use `naked make` in the same directory.  Naked will confirm your settings and then build the project directories and files from these settings.

SECONDARY COMMANDS
  none

OPTIONS
  none

EXAMPLES
  naked make
  naked make testapp"""
    print(help_string)
    exit_success()
    def post_response(self):
        try:
            the_url = prepare_url(self.url)
            http = HTTP(the_url)
            http.post()
            resp = http.response()

            # confirm that a response was returned, abort if not
            if resp == None and the_url.startswith('https://'):
                stderr(
                    "Unable to connect to the requested URL. This can happen if the secure HTTP protocol is not supported at the requested URL."
                )
                sys.exit(1)
            elif resp == None:
                stderr(
                    "Unable to connect to the requested URL. Please confirm your URL and try again."
                )
                sys.exit(1)

            if len(resp.history) > 0:
                count = len(resp.history)
                for i in range(count):
                    print(
                        str(resp.history[i].status_code) + " : " +
                        str(resp.history[i].url))
            print(str(http.res.status_code) + " : " + the_url)
            exit_success()
        except ConnectionError as ce:
            error_string = "Unable to connect to the URL, " + self.url
            stderr(error_string, 1)
        except Exception as e:
            raise e
def help():
    help_string = """
Naked dist Command Help
=======================
The dist secondary commands run the standard distutils 'python setup.py <command>' source/binary distribution commands.

USAGE
  naked dist <secondary_command>

SECONDARY COMMANDS   python setup.py <command(s)>
  all                  sdist bdist_wheel bdist_wininst upload
  register             register
  sdist                sdist upload
  swheel               sdist bdist_wheel upload
  wheel                bdist_wheel upload
  win                  bdist_wininst upload

OPTIONS
  none

EXAMPLES
  naked dist register
  naked dist sdist"""
    print(help_string)
    exit_success()
    def run(self):
        if self.app_name == None:
            i = InfoCompiler(None)
            data_container = i.getSetupFileInfo()
        else:
            i = InfoCompiler(self.app_name)
            data_container = i.getUserInfo()

        db = DirectoryBuilder(data_container)
        db.build()
        fb = FileBuilder(data_container)
        if fb.build_and_write():  # file writes were successful
            main_script_path = make_path(data_container.app_name, 'lib',
                                         data_container.app_name, 'app.py')
            settings_path = make_path(data_container.app_name, 'lib',
                                      data_container.app_name, 'settings.py')
            command_dir = make_path(data_container.app_name, 'lib',
                                    data_container.app_name, 'commands')
            setuppy_path = make_path(data_container.app_name, 'setup.py')
            print(" ")
            print(data_container.app_name + " was successfully built.")
            print(" ")
            print("-----")
            print("Main application script:  " + main_script_path)
            print("Settings file:  " + settings_path)
            print("Commands directory:  " + command_dir)
            print("setup.py file:  " + setuppy_path)
            print("-----")
            print(" ")
            print(
                "Use 'python setup.py develop' from the top level of your project and you can begin testing your application with the executable, "
                + data_container.app_name)
            exit_success()
Exemplo n.º 8
0
def help():
    help_string = """
Naked dist Command Help
=======================
The dist secondary commands run the standard distutils 'python setup.py <command>' source/binary distribution commands.

USAGE
  naked dist <secondary_command>

SECONDARY COMMANDS   python setup.py <command(s)>
  all                  sdist bdist_wheel bdist_wininst upload
  register             register
  sdist                sdist upload
  swheel               sdist bdist_wheel upload
  wheel                bdist_wheel upload
  win                  bdist_wininst upload

OPTIONS
  none

EXAMPLES
  naked dist register
  naked dist sdist"""
    print(help_string)
    exit_success()
def pyh_help():
    from Naked.toolshed.system import exit_success
    help_string = """
Naked pyh Command Help
======================
The pyh command searches the built-in Python documentation for a query term.  The query term can be a Python built-in module, class/type, method, or function.

USAGE
  naked pyh <query>

SECONDARY COMMANDS
  none

OPTIONS
  none

EXAMPLES
  Module Docs:   naked pyh sys

  Class Docs:    naked pyh dict

  Method Docs:   naked pyh dict.update

  Function Docs: naked pyh max"""

    print(help_string)
    exit_success()
Exemplo n.º 10
0
    def run(self):
        from Naked.toolshed.network import HTTP
        http = HTTP(self.url)  # use the python.org url for the classifier list

        print('•naked• Pulling the classifier list from python.org...')

        res = http.get()  # get the list
        test_list = res.split('\n')  # split on newlines

        if self.needle == "":  # user did not enter a search string, print the entire list
            print(
                "•naked• You did not provide a search string.  Here is the entire list:"
            )
            print(' ')
            for item in test_list:
                print(item)
        else:  # user entered a search string, find it
            lower_needle = self.needle.lower()
            print("•naked• Performing a case insensitive search for '" +
                  self.needle + "'")
            print(' ')
            filtered_list = [
                x for x in test_list if lower_needle in x.lower()
            ]  #case insensitive match for the search string
            for item in filtered_list:
                print(item)

        exit_success()  # exit with zero status code
Exemplo n.º 11
0
def pyh_help():
    from Naked.toolshed.system import exit_success
    help_string = """
Naked pyh Command Help
======================
The pyh command searches the built-in Python documentation for a query term.  The query term can be a Python built-in module, class/type, method, or function.

USAGE
  naked pyh <query>

SECONDARY COMMANDS
  none

OPTIONS
  none

EXAMPLES
  Module Docs:   naked pyh sys

  Class Docs:    naked pyh dict

  Method Docs:   naked pyh dict.update

  Function Docs: naked pyh max"""

    print(help_string)
    exit_success()
def compile_c_code(abs_dirpath):
    from Naked.toolshed.shell import execute
    from os import chdir

    chdir(abs_dirpath)
    print('•naked• Compiling the C source library files...')
    success = execute("python setup.py build_ext --inplace")
    if success:
        print(' ')
        print('•naked• C source code compile complete.')
        exit_success()
Exemplo n.º 13
0
def compile_c_code(abs_dirpath):
    from Naked.toolshed.shell import execute
    from os import chdir

    chdir(abs_dirpath)
    print('•naked• Compiling the C source library files...')
    success = execute("python setup.py build_ext --inplace")
    if success:
        print(' ')
        print('•naked• C source code compile complete.')
        exit_success()
 def run(self):
     py_found = False
     for i in range(self.number_of_dir_levels):
         if not self._is_testdir_at_this_level():
             os.chdir(os.pardir)
         else:
             py_found = True
             self._run_pytests()
             break
     if not py_found:
         stderr("Unable to locate your testing directory", 1)
     else:
         exit_success()
 def run(self):
     tox_found = False
     for i in range(self.number_of_dir_levels):
         if not self._is_tox_ini_at_this_level():
             os.chdir(os.pardir)
         else:
             tox_found = True
             self._run_tox()
             break
     if not tox_found:
         stderr("Unable to locate your tox.ini file.  Please navigate to your project directory.", 1)
     else:
         exit_success()
Exemplo n.º 16
0
 def run(self, command):
     setuppy_found = False
     for i in range(6): # navigate up at most 4 directory levels to search for the setup.py file
         if not self._is_setup_py_at_this_level():
             os.chdir(os.pardir)
         else:
             setuppy_found = True
             self._run_dist_command(command)
             break
     if not setuppy_found:
         stderr("Unable to locate the setup.py file for your project.  Please confirm that you are in your project directory and try again.", 1)
     else:
         exit_success()
Exemplo n.º 17
0
def help():
    help_string = """
Naked build Command Help
========================
The build command compiles the Naked C libraries.  This requires an installed C compiler.

USAGE
  naked build

SECONDARY COMMANDS
  none

OPTIONS
  none"""
    print(help_string)
    exit_success()
def help():
    help_string = """
Naked build Command Help
========================
The build command compiles the Naked C libraries.  This requires an installed C compiler.

USAGE
  naked build

SECONDARY COMMANDS
  none

OPTIONS
  none"""
    print(help_string)
    exit_success()
 def run(self):
     unit_found = False
     for i in range(self.number_of_dir_levels):
         if not self._is_testdir_at_this_level():
             os.chdir(os.pardir)
         else:
             unit_found = True
             os.chdir('tests')
             if file_exists(self.unittest):
                 self._run_unittest()
             else:
                 stderr("The unit test file " + self.unittest + " could not be found in the tests directory.")
     if not unit_found:
         stderr("Unable to locate your testing directory", 1)
     else:
         exit_success()
Exemplo n.º 20
0
 def run(self):
     lib_found = False
     for i in range(self.number_of_dir_levels):
         if not self._is_lib_at_this_level():
             os.chdir(os.pardir)
         else:
             lib_found = True
             break
     if lib_found:
         os.chdir('lib') # chdir to the lib directory if it is found
         if file_exists('profiler.py'): # confirm that profiler.py exists
             os.system('python profiler.py') # run the profiler.py file
             exit_success()
         else:
             stderr("Unable to locate a profiler.py file in your lib directory.", 1)
     else:
         stderr("Unable to locate your profiler.py file.  Please navigate to your project directory.", 1)
 def run(self, command):
     setuppy_found = False
     for i in range(
             6
     ):  # navigate up at most 4 directory levels to search for the setup.py file
         if not self._is_setup_py_at_this_level():
             os.chdir(os.pardir)
         else:
             setuppy_found = True
             self._run_dist_command(command)
             break
     if not setuppy_found:
         stderr(
             "Unable to locate the setup.py file for your project.  Please confirm that you are in your project directory and try again.",
             1)
     else:
         exit_success()
def help():
    help_string = """
Naked test Command Help
=======================
The test command allows you to run unit tests from any working directory in your project.

USAGE
  naked test <secondary command> [argument]

SECONDARY COMMANDS
  nose      -  run the nose test runner on your project
  pytest    -  run the py.test test runner on your project
  tox       -  run the tox test runner on your project
  unittest  -  run Python unit tests (built-in)

ARGUMENTS
  nose
     -- does not take additional arguments

  pytest
     -- does not take additional arguments

  tox [python version]
     -- You can include an optional tox Python version argument to run your
        tests with a single version of Python (instead of the versions
        specified in the tox.ini file). By default, the versions specified
        in your tox.ini file are run.

  unittest <test file>
     -- Mandatory unit test file path (relative to the tests directory)

OPTIONS
  none

EXAMPLES
  naked test nose
  naked test pytest
  naked test tox
  naked test tox py27
  naked test unittest test_app.py

A bottom to top search (from the working directory) is performed over up to 6 directory levels to find the 'tests' directory."""
    print(help_string)
    exit_success()
def help():
    from Naked.toolshed.system import exit_success
    help_string = """
Naked profile Command Help
==========================
The profile command runs cProfile and pstats on the code that you enter in test code block of your PROJECT/lib/profiler.py file.

USAGE
  naked profile

SECONDARY COMMANDS
  none

OPTIONS
  none

This command searches bottom to top (from the working directory) through up to 6 directory levels to identify the lib/profiler.py path."""

    print(help_string)
    exit_success()
Exemplo n.º 24
0
def help():
    from Naked.toolshed.system import exit_success
    help_string = """
Naked profile Command Help
==========================
The profile command runs cProfile and pstats on the code that you enter in test code block of your PROJECT/lib/profiler.py file.

USAGE
  naked profile

SECONDARY COMMANDS
  none

OPTIONS
  none

This command searches bottom to top (from the working directory) through up to 6 directory levels to identify the lib/profiler.py path."""

    print(help_string)
    exit_success()
def help():
    help_string = """
Naked locate Command Help
=========================
The locate command identifies the file path to commonly used files in your project directory.

USAGE
  naked locate <argument>

SECONDARY COMMANDS
  main     -  the main application script file, app.py
  setup    -  the setup.py file
  settings -  the project settings files, settings.py

OPTIONS
  none

EXAMPLE
  naked locate main"""
    print(help_string)
    exit_success()
Exemplo n.º 26
0
def help():
    help_string = """
Naked locate Command Help
=========================
The locate command identifies the file path to commonly used files in your project directory.

USAGE
  naked locate <argument>

SECONDARY COMMANDS
  main     -  the main application script file, app.py
  setup    -  the setup.py file
  settings -  the project settings files, settings.py

OPTIONS
  none

EXAMPLE
  naked locate main"""
    print(help_string)
    exit_success()
 def run(self):
     lib_found = False
     for i in range(self.number_of_dir_levels):
         if not self._is_lib_at_this_level():
             os.chdir(os.pardir)
         else:
             lib_found = True
             break
     if lib_found:
         os.chdir('lib')  # chdir to the lib directory if it is found
         if file_exists('profiler.py'):  # confirm that profiler.py exists
             os.system('python profiler.py')  # run the profiler.py file
             exit_success()
         else:
             stderr(
                 "Unable to locate a profiler.py file in your lib directory.",
                 1)
     else:
         stderr(
             "Unable to locate your profiler.py file.  Please navigate to your project directory.",
             1)
Exemplo n.º 28
0
def help():
    from Naked.toolshed.system import exit_success
    help_string = """
Naked args Command Help
=======================
The args command displays information about the data that are parsed from a command string to Command object attributes and that are obtained from Command object methods.  It is intended to help with the design of your application logic when you use the Naked command line parser.

USAGE
  naked args '<command statement>'

The command statement is a mandatory argument to the command.  It should include a complete command as it would be entered on the command line, including the executable.  The argument should be completely enclosed within quotes.

SECONDARY COMMANDS
  none

OPTIONS
  none

EXAMPLE
  naked args 'testapp save somestring --unicode -s --name=file.txt'"""
    print(help_string)
    exit_success()
def help():
    from Naked.toolshed.system import exit_success
    help_string = """
Naked args Command Help
=======================
The args command displays information about the data that are parsed from a command string to Command object attributes and that are obtained from Command object methods.  It is intended to help with the design of your application logic when you use the Naked command line parser.

USAGE
  naked args '<command statement>'

The command statement is a mandatory argument to the command.  It should include a complete command as it would be entered on the command line, including the executable.  The argument should be completely enclosed within quotes.

SECONDARY COMMANDS
  none

OPTIONS
  none

EXAMPLE
  naked args 'testapp save somestring --unicode -s --name=file.txt'"""
    print(help_string)
    exit_success()
Exemplo n.º 30
0
def help():
    help_string = """
Naked classify Command Help
===========================
The classify command performs a case-insensitive search of the PyPI application classifier list and displays the results.

USAGE
  naked classify [search string]

The search string argument is optional.  If you do not include a search string, the entire classifier list is displayed.

SECONDARY COMMANDS
  none

OPTIONS
  none

EXAMPLES
  naked classify
  naked classify Internet
"""
    print(help_string)
    exit_success()
Exemplo n.º 31
0
    def run(self):
        from Naked.toolshed.network import HTTP
        http = HTTP(self.url) # use the python.org url for the classifier list

        print('•naked• Pulling the classifier list from python.org...')

        res = http.get() # get the list
        test_list = res.split('\n') # split on newlines

        if self.needle == "": # user did not enter a search string, print the entire list
            print("•naked• You did not provide a search string.  Here is the entire list:")
            print(' ')
            for item in test_list:
                print(item)
        else: # user entered a search string, find it
            lower_needle = self.needle.lower()
            print("•naked• Performing a case insensitive search for '" + self.needle + "'")
            print(' ')
            filtered_list = [ x for x in test_list if lower_needle in x.lower() ] #case insensitive match for the search string
            for item in filtered_list:
                print(item)

        exit_success() # exit with zero status code
Exemplo n.º 32
0
def help():
    help_string = """
Naked classify Command Help
===========================
The classify command performs a case-insensitive search of the PyPI application classifier list and displays the results.

USAGE
  naked classify [search string]

The search string argument is optional.  If you do not include a search string, the entire classifier list is displayed.

SECONDARY COMMANDS
  none

OPTIONS
  none

EXAMPLES
  naked classify
  naked classify Internet
"""
    print(help_string)
    exit_success()
Exemplo n.º 33
0
 def _display_location(self):
     if self.needle == 'main':
         main_path = os.path.join('<PROJECT>', 'lib', '<PROJECT>', 'app.py')
         print("app.py : " + main_path)
         exit_success()
     elif self.needle == "settings":
         settings_path = os.path.join('<PROJECT>', 'lib', '<PROJECT>','settings.py')
         print("settings.py : " + settings_path)
         exit_success()
     elif self.needle == "setup":
         setup_path = os.path.join('<PROJECT>', 'setup.py')
         print("setup.py : " + setup_path)
         exit_success()
     else:
         stderr("Unable to process the command.  Use 'naked locate help' for more information.", 1)
 def _display_location(self):
     if self.needle == 'main':
         main_path = os.path.join('<PROJECT>', 'lib', '<PROJECT>', 'app.py')
         print("app.py : " + main_path)
         exit_success()
     elif self.needle == "settings":
         settings_path = os.path.join('<PROJECT>', 'lib', '<PROJECT>',
                                      'settings.py')
         print("settings.py : " + settings_path)
         exit_success()
     elif self.needle == "setup":
         setup_path = os.path.join('<PROJECT>', 'setup.py')
         print("setup.py : " + setup_path)
         exit_success()
     else:
         stderr(
             "Unable to process the command.  Use 'naked locate help' for more information.",
             1)
Exemplo n.º 35
0
 def run(self):
     cmd_list = shlex.split(self.com_string)
     c = Command(cmd_list[0], cmd_list[1:])
     print(' ')
     print("•naked• Assuming that your Command object is instantiated as an instance named 'c', the command that you entered would be parsed as follows:")
     print(' ')
     print('Application')
     print('-----------')
     print('c.app = ' + c.app)
     print(' ')
     print('Argument List Length')
     print('--------------------')
     print('c.argc = ' + str(c.argc))
     print(' ')
     print('Argument List Items')
     print('-------------------')
     print('c.argobj = ' + str(c.argobj))
     print(' ')
     print('Arguments by Zero Indexed Start Position')
     print('----------------------------------------')
     print('c.arg0 = ' + c.arg0)
     print('c.arg1 = ' + c.arg1)
     print('c.arg2 = ' + c.arg2)
     print('c.arg3 = ' + c.arg3)
     print('c.arg4 = ' + c.arg4)
     print(' ')
     print('Arguments by Named Position')
     print('---------------------------')
     print('c.first = ' + c.first)
     print('c.second = ' + c.second)
     print('c.third = ' + c.third)
     print('c.fourth = ' + c.fourth)
     print('c.fifth = ' + c.fifth)
     print(' ')
     print('Last Positional Argument')
     print('------------------------')
     print('c.arglp = ' + c.arglp)
     print('c.last = ' + c.last)
     print(' ')
     print('Primary & Secondary Commands')
     print('----------------------------')
     print('c.cmd = ' + c.cmd)
     print('c.cmd2 = ' + c.cmd2)
     print(' ')
     print('Option Exists Tests')
     print('------------------')
     print('c.option_exists() = ' + str(c.option_exists()))
     print('c.options = ' + str(c.options))
     print(' ')
     print('Option Argument Assignment')
     print('--------------------------')
     if c.option_exists(): # if there are options, iterate through and print arguments to them
         non_flag_options = False
         for x in range(len(c.optobj)):
             if '=' in c.optobj[x]:
                 continue # don't print flags, they are handled below
             else:
                 print('c.arg("' + c.optobj[x] + '") = ' + c.arg(c.optobj[x]))
                 non_flag_options = True
         if not non_flag_options:
             print("There are no short or long options in the command.")
     else: # otherwise, inform user that there are no options
         print("There are no short options, long options, or flags in your command.")
     print(' ')
     print('Flag Exists Tests')
     print('----------------')
     print('c.flag_exists() = ' + str(c.flag_exists()))
     print('c.flags = ' + str(c.flags))
     print(' ')
     print('Flag Argument Assignment')
     print('------------------------')
     if c.flag_exists():
         for y in c.optobj:
             if '=' in y:
                 the_flag = y.split('=')[0]
                 print('c.flag_arg("' + the_flag + '") = ' + c.flag_arg(the_flag))
     else: # provide message if there are no flags
         print("There are no flag style arguments (--flag=argument) in your command.")
     exit_success()
Exemplo n.º 36
0
 def print_version(self):
     print(self.app_version_string)
     exit_success()
Exemplo n.º 37
0
 def print_usage(self):
     print(self.usage)
     exit_success()
 def print_help(self):
     print(self.help)
     exit_success()
Exemplo n.º 39
0
 def print_version(self):
     print(self.app_version_string)
     exit_success()
Exemplo n.º 40
0
	def test_sys_exit_success(self):
		"""Test application exit with exit code 0"""
		with (self.assertRaises(SystemExit)) as sysexit:
			system.exit_success()
			self.assertEqual(0, sysexit.code)
 def run(self):
     cmd_list = shlex.split(self.com_string)
     c = Command(cmd_list[0], cmd_list[1:])
     print(' ')
     print(
         "•naked• Assuming that your Command object is instantiated as an instance named 'c', the command that you entered would be parsed as follows:"
     )
     print(' ')
     print('Application')
     print('-----------')
     print('c.app = ' + c.app)
     print(' ')
     print('Argument List Length')
     print('--------------------')
     print('c.argc = ' + str(c.argc))
     print(' ')
     print('Argument List Items')
     print('-------------------')
     print('c.argobj = ' + str(c.argobj))
     print(' ')
     print('Arguments by Zero Indexed Start Position')
     print('----------------------------------------')
     print('c.arg0 = ' + c.arg0)
     print('c.arg1 = ' + c.arg1)
     print('c.arg2 = ' + c.arg2)
     print('c.arg3 = ' + c.arg3)
     print('c.arg4 = ' + c.arg4)
     print(' ')
     print('Arguments by Named Position')
     print('---------------------------')
     print('c.first = ' + c.first)
     print('c.second = ' + c.second)
     print('c.third = ' + c.third)
     print('c.fourth = ' + c.fourth)
     print('c.fifth = ' + c.fifth)
     print(' ')
     print('Last Positional Argument')
     print('------------------------')
     print('c.arglp = ' + c.arglp)
     print('c.last = ' + c.last)
     print(' ')
     print('Primary & Secondary Commands')
     print('----------------------------')
     print('c.cmd = ' + c.cmd)
     print('c.cmd2 = ' + c.cmd2)
     print(' ')
     print('Option Exists Tests')
     print('------------------')
     print('c.option_exists() = ' + str(c.option_exists()))
     print('c.options = ' + str(c.options))
     print(' ')
     print('Option Argument Assignment')
     print('--------------------------')
     if c.option_exists(
     ):  # if there are options, iterate through and print arguments to them
         non_flag_options = False
         for x in range(len(c.optobj)):
             if '=' in c.optobj[x]:
                 continue  # don't print flags, they are handled below
             else:
                 print('c.arg("' + c.optobj[x] + '") = ' +
                       c.arg(c.optobj[x]))
                 non_flag_options = True
         if not non_flag_options:
             print("There are no short or long options in the command.")
     else:  # otherwise, inform user that there are no options
         print(
             "There are no short options, long options, or flags in your command."
         )
     print(' ')
     print('Flag Exists Tests')
     print('----------------')
     print('c.flag_exists() = ' + str(c.flag_exists()))
     print('c.flags = ' + str(c.flags))
     print(' ')
     print('Flag Argument Assignment')
     print('------------------------')
     if c.flag_exists():
         for y in c.optobj:
             if '=' in y:
                 the_flag = y.split('=')[0]
                 print('c.flag_arg("' + the_flag + '") = ' +
                       c.flag_arg(the_flag))
     else:  # provide message if there are no flags
         print(
             "There are no flag style arguments (--flag=argument) in your command."
         )
     exit_success()
Exemplo n.º 42
0
 def print_usage(self):
     print(self.usage)
     exit_success()
Exemplo n.º 43
0
 def test_sys_exit_success(self):
     """Test application exit with exit code 0"""
     with (self.assertRaises(SystemExit)) as sysexit:
         system.exit_success()
         self.assertEqual(0, sysexit.code)