Build the report by performing queries to Piwik
976645
def _build_report(self):
        """"""
        self.metrics = {}
        queries = {'visits': PiwikQueryReportEventMetricVisits(**self.params),
                   'unique_visits': PiwikQueryReportEventMetricUniqueVisits(**self.params),
                   'visit_duration': PiwikQueryReportEventMetricVisitDuration(**self.params),
                   'referrers': PiwikQueryReportEventMetricReferrers(**self.params),
                   'peak': PiwikQueryReportEventMetricPeakDateAndVisitors(**self.params)}

        for query_name, query in queries.iteritems():
            self.metrics[query_name] = query.get_result()

        self._fetch_contribution_info()
62611
def main():
    """"""
    parser = argparse.ArgumentParser(description='Generate a TPIP report as a CSV file.')
    parser.add_argument('output_filename', type=str, metavar='output-file',
                        help='the output path and filename', nargs='?')
    parser.add_argument('--only', type=str, help='only parse this package')
    args = parser.parse_args()

    output_path = os.path.abspath(args.output_filename) if args.output_filename else None

    skips = []
    tpip_pkgs = []
    for pkg_name, pkg_item in sorted(pkg_resources.working_set.by_key.items()):
        if args.only and args.only not in pkg_name.lower():
            continue
        if pkg_name in EXCLUDED_PACKAGES:
            skips.append(pkg_name)
            continue
        metadata_lines = get_metadata(pkg_item)
        tpip_pkg = process_metadata(pkg_name, metadata_lines)
        tpip_pkgs.append(force_ascii_values(tpip_pkg))

    print(json.dumps(tpip_pkgs, indent=2, sort_keys=True))
    print('Parsed %s packages\nOutput to CSV: `%s`\nIgnored packages: %s' % (
        len(tpip_pkgs),
        output_path,
        ', '.join(skips),
    ))
    output_path and write_csv_file(output_path, tpip_pkgs)
972345
def run(self):
        """"""
        print('---- CUSTOM DEVELOP ----')
        _develop.run(self)

        # build documentation
        print('---- BUILDING DOCS ----')
        docdir = os.path.join(self.setup_path, 'pyshtools', 'doc')
        self.mkpath(docdir)
        doc_builder = os.path.join(self.setup_path, 'pyshtools',
                                   'make_docs.py')
        doc_source = '.'
        check_call([sys.executable, doc_builder, doc_source, self.setup_path])

        print('---- ALL DONE ----')
323276
def generate_count_report!
      report = count_queries.inject({}) do |report_hash, (k, v)|
        report_hash[k] = solutions_to_counts(v.execute)
        report_hash
      end

      update(count_report: report)
    end
111354
def view_build():
    """"""
    build = g.build
    page_size = min(request.args.get('page_size', 10, type=int), 50)
    offset = request.args.get('offset', 0, type=int)

    ops = operations.BuildOps(build.id)
    has_next_page, candidate_list, stats_counts = ops.get_candidates(
        page_size, offset)

    # Collate by release name, order releases by latest creation. Init stats.
    release_dict = {}
    created_dict = {}
    run_stats_dict = {}
    for candidate in candidate_list:
        release_list = release_dict.setdefault(candidate.name, [])
        release_list.append(candidate)
        max_created = created_dict.get(candidate.name, candidate.created)
        created_dict[candidate.name] = max(candidate.created, max_created)
        run_stats_dict[candidate.id] = dict(
            runs_total=0,
            runs_complete=0,
            runs_successful=0,
            runs_failed=0,
            runs_baseline=0,
            runs_pending=0)

    # Sort each release by candidate number descending
    for release_list in release_dict.itervalues():
        release_list.sort(key=lambda x: x.number, reverse=True)

    # Sort all releases by created time descending
    release_age_list = [
        (value, key) for key, value in created_dict.iteritems()]
    release_age_list.sort(reverse=True)
    release_name_list = [key for _, key in release_age_list]

    # Count totals for each run state within that release.
    for candidate_id, status, count in stats_counts:
        stats_dict = run_stats_dict[candidate_id]
        for key in ops.get_stats_keys(status):
            stats_dict[key] += count

    return render_template(
        'view_build.html',
        build=build,
        release_name_list=release_name_list,
        release_dict=release_dict,
        run_stats_dict=run_stats_dict,
        has_next_page=has_next_page,
        current_offset=offset,
        next_offset=offset + page_size,
        last_offset=max(0, offset - page_size),
        page_size=page_size)
3826
def do_build_reports(directory):
    
    for cwd, dirs, files in os.walk(directory):
        for f in sorted(files):
            if f in ('job.ini', 'job_h.ini', 'job_haz.ini', 'job_hazard.ini'):
                job_ini = os.path.join(cwd, f)
                logging.info(job_ini)
                try:
                    reportwriter.build_report(job_ini, cwd)
                except Exception as e:
                    logging.error(str(e))
1036345
def _reportFutures(self):
        """"""
        try:
            while True:
                time.sleep(scoop.TIME_BETWEEN_STATUS_REPORTS)
                fids = set(x.id for x in scoop._control.execQueue.movable)
                fids.update(set(x.id for x in scoop._control.execQueue.ready))
                fids.update(set(x.id for x in scoop._control.execQueue.inprogress))
                self.socket.send_multipart([
                    STATUS_UPDATE,
                    pickle.dumps(fids),
                ])
        except AttributeError:
            # The process is being shut down.
            pass
1256856
def build_q(fields_dict, params_dict, request=None):
    
    # Building search query
    # queries generated by different search_fields are ANDed
    # if a search field is defined for more than one field, are put together with OR
    and_query = Q()

    for fieldname in fields_dict:
        search_field = fields_dict[fieldname]
        if fieldname in params_dict and params_dict[fieldname] != '' and params_dict[fieldname] != []:
            or_query = None

            if type(search_field) == type(list()):
                field_list = search_field
                search_operator = "__icontains"
                fixed_filters = None
                multiple_values = False
                custom_query_method = None
                value_mapper = None

            else: # dictionary of field definitions
                if search_field.get('ignore', False):
                    continue

                field_list = search_field['fields']
                search_operator = search_field.get('operator', None)
                fixed_filters = search_field.get('fixed_filters', None)
                multiple_values = search_field.get('multiple', False)
                custom_query_method =  search_field.get('custom_query', None)
                value_mapper =  search_field.get('value_mapper', None)

            for model_field in field_list:

                if multiple_values:
                    if hasattr(params_dict, "getlist"):
                        request_field_value = params_dict.getlist(fieldname)
                    elif type(params_dict[fieldname]) == list:
                        request_field_value = params_dict[fieldname]
                    else:
                        request_field_value = [params_dict[fieldname]]
                    if value_mapper:
                        request_field_value = [value_mapper(value) for value in request_field_value]
                else:
                    request_field_value = params_dict[fieldname] if not value_mapper else value_mapper(params_dict[fieldname])

                if not custom_query_method:
                    fieldname_key = model_field + search_operator
                    filter_dict = { fieldname_key : request_field_value}
                    if not or_query:
                        or_query = Q(**filter_dict)
                    else:
                        or_query = or_query | Q(**filter_dict)
                else:
                    #TODO: this is a hack for using request data in custom_query
                    #it would be better to pass ALSO the request to custom_query_method
                    if not request:
                        cf = custom_query_method(model_field, request_field_value, params_dict)
                    else:
                        cf = custom_query_method(model_field, request_field_value, request)

                    if not or_query:
                        or_query = cf
                    else:
                        or_query = or_query | cf

            #fixed_filters
            fixed_filters_q = Q()
            #fixed_filters must return a Q object or None
            if fixed_filters:
                if callable(fixed_filters):
                    fixed_filters_q = fixed_filters(params_dict)
                elif type(fixed_filters) is dict:
                    fixed_filters_q = Q(**fixed_filters)

            and_query = and_query & or_query
            and_query = and_query & fixed_filters_q


    return and_query
1072590
def build_pwpolicy_command(attribs, dir_info)
      ans  = %Q[#{dir_info[:pwpol]}]
      ans += %Q[ -a #{dir_info[:username]}]    unless dir_info[:username].nil? or
                                                      dir_info[:username].empty?
      ans += %Q[ -p "#{dir_info[:password]}"]  unless dir_info[:password].nil? or
                                                      dir_info[:password].empty?
      ans += %Q[ -n #{dir_info[:data_path]}]
      ans += %Q[ -u #{attribs[:record_name]}]
      ans += %Q[ -#{attribs[:attribute]}]
      ans += %Q[ "#{attribs[:value]}"]         unless attribs[:value].nil? or
                                                      attribs[:value].empty?
      attribs[:value] = nil
      return ans
    end
530144
async def get_reports(self):
        
        cmd = OTGW_CMD_REPORT
        reports = {}
        for value in OTGW_REPORTS.keys():
            ret = await self._wait_for_cmd(cmd, value)
            if ret is None:
                reports[value] = None
                continue
            reports[value] = ret[2:]
        status = {
            OTGW_ABOUT: reports.get(OTGW_REPORT_ABOUT),
            OTGW_BUILD: reports.get(OTGW_REPORT_BUILDDATE),
            OTGW_CLOCKMHZ: reports.get(OTGW_REPORT_CLOCKMHZ),
            OTGW_MODE: reports.get(OTGW_REPORT_GW_MODE),
            OTGW_SMART_PWR: reports.get(OTGW_REPORT_SMART_PWR),
            OTGW_THRM_DETECT: reports.get(OTGW_REPORT_THERMOSTAT_DETECT),
            OTGW_DHW_OVRD: reports.get(OTGW_REPORT_DHW_SETTING),
        }
        ovrd_mode = reports.get(OTGW_REPORT_SETPOINT_OVRD)
        if ovrd_mode is not None:
            ovrd_mode = str.upper(ovrd_mode[0])
            status.update({OTGW_SETP_OVRD_MODE: ovrd_mode})
        gpio_funcs = reports.get(OTGW_REPORT_GPIO_FUNCS)
        if gpio_funcs is not None:
            status.update({
                OTGW_GPIO_A: int(gpio_funcs[0]),
                OTGW_GPIO_B: int(gpio_funcs[1]),
            })
        led_funcs = reports.get(OTGW_REPORT_LED_FUNCS)
        if led_funcs is not None:
            status.update({
                OTGW_LED_A: led_funcs[0],
                OTGW_LED_B: led_funcs[1],
                OTGW_LED_C: led_funcs[2],
                OTGW_LED_D: led_funcs[3],
                OTGW_LED_E: led_funcs[4],
                OTGW_LED_F: led_funcs[5],
            })
        tweaks = reports.get(OTGW_REPORT_TWEAKS)
        if tweaks is not None:
            status.update({
                OTGW_IGNORE_TRANSITIONS: int(tweaks[0]),
                OTGW_OVRD_HB: int(tweaks[1]),
            })
        sb_temp = reports.get(OTGW_REPORT_SETBACK_TEMP)
        if sb_temp is not None:
            status.update({OTGW_SB_TEMP: float(sb_temp)})
        vref = reports.get(OTGW_REPORT_VREF)
        if vref is not None:
            status.update({OTGW_VREF: int(vref)})
        if (ovrd_mode is not None and ovrd_mode != OTGW_SETP_OVRD_DISABLED):
            status[DATA_ROOM_SETPOINT_OVRD] = float(
                reports[OTGW_REPORT_SETPOINT_OVRD][1:])
        self._update_status(status)
        return dict(self._protocol.status)
672350
def _do_query(self, query, iph, eth, in_port, msg):
        """"""
        datapath = msg.datapath
        dpid = datapath.id
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        # learn the querier.
        self._to_querier[dpid] = {
            'port': in_port,
            'ip': iph.src,
            'mac': eth.src
        }

        # set the timeout time.
        timeout = igmp.QUERY_RESPONSE_INTERVAL
        if query.maxresp:
            timeout = query.maxresp / 10

        self._to_hosts.setdefault(dpid, {})
        if query.address == '0.0.0.0':
            # general query. reset all reply status.
            for group in self._to_hosts[dpid].values():
                group['replied'] = False
                group['leave'] = None
        else:
            # specific query. reset the reply status of the specific
            # group.
            group = self._to_hosts[dpid].get(query.address)
            if group:
                group['replied'] = False
                group['leave'] = None

        actions = [parser.OFPActionOutput(ofproto.OFPP_FLOOD)]
        self._do_packet_out(
            datapath, msg.data, in_port, actions)

        # wait for REPORT messages.
        hub.spawn(self._do_timeout_for_query, timeout, datapath)
122791
def get_query(self, q, request):
        
        return Project.objects.filter(
            Q(pid__icontains=q)
            | Q(name__icontains=q)
        )
1295177
def reports(from_id, start_date = nil, end_date = nil)
      params = []

      if from_id
        params << "from_id=#{from_id}"
      end

      if start_date and not end_date
        raise 'must include both start_date and end_date'
      end
      if end_date and not start_date
        raise 'must include both start_date and end_date'
      end

      if start_date and end_date
        params << "start_date=#{start_date.strftime('%FT%T.%L%z')}"
        params << "end_date=#{end_date.strftime('%FT%T.%L%z')}"
      end

      query = "#{@endpoint}?"

      if params.size > 0
        query << params.join('&')
      end

      get query
    end
1027177
def run(self):
        """"""
        kwargs = {'query': self.get_data()}
        if self.data_type == "ip":
            kwargs.update({'query_type': 'ip'})
        elif self.data_type == "network":
            kwargs.update({'query_type': 'network'})
        elif self.data_type == 'autonomous-system':
            kwargs.update({'query_type': 'asn'})
        elif self.data_type == 'port':
            kwargs.update({'query_type': 'port'})
        else:
            self.notSupported()
            return False

        if self.service == 'observations':
            response = self.bs.get_observations(**kwargs)
            self.report(response)
        elif self.service == 'enrichment':
            response = self.bs.enrich(**kwargs)
            self.report(response)
        else:
            self.report({'error': 'Invalid service defined.'})
335839
def cli(obj, ids, query, filters):
    """"""
    client = obj['client']
    if ids:
        query = [('id', x) for x in ids]
    elif query:
        query = [('q', query)]
    else:
        query = build_query(filters)
    alerts = client.search(query)

    headers = {'id': 'ID', 'rawData': 'RAW DATA'}
    click.echo(
        tabulate([{'id': a.id, 'rawData': a.raw_data} for a in alerts], headers=headers, tablefmt=obj['output']))
103357
def build(config):
    """"""
    logger.info("\nRendering website now...\n")
    logger.info("entries:")
    tags = dict()
    entries = list()
    for post, post_id in find_new_posts_and_pages(DB):
        # this method will also parse the post's tags and
        # update the db collection containing the tags.
        if post.render():
            if post.header['kind'] in ['writing', 'link']:
                for tag in post.tags:
                    tag.posts = [post_id]
                    tags[tag.name] = tag
                entries.append(post)
            logger.info("%s" % post.path)

    for name, to in tags.items():
        logger.info("updating tag %s" % name)
        to.render()

    # This is expensive, we should insert only the recent entries
    # to the index using BeautifulSoup
    # update index
    logger.info("Updating index")
    last_entries, all_entries = _get_last_entries(DB, config['INDEX_SIZE'])
    last_entries = list(_filter_none_public(last_entries))
    update_index(last_entries)

    # update archive
    logger.info("Updating archive")

    # This is expensive, we should insert only the recent entries
    # to the archive using BeautifulSoup

    entries = [Entry.entry_from_db(
               os.path.join(CONFIG['content_root'],
                            e.get('filename')), e.doc_id) for e in
               DB.posts.all()]
    all_entries = list(_filter_none_public(all_entries))
    all_entries.sort(key=operator.attrgetter('date'), reverse=True)
    render_archive(all_entries[config['ARCHIVE_SIZE']:])
1351477
def build_queryset(self):
        """"""
        paths = [(os.path.join(self.build_prefix, 'index.html'), {})]
        self.request = None
        queryset = self.get_queryset()
        paginator = self.get_paginator(queryset, self.get_paginate_by(queryset))
        for page in paginator.page_range:
            paths.append(
                (os.path.join(self.build_prefix, 'page',
                              '%d' % page, 'index.html'), {'page': page}))
        for build_path, kwargs in paths:
            self.request = self.create_request(build_path)
            # Add a user with no permissions
            self.request.user = AnonymousUser()
            # Fake context so views work as expected
            self.kwargs = kwargs
            self.prep_directory(build_path)
            target_path = os.path.join(settings.BUILD_DIR, build_path)
            self.build_file(target_path, self.get_content())