Added a SAP connector and integrated the test system with coverage.py
This commit is contained in:
		
							parent
							
								
									b541ecb651
								
							
						
					
					
						commit
						01487db688
					
				
					 8 changed files with 450 additions and 115 deletions
				
			
		
							
								
								
									
										87
									
								
								bin/asksap.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								bin/asksap.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,87 @@
 | 
			
		|||
'''This script allows to get information about a given SAP RFC function
 | 
			
		||||
   module.'''
 | 
			
		||||
 | 
			
		||||
# ------------------------------------------------------------------------------
 | 
			
		||||
import sys, getpass
 | 
			
		||||
from optparse import OptionParser
 | 
			
		||||
from appy.shared.sap import Sap, SapError
 | 
			
		||||
 | 
			
		||||
# ------------------------------------------------------------------------------
 | 
			
		||||
WRONG_NG_OF_ARGS = 'Wrong number of arguments.'
 | 
			
		||||
ERROR_CODE = 1
 | 
			
		||||
P_OPTION = 'The password related to SAP user.'
 | 
			
		||||
G_OPTION = 'The name of a SAP group of functions'
 | 
			
		||||
 | 
			
		||||
# ------------------------------------------------------------------------------
 | 
			
		||||
class AskSap:
 | 
			
		||||
    '''This script allows to get information about a given RCF function module
 | 
			
		||||
       exposed by a distant SAP system.
 | 
			
		||||
 | 
			
		||||
       usage: %prog [options] host sysnr client user functionName
 | 
			
		||||
 | 
			
		||||
       "host"         is the server name or IP address where SAP runs.
 | 
			
		||||
       "sysnr"        is the SAP system/gateway number (example: 0)
 | 
			
		||||
       "client"       is the SAP client number (example: 040)
 | 
			
		||||
       "user"         is a valid SAP login
 | 
			
		||||
       "sapElement"   is the name of a SAP function (the default) or a given
 | 
			
		||||
                      group of functions (if option -g is given). If -g is
 | 
			
		||||
                      specified, sapElement can be "_all_" and all functions of
 | 
			
		||||
                      all groups are shown.
 | 
			
		||||
       Examples
 | 
			
		||||
       --------
 | 
			
		||||
       1) Retrieve info about the function named "ZFX":
 | 
			
		||||
          python asksap.py 127.0.0.1 0 040 USERGDY ZFX -p passwd
 | 
			
		||||
 | 
			
		||||
       2) Retrieve info about group of functions "Z_API":
 | 
			
		||||
          python asksap.py 127.0.0.1 0 040 USERGDY Z_API -p passwd -g
 | 
			
		||||
 | 
			
		||||
       3) Retrieve info about all functions in all groups:
 | 
			
		||||
          python asksap.py 127.0.0.1 0 040 USERGDY _all_ -p passwd -g
 | 
			
		||||
    '''
 | 
			
		||||
    def manageArgs(self, parser, options, args):
 | 
			
		||||
        # Check number of args
 | 
			
		||||
        if len(args) != 5:
 | 
			
		||||
            print WRONG_NG_OF_ARGS
 | 
			
		||||
            parser.print_help()
 | 
			
		||||
            sys.exit(ERROR_CODE)
 | 
			
		||||
 | 
			
		||||
    def run(self):
 | 
			
		||||
        optParser = OptionParser(usage=AskSap.__doc__)
 | 
			
		||||
        optParser.add_option("-p", "--password", action='store', type='string',
 | 
			
		||||
            dest='password', default='', help=P_OPTION)
 | 
			
		||||
        optParser.add_option("-g", "--group", action='store_true',
 | 
			
		||||
            dest='isGroup', default='', help=G_OPTION)
 | 
			
		||||
        (options, args) = optParser.parse_args()
 | 
			
		||||
        try:
 | 
			
		||||
            self.manageArgs(optParser, options, args)
 | 
			
		||||
            # Ask the password, if it was not given as an option.
 | 
			
		||||
            password = options.password
 | 
			
		||||
            if not password:
 | 
			
		||||
                password = getpass.getpass('Password for the SAP user: ')
 | 
			
		||||
            connectionParams = args[:4] + [password]
 | 
			
		||||
            print 'Connecting to SAP...'
 | 
			
		||||
            sap = Sap(*connectionParams)
 | 
			
		||||
            sap.connect()
 | 
			
		||||
            print 'Connected.'
 | 
			
		||||
            sapElement = args[4]
 | 
			
		||||
            if options.isGroup:
 | 
			
		||||
                # Returns info about the functions available in this group of
 | 
			
		||||
                # functions.
 | 
			
		||||
                info = sap.getGroupInfo(sapElement)
 | 
			
		||||
                prefix = 'Group'
 | 
			
		||||
            else:
 | 
			
		||||
                # Return info about a given function.
 | 
			
		||||
                info = sap.getFunctionInfo(sapElement)
 | 
			
		||||
                prefix = 'Function'
 | 
			
		||||
            print '%s: %s' % (prefix, sapElement)
 | 
			
		||||
            print info
 | 
			
		||||
            sap.disconnect()
 | 
			
		||||
        except SapError, se:
 | 
			
		||||
            sys.stderr.write(str(se))
 | 
			
		||||
            sys.stderr.write('\n')
 | 
			
		||||
            sys.exit(ERROR_CODE)
 | 
			
		||||
 | 
			
		||||
# ------------------------------------------------------------------------------
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    AskSap().run()
 | 
			
		||||
# ------------------------------------------------------------------------------
 | 
			
		||||
							
								
								
									
										116
									
								
								bin/generate.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								bin/generate.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,116 @@
 | 
			
		|||
'''This script allows to generate a product from a Appy application.'''
 | 
			
		||||
 | 
			
		||||
# ------------------------------------------------------------------------------
 | 
			
		||||
import sys, os.path
 | 
			
		||||
from optparse import OptionParser
 | 
			
		||||
from appy.gen.generator import GeneratorError
 | 
			
		||||
 | 
			
		||||
# ------------------------------------------------------------------------------
 | 
			
		||||
ERROR_CODE = 1
 | 
			
		||||
VALID_PRODUCT_TYPES = ('plone25', 'odt')
 | 
			
		||||
APP_NOT_FOUND = 'Application not found at %s.'
 | 
			
		||||
WRONG_NG_OF_ARGS = 'Wrong number of arguments.'
 | 
			
		||||
WRONG_OUTPUT_FOLDER = 'Output folder not found. Please create it first.'
 | 
			
		||||
PRODUCT_TYPE_ERROR = 'Wrong product type. Product type may be one of the ' \
 | 
			
		||||
                     'following: %s' % str(VALID_PRODUCT_TYPES)
 | 
			
		||||
C_OPTION = 'Removes from i18n files all labels that are not automatically ' \
 | 
			
		||||
           'generated from your gen-application. It can be useful during ' \
 | 
			
		||||
           'development, when you do lots of name changes (classes, ' \
 | 
			
		||||
           'attributes, states, transitions, etc): in this case, the Appy ' \
 | 
			
		||||
           'i18n label generation machinery produces lots of labels that ' \
 | 
			
		||||
           'then become obsolete.'
 | 
			
		||||
S_OPTION = 'Sorts all i18n labels. If you use this option, among the ' \
 | 
			
		||||
           'generated i18n files, you will find first all labels ' \
 | 
			
		||||
           'that are automatically generated by appy.gen, in some logical ' \
 | 
			
		||||
           'order (ie: field-related labels appear together, in the order ' \
 | 
			
		||||
           'they are declared in the gen-class). Then, if you have added ' \
 | 
			
		||||
           'labels manually, they will appear afterwards. Sorting labels ' \
 | 
			
		||||
           'may not be desired under development. Indeed, when no sorting ' \
 | 
			
		||||
           'occurs, every time you add or modify a field, class, state, etc, ' \
 | 
			
		||||
           'newly generated labels will all appear together at the end of ' \
 | 
			
		||||
           'the file; so it will be easy to translate them all. When sorting ' \
 | 
			
		||||
           'occurs, those elements may be spread at different places in the ' \
 | 
			
		||||
           'i18n file. When the development is finished, it may be a good ' \
 | 
			
		||||
           'idea to sort the labels to get a clean and logically ordered ' \
 | 
			
		||||
           'set of translation files.'
 | 
			
		||||
 | 
			
		||||
class GeneratorScript:
 | 
			
		||||
    '''usage: %prog [options] app productType outputFolder
 | 
			
		||||
 | 
			
		||||
       "app"          is the path to your Appy application, which may be a
 | 
			
		||||
                      Python module (= a file than ends with .py) or a Python
 | 
			
		||||
                      package (= a folder containing a file named __init__.py).
 | 
			
		||||
                      Your app may reside anywhere (but it needs to be
 | 
			
		||||
                      accessible by the underlying application server, ie Zope),
 | 
			
		||||
                      excepted within the generated product. Typically, if you
 | 
			
		||||
                      generate a Plone product, it may reside within
 | 
			
		||||
                      <yourZopeInstance>/lib/python, but not within the
 | 
			
		||||
                      generated product (typically stored in
 | 
			
		||||
                      <yourZopeInstance>/Products).
 | 
			
		||||
       "productType"  is the kind of product you want to generate
 | 
			
		||||
                      (currently, only "plone25" and 'odt' are supported;
 | 
			
		||||
                      in the near future, the "plone25" target will also produce
 | 
			
		||||
                      Plone 3-compliant code that will still work with
 | 
			
		||||
                      Plone 2.5).
 | 
			
		||||
       "outputFolder" is the folder where the product will be generated.
 | 
			
		||||
                      For example, if you specify /my/output/folder for your
 | 
			
		||||
                      application /home/gde/MyApp.py, this script will create
 | 
			
		||||
                      a folder /my/output/folder/MyApp and put in it the
 | 
			
		||||
                      generated product.
 | 
			
		||||
 | 
			
		||||
       Example: generating a Plone product
 | 
			
		||||
       -----------------------------------
 | 
			
		||||
       In your Zope instance named myZopeInstance, create a folder
 | 
			
		||||
       "myZopeInstance/lib/python/MyApp". Create into it your Appy application
 | 
			
		||||
       (we suppose here that it is a Python package, containing a __init__.py
 | 
			
		||||
       file and other files). Then, chdir into this folder and type
 | 
			
		||||
       "python <appyPath>/gen/generator.py . plone25 ../../../Products" and the
 | 
			
		||||
       product will be generated in myZopeInstance/Products/MyApp.
 | 
			
		||||
       "python" must refer to a Python interpreter that knows package appy.'''
 | 
			
		||||
 | 
			
		||||
    def generateProduct(self, options, application, productType, outputFolder):
 | 
			
		||||
        exec 'from appy.gen.%s.generator import Generator' % productType
 | 
			
		||||
        Generator(application, outputFolder, options).run()
 | 
			
		||||
 | 
			
		||||
    def manageArgs(self, parser, options, args):
 | 
			
		||||
        # Check number of args
 | 
			
		||||
        if len(args) != 3:
 | 
			
		||||
            print WRONG_NG_OF_ARGS
 | 
			
		||||
            parser.print_help()
 | 
			
		||||
            sys.exit(ERROR_CODE)
 | 
			
		||||
        # Check productType
 | 
			
		||||
        if args[1] not in VALID_PRODUCT_TYPES:
 | 
			
		||||
            print PRODUCT_TYPE_ERROR
 | 
			
		||||
            sys.exit(ERROR_CODE)
 | 
			
		||||
        # Check existence of application
 | 
			
		||||
        if not os.path.exists(args[0]):
 | 
			
		||||
            print APP_NOT_FOUND % args[0]
 | 
			
		||||
            sys.exit(ERROR_CODE)
 | 
			
		||||
        # Check existence of outputFolder basic type
 | 
			
		||||
        if not os.path.exists(args[2]):
 | 
			
		||||
            print WRONG_OUTPUT_FOLDER
 | 
			
		||||
            sys.exit(ERROR_CODE)
 | 
			
		||||
        # Convert all paths in absolute paths
 | 
			
		||||
        for i in (0,2):
 | 
			
		||||
            args[i] = os.path.abspath(args[i])
 | 
			
		||||
    def run(self):
 | 
			
		||||
        optParser = OptionParser(usage=GeneratorScript.__doc__)
 | 
			
		||||
        optParser.add_option("-c", "--i18n-clean", action='store_true',
 | 
			
		||||
            dest='i18nClean', default=False, help=C_OPTION)
 | 
			
		||||
        optParser.add_option("-s", "--i18n-sort", action='store_true',
 | 
			
		||||
            dest='i18nSort', default=False, help=S_OPTION)
 | 
			
		||||
        (options, args) = optParser.parse_args()
 | 
			
		||||
        try:
 | 
			
		||||
            self.manageArgs(optParser, options, args)
 | 
			
		||||
            print 'Generating %s product in %s...' % (args[1], args[2])
 | 
			
		||||
            self.generateProduct(options, *args)
 | 
			
		||||
        except GeneratorError, ge:
 | 
			
		||||
            sys.stderr.write(str(ge))
 | 
			
		||||
            sys.stderr.write('\n')
 | 
			
		||||
            optParser.print_help()
 | 
			
		||||
            sys.exit(ERROR_CODE)
 | 
			
		||||
 | 
			
		||||
# ------------------------------------------------------------------------------
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    GeneratorScript().run()
 | 
			
		||||
# ------------------------------------------------------------------------------
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue