<commit_before>__cmdname__ = 'delete_graphs'

import json
import re
import sys

import circonusapi
import log
import util


class Module(object):
    def __init__(self, api, account):
        self.api = api
        self.account = account

    def command(self, opts, pattern):
        """Delete multiple graphs at once

        Arguments:
            pattern     -- a regex to select the graphs to delete
        """
        rv = self.api.list_graphs()
        filtered_graphs = []
        for g in sorted(rv, lambda a, b: cmp(a['title'], b['title'])):
            if re.search(pattern, g['title']):
                filtered_graphs.append(g)
        log.msg("Going to DELETE the following graphs:")
        for g in filtered_graphs:
            log.msg("   ", g['title'])
        if util.confirm():
            for g in filtered_graphs:
                log.msgnb("Deleting %s..." % g['title'])
                try:
                    rv = self.api.remove_graph(graph_id=g['graph_id'])
                    log.msgnf("Success")
                except circonusapi.CirconusAPIError, e:
                    log.msgnf("Failed")
                    log.error(e.error)<commit_msg>Have to use % formatting with log.msg unlike with print<commit_after>__cmdname__ = 'delete_graphs'

import json
import re
import sys

import circonusapi
import log
import util


class Module(object):
    def __init__(self, api, account):
        self.api = api
        self.account = account

    def command(self, opts, pattern):
        """Delete multiple graphs at once

        Arguments:
            pattern     -- a regex to select the graphs to delete
        """
        rv = self.api.list_graphs()
        filtered_graphs = []
        for g in sorted(rv, lambda a, b: cmp(a['title'], b['title'])):
            if re.search(pattern, g['title']):
                filtered_graphs.append(g)
        log.msg("Going to DELETE the following graphs:")
        for g in filtered_graphs:
            log.msg("   %s" % g['title'])
        if util.confirm():
            for g in filtered_graphs:
                log.msgnb("Deleting %s..." % g['title'])
                try:
                    rv = self.api.remove_graph(graph_id=g['graph_id'])
                    log.msgnf("Success")
                except circonusapi.CirconusAPIError, e:
                    log.msgnf("Failed")
                    log.error(e.error)
{'fraction_non_alphanumeric': 0.11250522793810121, 'fraction_numerical': 0.0, 'mean_word_length': 1.800936768149883, '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': '2957765', 'n_tokens_mistral': 698, 'n_tokens_neox': 661, 'n_words': 186}