<commit_before>from dsl_parser import parser
import urllib2
import yaml
from tasks.list_operations.get_operations import get_for_plugin
from tasks.list_operations.get_package_name import extract_plugin_dir
import sys, traceback


"""
    This module is a collection of actions this module exposes.

    If exposed by a cli, this module defines the subcommands
"""

def validate( args ):
    """
    Validates a blueprint using the official dsl parser

    Example:

        validate(dict( path = '/path/to/blueprint' ) )

    Attributes:

        args (dict): a dict of arguments

    Returns:
        None
    """
    try:
        parser.parse_from_path(args.blueprint_path)
    except Exception as e:
        print(e)

def plugin_extract( args ):
    try:
        extract_plugin_dir( args.plugin_source_url, args.dest_dir )
    except Exception as e:
        print('unable to extract plugin to dir [{0}]. {1}'.format( args.dest_dir, e))




def list_operations( args ):
    try:
        results = []

        plugins_yaml = urllib2.urlopen(args.plugin_url).read()
        plugins_data = yaml.load( plugins_yaml )
        if 'plugins' not in plugins_data:
            raise Exception('invalid plugin yaml. missing plugins field')

        for plugin_name in plugins_data['plugins']:
            plugin_data = plugins_data['plugins'][plugin_name]
            results.append({ 'plugin_name' : plugin_name, 'operations' : get_for_plugin( plugin_data ) })


        print(results)
    except Exception as e:
        print('unable to list operations on plugin. {0}'.format( e ) )<commit_msg>fix(output): make output with double quotes<commit_after>from dsl_parser import parser
import urllib2
import json
import yaml
from tasks.list_operations.get_operations import get_for_plugin
from tasks.list_operations.get_package_name import extract_plugin_dir
import sys, traceback


"""
    This module is a collection of actions this module exposes.

    If exposed by a cli, this module defines the subcommands
"""

def validate( args ):
    """
    Validates a blueprint using the official dsl parser

    Example:

        validate(dict( path = '/path/to/blueprint' ) )

    Attributes:

        args (dict): a dict of arguments

    Returns:
        None
    """
    try:
        parser.parse_from_path(args.blueprint_path)
    except Exception as e:
        print(e)

def plugin_extract( args ):
    try:
        extract_plugin_dir( args.plugin_source_url, args.dest_dir )
    except Exception as e:
        print('unable to extract plugin to dir [{0}]. {1}'.format( args.dest_dir, e))




def list_operations( args ):
    try:
        results = []

        plugins_yaml = urllib2.urlopen(args.plugin_url).read()
        plugins_data = yaml.load( plugins_yaml )
        if 'plugins' not in plugins_data:
            raise Exception('invalid plugin yaml. missing plugins field')

        for plugin_name in plugins_data['plugins']:
            plugin_data = plugins_data['plugins'][plugin_name]
            results.append({ 'plugin_name' : plugin_name, 'operations' : get_for_plugin( plugin_data ) })

        # json.dumps - used to get output with double quotes - http://stackoverflow.com/a/18283758/1068746
        print(json.dumps(results))
    except Exception as e:
        print('unable to list operations on plugin. {0}'.format( e ) )
{'fraction_non_alphanumeric': 0.08968206358728255, 'fraction_numerical': 0.007498500299940012, 'mean_word_length': 2.937426210153483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3924736', 'n_tokens_mistral': 989, 'n_tokens_neox': 945, 'n_words': 292}