text:
doc = """\
Storage Compute manager

"""
import sys
from gevent import monkey
from gevent.subprocess import Popen, PIPE
monkey.patch_all()
import os
import glob
import socket
import subprocess
import json
import time
import datetime
import pdb
import re
import argparse
import ConfigParser
import signal
import syslog

global HOME_ENV_PATH
HOME_ENV_PATH = '/root'

from stats_daemon.sandesh.storage.ttypes import *
from pysandesh.sandesh_base import *
from sandesh_common.vns.ttypes import Module, NodeType
from sandesh_common.vns.constants import ModuleNames, NodeTypeNames,\
    Module2NodeType, INSTANCE_ID_DEFAULT
from sandesh_common.vns.constants import *

def usage():
    print doc
    sys.exit(255)
'''
EventManager class is used to creates events and send the same to \
 sandesh server(opserver)
'''

class osdMap:
    osd_disk = ''
    osd = ''
    osd_journal = ''

class diskUsage:
    disk = ''
    disk_used = ''
    disk_avail = ''
    disk_size = ''

class prevOsdLatency:
    # primary osd read latency sum
    prev_op_rsum = 0
    # replica osd read latency sum
    prev_subop_rsum = 0
    # primary osd total read latency samples
    prev_op_rcount = 0
    # replica osd total read latency samples
    prev_subop_rcount = 0
    # primary osd write latency sum
    prev_op_wsum = 0
    # replica osd write latency sum
    prev_subop_wsum = 0
    # primary osd total write latency samples
    prev_op_wcount = 0
    # replica osd total write latency samples
    prev_subop_wcount = 0

class EventManager:
    rules_data = []
    headers = dict()
    process_state_db = {}
    prev_list = []

    def __init__(self, node_type):
        self.stdin = sys.stdin
        self.stdout = sys.stdout
        self.stderr = sys.stderr
        self.max_cores = 4
        self.max_old_cores = 3
        self.max_new_cores = 1
        self.node_type = node_type
        self._hostname = socket.gethostname()
        self.dict_of_osds = dict()
        self.prev_latency_dict = dict()
        self.units = self.init_units()
        self.curr_read_kbytes = 0
        self.curr_write_kbytes = 0
        self.curr_reads = 0
        self.curr_writes = 0
        self.curr_read_latency = 0
        self.curr_write_latency = 0
        pattern = 'rm -rf ceph.conf; ln -s /etc/ceph/ceph.conf ceph.conf'
        self.call_subprocess(pattern)

    def exec_local(self, arg):
        ret = Popen('%s' %(arg), shell=True,
                                stdout=PIPE).stdout.read()
        ret = ret[:-1]
        return ret

    def cleanup_pid(self, pid):
        pid_list = []
        proc_run = self.exec_local('ps -ef | grep -w %s | grep -v grep | wc -l'
                                    %(pid))
        if proc_run != '0':
            my_pid = os.getpid()
            procs = self.exec_local('ps -ef | grep -w %s | grep -v grep'
                                    %(pid))
            lines = procs.splitlines()
            for line in lines:
                pid = line.split()[1]
                pid_list.append(pid)
            while len(pid_list) != 0:
                for pid in pid_list:
                    running = self.exec_local('ps -ef | grep -w %s | \
                                    grep -v grep | awk \'{print $2}\' | \
                                    grep -w %s | wc -l' %(pid, pid))
                    if running != '0':
                        self.exec_local('kill -9 %s' %(pid))
                    else:
                        pid_list.remove(pid)
                time.sleep(5)
    #end cleanup_pid

    def init_units(self):
        units = dict();
        units['K'] = 1024
        units['M'] = int(units['K']) * 1024
        units['G'] = int(units['M']) * 1024
        units['T'] = int(units['G']) * 1024
        units['P'] = int(units['T']) * 1024
        return units

    '''
        This function is a wrapper for subprocess call. Timeout functionality
        is used to timeout after 5 seconds of no response from subprocess call
        and the corresponding cmd will be logged into syslog
    '''
    def call_subprocess(self, cmd):
        times = datetime.datetime.now()
        # latest 14.0.4 requires "HOME" env variable to be passed
        # copy current environment variables and add "HOME" variable
        # pass the newly created environment variable to Popen subprocess
        env_home = os.environ.copy()
        env_home['HOME'] = HOME_ENV_PATH
        # stdout and stderr are redirected.
        # stderr not used (stdout validation is done so stderr check is
        # is not needed)
        try:
            p = Popen(cmd, stdout=PIPE, \
                stderr=PIPE, shell=True, env=env_home)
            while p.poll() is None:
                gevent.sleep(0.1)
                now = datetime.datetime.now()
                diff = now - times
                if diff.seconds > 5:
                    #os.kill(p.pid, signal.SIGKILL)
                    os.waitpid(-1, os.WNOHANG)
                    message = "command:" + cmd + " ---> hanged"
                    ssdlog = StorageStatsDaemonLog(message = message)
                    self.call_send(ssdlog)
                    self.cleanup_pid(p.pid)
                    return None
        except:
            pass
            return None
        # stdout is used
        return p.stdout.read()

    def call_send(self, send_inst):
        #sys.stderr.write('sending UVE:' +str(send_inst))
        send_inst.send()

    '''
    This function reads the ceph cluster status
    Parses the health status output and gets error reason if present \
    StorageCluster object created and information is Populated
    UVE send call invoked to send the StorageCluster object
    '''

    def create_and_send_cluster_stats(self, mon_id):
        res = self.call_subprocess('/usr/bin/ceph health detail | grep -v ^pg')
        if res is None:
            return
        cluster_id = self.exec_local('ceph --admin-daemon \
                          /var/run/ceph/ceph-mon.%s.asok quorum_status | \
                          grep fsid | \
                          cut -d \'"\'  -f4' %(mon_id))
        cluster_stats = StorageCluster()
        cluster_stats.cluster_id = cluster_id
        cluster_stats.name = cluster_id
        status = res.split(' ')[0]
        status_count = res.count(' ')
        if status_count >= 1:
            detail_info = res.split(' ', 1)[1]
            summary_info = res.split(' ', 1)[1].splitlines()[0]
            osd_stat = self.call_subprocess('/usr/bin/ceph osd dump | \
                          egrep -w \'(down|out)\' | cut -d \' \' -f 1')
            multiple = 0
            osd_string = ''
            if osd_stat != '':
                osd_entries = osd_stat.splitlines()
                for osd_entry in osd_entries:
                    if osd_entry != '':
                        if osd_string == '':
                            osd_string = osd_entry
                        else:
                            multiple = 1
                            osd_string = osd_string + ', ' + osd_entry
                if multiple == 0:
                    detail_info = detail_info + (' OSD %s is down' %(osd_string))
                    summary_info = summary_info + ('; OSD %s is down' %(osd_string))
                else:
                    detail_info = detail_info + (' OSDs %s are down' %(osd_string))
                    summary_info = summary_info + ('; OSDs %s are down' %(osd_string))
            detail_info = re.sub('\n', ';', detail_info)
        else:
            status = res.splitlines()[0]
            detail_info = ''
            summary_info = ''
        cluster_info = ClusterInfo()
        if status == 'HEALTH_OK':
            cluster_info.status = 0
        elif status == 'HEALTH_WARN':
            cluster_info.status = 1
        elif status == 'HEALTH_ERR':
            cluster_info.status = 2
        cluster_info.health_detail = detail_info
        cluster_info.health_summary = summary_info
        cluster_stats.info_stats = [cluster_info]
        cluster_stats_trace = StorageClusterTrace(data=cluster_stats)
        self.call_send(cluster_stats_trace)

    '''
    This function reads the ceph rados statistics.
    Parses this statistics output and gets the read_cnt/read_bytes \
    write_cnt/write_bytes. ComputeStoragePool object created and all \
    the above statictics are assigned
    UVE send call invoked to send the ComputeStoragePool object
    '''

    def create_and_send_pool_stats(self):
        res = self.call_subprocess('/usr/bin/rados df')
        if res is None:
            return
        arr = res.splitlines()
        for line in arr:
            if line != arr[0]:
                result = re.sub(
                    '\s+', ' ', line).strip()
                arr1 = result.split()
                READS = 7
                READKBS = 8
                WRITES = 9
                WRITEKBS = 10
                if len(arr1) == 10:
                    READS = 6
                    READKBS = 7
                    WRITES = 8
                    WRITEKBS = 9
                if arr1[0] != "total":
                    cs_pool = ComputeStoragePool()
                    cs_pool.name = self._hostname + ':' + arr1[0]
                    pool_stats = PoolStats()
                    pool_stats.reads = int(arr1[READS])
                    pool_stats.read_kbytes = int(arr1[READKBS])
                    pool_stats.writes = int(arr1[WRITES])
                    pool_stats.write_kbytes = int(arr1[WRITEKBS])
                    cs_pool.info_stats = [pool_stats]
                    pool_stats_trace = ComputeStoragePoolTrace(data=cs_pool)
                    self.call_send(pool_stats_trace)

    def populate_osd_total_stats(self, osdname, osd_stats, prev_osd_latency):
        ceph_name = "ceph-" + osdname + ".asok"
        cmd = "ceph --admin-daemon /var/run/ceph/" + ceph_name + \
              " perf dump | egrep  -w \"\\\"op_w\\\":|\\\"" + \
              "op_r\\\":|\\\"subop_r\\\":|\\\"subop_w\\\":|\\\"" + \
              "op_r_out_bytes\\\":|\\\"subop_r_out_bytes\\\":|" + \
              "\\\"op_w_in_bytes\\\":|\\\"subop_w_in_bytes\\\":\""
        try:
            res1 = self.call_subprocess(cmd)
            if res1 is None:
                return False
            osd_stats.stats_time = datetime.datetime.now()
            arr1 = res1.splitlines()
            for line1 in arr1:
                result = re.sub('\s+', ' ', line1).strip()
                line2 = result.split(":")
                if len(line2) != 0:
                    if line2[0].find('subop_r_out_bytes') != -1 or \
                        line2[0].find('op_r_out_bytes') != -1:
                        osd_stats.read_kbytes += int(
                            line2[1].rstrip(",").strip(' ')) / 1024
                    elif line2[0].find('subop_w_in_bytes') != -1 or \
                        line2[0].find('op_w_in_bytes') != -1:
                        osd_stats.write_kbytes += int(
                            line2[1].rstrip(",").strip(' ')) / 1024
                    elif line2[0].find('subop_r') != -1 or \
                        line2[0].find('op_r') != -1:
                        osd_stats.reads += int(
                            line2[1].rstrip(",").strip(' '))
                    elif line2[0].find('subop_w') != -1 or \
                        line2[0].find('op_w') != -1:
                        osd_stats.writes += int(
                            line2[1].rstrip(",").strip(' '))
        except:
            pass

        res2 = self.populate_osd_latency_stats(osdname,  osd_stats,
                                               prev_osd_latency)
        if res2 is None:
            return False
        return True

    def diff_read_kbytes(self, line, osd_stats, temp_osd_stats,
                         osd_prev_stats, diff_time):
        # 'line' format : " xyz,"
        self.curr_read_kbytes += int(line.rstrip(",").strip(' ')) / 1024
        temp_osd_stats.read_kbytes = self.curr_read_kbytes
        osd_stats.read_kbytes = self.curr_read_kbytes - \
                                      osd_prev_stats.read_kbytes
        osd_stats.read_kbytes = int(osd_stats.read_kbytes / diff_time)

    def diff_write_kbytes(self, line, osd_stats, temp_osd_stats,
                          osd_prev_stats, diff_time):
        # 'line' format : " xyz,"
        self.curr_write_kbytes += int(line.rstrip(",").strip(' ')) / 1024
        temp_osd_stats.write_kbytes = self.curr_write_kbytes
        osd_stats.write_kbytes = self.curr_write_kbytes - \
                                      osd_prev_stats.write_kbytes
        osd_stats.write_kbytes = int(osd_stats.write_kbytes / diff_time)

    def diff_read_cnt(self, line, osd_stats, temp_osd_stats,
                      osd_prev_stats, diff_time):
        # 'line' format : " xyz,"
        self.curr_reads += int(line.rstrip(",").strip(' '))
        temp_osd_stats.reads = self.curr_reads
        osd_stats.reads = self.curr_reads - \
                                      osd_prev_stats.reads
        osd_stats.reads = int(osd_stats.reads / diff_time)

    def diff_write_cnt(self, line, osd_stats, temp_osd_stats,
                       osd_prev_stats, diff_time):
        # 'line' format : " xyz,"
        self.curr_writes += int(line.rstrip(",").strip(' '))
        temp_osd_stats.writes = self.curr_writes
        osd_stats.writes = self.curr_writes - \
                                      osd_prev_stats.writes
        osd_stats.writes = int(osd_stats.writes / diff_time)

    def populate_osd_diff_stats(self, osdname, osd_stats,
                                temp_osd_stats, osd_prev_stats):
        ceph_name = "ceph-" + osdname + ".asok"
        cmd = "ceph --admin-daemon /var/run/ceph/" + ceph_name + \
              " perf dump | egrep  -w \"\\\"op_w\\\":|\\\"" + \
              "op_r\\\":|\\\"subop_r\\\":|\\\"subop_w\\\":|\\\"" + \
              "op_r_out_bytes\\\":|\\\"subop_r_out_bytes\\\":|" + \
              "\\\"op_w_in_bytes\\\":|\\\"subop_w_in_bytes\\\":\""
        try:
            res1 = self.call_subprocess(cmd)
            if res1 is None:
                return False
            stats_time = datetime.datetime.now()
            diff_time = stats_time - osd_prev_stats.stats_time
            fdiff_time = float(diff_time.seconds) + \
                            float(diff_time.microseconds)/1000000
            temp_osd_stats.stats_time = stats_time
            arr1 = res1.splitlines()
            for line1 in arr1:
                result = re.sub('\s+', ' ', line1).strip()
                line2 = result.split(":")
                if len(line2) != 0:
                    if line2[0].find('subop_r_out_bytes') != -1 or \
                        line2[0].find('op_r_out_bytes') != -1:
                        self.diff_read_kbytes(line2[1],
                                            osd_stats,
                                            temp_osd_stats,
                                            osd_prev_stats,
                                            fdiff_time)
                    elif line2[0].find('subop_w_in_bytes') != -1 or \
                        line2[0].find('op_w_in_bytes') != -1:
                        self.diff_write_kbytes(line2[1],
                                            osd_stats,
                                            temp_osd_stats,
                                            osd_prev_stats,
                                            fdiff_time)
                    elif line2[0].find('subop_r') != -1 or \
                        line2[0].find('op_r') != -1:
                        self.diff_read_cnt(line2[1],
                                            osd_stats,
                                            temp_osd_stats,
                                            osd_prev_stats,
                                            fdiff_time)
                    elif line2[0].find('subop_w') != -1 or \
                        line2[0].find('op_w') != -1:
                        self.diff_write_cnt(line2[1],
                                            osd_stats,
                                            temp_osd_stats,
                                            osd_prev_stats,
                                            fdiff_time)
        except:
            pass
        return True

    def compute_read_latency(self, arr, osd_stats,
                             prev_osd_latency, op_flag):
        # 'line' format : ['op_read_latency', 'avgcount', '2822,', 'sum', '240.2423},']

        avgcount = int(arr[2].rstrip(","))
        # 'arr' format : "'sum': xyz.yzw},"
        sum_rlatency = int(float(arr[4].rstrip("},")))

        # sum_rlatency is in seconds
        # multiplied by 1000 to convert seconds to milliseconds
        if avgcount != 0:
            # op_flag = 1 indicates replica osd read latency
            if op_flag == 1:
                if(avgcount > prev_osd_latency.prev_subop_rcount):
                    osd_stats.op_r_latency += ((sum_rlatency * 1000) - \
                        (prev_osd_latency.prev_subop_rsum * 1000)) / \
                        (avgcount - prev_osd_latency.prev_subop_rcount)
                prev_osd_latency.prev_subop_rsum = sum_rlatency
                prev_osd_latency.prev_subop_rcount = avgcount
            # op_flag = 2 indicates primary osd read latency
            if op_flag == 2:
                if(avgcount > prev_osd_latency.prev_op_rcount):
                    osd_stats.op_r_latency += ((sum_rlatency * 1000) - \
                        (prev_osd_latency.prev_op_rsum * 1000)) / \
                        (avgcount - prev_osd_latency.prev_op_rcount)
                prev_osd_latency.prev_op_rsum = sum_rlatency
                prev_osd_latency.prev_op_rcount = avgcount
        else:
            osd_stats.op_r_latency += 0
            # op_flag = 1 indicates replica osd read latency
            if op_flag == 1:
                prev_osd_latency.prev_subop_rsum = 0
                prev_osd_latency.prev_subop_rcount = 0
            # op_flag = 2 indicates primary osd read latency
            if op_flag == 2:
                prev_osd_latency.prev_op_rsum = 0
                prev_osd_latency.prev_op_rcount = 0

    def compute_write_latency(self, arr, osd_stats,
                              prev_osd_latency, op_flag):
        # 'line' format : ['op_read_latency', 'avgcount', '2822,', 'sum', '240.2423},']

        avgcount = int(arr[2].rstrip(","))
        # 'arr' format : "'sum': xyz.yzw},"
        sum_wlatency = int(float(arr[4].rstrip("},")))
        # sum_wlatency is in seconds
        # multiplied by 1000 to convert seconds to milliseconds
        if avgcount != 0:
            # op_flag = 1 indicates replica osd write latency
            if op_flag == 1:
                if(avgcount > prev_osd_latency.prev_subop_wcount):
                    osd_stats.op_w_latency += ((sum_wlatency * 1000) - \
                        (prev_osd_latency.prev_subop_wsum * 1000)) / \
                        (avgcount - prev_osd_latency.prev_subop_wcount)
                prev_osd_latency.prev_subop_wsum = sum_wlatency
                prev_osd_latency.prev_subop_wcount = avgcount
            # op_flag = 2 indicates primary osd write latency
            if op_flag == 2:
                if(avgcount > prev_osd_latency.prev_op_wcount):
                    osd_stats.op_w_latency += ((sum_wlatency * 1000) - \
                        (prev_osd_latency.prev_op_wsum * 1000)) / \
                        (avgcount - prev_osd_latency.prev_op_wcount)
                prev_osd_latency.prev_op_wsum = sum_wlatency
                prev_osd_latency.prev_op_wcount = avgcount
        else:
            osd_stats.op_w_latency += 0
            # op_flag = 1 indicates replica osd write latency
            if op_flag == 1:
                prev_osd_latency.prev_subop_wsum = 0
                prev_osd_latency.prev_subop_wcount = 0
            # op_flag = 2 indicates primary osd write latency
            if op_flag == 2:
                prev_osd_latency.prev_op_wsum = 0
                prev_osd_latency.prev_op_wcount = 0

    def populate_osd_latency_stats(self, osdname, osd_stats, prev_osd_latency):
       lat_list={"op_r_latency","subop_r_latency","op_w_latency","subop_w_latency"}
       for entry in lat_list:
           ceph_name = "ceph-" + osdname + ".asok"
           cmd = ('ceph --admin-daemon /var/run/ceph/%s perf dump | \
               egrep -A5 -w %s |tr \"\\\"\" \" \" | \
               awk \'BEGIN{start=0;title=\"\";avgcount=\"\";sum=\"\"} \
               {i=1;while (i<=NF) {if($i == \"{\"){start=1} \
               if($i == \"}\" && start==1){break} \
               if($i==\"%s\"){title=$i} \
               if($i==\"avgcount\"){i=i+2;avgcount=$i} \
               if($i==\"sum\"){i=i+2;sum=$i}i=i+1}} \
               END{print title \" avgcount \" avgcount \" sum \" sum}\''
               %(ceph_name, entry, entry))
           res = self.call_subprocess(cmd)
           if res is None:
               return False
           res.lstrip(' ')
           line = res.split(' ')
           # subop_r_latency: replica osd read latency value
           if line[0] == 'subop_r_latency':
               self.compute_read_latency(line,
                   osd_stats, prev_osd_latency, 1)
           # op_r_latency: primary osd read latency value
           elif line[0] == 'op_r_latency':
               self.compute_read_latency(line,
                   osd_stats, prev_osd_latency, 2)
           # subop_w_latency: replica osd write latency value
           elif line[0] == 'subop_w_latency':
               self.compute_write_latency(line,
                   osd_stats, prev_osd_latency, 1)
           # op_w_latency: primary osd write latency value
           elif line[0] == 'op_w_latency':
               self.compute_write_latency(line,
                   osd_stats, prev_osd_latency, 2)
       return True

    '''
    This function checks if an osd is active, if yes parses output of \
    osd dump ComputeStorageOsd object created and statictics are assigned
    UVE send call invoked to send the ComputeStorageOsd object
    '''

    def create_and_send_osd_stats(self):
        res = self.call_subprocess('ls /var/lib/ceph/osd')
        if res is None:
            return
        arr = res.splitlines()
        linecount = 0
        for line in arr:
            no_prev_osd = 0
            cmd = "cat /var/lib/ceph/osd/" + arr[linecount] + "/active"
            is_active = self.call_subprocess(cmd)
            if is_active is None:
                linecount = linecount + 1
                continue
            #instantiate osd and its state
            cs_osd = ComputeStorageOsd()
            cs_osd_state = ComputeStorageOsdState()
            osd_stats = OsdStats()
            temp_osd_stats = OsdStats()
            prev_osd_latency = prevOsdLatency()
            #initialize fields
            osd_stats.reads = 0
            osd_stats.writes = 0
            osd_stats.read_kbytes = 0
            osd_stats.write_kbytes = 0
            osd_stats.op_r_latency = 0
            osd_stats.op_w_latency = 0
            self.curr_read_kbytes = 0
            self.curr_write_kbytes = 0
            self.curr_reads = 0
            self.curr_writes = 0
            self.curr_read_latency = 0
            self.curr_write_latency = 0
            # osd state is active and not down
            if is_active == "ok\n":
                cs_osd_state.status = "active"
                num = arr[linecount].split('-')[1]
                uuid = self.exec_local('ceph --admin-daemon \
                            /var/run/ceph/ceph-osd.%s.asok status 2>/dev/null | \
                            grep osd_fsid  | awk \'{print $2}\' | \
                            cut -d \'"\' -f 2' %(num))
                if uuid is '':
                    linecount = linecount + 1
                    continue
                cs_osd.uuid = uuid.rstrip("\n")
                osd_prev_stats = self.dict_of_osds.get(
                    cs_osd.uuid)
                osd_name = "osd." + num
                cs_osd.name = self._hostname + ':' + osd_name
                if osd_prev_stats is None:
                    no_prev_osd = 1
                    rval = self.populate_osd_total_stats(osd_name,
                                                         osd_stats,
                                                         prev_osd_latency)
                else:
                    prev_osd_latency = self.prev_latency_dict.get(
                        cs_osd.uuid)
                    rval = self.populate_osd_diff_stats(osd_name, osd_stats,
                                                        temp_osd_stats,
                                                        osd_prev_stats)
                    if rval == False:
                        linecount = linecount + 1
                        continue
                    rval = self.populate_osd_latency_stats(osd_name,
                                                           osd_stats,
                                                           prev_osd_latency)
                if rval == False:
                    linecount = linecount + 1
                    continue
            else:
                cs_osd_state.status = "inactive"
            if no_prev_osd == 0:
                cs_osd.info_stats = [osd_stats]
                cs_osd.info_state = cs_osd_state
                osd_stats_trace = ComputeStorageOsdTrace(
                    data=cs_osd)
                self.call_send(osd_stats_trace)
                self.dict_of_osds[
                    cs_osd.uuid] = temp_osd_stats
                self.prev_latency_dict[cs_osd.uuid] = prev_osd_latency
            else:
                self.dict_of_osds[cs_osd.uuid] = osd_stats
                self.prev_latency_dict[cs_osd.uuid] = prev_osd_latency
            linecount = linecount + 1

    def find_osdmaplist(self, osd_map, disk):
        for osdmap_obj in osd_map:
            if osdmap_obj.osd_disk.find(disk) != -1:
                return 'y'
        return 'n'

    def find_diskusagelist(self, disk_usage, disk):
        for disk_usage_obj in disk_usage:
            if disk_usage_obj.disk.find(disk) != -1:
                return disk_usage_obj
        return None

    def compute_usage(self, disk_usage_obj, unit):
        if unit.isalpha():
            return long(float(disk_usage_obj.
                    disk_used.strip(unit)) * self.units[unit])
        return 0

    '''
    This function parses output of iostat and assigns statistice to \
    ComputeStorageDisk
    UVE send call invoked to send the ComputeStorageDisk object
    '''

    def create_and_send_disk_stats(self):
        # iostat to get the raw disk list
        cmd = 'iostat -x 4 2 | awk \'{arr[NR]=$0} \
            END{for(i=(NR/2)+1;i<NR;i++) { print arr[i] }}\''
        res = self.call_subprocess(cmd)
        if res is None:
            return
        disk_list = res.splitlines()
        # osd disk list to get the mapping of osd to
        # raw disk
        # cd to /etc/ceph so that ceph-deploy command logs output to
        # /var/log/ceph and not /root
        # pattern = 'cd /etc/ceph && ceph-deploy disk list %s 2>&1' \
        #             %(self._hostname)
        pattern = 'cat /proc/mounts | grep "\/var\/lib\/ceph\/osd\/ceph"'
        res = self.call_subprocess(pattern)
        if res is None:
            return
        osd_list = res.splitlines()
        osd_map = []
        for line in osd_list:
            arr1 = line.split()
            osd_map_obj = osdMap()
            osd_map_obj.osd_disk = arr1[0]
            osd_map_obj.osd = 'osd.%s' %(arr1[1].split('-')[1])
            cmd = 'ls -l %s/journal | awk \'{print $11}\'' %(arr1[1])
            journal_uuid = self.call_subprocess(cmd).strip('\r\n')
            cmd = 'ls -l %s | awk \'{print $11}\'' %(journal_uuid)
            journal_disk = self.call_subprocess(cmd).strip('\r\n')
            if journal_disk[0] != '/':
                journal_disk = '/dev/%s' %(journal_disk.split('/')[2])
            osd_map_obj.osd_journal = journal_disk
            osd_map.append(osd_map_obj)

        # df used to get the free space of all disks
        res1 = self.call_subprocess('df -hl')
        if res1 is None:
            return
        df_list = res1.splitlines()
        disk_usage = []
        for line in df_list:
            if line.find('sda') != -1 or \
                line.find('vda') != -1:
                # replace multiple spaces to single
                # space here
                result = re.sub(
                    '\s+', ' ', line).strip()
                arr1 = result.split()
                if arr1[5] == '/':
                    disk_usage_obj = diskUsage()
                    disk_usage_obj.disk = arr1[0]
                    disk_usage_obj.disk_size = arr1[1]
                    disk_usage_obj.disk_used = arr1[2]
                    disk_usage_obj.disk_avail = arr1[3]
                    disk_usage.append(disk_usage_obj)

                elif line.find('sd') != -1 or \
                    line.find('vd') != -1:
                    # replace multiple spaces to single
                    # space here
                    result = re.sub(
                        '\s+', ' ', line).strip()
                    arr1 = result.split()
                    disk_usage_obj = diskUsage()
                    disk_usage_obj.disk = arr1[0]
                    disk_usage_obj.disk_size = arr1[1]
                    disk_usage_obj.disk_used = arr1[2]
                    disk_usage_obj.disk_avail = arr1[3]
                    disk_usage.append(disk_usage_obj)

# create a dictionary of disk_name: model_num + serial_num
        new_dict = dict()
        resp = self.call_subprocess('ls -l /dev/disk/by-id/')
        if resp is None:
            return
        arr_disks = resp.splitlines()
        for line in arr_disks[1:]:
            resp1 = line.split()
            if (resp1[-1].find('sd') != -1 and
                resp1[8].find('part') == -1 and
                    resp1[8].find('ata') != -1):
                    new_dict[resp1[-1].split('/')[2]] = resp1[8]

        #cs_disk1 = ComputeStorageDisk()
        #cs_disk1.list_of_curr_disks = []
        for line in disk_list:       # this will have all rows
            # replace multiple spaces to single space here
            result = re.sub('\s+', ' ', line).strip()
            arr1 = result.split()
            if len(arr1) != 0 and (arr1[0].find('sd') != -1 or \
                arr1[0].find('vd') != -1):
                cs_disk = ComputeStorageDisk()
                cs_disk.name = self._hostname + ':' + arr1[0]
                osd_id = self.exec_local('cat /proc/mounts | \
                            grep %s | grep ceph | grep -v tmp | \
                            awk \'{print $2}\' | cut -d \'-\' -f 2'
                            %(arr1[0]))
                if osd_id == '':
                    cs_disk.uuid = ''
                else:
                    uuid = self.exec_local('ceph --admin-daemon \
                            /var/run/ceph/ceph-osd.%s.asok status 2>/dev/null | \
                            grep osd_fsid  | awk \'{print $2}\' | \
                            cut -d \'"\' -f 2' %(osd_id))
                    cs_disk.uuid = uuid
                #cs_disk1.list_of_curr_disks.append(arr1[0])
                cs_disk.is_osd_disk = self.find_osdmaplist(osd_map, arr1[0])
                disk_usage_obj = self.find_diskusagelist(disk_usage, arr1[0])
                if disk_usage_obj is None:
                    cs_disk.current_disk_usage = 0
                else:
                    last = disk_usage_obj.disk_used[-1:]
                    cs_disk.current_disk_usage = \
                        self.compute_usage(disk_usage_obj, last)
                disk_stats = DiskStats()
                disk_stats.reads = 0
                disk_stats.writes = 0
                disk_stats.read_kbytes = 0
                disk_stats.write_kbytes = 0
                disk_stats.op_r_latency = 0
                disk_stats.op_w_latency = 0
                if arr1[0] in new_dict:
                    if cs_disk.uuid == '':
                        cs_disk.uuid = new_dict.get(arr1[0])
                disk_stats.iops = int(float(arr1[3]) + float(arr1[4]))
                disk_stats.bw = int(float(arr1[5])) + \
                    int(float(arr1[6]))
                disk_stats.reads = int(float(arr1[3]))
                disk_stats.writes = int(float(arr1[4]))
                disk_stats.read_kbytes = int(float(arr1[5]))
                disk_stats.write_kbytes = int(float(arr1[6]))
                disk_stats.op_r_latency = int(float(arr1[10]))
                disk_stats.op_w_latency = int(float(arr1[11]))
                cs_disk.info_stats = [disk_stats]
                disk_stats_trace = ComputeStorageDiskTrace(data=cs_disk)
                self.call_send(disk_stats_trace)

        #cs_disk1_trace = ComputeStorageDiskTrace(data=cs_disk1)
        # sys.stderr.write('sending UVE:' +str(cs_disk1_trace))
        #if len(set(cs_disk1.list_of_curr_disks).
        #       difference(set(self.prev_list))) != 0:
        #    self.call_send(cs_disk1_trace)
        #self.prev_list = []
        #for i in xrange(0, len(cs_disk1.list_of_curr_disks)-1):
        #    self.prev_list.append(cs_disk1.list_of_curr_disks[i])

    # send UVE for updated process state database
    def send_process_state_db(self):
        sleep_time = 20
        # Check if the mon is the mon leader
        # Send pool stats and cluster stats from the mon leader alone
        mon_running = self.exec_local('ls /var/run/ceph/ceph-mon*.asok \
                                        2> /dev/null | wc -l')

        if mon_running != '0':
            mon_id = self.exec_local('ls  /var/run/ceph/ceph-mon*.asok | \
                                        cut -d \'.\'  -f 2')
            mon_leader = self.exec_local('ceph --admin-daemon \
                          /var/run/ceph/ceph-mon.%s.asok quorum_status | \
                          grep quorum_leader_name | \
                          cut -d \'"\'  -f4' %(mon_id))
            if mon_id == mon_leader:
                self.create_and_send_cluster_stats(mon_id)
                self.create_and_send_pool_stats()
                if self.node_type != "storage-compute":
                    sleep_time = 10

        # Send disk stats from all the storage compute nodes
        if self.node_type == "storage-compute":
            self.create_and_send_osd_stats()
            self.create_and_send_disk_stats()
            sleep_time = 6

        time.sleep(sleep_time)
        return

    def runforever(self, test=False):
        # sleep for 6 seconds. There is a sleep in iostat for 4 seconds
        # send pool/disk/osd information to db
        while 1:
            self.send_process_state_db()

def parse_args(args_str):

    # Source any specified config/ini file
    # Turn off help, so we show all options in response to -h
    conf_parser = argparse.ArgumentParser(add_help=False)

    conf_parser.add_argument("-c", "--conf_file",
                             help="Specify config file", metavar="FILE")

    args, remaining_argv = conf_parser.parse_known_args(args_str.split())

    defaults = {
        'node_type': 'storage-compute',
        'log_local': True,
        'log_level': 'SYS_NOTICE',
        'log_category': '',
        'log_file': Sandesh._DEFAULT_LOG_FILE,
    }
    defaults.update(SandeshConfig.get_default_options(['DEFAULTS']))
    sandesh_opts = SandeshConfig.get_default_options()

    if args.conf_file:
        config = ConfigParser.SafeConfigParser()
        config.read([args.conf_file])
        if 'DEFAULTS' in config.sections():
            defaults.update(dict(config.items("DEFAULTS")))
        SandeshConfig.update_options(sandesh_opts, config)

    # Override with CLI options
    # Don't surpress add_help here so it will handle -h
    parser = argparse.ArgumentParser(
        # Inherit options from config_parser
        parents=[conf_parser],
        # script description with -h/--help
        description=__doc__,
        # Don't mess with format of description
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )

    defaults.update(sandesh_opts)
    parser.set_defaults(**defaults)

    parser.add_argument("--log_local", action="store_true",
                        help="Enable local logging of sandesh messages")
    parser.add_argument("--node_type",
                        help="node type of the storage")
    parser.add_argument("--log_level",
                        help="Severity level for local logging of sandesh messages")
    parser.add_argument("--log_category",
                        help="Category filter for local logging of sandesh messages")
    parser.add_argument("--log_file",
                        help="Filename for the logs to be written to")
    SandeshConfig.add_parser_arguments(parser)

    args = parser.parse_args(remaining_argv)
    return args

def main(args_str=None):

    if not args_str:
        args_str = ' '.join(sys.argv[1:])
    args = parse_args(args_str)

    prog = EventManager(args.node_type)

    collector_addr = []
    if (args.node_type == 'storage-compute' or args.node_type == 'storage-master'):
        #storage node module initialization part
        module = Module.STORAGE_STATS_MGR
        module_name = ModuleNames[module]
        node_type = Module2NodeType[module]
        node_type_name = NodeTypeNames[node_type]
        instance_id = INSTANCE_ID_DEFAULT
        sandesh_config = SandeshConfig.from_parser_arguments(args)
        sandesh_global.init_generator(
            module_name,
            socket.gethostname(),
            node_type_name,
            instance_id,
            collector_addr,
            module_name,
            HttpPortStorageStatsmgr,
            ['stats_daemon.sandesh.storage'],
            config=sandesh_config)

        sandesh_global.set_logging_params(
            enable_local_log=args.log_local,
            category=args.log_category,
            level=args.log_level,
            file=args.log_file, enable_syslog=False,
            syslog_facility='LOG_LOCAL0')
    gevent.joinall([gevent.spawn(prog.runforever)])

if __name__ == '__main__':
    main()


text:
require File.expand_path("../endpoint_marshal_fail", __FILE__)

Artifice.deactivate

class EndpointMarshalFailBasicAuthentication < EndpointMarshalFail
  before do
    unless env["HTTP_AUTHORIZATION"]
      halt 401, "Authentication info not supplied"
    end
  end
end

Artifice.activate_with(EndpointMarshalFailBasicAuthentication)

redpajama_set_name: RedPajamaGithub


text:
The tables below provide OS version information supported by .NET Core 2.0.

## Keys used in the tables

* **Bold numbers** indicate additions to this release.
* A '+' indicates the minimum supported version.
* Where possible, links to Distribution-owned lifecycle documentation is provided.

## Windows

OS                            | Version                       | Architectures  | Notes
------------------------------|-------------------------------|----------------|-----
Windows Client                | 7 SP1+, 8.1                  | x64, x86       |
Windows 10 Client             | Version 1607+                 | x64, x86       |
Windows Server                | 2008 R2 SP1+                  | x64, x86       |

See the [Windows Lifecycle Fact Sheet](https://support.microsoft.com/en-us/help/13853/windows-lifecycle-fact-sheet) for details regarding each Windows release lifecycle.

## macOS

OS                            | Version                       | Architectures  | Notes
------------------------------|-------------------------------|----------------|-----
Mac OS X                      | 10.12+                        | x64            | [Apple Support Sitemap](https://support.apple.com/sitemap)
 [Apple Security Updates](https://support.apple.com/en-us/HT201222)

## Linux

OS                            | Version                       | Architectures  | Notes
------------------------------|-------------------------------|----------------|-----
Red Hat Enterprise Linux      | 6                             | x64            | [Red Hat support policy](https://access.redhat.com/support/policy/updates/errata/)
Red Hat Enterprise Linux
 CentOS
 Oracle Linux     | 7                             | x64            | [Red Hat support policy](https://access.redhat.com/support/policy/updates/errata/)
 [CentOS lifecycle](https://wiki.centos.org/FAQ/General#head-fe8a0be91ee3e7dea812e8694491e1dde5b75e6d)
 [Oracle Linux lifecycle](http://www.oracle.com/us/support/library/elsp-lifetime-069338.pdf)
Fedora                        | 27                | x64            | [Fedora lifecycle](https://fedoraproject.org/wiki/End_of_life)
Debian                        | 9, 8.7+                   | x64            | [Debian lifecycle](https://wiki.debian.org/DebianReleases)
Ubuntu                        | 18.04, 17.10, 16.04, 14.04       | x64            | [Ubuntu lifecycle](https://wiki.ubuntu.com/Releases)
Linux Mint                    | 18, 17                    | x64            | [Linux Mint end of life announcements](https://forums.linuxmint.com/search.php?keywords=%22end+of+life%22&terms=all&author=&sc=1&sf=titleonly&sr=posts&sk=t&sd=d&st=0&ch=300&t=0&submit=Search)
openSUSE                      | 42.3+                         | x64            | [OpenSUSE lifecycle](https://en.opensuse.org/Lifetime)
SUSE Enterprise Linux (SLES)  | 12 SP2+                   | x64            | [SUSE lifecycle](https://www.suse.com/lifecycle/)

* **Bold numbers** indicate additions in this release.
* '+' indicates the minimum supported version.

## Out of support OS versions

Support for the following versions was ended by the distribution owners and are [not supported by .NET Core 2](https://github.com/dotnet/core/blob/master/os-lifecycle-policy.md).

OS         | Version  | End of Life | Supported Version
-----------|----------|-------------|------------------
Fedora     | 26       | [May 2018](https://fedoramagazine.org/fedora-26-end-life/) | 27+
Fedora     | 25       | [December 2017](https://fedoramagazine.org/fedora-25-end-life/) | 27+
Fedora     | 24       | [August 2017](https://fedoramagazine.org/fedora-24-eol/) | 27+
openSUSE   | 42.2     | [January 2018](https://lists.opensuse.org/opensuse-security-announce/2017-11/msg00066.html)  | 42.3
openSUSE   | 42.1     | [May 2017](https://lists.opensuse.org/opensuse-security-announce/2017-05/msg00053.html)  | 42.3
Ubuntu     | 17.04    | [January 2018](https://lists.ubuntu.com/archives/ubuntu-announce/2018-January.txt) | 17.10 |
Ubuntu     | 16.10    | [July 2017](https://lists.ubuntu.com/archives/ubuntu-announce/2017-July/000223.html) | 17.10


text:
use std::result::Result;

use super::bytes::{InnerBytes, NetworkBytes, NetworkBytesMut};
use super::Incomplete;
use crate::MacAddr;

const DST_MAC_OFFSET: usize = 0;
const SRC_MAC_OFFSET: usize = 6;
const ETHERTYPE_OFFSET: usize = 12;

// We don't support 802.1Q tags.
// TODO: support 802.1Q tags?! If so, don't forget to change the speculative_test_* functions
// for ARP and IPv4.
/// Payload offset in an ethernet frame
pub const PAYLOAD_OFFSET: usize = 14;

/// Ethertype value for ARP frames.
pub const ETHERTYPE_ARP: u16 = 0x0806;
/// Ethertype value for IPv4 packets.
pub const ETHERTYPE_IPV4: u16 = 0x0800;

/// Describes the errors which may occur when handling Ethernet frames.
#[derive(Debug, PartialEq, Eq)]
pub enum Error {
    /// The specified byte sequence is shorter than the Ethernet header length.
    SliceTooShort,
}

/// Interprets the inner bytes as an Ethernet frame.
pub struct EthernetFrame<'a, T: 'a> {
    bytes: InnerBytes<'a, T>,
}

#[allow(clippy::len_without_is_empty)]
impl<'a, T: NetworkBytes> EthernetFrame<'a, T> {
    /// Interprets `bytes` as an Ethernet frame without any validity checks.
    ///
    /// # Panics
    ///
    ///  This method does not panic, but further method calls on the resulting object may panic if
    /// `bytes` contains invalid input.
    #[inline]
    pub fn from_bytes_unchecked(bytes: T) -> Self {
        EthernetFrame {
            bytes: InnerBytes::new(bytes),
        }
    }

    /// Checks whether the specified byte sequence can be interpreted as an Ethernet frame.
    #[inline]
    pub fn from_bytes(bytes: T) -> Result<Self, Error> {
        if bytes.len() < PAYLOAD_OFFSET {
            return Err(Error::SliceTooShort);
        }

        Ok(EthernetFrame::from_bytes_unchecked(bytes))
    }

    /// Returns the destination MAC address.
    #[inline]
    pub fn dst_mac(&self) -> MacAddr {
        MacAddr::from_bytes_unchecked(&self.bytes[DST_MAC_OFFSET..SRC_MAC_OFFSET])
    }

    /// Returns the source MAC address.
    #[inline]
    pub fn src_mac(&self) -> MacAddr {
        MacAddr::from_bytes_unchecked(&self.bytes[SRC_MAC_OFFSET..ETHERTYPE_OFFSET])
    }

    /// Returns the ethertype of the frame.
    #[inline]
    pub fn ethertype(&self) -> u16 {
        self.bytes.ntohs_unchecked(ETHERTYPE_OFFSET)
    }

    /// Returns the offset of the payload within the frame.
    #[inline]
    pub fn payload_offset(&self) -> usize {
        PAYLOAD_OFFSET
    }

    /// Returns the payload of the frame as an `[&u8]` slice.
    #[inline]
    pub fn payload(&self) -> &[u8] {
        self.bytes.split_at(self.payload_offset()).1
    }

    /// Returns the length of the frame.
    #[inline]
    pub fn len(&self) -> usize {
        self.bytes.len()
    }
}

impl<'a, T: NetworkBytesMut> EthernetFrame<'a, T> {
    /// Attempts to write an Ethernet frame using the given header fields to `buf`.
    fn new_with_header(
        buf: T,
        dst_mac: MacAddr,
        src_mac: MacAddr,
        ethertype: u16,
    ) -> Result<Self, Error> {
        if buf.len() < PAYLOAD_OFFSET {
            return Err(Error::SliceTooShort);
        }

        let mut frame = EthernetFrame::from_bytes_unchecked(buf);

        frame
            .set_dst_mac(dst_mac)
            .set_src_mac(src_mac)
            .set_ethertype(ethertype);

        Ok(frame)
    }

    /// Attempts to write an incomplete Ethernet frame (whose length is currently unknown) to `buf`,
    /// using the specified header fields.
    #[inline]
    pub fn write_incomplete(
        buf: T,
        dst_mac: MacAddr,
        src_mac: MacAddr,
        ethertype: u16,
    ) -> Result<Incomplete<Self>, Error> {
        Ok(Incomplete::new(Self::new_with_header(
            buf, dst_mac, src_mac, ethertype,
        )?))
    }

    /// Sets the destination MAC address.
    #[inline]
    pub fn set_dst_mac(&mut self, addr: MacAddr) -> &mut Self {
        self.bytes[DST_MAC_OFFSET..SRC_MAC_OFFSET].copy_from_slice(addr.get_bytes());
        self
    }

    /// Sets the source MAC address.
    #[inline]
    pub fn set_src_mac(&mut self, addr: MacAddr) -> &mut Self {
        self.bytes[SRC_MAC_OFFSET..ETHERTYPE_OFFSET].copy_from_slice(addr.get_bytes());
        self
    }

    /// Sets the ethertype of the frame.
    #[inline]
    pub fn set_ethertype(&mut self, value: u16) -> &mut Self {
        self.bytes.htons_unchecked(ETHERTYPE_OFFSET, value);
        self
    }

    /// Returns the payload of the frame as a `&mut [u8]` slice.
    #[inline]
    pub fn payload_mut(&mut self) -> &mut [u8] {
        // We need this let to avoid confusing the borrow checker.
        let offset = self.payload_offset();
        self.bytes.split_at_mut(offset).1
    }
}

impl<'a, T: NetworkBytes> Incomplete<EthernetFrame<'a, T>> {
    /// Completes the inner frame by shrinking it to its actual length.
    ///
    /// # Panics
    ///
    /// This method panics if `len` is greater than the length of the inner byte sequence.
    #[inline]
    pub fn with_payload_len_unchecked(mut self, payload_len: usize) -> EthernetFrame<'a, T> {
        let payload_offset = self.inner.payload_offset();
        self.inner
            .bytes
            .shrink_unchecked(payload_offset + payload_len);
        self.inner
    }
}

#[cfg(test)]
mod tests {
    use std::fmt;

    use super::*;

    impl<'a, T: NetworkBytes> fmt::Debug for EthernetFrame<'a, T> {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            write!(f, "(Ethernet frame)")
        }
    }

    #[test]
    fn test_ethernet_frame() {
        let mut a = [0u8; 10000];
        let mut bad_array = [0u8; 1];

        let dst_mac = MacAddr::parse_str("01:23:45:67:89:ab").unwrap();
        let src_mac = MacAddr::parse_str("cd:ef:01:23:45:67").unwrap();
        let ethertype = 1289;

        assert_eq!(
            EthernetFrame::from_bytes(bad_array.as_ref()).unwrap_err(),
            Error::SliceTooShort
        );
        assert_eq!(
            EthernetFrame::new_with_header(bad_array.as_mut(), dst_mac, src_mac, ethertype)
                .unwrap_err(),
            Error::SliceTooShort
        );

        {
            let mut f1 =
                EthernetFrame::new_with_header(a.as_mut(), dst_mac, src_mac, ethertype).unwrap();

            assert_eq!(f1.dst_mac(), dst_mac);
            assert_eq!(f1.src_mac(), src_mac);
            assert_eq!(f1.ethertype(), ethertype);
            f1.payload_mut()[1] = 132;
        }

        {
            let f2 = EthernetFrame::from_bytes(a.as_ref()).unwrap();

            assert_eq!(f2.dst_mac(), dst_mac);
            assert_eq!(f2.src_mac(), src_mac);
            assert_eq!(f2.ethertype(), ethertype);
            assert_eq!(f2.payload()[1], 132);
            assert_eq!(f2.len(), f2.bytes.len());
        }

        {
            let f3 =
                EthernetFrame::write_incomplete(a.as_mut(), dst_mac, src_mac, ethertype).unwrap();
            let f3_complete = f3.with_payload_len_unchecked(123);
            assert_eq!(f3_complete.len(), f3_complete.payload_offset() + 123);
        }
    }
}


text:
shared_examples 'a data page' do |table_ids:|
  it 'contains all required tables' do
    table_ids.each do |table_id|
      expect(page).to have_table table_id
    end
  end
end


text:
package at.dotpoint.gradle.cross.specification;

import at.dotpoint.gradle.cross.options.model.IOptions;

/**
 * Created by RK on 2016-11-13.
 */
public interface ITestComponentSpec extends IGeneralComponentSpec
{
	//
	IOptions getOptions();

	//
	String getMain();
}


text:
import React from 'react'
import {mount, shallow} from 'enzyme'
import {expect} from 'chai'

import Header from '../../components/Header.react'

describe('Header', () => {
    let location
    let header
    let loginMenu
    let signupMenu
    let homeMenu
    let profileMenu
    let logoutMenu

    let menuTitle

    let initMenu = () => {
        loginMenu = header.find('#header-item-login')
        signupMenu = header.find('#header-item-signup')
        homeMenu = header.find('#header-item-home')
        profileMenu = header.find('#header-item-profile')
        logoutMenu = header.find('#header-item-logout')

        menuTitle = header.find('#header-title').first()
    }

    beforeEach(() => {
        location = {
            pathname: '/'
        }

        header = mount(<Header location={location} />)
        initMenu()
    })

    it('should render', () => {
        expect(header).to.exist
    })

    it('should initialise state', () => {
        expect(header.state().isLoggedIn).to.equal(false)
        expect(header.state().isNavigationExpanded).to.equal(false)
        expect(header.state().navClass).to.equal('collapsed')
    })

    it('should render the correct menu',  () => {
        expect(loginMenu).to.exist
        expect(loginMenu).to.have.length(1)
        loginMenu = loginMenu.first()
        expect(loginMenu.text()).to.equal('Login')

        expect(signupMenu).to.exist
        expect(signupMenu).to.have.length(1)
        signupMenu = signupMenu.first()
        expect(signupMenu.text()).to.equal('Signup')

        expect(homeMenu).to.exist
        expect(homeMenu).to.have.length(1)
        homeMenu = homeMenu.first()
        expect(homeMenu.text()).to.equal('Calculator')

        expect(logoutMenu).to.have.length(0)
        expect(profileMenu).to.have.length(0)

        header.setState({
            'isLoggedIn': true
        })

        initMenu()

        expect(logoutMenu).to.exist
        expect(logoutMenu).to.have.length(1)
        logoutMenu = logoutMenu.first()
        expect(logoutMenu.text()).to.equal('Logout')

        expect(profileMenu).to.exist
        expect(profileMenu).to.have.length(1)
        profileMenu = profileMenu.first()
        expect(profileMenu.text()).to.equal('Profile')

        expect(homeMenu).to.exist
        expect(homeMenu).to.have.length(1)
        homeMenu = homeMenu.first()
        expect(homeMenu.text()).to.equal('Calculator')

        expect(loginMenu).to.have.length(0)
        expect(signupMenu).to.have.length(0)
    })

    it('should render the correct title', () => {
        expect(menuTitle.text()).to.equal('Calculator')

        header = mount(<Header location={{pathname: '/profile'}} />)
        initMenu()
        expect(menuTitle.text()).to.equal('Profile')

        header = mount(<Header location={{pathname: '/login'}} />)
        initMenu()
        expect(menuTitle.text()).to.equal('Login')

        header = mount(<Header location={{pathname: '/signup'}} />)
        initMenu()
        expect(menuTitle.text()).to.equal('Signup')
    })
})


text:
"""
Test the Results classes

"""

import re
from urlparse import urlparse

from pyesgf.search.connection import SearchConnection

from .config import TEST_SERVICE

def test_result1():
    conn = SearchConnection(TEST_SERVICE, distrib=False)

    ctx = conn.new_context(project='CMIP5')
    results = ctx.search()

    r1 = results[0]
    assert re.match(r'cmip5\.output1\.IPSL\..\|vesg.ipsl.fr', r1.dataset_id)

def test_file_context():
    conn = SearchConnection(TEST_SERVICE, distrib=False)

    ctx = conn.new_context(project='CMIP5')
    results = ctx.search()

    r1 = results[0]
    f_ctx = r1.file_context()

    assert f_ctx.facet_constraints['dataset_id'] == r1.dataset_id

def test_file_list():
    conn = SearchConnection(TEST_SERVICE, distrib=False)

    ctx = conn.new_context(project='CMIP5')
    results = ctx.search()

    r1 = results[0]
    f_ctx = r1.file_context()

    file_results = f_ctx.search()
    f1 = file_results[0]

    ds_id, shard = r1.dataset_id.split('|')
    download_url = f1.download_url

    # Assumes dataset is published with DRS path.
    ds_subpath = ds_id.replace('.', '/')
    assert ds_subpath.lower() in download_url.lower()

def test_file_list2():
    conn = SearchConnection(TEST_SERVICE, distrib=False)

    ctx = conn.new_context(project='CMIP5')
    results = ctx.search()

    r1 = results[0]
    f_ctx = r1.file_context()

    file_results = f_ctx.search()
    for file_result in file_results:
        print file_result.download_url
        assert re.match(r'http://vesg.ipsl.fr/thredds/.*\.nc', file_result.download_url)

def test_aggregations():
    conn = SearchConnection(TEST_SERVICE, distrib=False)

    ctx = conn.new_context(project='CMIP5')
    results = ctx.search()

    r1 = results[0]
    agg_ctx = r1.aggregation_context()

    agg_results = agg_ctx.search()
    agg1 = agg_results[0]

    ds_id, shard = r1.dataset_id.split('|')
    las_url = agg1.urls['LAS'][0][0]

    #!FIXME: A pretty dumb test for a correct aggregation
    assert '.aggregation' in las_url

def test_index_node():
    conn = SearchConnection(TEST_SERVICE, distrib=False)

    ctx = conn.new_context(project='CMIP5')
    results = ctx.search()

    r1 = results[0]
    service = urlparse(TEST_SERVICE)

    assert r1.index_node == service.hostname

def test_other_index_node():
    conn = SearchConnection(TEST_SERVICE, distrib=True)

    ctx = conn.new_context(project='CMIP5', institute='INM')
    results = ctx.search()

    r1 = results[0]
    service = urlparse(TEST_SERVICE)
    print 'index_node = %s' % r1.index_node

    assert r1.index_node is not None
    assert r1.index_node != service.hostname

def test_shards_constrain():
    # Test that a file-context constrains the shard list

    conn = SearchConnection(TEST_SERVICE, distrib=True)

    ctx = conn.new_context(project='CMIP5')
    results = ctx.search()

    r1 = results[0]
    f_ctx = r1.file_context()

    #!TODO: white-box test.  Refactor.
    query_dict = f_ctx._build_query()
    full_query = f_ctx.connection._build_query(query_dict, shards=f_ctx.shards)

    #!TODO: Force fail to see whether shards is passed through.
    q_shard = full_query['shards']
    # Check it isn't a ',' separated list
    assert ',' not in q_shard
    q_shard_host = q_shard.split(':')[0]
    assert q_shard_host == r1.json['index_node']

    # Now make the query to make sure it returns data from the right index_node
    f_results = f_ctx.search()
    f_r1 = results[0]
    assert f_r1.json['index_node'] == r1.json['index_node']

def test_shards_constrain2():
    # Regression test for issue #8 reported by ian.edmond@metoffice.gov.uk
    conn = SearchConnection('http://pcmdi9.llnl.gov/esg-search',distrib=True)

    ctx = conn.new_context(experiment='piControl', time_frequency='day', variable='pr', ensemble='r1i1p1')
    ctx = ctx.constrain(query='cmip5.output1.BCC.bcc-csm1-1-m.piControl.day.atmos.day.r1i1p1')
    s = ctx.search()

    ds = s[0]

    publicationDataset, server = ds.dataset_id.split('|')
    print publicationDataset, server, ds.json['replica']

    searchContext = ds.file_context()
    searchContext=searchContext.constrain(variable='pr')
    for j in searchContext.search():
        print j.download_url, j.checksum, j.checksum_type, j.size

def test_shards_constrain3():
    # Regression test for issue #8 reported by ian.edmond@metoffice.gov.uk
    conn = SearchConnection('http://pcmdi9.llnl.gov/esg-search',distrib=True)

    ctx = conn.new_context(query='cmip5.output1.CMCC.CMCC-CESM.historical.mon.atmos.Amon.r1i1p1.v20130416')
    s = ctx.search()

    ds = s[0]

    publicationDataset, server = ds.dataset_id.split('|')
    print publicationDataset, server, ds.json['replica']

    searchContext = ds.file_context()
    searchContext=searchContext.constrain(variable='pr')
    for j in searchContext.search():
        print j.download_url, j.checksum, j.checksum_type, j.size

def test_shards_constrain4():
    # Regression test for issue #8 reported by ian.edmond@metoffice.gov.uk
    conn = SearchConnection('http://pcmdi9.llnl.gov/esg-search',distrib=True)

    ctx = conn.new_context(query='cmip5.output1.BCC.bcc-csm1-1-m.historical.mon.atmos.Amon.r1i1p1.v20120709')
    s = ctx.search()

    ds = s[0]

    publicationDataset, server = ds.dataset_id.split('|')
    print publicationDataset, server, ds.json['replica']

    searchContext = ds.file_context()
    searchContext=searchContext.constrain(variable='tas')
    for j in searchContext.search():
        print j.download_url, j.checksum, j.checksum_type, j.size


text:
return Def.Sprite {
	Texture=NOTESKIN:GetPath( '_downleftp1', 'tap lift' );
	Frames = Sprite.LinearFrames( 6, 1 );
};


text:
section form fieldset { padding: 0.5em 0; }

section form label { line-height: 1.2rem; font-weight: normal; font-size: 0.8rem; display: block; }

section form label span { display: block; }

section form label span.sub { color: #8E8E8E; }

section form input[type="text"], section form input[type="password"] { font-size: 1.3rem; font-family: monospace; width: 100%; }

section form button { cursor: pointer; font-size: 0.7rem; text-transform: uppercase; }

section form div.submit { text-align: right; padding: 0.5rem 0 0 0; }

section { padding: 0 1rem 1rem 1rem; color: #000; background-color: #fff; font-weight: bold; margin: 1em; float: left; -moz-border-radius: 5px; -webkit-border-radius: 5px; -khtml-border-radius: 5px; border-radius: 5px; }

section div.field_invalid { border: 1px dashed #F00919; padding: 0.5em; }

section div.error_msg { color: #F00919; font-style: italic; font-size: smaller; }

section div.error_server { font-size: larger; padding: 1em 0; }

section div.success_msg { background-color: #FFFEE2; margin: 0.5em 0 0 0; padding: 0.5em; background-color: #B0C460; color: #fff; }

section h2 { font-weight: bolder; font-size: 0.8rem; padding: 0.5rem 0 0.5rem 0; text-align: center; color: #616161; }

nav { height: 100%; background-color: #fff; border: 0; max-width: 200px; padding: 1em; text-align: right; float: left; }

nav h1 { font-size: 1.5rem; }

nav p { font-size: 0.8rem; line-height: 1rem; }

nav div.disclaimer { color: #616161; }

nav ul li { display: block; list-style: none; }

html { height: 100%; }

body { height: 100%; background-color: #F5F5F5; }

a:link { color: #000; }

a:visited { color: #8E8E8E; }

a:hover { color: #C0002C; }

h1.site_name { color: #000; font-family: AghjaMedium; font-weight: normal; font-style: normal; margin: 0.5em 0; }

h2, h3 { color: #363636; text-transform: uppercase; font-size: smaller; padding: 0.5em 0; margin: 0; }

p { margin: 0 0 0.5em 0; }

div.disclaimer { color: #8E8E8E; }

section.loading form div.buttons { display: none; }

section.loading div.loading_msg { background-color: #FFFEE2; }


text:
<?php

namespace Sylius\Bundle\AttributeBundle\Form\Type;

use Sylius\Bundle\AttributeBundle\Form\EventListener\BuildAttributeFormChoicesListener;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Sylius\Component\Attribute\Model\AttributeTypes;
use Symfony\Component\Form\FormBuilderInterface;

/**
 * Attribute Translation type.

 * @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
 */
class AttributeTranslationType extends AbstractResourceType
{
    /**
     * Subject name.
     *
     * @var string
     */
    protected $subjectName;

    /**
     * Constructor.
     *
     * @param string $dataClass
     * @param array  $validationGroups
     * @param string $subjectName
     */
    public function __construct($dataClass, array $validationGroups, $subjectName)
    {
       parent::__construct($dataClass, $validationGroups);

        $this->subjectName = $subjectName;
    }

    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('presentation', 'text', array(
                'label' => 'sylius.form.attribute.presentation'
            ))
        ;
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return sprintf('sylius_%s_attribute_translation', $this->subjectName);
    }
}


text:
cygwin=false
case "`uname`" in
CYGWIN*) cygwin=true;;
esac

# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ]; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '.*/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

# Get standard environment variables
PRGDIR=`dirname "$PRG"`
CATALINA_HOME=`cd "$PRGDIR/.." ; pwd`
if [ -r "$CATALINA_HOME"/bin/setenv.sh ]; then
  . "$CATALINA_HOME"/bin/setenv.sh
fi

# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin; then
  [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  [ -n "$CATALINA_HOME" ] && CATALINA_HOME=`cygpath --unix "$CATALINA_HOME"`
  [ -n "$CATALINA_BASE" ] && CATALINA_BASE=`cygpath --unix "$CATALINA_BASE"`
  [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
  [ -n "$JSSE_HOME" ] && JSSE_HOME=`cygpath --path --unix "$JSSE_HOME"`
fi

# Get standard Java environment variables
if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then
  BASEDIR="$CATALINA_HOME"
  . "$CATALINA_HOME"/bin/setclasspath.sh
else
  echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"
  echo "This file is needed to run this program"
  exit 1
fi

# Add on extra jar files to CLASSPATH
if [ -n "$JSSE_HOME" ]; then
  CLASSPATH="$CLASSPATH":"$JSSE_HOME"/lib/jcert.jar:"$JSSE_HOME"/lib/jnet.jar:"$JSSE_HOME"/lib/jsse.jar
fi
CLASSPATH="$CLASSPATH":"$CATALINA_HOME"/bin/bootstrap.jar

if [ -z "$CATALINA_BASE" ] ; then
  CATALINA_BASE="$CATALINA_HOME"
fi

if [ -z "$CATALINA_TMPDIR" ] ; then
  # Define the java.io.tmpdir to use for Catalina
  CATALINA_TMPDIR="$CATALINA_BASE"/temp
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
  JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  CATALINA_HOME=`cygpath --path --windows "$CATALINA_HOME"`
  CATALINA_BASE=`cygpath --path --windows "$CATALINA_BASE"`
  CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  JSSE_HOME=`cygpath --path --windows "$JSSE_HOME"`
fi

# ----- Execute The Requested Command -----------------------------------------

echo "Using CATALINA_BASE:   $CATALINA_BASE"
echo "Using CATALINA_HOME:   $CATALINA_HOME"
echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
echo "Using JAVA_HOME:       $JAVA_HOME"

if [ "$1" = "jpda" ] ; then
  if [ -z "$JPDA_TRANSPORT" ]; then
    JPDA_TRANSPORT="dt_socket"
  fi
  if [ -z "$JPDA_ADDRESS" ]; then
    JPDA_ADDRESS="8000"
  fi
  if [ -z "$JPDA_OPTS" ]; then
    JPDA_OPTS="-Xdebug -Xrunjdwp:transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=n"
  fi
  CATALINA_OPTS="$CATALINA_OPTS $JPDA_OPTS"
  shift
fi

if [ "$1" = "debug" ] ; then

  shift
  if [ "$1" = "-security" ] ; then
    echo "Using Security Manager"
    shift
    exec "$_RUNJDB" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -sourcepath "$CATALINA_HOME"/../../jakarta-tomcat-4.0/catalina/src/share \
      -Djava.security.manager \
      -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start
  else
    exec "$_RUNJDB" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -sourcepath "$CATALINA_HOME"/../../jakarta-tomcat-4.0/catalina/src/share \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start
  fi

elif [ "$1" = "embedded" ] ; then

  shift
  echo "Embedded Classpath: $CLASSPATH"
  exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
    -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
    -Dcatalina.base="$CATALINA_BASE" \
    -Dcatalina.home="$CATALINA_HOME" \
    -Djava.io.tmpdir="$CATALINA_TMPDIR" \
    org.apache.catalina.startup.Embedded "$@"

elif [ "$1" = "run" ]; then

  shift
  if [ "$1" = "-security" ] ; then
    echo "Using Security Manager"
    shift
    exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -Djava.security.manager \
      -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start
  else
    exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start
  fi

elif [ "$1" = "start" ] ; then

  shift
  touch "$CATALINA_BASE"/logs/catalina.out
  if [ "$1" = "-security" ] ; then
    echo "Using Security Manager"
    shift
    "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -Djava.security.manager \
      -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start \
      >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &
  else
    "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start \
      >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &
  fi

elif [ "$1" = "stop" ] ; then

  shift
  exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
    -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
    -Dcatalina.base="$CATALINA_BASE" \
    -Dcatalina.home="$CATALINA_HOME" \
    -Djava.io.tmpdir="$CATALINA_TMPDIR" \
    org.apache.catalina.startup.Bootstrap "$@" stop

else

  echo "Usage: catalina.sh ( commands ... )"
  echo "commands:"
  echo "  debug             Start Catalina in a debugger"
  echo "  debug -security   Debug Catalina with a security manager"
  echo "  embedded          Start Catalina in embedded mode"
  echo "  jpda start        Start Catalina under JPDA debugger"
  echo "  run               Start Catalina in the current window"
  echo "  run -security     Start in the current window with security manager"
  echo "  start             Start Catalina in a separate window"
  echo "  start -security   Start in a separate window with security manager"
  echo "  stop              Stop Catalina"
  exit 1

fi


text:
function c = structureConstants( phi, mu, nL, nL2, nPar )
% STRUCTURECONSTANTS Compute the structure constnants associated with
% multiplication of basis elements.
%
% Input arguments:
%
% phi:     Array of size [ nS, nLMax ] where nS is the number of samples and
%          nLMax the total number of available basis functions.
%
% mu:      Inner product weight array of size [ nS, 1 ]. The phi's
%          are assumed to be orthonormal with respect to the mu inner product.
%
% nL, nL2: Positive integers <= nLMax determining the size of the structure
%          constant array. If nL is unspecified or empty, it is set to nLMax.
%          If nL2 is unspecified or empty, it is set to nL.
%
% nPar:    Number of workers for parallel for loop calculation. Calculation
%          reverts to serial for loop if nPar is set to 0 or is unspecified.
%
% Output arguments:
%
% c:       Array of size [ nL, nL, nL2 ] containing the structure constants.
%          Specifically, c( i, j, k ) = < phi( :, i ), phi( :, j ) phi( :, k ) >
%          where < , > denotes the mu-weighted inner product.
%
% Modified 2021/03/06.

if nargin == 2 || isempty( nL )
    nL = size( phi, 2 );
end

if nargin <+ 3 || isempty( nL2 )
    nL2 = nL:
end

if nargin <= 4
    nPar = 0;
end

% Compute mu-weighted basis functions
phiMu = ( phi( :, 1 : nL ) .* mu )';

% Compute structure constants
c = zeros( nL, nL, nL2 );
parfor( i = 1 : nL2, nPar )
    c( :, :, i ) = phiMu * ( phi( :, 1 : nL ) .* phi( :, i ) );
end


text:
/**
 * Router, an object heavily influenced by Crossroads.js by Miller Medeiros (https://github.com/millermedeiros/crossroads.js) and Christoph Pojer's MooTools-Router (https://github.com/cpojer/mootools-router)
 * date - Jul 29, 2012
 * crossroads.js commit - 3b413b0b506b0c04f80b03194d4c1abaeccc9574

 * @type {Class}
 */
var collectionObj = require('../collection/main'),
    routeObj = require('../route/main'),
    signalFactory = require('../../utils/signalFactory');

var Router = new Class({
    Extends: collectionObj.Collection,

    options: {
        Model: {
            constructor: routeObj.Route,
            options: {
                defaults: {
                    typecast: false,
                    normalizer: null
                }
            }
        },
        greedy: false,
        greedyEnabled: true
    },

    _prevRoutes: [],

    _prevMatchedRequest: null,

    _prevBypassedRequest: null,

    _add: function(route){
        // placement of route is determined by the priority property
        var priority = instanceOf(route, routeObj.Route) ? route.get('priority') : route.priority || (route.priority = 0);

        this.parent(route, this._calcPriority(priority));

        return this;
    },

    /**
     * _calcPriority uses a priority number to calculate what should be the returned insertion point.
     * @param  {Number} priority The value used to determine the insertion index
     * @return {Number}          The resolved index;
     */
    _calcPriority: function(priority){
        var route, n = this.length;

        do { --n; } while ( (route = this.get(n), route) && priority <= route.get('priority'));

        return n + 1;
    },

    resetState: function(){
        this._prevRoutes.length = 0;
        this._prevMatchedRequest = null;
        this._prevBypassedRequest = null;
        return this
    },

    parse: function(request, defaultArgs){
        request = request || '';
        defaultArgs = defaultArgs || [];

        if (request !== this._prevMatchedRequest && request !== this._prevBypassedRequest) {
            var routes = this._getMatchedRoutes(request),
                i = 0,
                n = routes.length,
                cur;

            if (n) {
                this._prevMatchedRequest = request;

                this._notifyPrevRoutes(routes, request);

                this._prevRoutes = routes;

                //should be incremental loop, execute routes in order
                while (i < n) {
                    cur = routes[i];
                    cur.route.signalMatch.apply(cur.route, defaultArgs.concat(cur.params));
                    cur.isFirst = !i;
                    this.signalMatch.apply(this, defaultArgs.concat([request, cur]));
                    i += 1;
                }
            } else {
                this._prevBypassedRequest = request;
                this.signalDefault.apply(this, defaultArgs.concat([request]));
            }
        }

        return this;
    },

    empty: function(){
        this.resetState();

        this.parent();

        return this;
    },

    _notifyPrevRoutes: function(matchedRoutes, request){
        var i = 0, prev;

        while (prev = this._prevRoutes[i++]) {
            //check if switched exist since route may be disposed
            if (/*prev.route.switched && */this._didSwitch(prev.route, matchedRoutes)) {
                prev.route.signalPass(request);
                // prev.route.fireEvent('pass', request);
            }
        }

        return this;
    },

    _didSwitch: function(route, matchedRoutes){
        var i = 0, matched;

        while (matched = matchedRoutes[i++]) {
            // only dispatch switched if it is going to a different route
            if (matched.route === route) {
                return false;
            }
        }

        return true;
    },

    _getMatchedRoutes : function (request) {
        var res = [],
            n = this.length,
            route;

        //should be decrement loop since higher priorities are added at the end of array
        while (route = this.get(--n)) {
            if ((!res.length || this.options.greedy || route.get('greedy')) && route.match(request)) {
                res.push({
                    route : route,
                    params : route.parse(request)
                });
            }
            if (!this.options.greedyEnabled && res.length) {
                break;
            }
        }

        return res;
    }
});

Router.NORM_AS_ARRAY = function(req, vals){
    return [vals.vals_];
};

Router.NORM_AS_OBJECT = function(req, vals){
    return [vals];
};

Router.implement(
    signalFactory(['match', 'default'])
);

exports.Router = Router;


text:
Contact Us

Get in touch

<form class="row"  method="post" name="emailform" action="./components/form-to-email.php">

        Name
        <input class="column form-input" type="text" placeholder="Steve McQueen" name="name">

        Email
        <input class="column form-input" type="email" placeholder="mcqueenie@mail.co.uk" name="email" required>

        Message
        <textarea class="column form-input" placeholder="" name="message" required></textarea>

        <button class="form-button" type="submit" value="Submit" name="submit">Send</button>

</form>

"Make Yourself at Home!"

Tulipa Apartment is owned & maintained by Mary & John Clifford

<?php include('components/location.php'); ?>


text:
<?php

namespace Checkout\tests\Models\Payments;

use Checkout\Models\Tokens\Card;
use Checkout\tests\Helpers\Tokens;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

class CardTest extends TestCase
{
    public function testCreate()
    {
        $class = new ReflectionClass('Checkout\Models\Tokens\Card');
        $method = $class->getMethod('create');
        $method->setAccessible(true);

        $model = Tokens::generateCardModel();
        $response = $model->getValues();

        $result = $method->invokeArgs($model, array($response));
        $this->assertInstanceOf(Card::class, $result);
    }
}


text:
describe('Login', function () {
    var loginPage = require('./auth_page.js');

    var mockModule;

    beforeEach(function () {
        mockModule = require('./redirect_mock.js');
        browser.addMockModule('redirectMock', mockModule.authMock);
        browser.get('/#/dashboard');
    });

    afterEach(function () {
        browser.removeMockModule('redirectMock');
    });

    it('should redirect to default user dashboard', function () {
        browser.get('/#/auth/login/');
        loginPage.userName.sendKeys('test_user');
        loginPage.password.sendKeys('test_user');
        loginPage.submitButton.click();
        expect(browser.getCurrentUrl()).toBe(browser.baseUrl + '/#/dashboard/1/');
        expect(browser.isElementPresent(by.id('test_user'))).toBe(true);
    });

    it('use redirect on previous page', function () {
        browser.get('/#/testplan/1');
        loginPage.loginButton.click();
        loginPage.userName.sendKeys('test_user');
        loginPage.password.sendKeys('test_user');
        loginPage.submitButton.click();
        expect(browser.getCurrentUrl()).toBe(browser.baseUrl + '/#/testplan/1');
        expect(browser.isElementPresent(by.id('test_user'))).toBe(true);
    });

});


text:
namespace FermentationController {
    using System;
    using Xamarin.Forms;
    using Xamarin.Forms.Xaml;

    public partial class MainPageView : ContentPage {

        private Entry entryEcho;

        private Button btnEcho;

        private Label lblEchoReturnData;

        private Button btnSetTimeNow;

        private Button btnStatus;

        private Label lblStatusReturnData;

        private Button btnCreateProfile;

        private void InitializeComponent() {
            this.LoadFromXaml(typeof(MainPageView));
            entryEcho = this.FindByName<Entry>("entryEcho");
            btnEcho = this.FindByName<Button>("btnEcho");
            lblEchoReturnData = this.FindByName<Label>("lblEchoReturnData");
            btnSetTimeNow = this.FindByName<Button>("btnSetTimeNow");
            btnStatus = this.FindByName<Button>("btnStatus");
            lblStatusReturnData = this.FindByName<Label>("lblStatusReturnData");
            btnCreateProfile = this.FindByName<Button>("btnCreateProfile");
        }
    }
}


text:
#ifndef HAD_CONFIG_H
#define HAD_CONFIG_H
#ifndef _HAD_ZIPCONF_H
#include "zipconf.h"
#endif

#include "build/build_config.h"

/* BEGIN DEFINES */
/* #undef HAVE___PROGNAME */
/* #undef HAVE__CLOSE */
/* #undef HAVE__DUP */
/* #undef HAVE__FDOPEN */
/* #undef HAVE__FILENO */
/* #undef HAVE__SETMODE */
/* #undef HAVE__SNPRINTF */
/* #undef HAVE__STRDUP */
/* #undef HAVE__STRICMP */
/* #undef HAVE__STRTOI64 */
/* #undef HAVE__STRTOUI64 */
/* #undef HAVE__UMASK */
/* #undef HAVE__UNLINK */
/* #undef HAVE_ARC4RANDOM */
/* #undef HAVE_CLONEFILE */
/* #undef HAVE_COMMONCRYPTO */
/* #undef HAVE_CRYPTO */
/* #undef HAVE_FICLONERANGE */
#define HAVE_FILENO
#if !defined(OS_WIN)
#define HAVE_FSEEKO
#define HAVE_FTELLO
#endif
/* #undef HAVE_GETPROGNAME */
/* #undef HAVE_GNUTLS */
/* #undef HAVE_LIBBZ2 */
/* #undef HAVE_LIBLZMA */
/* #undef HAVE_LOCALTIME_R */
#if !defined(OS_WIN)
#define HAVE_LOCALTIME_R
#endif
/* #undef HAVE_MBEDTLS */
/* #undef HAVE_MKSTEMP */
/* #undef HAVE_NULLABLE */
/* #undef HAVE_OPENSSL */
/* #undef HAVE_SETMODE */
#define HAVE_SNPRINTF
#if !defined(OS_WIN)
#define HAVE_STRCASECMP
#endif
#define HAVE_STRDUP
#if defined(OS_WIN)
#define HAVE_STRICMP
#endif
#define HAVE_STRTOLL
#define HAVE_STRTOULL
/* #undef HAVE_STRUCT_TM_TM_ZONE */
#define HAVE_STDBOOL_H
#if !defined(OS_WIN)
#define HAVE_STRINGS_H
#define HAVE_UNISTD_H
#endif
/* #undef HAVE_WINDOWS_CRYPTO */
#define SIZEOF_OFF_T 8
#define SIZEOF_SIZE_T 8
/* #undef HAVE_DIRENT_H */
#define HAVE_FTS_H
/* #undef HAVE_NDIR_H */
/* #undef HAVE_SYS_DIR_H */
/* #undef HAVE_SYS_NDIR_H */
/* #undef WORDS_BIGENDIAN */
#define HAVE_SHARED
/* END DEFINES */
#define PACKAGE "libzip"
#define VERSION "1.7.3"

#endif /* HAD_CONFIG_H */


text:
require 'rails/generators'
require 'rails/generators/active_record'

module Enjoy::News::Migrations
  class InstallGenerator < Rails::Generators::Base
    include ActiveRecord::Generators::Migration
    source_root File.expand_path('../templates', __FILE__)

    desc 'Enjoy::News migration generator'
    def install
      if Enjoy::News.active_record?
        %w(news).each do |table_name|
          migration_template "migration_#{table_name}.rb", "db/migrate/enjoy_news_create_#{table_name}.rb"
        end
      end
    end
  end
end


text:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Bio;
using Bio.Algorithms.Alignment;
using Bio.Algorithms.SuffixTree;
using Bio.Extensions;
using Bio.IO;
using Bio.IO.FastA;
using Bio.Util;

namespace NucmerUtil
{
    /// <summary>
    /// Command line arguments for NUCmer.
    /// </summary>
    internal class NucmerArguments
    {
        #region Public Fields

        /// <summary>
        /// Paths of reference and query file.
        /// </summary>
        public string[] FilePath = null;

        /// <summary>
        /// Use anchor matches that are unique in both the reference and query.
        /// </summary>
        public bool Mum = false;

        /// <summary>
        /// Use anchor matches that are unique in the reference but not necessarily unique in the query (default behavior).
        /// </summary>
        public bool MumReference = true;

        /// <summary>
        /// Use all anchor matches regardless of their uniqueness.
        /// </summary>
        public bool MaxMatch = false;

        /// <summary>
        /// Distance an alignment extension will attempt to extend poor scoring regions before giving up (default 200).
        /// </summary>
        public int BreakLength = 200;

        /// <summary>
        /// Minimum cluster length (default 65).
        /// </summary>
        public int MinCluster = 65;

        /// <summary>
        /// Maximum diagonal difference factor for clustering, i.e. diagonal difference / match separation (default 0.12).
        /// </summary>
        public double DiagFactor = 0.12;

        /// <summary>
        /// Align only the forward strands of each sequence.
        /// </summary>
        public bool Forward = false;

        /// <summary>
        /// Maximum gap between two adjacent matches in a cluster (default 90).
        /// </summary>
        public int MaxGap = 90;

        /// <summary>
        /// Print the help information.
        /// </summary>
        public bool Help = false;

        /// <summary>
        /// Minimum length of an maximal exact match (default 20).
        /// </summary>
        public int MinMatch = 20;

        /// <summary>
        /// Output file.
        /// </summary>
        public string OutputFile = null;

        /// <summary>
        /// Align only the reverse strand of the query sequence to the forward strand of the reference.
        /// </summary>
        public bool Reverse = false;

        /// <summary>
        /// Toggle the outward extension of alignments from their anchoring clusters. Setting --noextend will
        /// prevent alignment extensions but still align the DNA between clustered matches and create the .delta file
        /// (default --extend).
        /// </summary>
        public bool NotExtend = false;

        /// <summary>
        /// Display verbose logging during processing.
        /// </summary>
        public bool Verbose = false;

        /// <summary>
        ///  Gets or sets maximum fixed diagonal difference
        /// </summary>
        public int FixedSeparation = 5;
        #endregion

        #region Private Fields

        /// <summary>
        /// Get the total number of delta for validation purpose
        /// </summary>
        private long _toltalDeltas;

        /// <summary>
        /// Count the number of processed queries.
        /// </summary>
        long _queryCount;

        #endregion

        #region Public Method

        /// <summary>
        /// Align the sequences.
        /// </summary>
        public void Align()
        {
            TimeSpan nucmerSpan = new TimeSpan();
            Stopwatch runNucmer = new Stopwatch();
            FileInfo refFileinfo = new FileInfo(this.FilePath[0]);
            long refFileLength = refFileinfo.Length;

            runNucmer.Restart();
            IEnumerable<ISequence> referenceSequence = Parse(this.FilePath[0]);
            runNucmer.Stop();

            if (this.Verbose)
            {
                Console.Error.WriteLine();
                Console.Error.WriteLine("  Processed Reference FastA file: {0}", Path.GetFullPath(this.FilePath[0]));
                Console.Error.WriteLine("            Read/Processing time: {0}", runNucmer.Elapsed);
                Console.Error.WriteLine("            File Size           : {0}", refFileLength);
                Console.Error.WriteLine();
            }

            refFileinfo = new FileInfo(this.FilePath[1]);
            refFileLength = refFileinfo.Length;

            runNucmer.Restart();
            IEnumerable<ISequence> querySequence = ParseWithPosition(this.FilePath[1]);
            runNucmer.Stop();

            if (this.Verbose)
            {
                Console.Error.WriteLine("  Processed Query FastA file: {0}", Path.GetFullPath(this.FilePath[1]));
                Console.Error.WriteLine("            Read/Processing time: {0}", runNucmer.Elapsed);
                Console.Error.WriteLine("            File Size           : {0}", refFileLength);
                if (!string.IsNullOrEmpty(this.OutputFile))
                {
                    Console.Error.WriteLine();
                    Console.Error.WriteLine("  Writing output to             : {0}", Path.GetFullPath(this.OutputFile));
                }
                Console.Error.WriteLine();

                if (Forward)
                    Console.Error.WriteLine("  Including forward strand of query sequence only.");
                else if (Reverse)
                    Console.Error.WriteLine("  Including reverse strand of query sequence only.");
                else
                    Console.Error.WriteLine("  Including both forward and reverse strands of query sequence.");
            }

            // Remove any existing output file - we will overwrite it.
            if (!string.IsNullOrEmpty(this.OutputFile))
            {
                if (File.Exists(this.OutputFile))
                    File.Delete(this.OutputFile);
            }

            // Align the DNA between clustered matches and create a delta.
            if (this.NotExtend)
            {
                runNucmer.Restart();
                IList<List<IList<Cluster>>> clusters = this.GetCluster(referenceSequence, querySequence);
                runNucmer.Stop();
                nucmerSpan = nucmerSpan.Add(runNucmer.Elapsed);

                runNucmer.Restart();
                this.WriteCluster(clusters, referenceSequence, querySequence);
                runNucmer.Stop();
            }
            // Normal operation.
            else
            {
                runNucmer.Restart();
                IEnumerable<IEnumerable<DeltaAlignment>> delta = this.GetDelta(referenceSequence, querySequence);
                runNucmer.Stop();
                nucmerSpan = nucmerSpan.Add(runNucmer.Elapsed);

                runNucmer.Restart();
                this.WriteDelta(delta);
                runNucmer.Stop();
            }

            if (this.Verbose)
            {
                Console.Error.WriteLine();
                Console.Error.WriteLine("                Compute time: {0}", nucmerSpan);
                Console.Error.WriteLine("                  Write time: {0}", runNucmer.Elapsed);
            }
        }

        #endregion

        #region Private Methods

        /// <summary>
        /// Given a list of sequences, create a new list with only the Reverse Complements
        /// of the original sequences.
        /// </summary>
        /// <param name="sequenceList">List of sequence.</param>
        /// <returns>Returns the list of sequence.</returns>
        private static IEnumerable<ISequence> ReverseComplementSequenceList(IEnumerable<ISequence> sequenceList)
        {
            foreach (ISequence rcSequence in sequenceList.Select(seq => seq.GetReverseComplementedSequence()))
            {
                if (rcSequence != null)
                {
                    rcSequence.MarkAsReverseComplement();
                    yield return rcSequence;
                }
            }
        }

        /// <summary>
        /// Given a list of sequences, create a new list with the original sequence followed
        /// by the Reverse Complement of that sequence.
        /// </summary>
        /// <param name="sequenceList">List of sequence.</param>
        /// <returns>Returns the List of sequence.</returns>
        private static IEnumerable<ISequence> AddReverseComplementsToSequenceList(IEnumerable<ISequence> sequenceList)
        {
            foreach (ISequence seq in sequenceList)
            {
                yield return seq;

                ISequence rcSequence = seq.GetReverseComplementedSequence();
                if (rcSequence != null)
                {
                    rcSequence.MarkAsReverseComplement();
                    yield return rcSequence;
                }
            }
        }

        /// <summary>
        /// Returns the cluster.
        /// </summary>
        /// <param name="referenceSequence">The Reference sequences.</param>
        /// <param name="originalQuerySequences">The Query sequences.</param>
        /// <returns>Returns list of clusters.</returns>
        private IList<List<IList<Cluster>>> GetCluster(IEnumerable<ISequence> referenceSequence, IEnumerable<ISequence> originalQuerySequences)
        {
            var clusters = new List<List<IList<Cluster>>>();
            var clusters1 = new List<IList<Cluster>>();

            IEnumerable<ISequence> querySequences =
                Forward ? originalQuerySequences
                        : (Reverse
                            ? ReverseComplementSequenceList(originalQuerySequences)
                            : AddReverseComplementsToSequenceList(originalQuerySequences));

            _queryCount += querySequences.Count();

            foreach (var sequence in referenceSequence)
            {
                NUCmer nucmer = new NUCmer(sequence)
                {
                    FixedSeparation = FixedSeparation,
                    BreakLength = BreakLength,
                    LengthOfMUM = MinMatch,
                    MaximumSeparation = MaxGap,
                    MinimumScore = MinCluster,
                    SeparationFactor = (float) DiagFactor
                };

                clusters1.AddRange(querySequences.Select(qs => nucmer.GetClusters(qs, !MaxMatch, qs.IsMarkedAsReverseComplement())));
            }

            clusters.Add(clusters1);

            return clusters;
        }

        /// <summary>
        /// Gets the Delta for list of query sequences.
        /// </summary>
        /// <param name="referenceSequence">The reference sequence.</param>
        /// <param name="originalQuerySequences">The query sequence.</param>
        /// <returns>Returns list of IEnumerable Delta Alignment.</returns>
        private IEnumerable<IEnumerable<DeltaAlignment>> GetDelta(IEnumerable<ISequence> referenceSequence, IEnumerable<ISequence> originalQuerySequences)
        {
            IEnumerable<ISequence> querySequences =
                Forward ? originalQuerySequences
                : (Reverse
                    ? ReverseComplementSequenceList(originalQuerySequences)
                    : AddReverseComplementsToSequenceList(originalQuerySequences));

            foreach (ISequence refSeq in referenceSequence)
            {
                NUCmer nucmer = new NUCmer(refSeq)
                {
                    FixedSeparation = FixedSeparation,
                    BreakLength = BreakLength,
                    LengthOfMUM = MinMatch,
                    MaximumSeparation = MaxGap,
                    MinimumScore = MinCluster,
                    SeparationFactor = (float) DiagFactor
                };

                foreach (ISequence qs in querySequences)
                {
                    _queryCount++;
                    yield return nucmer.GetDeltaAlignments(qs, !MaxMatch, qs.IsMarkedAsReverseComplement());
                }
            }
        }

        /// <summary>
        /// Parses the file.
        /// </summary>
        /// <param name="fileName">The FileName.</param>
        /// <returns>List of sequence.</returns>
        private static IEnumerable<ISequence> Parse(string fileName)
        {
            if (Helper.IsZippedFasta(fileName))
            {
                var parser = new GZipFastAParser();
                return parser.Parse(fileName);
            }
            else
            {
                var parser = new FastAParser();
                return parser.Parse(fileName);
            }
        }

        /// <summary>
        /// Parses the file.
        /// </summary>
        /// <param name="fileName">The FileName.</param>
        /// <returns>List of sequence.</returns>
        private static IEnumerable<ISequence> ParseWithPosition(string fileName)
        {
            using (var stream = File.OpenRead(fileName))
            {
                FastASequencePositionParser parser = new FastASequencePositionParser(stream);
                return parser.Parse().ToList();
            }
        }

        /// <summary>
        /// Writes cluster for query sequences.
        /// </summary>
        /// <param name="clusters">The Clusters.</param>
        /// <param name="referenceSequence">The reference sequence.</param>
        /// <param name="querySequence">The query sequence.</param>
        private void WriteCluster(IList<List<IList<Cluster>>> clusters,
            IEnumerable<ISequence> referenceSequence, IEnumerable<ISequence> querySequence)
        {
            TextWriter textWriterConsoleOutSave = Console.Out;
            if (!string.IsNullOrEmpty(this.OutputFile))
            {
                FileStream fileStreamConsoleOut = new FileStream(this.OutputFile, FileMode.Create);
                Console.SetOut(new StreamWriter(fileStreamConsoleOut) { AutoFlush = true });
            }

            int refIndex = 0;
            foreach (ISequence refSeq in referenceSequence)
            {
                List<IList<Cluster>> queryCluster = clusters[refIndex++];
                int queryIndex = 0;
                foreach (ISequence querySeq in querySequence)
                {
                    IEnumerable<Cluster> cluster = queryCluster[queryIndex++];
                    if (cluster != null)
                    {
                        Console.WriteLine(refSeq.ID + " " + querySeq.ID);
                        foreach (Cluster c in cluster)
                        {
                            foreach (MatchExtension ext in c.Matches)
                            {
                                Console.WriteLine(ext.ReferenceSequenceOffset + " " + ext.QuerySequenceOffset + " " + ext.Length);
                            }
                        }
                    }
                }
            }

            Console.SetOut(textWriterConsoleOutSave);
        }

         /// <summary>
        /// Writes delta for query sequences.
        /// </summary>
        /// <param name="delta">The Deltas.</param>
        private void WriteDelta(IEnumerable<IEnumerable<DeltaAlignment>> delta)
        {
            TextWriter textWriterConsoleOutSave = Console.Out;
             if (!string.IsNullOrEmpty(this.OutputFile))
            {
                Console.SetOut(new StreamWriter(this.OutputFile));
            }

            long sequenceCount = 0;
            long deltaPositionInFile = 0;

            foreach (IEnumerable<DeltaAlignment> align in delta)
            {
                sequenceCount++;
                // Note: Repeat Resolution step of comparative assembly needs all delta
                //       alignments to belong to a query sequence should be consecutively placed.
                foreach (DeltaAlignment deltaAlignment in align)
                {
                    deltaAlignment.Id = deltaPositionInFile;
                    string deltaString =  Helper.GetString(deltaAlignment);
                    deltaPositionInFile += deltaString.Length;
                    Console.Write(deltaString);
                    _toltalDeltas++;
                }

                Console.Out.Flush();

                if (sequenceCount % 1000 == 0)
                {
                    Console.Error.WriteLine("  Processed {0} sequences - {1}", sequenceCount, DateTime.Now);
                }
            }

            Console.Error.WriteLine("  Processed {0} sequences - {1}", sequenceCount, DateTime.Now);
            Console.Error.WriteLine("  Total Number of Delta(s) = {0} by processing {1} query sequence(s)", _toltalDeltas, _queryCount);

            Console.SetOut(textWriterConsoleOutSave);
        }
        #endregion
    }
}


text:
import { Injectable } from '@angular/core';
import * as io from 'socket.io-client';

@Injectable()
export class WebSocketService {

  private socket: SocketIOClient.Socket;

  constructor() { }

  connect(): void {
    this.socket = io({'path': '/ws'});
  }

  getSocket(): SocketIOClient.Socket {
    return this.socket;
  }

}


text:
var

	// Map over jQuery in case of overwrite
	_jQuery = window.jQuery,

	// Map over the $ in case of overwrite
	_$ = window.$;

jQuery.noConflict = function( deep ) {
	if ( window.$ === jQuery ) {
		window.$ = _$;
	}

	if ( deep && window.jQuery === jQuery ) {
		window.jQuery = _jQuery;
	}

	return jQuery;
};

// Expose jQuery and $ identifiers, even in
// AMD (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
// and CommonJS for browser emulators (#13566)
if ( !noGlobal ) {
	window.jQuery = window.$ = jQuery;
}