示例#1
0
文件: diff.py 项目: dnzengou/clan
    def __call__(self, args):
        """
        Compare two data files and generate a report of their differences.
        """
        self.args = args
        self.field_definitions = load_field_definitions()

        with open(self.args.report_a_path) as f:
            report_a = json.load(f, object_pairs_hook=OrderedDict)

        with open(self.args.report_b_path) as f:
            report_b = json.load(f, object_pairs_hook=OrderedDict)

        diff = self.diff(report_a, report_b)

        output_format = os.path.splitext(self.args.output_path)[1]

        if output_format == '.html':
            with open(self.args.output_path, 'w') as f:
                self.html(diff, f)
        elif output_format == '.json':
            with open(self.args.output_path, 'w') as f:
                json.dump(diff, f, indent=4)
        else:
            raise Exception('Unsupported output format: %s. Must be .html or .json.' % output_format) 
示例#2
0
    def __call__(self, args):
        """
        Compare two data files and generate a report of their differences.
        """
        self.args = args
        self.field_definitions = load_field_definitions()

        with open(self.args.report_a_path) as f:
            report_a = json.load(f, object_pairs_hook=OrderedDict)

        with open(self.args.report_b_path) as f:
            report_b = json.load(f, object_pairs_hook=OrderedDict)

        diff = self.diff(report_a, report_b)

        output_format = os.path.splitext(self.args.output_path)[1]

        if output_format == '.html':
            with open(self.args.output_path, 'w') as f:
                self.html(diff, f)
        elif output_format == '.json':
            with open(self.args.output_path, 'w') as f:
                json.dump(diff, f, indent=4)
        else:
            raise Exception(
                'Unsupported output format: %s. Must be .html or .json.' %
                output_format)
示例#3
0
文件: report.py 项目: onyxfish/clan
    def __call__(self, args):
        self.args = args
        self.field_definitions = load_field_definitions()

        if not self.args.auth:
            home_path = os.path.expanduser('~/.clan_auth.dat')

            if os.path.exists('analytics.dat'):
                self.args.auth = 'analytics.dat'
            elif os.path.exists(home_path):
                self.args.auth = home_path
            else:
                raise Exception('Could not locate local authorization token (analytics.dat). Please specify it using --auth or run "clan auth".')

        storage = Storage(self.args.auth)
        credentials = storage.get()

        if not credentials or credentials.invalid:
            raise Exception('Invalid authentication. Please run "clan auth" to generate a new token.')

        http = credentials.authorize(http=httplib2.Http())
        self.service = discovery.build('analytics', 'v3', http=http)

        input_format = os.path.splitext(self.args.input_path)[1]

        if input_format == '.json':
            with open(self.args.input_path) as f:
                report = json.load(f, object_pairs_hook=OrderedDict)
        elif input_format == '.yml' or input_format == '.yaml':
            with open(self.args.input_path) as f:
                self.config = yaml.load(f)

            if 'property-id' not in self.config:
                raise Exception('You must specify a property-id either in your YAML file or using the --property-id argument.')

            report = self.report()
        else:
            raise Exception('Unsupported input format: %s. Must be .yml or .json.' % input_format)

        output_format = os.path.splitext(self.args.output_path)[1]

        if output_format == '.html':
            with open(self.args.output_path, 'w') as f:
                self.html(report, f)
        elif output_format == '.json':
            with open(self.args.output_path, 'w') as f:
                json.dump(report, f, indent=4)
        else:
            raise Exception('Unsupported output format: %s. Must be .html or .json.' % output_format) 
示例#4
0
文件: models.py 项目: livlab/carebot
from itertools import izip
import json
import subprocess

from clan import utils as clan_utils
from django.core.urlresolvers import reverse
from django.db import models
from django.dispatch import receiver
from django.utils import timezone
import requests
import yaml

import app_config
import utils

FIELD_DEFINITIONS = clan_utils.load_field_definitions()

class Query(models.Model):
    """
    A clan query.
    """
    slug = models.SlugField(max_length=128, primary_key=True)
    name = models.CharField(max_length=128)
    description = models.CharField(max_length=256, default='', blank=True)
    is_comparable = models.BooleanField(default=True,
        help_text='Should this query be available for cross-project comparison.')
    clan_yaml = models.TextField()

    class Meta:
        ordering = ('name',)
        verbose_name_plural = 'queries'
示例#5
0
文件: models.py 项目: livlab/carebot
from itertools import izip
import json
import subprocess

from clan import utils as clan_utils
from django.core.urlresolvers import reverse
from django.db import models
from django.dispatch import receiver
from django.utils import timezone
import requests
import yaml

import app_config
import utils

FIELD_DEFINITIONS = clan_utils.load_field_definitions()


class Query(models.Model):
    """
    A clan query.
    """
    slug = models.SlugField(max_length=128, primary_key=True)
    name = models.CharField(max_length=128)
    description = models.CharField(max_length=256, default='', blank=True)
    is_comparable = models.BooleanField(
        default=True,
        help_text='Should this query be available for cross-project comparison.'
    )
    clan_yaml = models.TextField()