Пример #1
0
def get_poi_tuple(poi=None):
    """
    Takes the poi or None and returns the container_dir and the product name either of the passed poi
    (<container_name>: <product_name>) or from os.environ-
    :param poi: optional; <container_name>: <product_name>
    :return: tuple of the container directory and the product name
    """
    if poi:
        parts = poi.split(':')
        if len(parts) == 2:
            container_name, product_name = parts
            if container_name not in tasks.get_containers():
                print('No such container')
                sys.exit(1)
            elif product_name not in tasks.get_products(container_name):
                print('No such product')
                sys.exit(1)
            else:
                container_dir = tasks.get_container_dir(container_name)
        else:
            print('Please check your arguments: --poi <container>:<product>')
            sys.exit(1)
    else:
        container_dir = os.environ.get('CONTAINER_DIR')
        product_name = os.environ.get('PRODUCT_NAME')

    return container_dir, product_name
Пример #2
0
def cd(doi):
    '''cd to directory of interest(doi)
    
    a doi can be:
    
    herbert - the container named "herbert"
    herbert:website - product "website" located in container "herbert"
    '''
    parts = doi.split(':')
    if len(parts) == 1:
        container_name, product_name = parts[0], None
    elif len(parts) == 2:
        container_name, product_name = parts[0], parts[1]
    else:
        print 'unable to parse context - format: <container_name>:<product_name>'
        sys.exit(1)

    if container_name not in tasks.get_containers():
        print 'No such container'
    else:
        if product_name:
            if product_name not in tasks.get_products(container_name):
                print 'No such product'
            else:
                print tasks.conf.SOURCE_HEADER
                print 'cd ' + tasks.get_product_dir(container_name, product_name)
        else:
            print tasks.conf.SOURCE_HEADER
            print 'cd ' + tasks.get_container_dir(container_name)
Пример #3
0
def switch(poi):
    '''switch context to product of interest(poi)
    
    a poi is:
    
    herbert:website - for product "website" located in container "herbert"
    
    After the context has been switched to herbert:website additional commands may be available
    that are relevant to herbert:website
    '''
    parts = poi.split(':')
    if len(parts) == 2:
        container_name, product_name = parts
    else:
        print 'unable to parse context: ', poi
        sys.exit(1)

    if container_name not in tasks.get_containers():
        print 'No such container'
    elif product_name not in tasks.get_products(container_name):
        print 'No such product'
    else:
        print SWITCH_TEMPLATE % dict(
            source_header=tasks.conf.SOURCE_HEADER,
            container_name=container_name,
            product_name=product_name
        )
Пример #4
0
Файл: tasks.py Проект: WiRai/ape
def export_config_to_equation(poi=None):
    """
    Generates a product.equation file for the given product name.
    It generates it from the <product_name>.config file in the products folder.
    For that you need to have your project imported to featureIDE and set the correct settings.
    """
    import os
    config_file_path = None
    equation_file_path = None
    if poi:
        parts = poi.split(':')
        if len(parts) == 2:
            container_name, product_name = parts
            if container_name not in tasks.get_containers():
                print('No such container')
            elif product_name not in tasks.get_products(container_name):
                print('No such product')
            else:
                cont_dir = tasks.get_container_dir(container_name)
                equation_file_path = os.path.join(cont_dir, 'products',
                                                  product_name,
                                                  'product.equation')
                config_file_path = os.path.join(cont_dir, 'products',
                                                product_name + '.config')
        else:
            print('Please check your arguments: --poi <container>:<product>')
    else:
        cont_dir = os.environ.get('CONTAINER_DIR')
        equation_file_path = os.path.join(cont_dir, 'products',
                                          os.environ.get('PRODUCT_NAME'),
                                          'product.equation')
        config_file_path = os.path.join(
            cont_dir, 'products',
            os.environ.get('PRODUCT_NAME') + '.config')
    if equation_file_path and config_file_path:
        config_new = list()
        try:
            with open(config_file_path, 'r') as config_file:
                config_old = config_file.readlines()
                for line in config_old:
                    # in FeatureIDE we cant use '.' for the paths to sub-features so we used '__'
                    # e.g. django_productline__features__development
                    if len(line.split('__')) <= 2:
                        config_new.append(line)
                    else:
                        config_new.append(line.replace('__', '.'))
        except IOError as e:
            print(
                'Config file not found. Please make sure you have a valid .config-file in your products folder.\n'
                ' Also make sure that this file has the same name as your product.'
            )
        try:
            with open(equation_file_path, 'w+') as eq_file:
                eq_file.writelines(config_new)
        except IOError as e:
            print(
                'product.equation file not found. Please make sure you have a valid product.equation in your chosen product'
            )
    else:
        print('Please check your arguments: --poi <container>:<product>')
Пример #5
0
Файл: tasks.py Проект: WiRai/ape
def cd(doi):
    '''cd to directory of interest(doi)

    a doi can be:

    herbert - the container named "herbert"
    herbert:website - product "website" located in container "herbert"
    '''
    parts = doi.split(':')
    if len(parts) == 1:
        container_name, product_name = parts[0], None
    elif len(parts) == 2:
        container_name, product_name = parts[0], parts[1]
    else:
        print 'unable to parse context - format: <container_name>:<product_name>'
        sys.exit(1)

    if container_name not in tasks.get_containers():
        print 'No such container'
    else:
        if product_name:
            if product_name not in tasks.get_products(container_name):
                print 'No such product'
            else:
                print tasks.conf.SOURCE_HEADER
                print 'cd ' + tasks.get_product_dir(container_name,
                                                    product_name)
        else:
            print tasks.conf.SOURCE_HEADER
            print 'cd ' + tasks.get_container_dir(container_name)
Пример #6
0
def get_poi_tuple(poi=None):
    """
    Takes the poi or None and returns the container_dir and the product name either of the passed poi
    (<container_name>: <product_name>) or from os.environ-
    :param poi: optional; <container_name>: <product_name>
    :return: tuple of the container directory and the product name
    """
    if poi:
        parts = poi.split(':')
        if len(parts) == 2:
            container_name, product_name = parts
            if container_name not in tasks.get_containers():
                print('No such container')
                sys.exit(1)
            elif product_name not in tasks.get_products(container_name):
                print('No such product')
                sys.exit(1)
            else:
                container_dir = tasks.get_container_dir(container_name)
        else:
            print('Please check your arguments: --poi <container>:<product>')
            sys.exit(1)
    else:
        container_dir = os.environ.get('CONTAINER_DIR')
        product_name = os.environ.get('PRODUCT_NAME')

    return container_dir, product_name
Пример #7
0
Файл: tasks.py Проект: WiRai/ape
def switch(poi):
    '''switch context to product of interest(poi)

    a poi is:

    herbert:website - for product "website" located in container "herbert"

    After the context has been switched to herbert:website additional commands may be available
    that are relevant to herbert:website
    '''
    parts = poi.split(':')
    if len(parts) == 2:
        container_name, product_name = parts
    else:
        print 'unable to parse context: ', poi
        sys.exit(1)

    if container_name not in tasks.get_containers():
        print 'No such container'
    elif product_name not in tasks.get_products(container_name):
        print 'No such product'
    else:
        print SWITCH_TEMPLATE % dict(source_header=tasks.conf.SOURCE_HEADER,
                                     container_name=container_name,
                                     product_name=product_name)
Пример #8
0
Файл: tasks.py Проект: WiRai/ape
def import_config_from_equation(poi=None):
    """
    Generates a <productname>.config file from the product.equation of the given (or activated) product name and places it in your products dir.
    """
    import os
    config_file_path = None
    equation_file_path = None
    if poi:
        parts = poi.split(':')
        if len(parts) == 2:
            container_name, product_name = parts
            if container_name not in tasks.get_containers():
                print('No such container')
            elif product_name not in tasks.get_products(container_name):
                print('No such product')
            else:
                cont_dir = tasks.get_container_dir(container_name)
                equation_file_path = os.path.join(cont_dir, 'products',
                                                  product_name,
                                                  'product.equation')
                config_file_path = os.path.join(cont_dir, 'products',
                                                product_name + '.config')
        else:
            print('Please check your arguments: --poi <container>:<product>')
    else:
        # If a product is already activated it gets selected automatically if no arguments are passed.
        product_name = os.environ.get('PRODUCT_NAME')
        cont_dir = os.environ.get('CONTAINER_DIR')
        equation_file_path = os.path.join(cont_dir, 'products', product_name,
                                          'product.equation')
        config_file_path = os.path.join(cont_dir, 'products',
                                        product_name + '.config')
    if equation_file_path and config_file_path:
        config_new = list()
        try:
            with open(equation_file_path, 'r') as eq_file:
                config_old = eq_file.readlines()
                for line in config_old:
                    # in FeatureIDE we cant use '.' for the paths to sub-features so we used '__'
                    # e.g. django_productline__features__development
                    if not line.startswith('#'):
                        if len(line.split('.')) <= 2:
                            config_new.append(line)
                        else:
                            config_new.append(line.replace('.', '__'))
        except IOError as e:
            print(
                'Equation file not found. Please make sure you have a valid product.equation in your products/<product_name>/. \n'
            )
        try:
            with open(config_file_path, 'w+') as config_file:
                config_file.writelines(config_new)
        except IOError as e:
            print(
                '{product_name}.config file not found. \n '
                'Please make sure you have a valid <product_name>.config in your products directory.'
                .format(product_name=product_name))
    else:
        print('Please check your arguments: --poi <container>:<product>')
Пример #9
0
Файл: tasks.py Проект: WiRai/ape
def get_unified_prod_eq(container_name):
    """Return set containg all single entries from each products product.equation"""
    products = tasks.get_products(container_name)
    prod_eq = set()
    for prod in products:
        prod_dir = tasks.get_product_dir(container_name, prod)
        prod_eq = prod_eq.union(tasks.parse_prod_eq(prod_dir))
    return prod_eq
Пример #10
0
def import_config_from_equation(poi=None):
    """
    Generates a <productname>.config file from the product.equation of the given (or activated)
    product name and places it in your products dir.
    """
    import os
    config_file_path = None
    equation_file_path = None

    if poi:
        parts = poi.split(':')
        if len(parts) == 2:
            container_name, product_name = parts
            if container_name not in tasks.get_containers():
                print('No such container')
            elif product_name not in tasks.get_products(container_name):
                print('No such product')
            else:
                cont_dir = tasks.get_container_dir(container_name)
                equation_file_path = os.path.join(cont_dir, 'products', product_name, 'product.equation')
                config_file_path = os.path.join(cont_dir, 'products', product_name + '.config')
        else:
            print('Please check your arguments: --poi <container>:<product>')
    else:
        # If a product is already activated it gets selected automatically if no arguments are passed.
        product_name = os.environ.get('PRODUCT_NAME')
        cont_dir = os.environ.get('CONTAINER_DIR')
        equation_file_path = os.path.join(cont_dir, 'products', product_name, 'product.equation')
        config_file_path = os.path.join(cont_dir, 'products', product_name + '.config')
    if equation_file_path and config_file_path:
        config_new = list()
        try:
            with open(equation_file_path, 'r') as eq_file:
                config_old = eq_file.readlines()
                for line in config_old:
                    # in FeatureIDE we cant use '.' for the paths to sub-features so we used '__'
                    # e.g. django_productline__features__development
                    if not line.startswith('#'):
                        if len(line.split('.')) <= 2:
                            config_new.append(line)
                        else:
                            config_new.append(line.replace('.', '__'))
        except IOError as e:
            print(
                'Equation file not found. Please make sure you have a valid product.equation in your products/<product_name>/. \n')
        try:
            with open(config_file_path, 'w+') as config_file:
                config_file.writelines(config_new)
        except IOError as e:
            print('{product_name}.config file not found. \n '
                  'Please make sure you have a valid <product_name>.config in your products directory.'.format(
                product_name=product_name))
    else:
        print('Please check your arguments: --poi <container>:<product>')
Пример #11
0
def info():
    '''list information about this productive environment'''
    print
    print 'root directory         :', tasks.conf.APE_ROOT
    print
    print 'active container       :', os.environ.get('CONTAINER_NAME', '')
    print
    print 'active product         :', os.environ.get('PRODUCT_NAME', '')
    print
    print 'ape feature selection  :', tasks.FEATURE_SELECTION
    print
    print 'containers and products:'
    print '-' * 30
    print
    for container_name in tasks.get_containers():
        print container_name
        for product_name in tasks.get_products(container_name):
            print '    ' + product_name
    print
Пример #12
0
Файл: tasks.py Проект: WiRai/ape
def info():
    '''list information about this productive environment'''
    print
    print 'root directory         :', tasks.conf.APE_ROOT
    print
    print 'active container       :', os.environ.get('CONTAINER_NAME', '')
    print
    print 'active product         :', os.environ.get('PRODUCT_NAME', '')
    print
    print 'ape feature selection  :', tasks.FEATURE_SELECTION
    print
    print 'containers and products:'
    print '-' * 30
    print
    for container_name in tasks.get_containers():
        print container_name
        for product_name in tasks.get_products(container_name):
            print '    ' + product_name
    print
Пример #13
0
def info():
    """
    List information about this productive environment
    :return:
    """
    print()
    print('root directory         :', tasks.conf.APE_ROOT)
    print()
    print('active container       :', os.environ.get('CONTAINER_NAME', ''))
    print()
    print('active product         :', os.environ.get('PRODUCT_NAME', ''))
    print()
    print('ape feature selection  :', tasks.FEATURE_SELECTION)
    print()
    print('containers and products:')
    print('-' * 30)
    print()
    for container_name in tasks.get_containers():
        print(container_name)
        for product_name in tasks.get_products(container_name):
            print('    ' + product_name)
    print()
Пример #14
0
def info():
    """
    List information about this productive environment
    :return:
    """
    print()
    print('root directory         :', tasks.conf.APE_ROOT)
    print()
    print('active container       :', os.environ.get('CONTAINER_NAME', ''))
    print()
    print('active product         :', os.environ.get('PRODUCT_NAME', ''))
    print()
    print('ape feature selection  :', tasks.FEATURE_SELECTION)
    print()
    print('containers and products:')
    print('-' * 30)
    print()
    for container_name in tasks.get_containers():
        print(container_name)
        for product_name in tasks.get_products(container_name):
            print('    ' + product_name)
    print()
Пример #15
0
def switch(poi):
    """
    Zaps into a specific product specified by switch context to the product of interest(poi)
    A poi is:
        sdox:dev - for product "dev" located in container "sdox"

    If poi does not contain a ":" it is interpreted as product name implying that a product within this
    container is already active. So if this task is called with ape zap prod (and the corresponding container is
    already zapped in), than only the product is switched.

    After the context has been switched to sdox:dev additional commands may be available
    that are relevant to sdox:dev
    :param poi: product of interest, string: <container_name>:<product_name> or <product_name>.
    """

    parts = poi.split(':')
    if len(parts) == 2:
        container_name, product_name = parts
    elif len(parts) == 1 and os.environ.get('CONTAINER_NAME'):
        # interpret poi as product name if already zapped into a product in order
        # to enable simply switching products by doing ape zap prod.
        container_name = os.environ.get('CONTAINER_NAME')
        product_name = parts[0]
    else:
        print('unable to find poi: ', poi)
        sys.exit(1)

    if container_name not in tasks.get_containers():
        raise ContainerNotFound('No such container %s' % container_name)
    elif product_name not in tasks.get_products(container_name):
        raise ProductNotFound('No such product %s' % product_name)
    else:
        print(SWITCH_TEMPLATE.format(
            source_header=tasks.conf.SOURCE_HEADER,
            container_name=container_name,
            product_name=product_name
        ))
Пример #16
0
def switch(poi):
    """
    Zaps into a specific product specified by switch context to the product of interest(poi)
    A poi is:
        sdox:dev - for product "dev" located in container "sdox"

    If poi does not contain a ":" it is interpreted as product name implying that a product within this
    container is already active. So if this task is called with ape zap prod (and the corresponding container is
    already zapped in), than only the product is switched.

    After the context has been switched to sdox:dev additional commands may be available
    that are relevant to sdox:dev
    :param poi: product of interest, string: <container_name>:<product_name> or <product_name>.
    """

    parts = poi.split(':')
    if len(parts) == 2:
        container_name, product_name = parts
    elif len(parts) == 1 and os.environ.get('CONTAINER_NAME'):
        # interpret poi as product name if already zapped into a product in order
        # to enable simply switching products by doing ape zap prod.
        container_name = os.environ.get('CONTAINER_NAME')
        product_name = parts[0]
    else:
        print('unable to find poi: ', poi)
        sys.exit(1)

    if container_name not in tasks.get_containers():
        raise ContainerNotFound('No such container %s' % container_name)
    elif product_name not in tasks.get_products(container_name):
        raise ProductNotFound('No such product %s' % product_name)
    else:
        print(SWITCH_TEMPLATE.format(
            source_header=tasks.conf.SOURCE_HEADER,
            container_name=container_name,
            product_name=product_name
        ))
Пример #17
0
def cd(doi):
    """
    cd to directory of interest(doi)

    a doi can be:

    herbert - the container named "herbert"
    sdox:dev - product "website" located in container "herbert"
    :param doi:
    :return:
    """

    parts = doi.split(':')

    if len(parts) == 2:
        container_name, product_name = parts[0], parts[1]
    elif len(parts) == 1 and os.environ.get('CONTAINER_NAME'):
        # interpret poi as product name if already zapped into a product in order
        # to enable simply switching products by doing ape zap prod.
        product_name = parts[0]
        container_name = os.environ.get('CONTAINER_NAME')
    else:
        print('unable to parse context - format: <container_name>:<product_name>')
        sys.exit(1)

    if container_name not in tasks.get_containers():
        print('No such container')
    else:
        if product_name:
            if product_name not in tasks.get_products(container_name):
                print('No such product')
            else:
                print(tasks.conf.SOURCE_HEADER)
                print('cd ' + tasks.get_product_dir(container_name, product_name))
        else:
            print(tasks.conf.SOURCE_HEADER)
            print('cd ' + tasks.get_container_dir(container_name))
Пример #18
0
def cd(doi):
    """
    cd to directory of interest(doi)

    a doi can be:

    herbert - the container named "herbert"
    sdox:dev - product "website" located in container "herbert"
    :param doi:
    :return:
    """

    parts = doi.split(':')

    if len(parts) == 2:
        container_name, product_name = parts[0], parts[1]
    elif len(parts) == 1 and os.environ.get('CONTAINER_NAME'):
        # interpret poi as product name if already zapped into a product in order
        # to enable simply switching products by doing ape zap prod.
        product_name = parts[0]
        container_name = os.environ.get('CONTAINER_NAME')
    else:
        print('unable to parse context - format: <container_name>:<product_name>')
        sys.exit(1)

    if container_name not in tasks.get_containers():
        print('No such container')
    else:
        if product_name:
            if product_name not in tasks.get_products(container_name):
                print('No such product')
            else:
                print(tasks.conf.SOURCE_HEADER)
                print('cd ' + tasks.get_product_dir(container_name, product_name))
        else:
            print(tasks.conf.SOURCE_HEADER)
            print('cd ' + tasks.get_container_dir(container_name))