Beispiel #1
0
FileSystemManager manager

Construct and parse results of the teplate manager

'''
import os
import re
from pprint import pformat
from ade.manager.exceptions import ConfigError

try:
    import efesto_logger as logging
except:
    import logging

logger = logging.getLogger(__name__)


class FileSystemManager(object):
    ''' Return an instance of FileSystemManager.

    :param config: the config for the project.
    :type config: dict
    :param template_manager: An instance of the templateManager.
    :type template_manager: TemplateManager

    '''
    def __init__(self, config, template_manager):
        self.template_manager = template_manager

        self.mount_point = config['project_mount_point']
Beispiel #2
0
def run():
    """
    Main entry point of ade command line.

    """
    args = arguments()
    config_path = args.get('config_path')
    if not config_path:
        print 'Please define: $ADE_CONFIG_PATH'
        return

    # Setup logging
    level = getattr(logging, args.get('verbose').upper())
    logger = logging.getLogger(__name__)
    logger.setLevel(level)

    # Print the given arguments
    # logger.debug('Arguments: {0}'.format(pformat(args)))

    # Create a dictionary from the user's import data
    input_data = args.get('data', [''])
    input_data = dict(
        [datum.split('=') for datum in input_data if '=' in datum])

    path = args.get('path')
    # Get the mountpoint
    if not os.path.exists(path):
        logger.warning('Input path {0} does not exist.'.format(path))
        return

    config_mode = args.get('mode')
    logger.info('loading mode {0} '.format(config_mode))
    config_manager = config.ConfigManager(config_path)
    if config_mode not in config_manager.modes:
        raise ConfigError('Mode {0} is not available'.format(config_mode))

    config_mode = config_manager.get(config_mode)

    root_template = config_mode['root_template']

    # Create a new manager

    template_manager = template.TemplateManager(config_mode)
    manager = filesystem.FileSystemManager(config_mode, template_manager)

    input_template = args.get('template')

    if args.get('action') == 'create':
        # current_data = manager.parse(path, root_template)
        manager.build(input_template, input_data, path)

    if args.get('action') == 'parse':
        path = os.path.realpath(path)

        if not os.path.exists(path):
            logger.warning('{0} does not exist.'.format(path))
            return

        results = manager.parse(path, root_template)
        if results:
            print json.dumps(results[0])
        else:
            logger.info('No data found to parse from {0}'.format(path))
Beispiel #3
0
Construct and parse results of the teplate manager

'''
import os
import re
from pprint import pformat
from ade.manager.exceptions import ConfigError

try:
    import efesto_logger as logging
except:
    import logging


logger = logging.getLogger(__name__)


class FileSystemManager(object):
    ''' Return an instance of FileSystemManager.

    :param config: the config for the project.
    :type config: dict
    :param template_manager: An instance of the templateManager.
    :type template_manager: TemplateManager

    '''

    def __init__(self, config, template_manager):
        self.template_manager = template_manager
Beispiel #4
0
def run():
    """
    Main entry point of ade command line.

    """
    args = arguments()
    config_path = args.get('config_path')
    if not config_path:
        print 'Please define: $ADE_CONFIG_PATH'
        return

    # Setup logging
    level = getattr(logging, args.get('verbose').upper())
    logger = logging.getLogger(__name__)
    logger.setLevel(level)

    # Print the given arguments
    # logger.debug('Arguments: {0}'.format(pformat(args)))

    # Create a dictionary from the user's import data
    input_data = args.get('data', [''])
    input_data = dict(
        [datum.split('=') for datum in input_data if '=' in datum]
    )

    path = args.get('path')
    # Get the mountpoint
    if not os.path.exists(path):
            logger.warning('Input path {0} does not exist.'.format(path))
            return

    config_mode = args.get('mode')
    logger.info('loading mode {0} '.format(config_mode))
    config_manager = config.ConfigManager(config_path)
    if config_mode not in config_manager.modes:
        raise ConfigError('Mode {0} is not available'.format(config_mode))

    config_mode = config_manager.get(config_mode)

    root_template = config_mode['root_template']

    # Create a new manager

    template_manager = template.TemplateManager(config_mode)
    manager = filesystem.FileSystemManager(
        config_mode,
        template_manager
        )

    input_template = args.get('template')

    if args.get('action') == 'create':
        # current_data = manager.parse(path, root_template)
        manager.build(input_template, input_data, path)

    if args.get('action') == 'parse':
        path = os.path.realpath(path)

        if not os.path.exists(path):
            logger.warning('{0} does not exist.'.format(path))
            return

        results = manager.parse(path, root_template)
        if results:
            print json.dumps(results[0])
        else:
            logger.info('No data found to parse from {0}'.format(path))