Esempio n. 1
0
 def _get_users(child, slot):
     record = do_some(child, 'disp max-online slot {s}'.format(s=slot))
     users = re_find(r'Max online users since startup\s+:\s+(\d+)', record)
     users = int(users or 0)
     date = re_find(r'Time of max online users\s+:\s+(\d{4}-\d{2}-\d{2})',
                    record)
     return (slot, users, date)
Esempio n. 2
0
File: S85.py Progetto: sjava/weihu
 def _get_info(record):
     name = re_find(r'(\S+) current state :', record)
     state = re_find(r'current state : ?(\S+ ?\S+)', record)
     desc = re_find(r'Description: (\S+ *\S+)', record)
     inTraffic = int(re_find(
         r'\d+ seconds input:\s+\d+\spackets/sec\s(\d+)\sbits/sec', record) or 0) / 1000000
     outTraffic = int(re_find(
         r'\d+ seconds output:\s+\d+\spackets/sec\s(\d+)\sbits/sec', record) or 0) / 1000000
     return dict(name=name, desc=desc, state=state, inTraffic=inTraffic, outTraffic=outTraffic)
Esempio n. 3
0
File: Zte.py Progetto: sjava/weihu
 def _get_desc_mode(child, group):
     rslt = do_some(child, 'show run int {name}'.format(name=group['name']))
     desc = re_find(r'description\s+(\S+)', rslt)
     group['desc'] = desc
     rslt = do_some(child, 'show run int {inf}'.format(
         inf=group['infs'][0]))
     mode = re_find(r'smartgroup\s\d+\smode\s(\S+)', rslt)
     group['mode'] = mode
     return group
Esempio n. 4
0
 def _get_group(child, group):
     rslt = do_some(
         child, 'disp link-aggregation {group}'.format(group=group))
     desc = re_find(r'description:(\S+)', rslt)
     mode = re_find(r'work mode:\s+(\S+)', rslt)
     temp = re_all(r'(\d+/\d+)\s+(\d\S+)', rslt)
     temp1 = lmapcat(lambda x: ['{0}/{1}'.format(x[0], y)
                                for y in x[1].split(',')], temp)
     return dict(name=group, desc=desc, mode=mode, infs=temp1)
Esempio n. 5
0
 def _get_info(record):
     name = re_find(r'((?:xg|g|f)ei\S+) is \w+ ?\w*,', record)
     state = re_find(r'(?:xg|g|f)ei\S+ is (\w+ ?\w+),', record)
     desc = re_find(r'Description is (\S+ *\S+)', record)
     inTraffic = int(
         re_find(r'120s input.*:\s(\d+)Bps', record)) * 8 / 1000000
     outTraffic = int(
         re_find(r'120s output.*:\s(\d+)Bps', record)) * 8 / 1000000
     return dict(name=name, desc=desc, state=state, inTraffic=inTraffic, outTraffic=outTraffic)
Esempio n. 6
0
 def _get_desc_mode(child, group):
     rslt = do_some(child, 'show run int {name}'.format(name=group['name']))
     desc = re_find(r'description\s+(\S+)', rslt)
     group['desc'] = desc
     rslt = do_some(child,
                    'show run int {inf}'.format(inf=group['infs'][0]))
     mode = re_find(r'smartgroup\s\d+\smode\s(\S+)', rslt)
     group['mode'] = mode
     return group
Esempio n. 7
0
File: ME60.py Progetto: sjava/weihu
 def _get_users(child, slot):
     record = do_some(
         child, 'disp max-online slot {s}'.format(s=slot))
     users = re_find(
         r'Max online users since startup\s+:\s+(\d+)', record)
     users = int(users or 0)
     date = re_find(
         r'Time of max online users\s+:\s+(\d{4}-\d{2}-\d{2})', record)
     return (slot, users, date)
Esempio n. 8
0
 def _get_group(child, group):
     rslt = do_some(
         child, 'disp link-aggregation {group}'.format(group=group))
     desc = re_find(r'description:(\S+)', rslt)
     mode = re_find(r'work mode:\s+(\S+)', rslt)
     temp = re_all(r'(\d+/\d+)\s+(\d\S+)', rslt)
     temp1 = lmapcat(
         lambda x: ['{0}/{1}'.format(x[0], y) for y in x[1].split(',')],
         temp)
     return dict(name=group, desc=desc, mode=mode, infs=temp1)
Esempio n. 9
0
File: S89.py Progetto: sjava/weihu
 def _get_desc(child, group):
     name = group['name']
     rslt = do_some(child, 'show run interface {name}'.format(name=name))
     desc = re_find(r'description\s(\S+ *\S*)', rslt)
     mode = re_find(r'smartgroup mode (\S+)', rslt)
     if mode == '802.3ad':
         mode = 'yes'
     group['desc'] = desc
     group['mode'] = mode
     return group
Esempio n. 10
0
File: S93.py Progetto: sjava/weihu
 def _get_info(record):
     name = re_find(r'interface\s(eth-trunk)(\d+)', record, flags=re.I)
     name = ' '.join(name).lower()
     mode = re_find(r'mode\s(\S+)', record)
     if mode is None:
         mode = 'manual'
     elif 'lacp' in mode:
         mode = 'yes'
     desc = re_find(r'description\s(\S+ *\S*)', record)
     return dict(name=name, mode=mode, desc=desc)
Esempio n. 11
0
File: S89.py Progetto: sjava/weihu
 def _get_desc(child, inf):
     name = inf['name']
     rslt = do_some(child, 'show run interface {name}'.format(name=name))
     desc = re_find(r'description\s(\S+ *\S*)', rslt)
     group = re_find(r'(smartgroup\s\d+)', rslt)
     if group is not None:
         group = group.replace(' ', '')
     inf['desc'] = desc
     inf['group'] = group
     return inf
Esempio n. 12
0
File: S89.py Progetto: sjava/weihu
 def _get_desc(child, group):
     name = group['name']
     rslt = do_some(child, 'show run interface {name}'.format(name=name))
     desc = re_find(r'description\s(\S+ *\S*)', rslt)
     mode = re_find(r'smartgroup mode (\S+)', rslt)
     if mode == '802.3ad':
         mode = 'yes'
     group['desc'] = desc
     group['mode'] = mode
     return group
Esempio n. 13
0
File: T64.py Progetto: sjava/weihu
 def _get_desc(child, inf):
     name = inf['name']
     rslt = do_some(child, 'show run interface {name}'.format(name=name))
     desc = re_find(r'description\s(\S+ *\S*)', rslt)
     group = re_find(r'(smartgroup\s\d+)', rslt)
     if group:
         group = group.replace(' ', '')
     inf['desc'] = desc
     inf['group'] = group
     return inf
Esempio n. 14
0
 def _get_traffic(child, inf):
     rslt = do_some(child, 'show interface {inf}'.format(inf=inf))
     state = re_find(
         r'{inf}\sis\s(\w+\s?\w+),'.format(inf=inf), rslt).lower()
     bw = int(re_find(r'BW\s(\d+)\sKbps', rslt)) / 1000
     inTraffic = int(
         re_find(r'120s input.*:\s(\d+)Bps', rslt)) * 8 / 1000000
     outTraffic = int(
         re_find(r'120s output.*:\s(\d+)Bps', rslt)) * 8 / 1000000
     infDict = dict(name=inf, state=state, bw=bw,
                    inTraffic=inTraffic, outTraffic=outTraffic)
     return infDict
Esempio n. 15
0
File: S93.py Progetto: sjava/weihu
 def _get_traffic(child, inf):
     rslt = do_some(child, 'disp int {inf}'.format(inf=inf))
     state = re_find(r'{inf}\scurrent\sstate\s:\s?(\w+\s?\w+)'
                     .format(inf=inf), rslt).lower()
     bw = int(re_find(r'Speed\s+:\s+(\d+),', rslt))
     inTraffic = int(
         re_find(r'300 seconds input rate (\d+)\sbits/sec', rslt)) / 1000000
     outTraffic = int(
         re_find(r'300 seconds output rate (\d+)\sbits/sec', rslt)) / 1000000
     infDict = dict(name=inf, state=state, bw=bw,
                    inTraffic=inTraffic, outTraffic=outTraffic)
     return infDict
Esempio n. 16
0
File: Zte.py Progetto: sjava/weihu
 def _get_info(child, inf):
     rslt = do_some(child, 'show int {inf}'.format(inf=inf))
     desc = re_find(r'Description\sis\s(\S+)', rslt)
     state = re_find(r'{inf}\sis\s(\S+\s?\S+),'.format(inf=inf), rslt)
     bw = re_find(r'BW\s(\d+)\sKbits', rslt)
     bw = int(bw or 0) / 1000
     inTraffic = re_find(r'seconds\sinput\srate\s?:\s+(\d+)\sBps', rslt)
     inTraffic = int(inTraffic or 0) * 8 / 1e6
     outTraffic = re_find(r'seconds\soutput\srate:\s+(\d+)\sBps', rslt)
     outTraffic = int(outTraffic or 0) * 8 / 1e6
     return dict(name=inf, desc=desc, state=state, bw=bw,
                 inTraffic=inTraffic, outTraffic=outTraffic)
Esempio n. 17
0
 def _get_info(record):
     name = re_find(r'((?:xg|g|f)ei\S+) is \w+ ?\w*,', record)
     state = re_find(r'(?:xg|g|f)ei\S+ is (\w+ ?\w+),', record)
     desc = re_find(r'Description is (\S+ *\S+)', record)
     inTraffic = int(re_find(r'120s input.*:\s(\d+)Bps',
                             record)) * 8 / 1000000
     outTraffic = int(re_find(r'120s output.*:\s(\d+)Bps',
                              record)) * 8 / 1000000
     return dict(name=name,
                 desc=desc,
                 state=state,
                 inTraffic=inTraffic,
                 outTraffic=outTraffic)
Esempio n. 18
0
File: S89.py Progetto: sjava/weihu
 def _get_traffic(child, inf):
     rslt = do_some(child, 'show interface {inf}'.format(inf=inf))
     state = re_find(r'{inf}\sis\s(\w+\s?\w*)'.format(inf=inf),
                     rslt).lower()
     bw = int(re_find(r'BW\s(\d+)\sKbits', rslt)) / 1000
     inTraffic = int(re_find(r'120 seconds input.*:\s+(\d+)\sBps',
                             rslt)) * 8 / 1000000
     outTraffic = int(re_find(r'120 seconds output.*:\s+(\d+)\sBps',
                              rslt)) * 8 / 1000000
     infDict = dict(name=inf,
                    state=state,
                    bw=bw,
                    inTraffic=inTraffic,
                    outTraffic=outTraffic)
     return infDict
Esempio n. 19
0
File: S85.py Progetto: sjava/weihu
 def _get_info(record):
     name = re_find(r'(\S+) current state :', record)
     state = re_find(r'current state : ?(\S+ ?\S+)', record)
     desc = re_find(r'Description: (\S+ *\S+)', record)
     inTraffic = int(
         re_find(r'\d+ seconds input:\s+\d+\spackets/sec\s(\d+)\sbits/sec',
                 record) or 0) / 1000000
     outTraffic = int(
         re_find(r'\d+ seconds output:\s+\d+\spackets/sec\s(\d+)\sbits/sec',
                 record) or 0) / 1000000
     return dict(name=name,
                 desc=desc,
                 state=state,
                 inTraffic=inTraffic,
                 outTraffic=outTraffic)
Esempio n. 20
0
def get_itv_online(ip):
    try:
        child = telnet(ip)
        rslt = do_some(child,
                       'disp access-user online-total-number domain vod')
        count = re_find(r'total users\s+:\s+(\d+)', rslt, flags=re.I)
        count = int(count) if count else 0
        rslt = do_some(child,
                       'disp access-user online-total-number domain itv')
        count1 = re_find(r'total users\s+:\s+(\d+)', rslt, flags=re.I)
        count1 = int(count1) if count1 else 0
        close(child)
    except (pexpect.EOF, pexpect.TIMEOUT):
        return ('fail', None, ip)
    return ('success', count + count1, ip)
Esempio n. 21
0
 def _get_info(child, inf):
     rslt = do_some(child, 'show int {inf}'.format(inf=inf))
     desc = re_find(r'Description\sis\s(\S+)', rslt)
     state = re_find(r'{inf}\sis\s(\S+\s?\S+),'.format(inf=inf), rslt)
     bw = re_find(r'BW\s(\d+)\sKbits', rslt)
     bw = int(bw or 0) / 1000
     inTraffic = re_find(r'seconds\sinput\srate\s?:\s+(\d+)\sBps', rslt)
     inTraffic = int(inTraffic or 0) * 8 / 1e6
     outTraffic = re_find(r'seconds\soutput\srate:\s+(\d+)\sBps', rslt)
     outTraffic = int(outTraffic or 0) * 8 / 1e6
     return dict(name=inf,
                 desc=desc,
                 state=state,
                 bw=bw,
                 inTraffic=inTraffic,
                 outTraffic=outTraffic)
Esempio n. 22
0
def _parse_time_signature_string(time_signature_str):
    """ Take in a string representation of a time signature and return an models.TimeSignature

    .. doctests ::

        >>> _parse_time_signature_string('7')  # doctest: +ELLIPSIS
        Traceback (most recent call last):
            ...
        ValueError: bad time signature...
        >>> _parse_time_signature_string('4/5')  # doctest: +ELLIPSIS
        Traceback (most recent call last):
            ...
        ValueError: bad time signature...
        >>> _parse_time_signature_string('0/4')  # doctest: +ELLIPSIS
        Traceback (most recent call last):
            ...
        ValueError: bad time signature...
        >>> _parse_time_signature_string('4/4')
        TimeSignature(count=4, unit=4)

    :param time_signature_str: string representation of a time signature
    :rtype: models.TimeSignature
    :raises: ValueError
    """
    tokens = funcy.re_find(r'^(\d+)/([48])$', time_signature_str)
    if tokens is None:
        raise ValueError('bad time signature, must be of the form int/int, with ' +
                         'only 4 and 8 supported as units')
    if int(tokens[0]) < 1:
        raise ValueError('bad time signature, cannot have a count of 0')
    return models.TimeSignature(int(tokens[0]), int(tokens[1]))
Esempio n. 23
0
def read_table(table, filename):
    print('  reading %s' % filename)
    _original_table = table
    # Strip leading comments
    if table[0] in '#^':
        table = re.sub(r'^(?:[#^].*\n)+', '', table)
    # Extract platform table (for some supplementary files)
    if 'latform_table_begin' in table:
        table = re_find(
            r'![Pp]latform_table_begin\s+(.*?)![Pp]latform_table_end', table,
            re.S)

    # Try reading table
    try:
        df = pd.read_table(io.StringIO(table),
                           index_col=0,
                           dtype=str,
                           engine='c')
    except Exception as e:
        cprint('Failed to parse %s: %s' % (filename, e), 'red')
        dump_error('read_table', {filename: _original_table})
        return None

    df.index = df.index.map(str)
    df.columns = df.columns.map(simplify_colname)
    # Drop columns with same name
    return df.ix[:, ~df.columns.duplicated()]
Esempio n. 24
0
def _extract_latest_from_search_triple(triple):
    """Try to extract latest version number from a triple of search results"""
    description, installed, latest = triple
    if re_test(r'\s*ballet \(.+\)\s*-\s*\w*', description):
        if 'INSTALLED' in installed and 'LATEST' in latest:
            return re_find(r'\s*LATEST:\s*(.+)', latest)
    return None
Esempio n. 25
0
    def calc_clicked(self):

        time.sleep(1)

        self.browser_visit('dashboard')

        #logging.warn("finding element by xpath")
        elem = self.browser.find_by_xpath(
            '/html/body/table[2]/tbody/tr/td[2]/table/tbody/tr/td[2]/table[2]/tbody/tr/td'
        )

        # The click status box says: <div align="center"><strong><font color="#FFFFFF">Surf Clicked Today: 0<br>You have clicked on 10 ads within the last 24 hours<br>
        # The click status box says: <div align="center"><strong><font color="#FFFFFF">Surf Clicked Today: 6<br>You have NOT clicked on 10 ads within the last 24 hours<br>

        html = get_element_html(self.browser.driver, elem[0]._element)
        find = html.find("You have NOT clicked on")

        print("HTML={0}. Find={1}.".format(html, find))

        if html.find("You have NOT clicked on") != -1:
            return -1
        else:
            clicked = funcy.silent(int)(
                funcy.re_find(r'You have clicked on (\d+)', html))
            return clicked

        raise("Could not calculate clicked.")
Esempio n. 26
0
def parse_tickets(text):
    result = {'tickets': {}, 'warnings': []}

    # Parse total number of tickets
    total_s, ticket_s = re.split(r'30\s*000', text, 2)
    result['total'] = silent(int)(re.sub(r'\D', '',
                                         re_find(r'[\d\s]+\D*$', total_s)))

    # Parse (nick, ticket count) pairs
    known_names = read_names()
    ticket_pairs = re.findall(r'(\w[\w\d \|]*)\W+((?:\w )?[\doOоО]+\b)?',
                              ticket_s)
    tickets = {}
    for name, count in ticket_pairs:
        # Check if name is known or similar enough to known one
        name, warning = parse_name(name)
        if warning:
            result['warnings'].append(warning)
        if name is None:
            continue

        # Parse number part
        count = parse_number(count)
        if count is None:
            result['warnings'].append('No count for %s' % name)

        if count is not None:
            result['tickets'][name] = count

    return result
Esempio n. 27
0
 def _get_active_port(child, slot):
     info = do_some(child, 'display board 0/{0}'.format(slot))
     ports = [
         re_find(r'\d+', x) for x in info.split('\r\n')
         if re_test(r'ge\s+normal.*online(?i)', x)
     ]
     return ['{0}/{1}'.format(slot, port) for port in ports]
Esempio n. 28
0
def get_inf(ip, inf):
    try:
        child = telnet(ip)
        slot, port = inf.rsplit('/', 1)
        rslt = do_some(child, 'display board {slot}'.format(slot=slot))
        name = re_find(r'Board Name\s+:\s\w+(ETH)\w+', rslt) or 'giu'
        do_some(child, 'conf')
        do_some(child, 'interface {name} {slot}'.format(name=name, slot=slot))
        info = do_some(child, 'disp port state {port}'.format(port=port))
        do_some(child, 'quit')
        do_some(child, 'quit')
        close(child)
    except (pexpect.EOF, pexpect.TIMEOUT):
        return ('fail', None, ip)
    state = 'up' if re_find(r'port is online', info) else 'down'
    return ('success', state, ip)
Esempio n. 29
0
 def _get_inf(child, board):
     slot, boardName = board
     rslt = do_some(child, 'disp board 0/{slot}'.format(slot=slot))
     rslt = [
         re_find(r'(\d+).*-\s+(?:auto_)?(\d+)', x)
         for x in rslt.split('\r\n') if 'online' in x
     ]
     if boardName.lower() == 'gic':
         boardName = 'giu'
     child.sendline('conf')
     child.expect(prompter)
     child.sendline('interface {boardName} 0/{slot}'.format(
         boardName=boardName, slot=slot))
     child.expect(prompter)
     temp = []
     for x, y in rslt:
         traffic = do_some(child, 'disp port traffic {port}'.format(port=x))
         inTraffic, outTraffic = re_all(r'\(octets/s\)\s+=(\d+)', traffic)
         inTraffic = int(inTraffic) * 8 / 1e6
         outTraffic = int(outTraffic) * 8 / 1e6
         bw = int(y or 0)
         temp.append(
             dict(
                 name='0/{slot}/{port}'.format(slot=slot, port=x),
                 desc='cannot set',
                 bw=bw,
                 state='up',
                 inTraffic=inTraffic,
                 outTraffic=outTraffic))
     child.sendline('quit')
     child.expect(prompter)
     child.sendline('quit')
     child.expect(prompter)
     return temp
Esempio n. 30
0
def update_model():
    #  clear_log()
    nodes = graph.cypher.execute("match (s:Switch) return s.ip as ip")
    switchs = [x['ip'] for x in nodes]
    for x in switchs:
        mark = 'success'
        try:
            session = easysnmp.Session(hostname=x,
                                       community=community,
                                       version=1)
            rslt = session.get('1.3.6.1.2.1.1.1.0').value
            model = re_find(r'((?<=Quidway )S\d+|(?<=ZXR10 )\w+(?= Software))',
                            rslt)
            #  model = re_find(r'(?:Quidway (S\d+)|ZXR10 (\w+) Software)', rslt)
            #  model = select(bool, model)[0]
            if model.startswith('8905'):
                model = 'S' + model
            hostname = session.get('1.3.6.1.2.1.1.5.0').value
        except (easysnmp.EasySNMPTimeoutError) as e:
            mark = 'fail'
            graph.cypher.execute(
                "match (s:Switch) where s.ip={ip} set s.snmpState='abnormal'",
                ip=x)
        if mark == 'success':
            graph.cypher.execute(
                "match (s:Switch) where s.ip={ip} set s.model={model},s.hostname={hostname},s.snmpState='normal'",
                ip=x,
                model=model,
                hostname=hostname)
Esempio n. 31
0
def update_model():
    #  clear_log()
    nodes = graph.cypher.execute("match (s:Switch) return s.ip as ip")
    switchs = [x['ip'] for x in nodes]
    for x in switchs:
        mark = 'success'
        try:
            session = easysnmp.Session(
                hostname=x, community=community, version=1)
            rslt = session.get('1.3.6.1.2.1.1.1.0').value
            model = re_find(
                r'((?<=Quidway )S\d+|(?<=ZXR10 )\w+(?= Software))', rslt)
            #  model = re_find(r'(?:Quidway (S\d+)|ZXR10 (\w+) Software)', rslt)
            #  model = select(bool, model)[0]
            if model.startswith('8905'):
                model = 'S' + model
            hostname = session.get('1.3.6.1.2.1.1.5.0').value
        except (easysnmp.EasySNMPTimeoutError) as e:
            mark = 'fail'
            graph.cypher.execute(
                "match (s:Switch) where s.ip={ip} set s.snmpState='abnormal'",
                ip=x)
        if mark == 'success':
            graph.cypher.execute(
                "match (s:Switch) where s.ip={ip} set s.model={model},s.hostname={hostname},s.snmpState='normal'",
                ip=x, model=model, hostname=hostname)
Esempio n. 32
0
def get_inf(ip, inf):
    try:
        child = telnet(ip)
        slot, port = inf.rsplit('/', 1)
        rslt = do_some(child, 'display board {slot}'.format(slot=slot))
        name = re_find(r'Board Name\s+:\s\w+(ETH)\w+', rslt) or 'giu'
        do_some(child, 'conf')
        do_some(child, 'interface {name} {slot}'.format(name=name, slot=slot))
        info = do_some(child, 'disp port state {port}'.format(port=port))
        do_some(child, 'quit')
        do_some(child, 'quit')
        close(child)
    except (pexpect.EOF, pexpect.TIMEOUT):
        return ('fail', None, ip)
    state = 'up' if re_find(r'port is online', info) else 'down'
    return ('success', state, ip)
Esempio n. 33
0
 def _get_inf(child, board):
     slot, boardName = board
     rslt = do_some(child, 'disp board 0/{slot}'.format(slot=slot))
     rslt = [re_find(r'(\d+).*-\s+(?:auto_)?(\d+)', x)
             for x in rslt.split('\r\n')
             if 'online' in x]
     if boardName.lower() == 'gic':
         boardName = 'giu'
     child.sendline('conf')
     child.expect(prompter)
     child.sendline(
         'interface {boardName} 0/{slot}'.format(boardName=boardName, slot=slot))
     child.expect(prompter)
     temp = []
     for x, y in rslt:
         traffic = do_some(child, 'disp port traffic {port}'.format(port=x))
         inTraffic, outTraffic = re_all(r'\(octets/s\)\s+=(\d+)', traffic)
         inTraffic = int(inTraffic) * 8 / 1e6
         outTraffic = int(outTraffic) * 8 / 1e6
         bw = int(y or 0)
         temp.append(dict(name='0/{slot}/{port}'.format(slot=slot, port=x),
                          desc='cannot set', bw=bw, state='up',
                          inTraffic=inTraffic, outTraffic=outTraffic))
     child.sendline('quit')
     child.expect(prompter)
     child.sendline('quit')
     child.expect(prompter)
     return temp
Esempio n. 34
0
File: T64.py Progetto: sjava/weihu
 def _get_desc(child, group):
     name = group['name']
     rslt = do_some(child, 'show run interface {name}'.format(name=name))
     desc = re_find(r'description\s(\S+ *\S*)', rslt)
     group['desc'] = desc
     if group['mode'] == 'active':
         group['mode'] = 'yes'
     return group
Esempio n. 35
0
File: S85.py Progetto: sjava/weihu
 def _get_traffic(child, inf):
     rslt = do_some(child, 'disp int {inf}'.format(inf=inf))
     state = re_find(r'{inf}\scurrent\sstate\s:\s?(\w+\s?\w+)'
                     .format(inf=inf), rslt).lower()
     bw = re_find(r'(\d+[MG])bps-speed mode', rslt)
     if bw is None:
         bw = 0
     elif 'M' in bw:
         bw = int(bw.replace('M', ''))
     else:
         bw = int(bw.replace('G', '')) * 1000
     inTraffic = int(re_find(
         r'\d+ seconds input:\s+\d+\spackets/sec\s(\d+)\sbits/sec', rslt)) / 1000000
     outTraffic = int(re_find(
         r'\d+ seconds output:\s+\d+\spackets/sec\s(\d+)\sbits/sec', rslt)) / 1000000
     infDict = dict(name=inf, state=state, bw=bw,
                    inTraffic=inTraffic, outTraffic=outTraffic)
     return infDict
Esempio n. 36
0
File: S85.py Progetto: sjava/weihu
def get_inf(ip, inf):
    try:
        child = telnet(ip)
        rslt = do_some(child, 'display interface {inf}'.format(inf=inf))
        close(child)
    except (pexpect.EOF, pexpect.TIMEOUT) as e:
        return ('fail', None, ip)
    state = re_find(r'current state :(\w+\s?\w+)', rslt)
    return ('success', state, ip)
Esempio n. 37
0
def multiple_packaged_versions(package_name):
    """ Look through built package directory and see if there are multiple versions there """
    dist_files = os.listdir('dist')
    versions = set()
    for filename in dist_files:
        version = funcy.re_find(r'{}-(.+).tar.gz'.format(package_name), filename)
        if version:
            versions.add(version)
    return len(versions) > 1
Esempio n. 38
0
File: S89.py Progetto: sjava/weihu
def get_inf(ip, inf):
    try:
        child = telnet(ip)
        rslt = do_some(child, 'show interface {inf}'.format(inf=inf))
        close(child)
    except (pexpect.EOF, pexpect.TIMEOUT):
        return ('fail', None, ip)
    state = re_find(r'is (\w+\s?\w+)', rslt)
    return ('success', state, ip)
Esempio n. 39
0
def get_ast(func):
    # Get function source
    source = inspect.getsource(func)

    # Fix extra indent if present
    spaces = re_find(r"^\s+", source)
    if spaces:
        source = re.sub(r"(^|\n)" + spaces, "\n", source)

    return ast.parse(source, func_file(func), "single")
Esempio n. 40
0
def multiple_packaged_versions(package_name):
    """ Look through built package directory and see if there are multiple versions there """
    dist_files = os.listdir('dist')
    versions = set()
    for filename in dist_files:
        version = funcy.re_find(r'{}-(.+).tar.gz'.format(package_name),
                                filename)
        if version:
            versions.add(version)
    return len(versions) > 1
Esempio n. 41
0
def count_contributions_scrape(g, repo: Repository) -> int:
    """Count contributors as they approximately appear on repo page

    On the repo page, the number of contributors is displayed in a badge. If the number is greater than some threshold (which appears to be 5000), then "5,000+" is displayed. You can get the count in this case by counting the elements of the unordered list of profiles that is shown plus the number of contributors linked to in the supplemental link. We don't implement all of that functionality here, in this case we don't count the list of profiles so it is just an approximate count.
    """
    url = f'https://github.com/{repo.id}'
    response = requests.get(url)
    response.raise_for_status()
    body = response.text
    soup = BeautifulSoup(body, 'html.parser')

    tags = soup.find_all('a', href=re.compile('graphs/contributors'))
    for tag in tags:
        if child := tag.find('span', class_='Counter'):
            # not accurate count if shows "5,000+"
            if '+' not in child.text:
                return child.text

        if text := fy.re_find(r'.* (\d[,\d]+) contributors.*', tag.text):
            return text
Esempio n. 42
0
def test_set_version(tmpdir):
    with tmpdir.as_cwd():
        version_file = helpers.package_file_path('_version.py', PACKAGE_NAME)
        _make_package(PACKAGE_NAME, empty_module_files=[os.path.basename(version_file)])
        snippet_content = snippets.get_snippet_content('_version.py')
        with open(version_file, 'w') as _version_py:
            _version_py.write(snippet_content)
        project.set_version(PACKAGE_NAME, '1.2.3')
        version_file_content = helpers.get_file_content(version_file)
        found = funcy.re_find(project.VERSION_SET_REGEX, version_file_content)
        assert found['version'] == '1.2.3'
Esempio n. 43
0
def _parse_remotes(conf):
    result = {"remote": {}}

    for section, val in conf.items():
        name = re_find(r'^\s*remote\s*"(.*)"\s*$', section)
        if name:
            result["remote"][name] = val
        else:
            result[section] = val

    return result
Esempio n. 44
0
def _parse_named(conf):
    result = {"remote": {}, "machine": {}}

    for section, val in conf.items():
        match = re_find(r'^\s*(remote|machine)\s*"(.*)"\s*$', section)
        if match:
            key, name = match
            result[key][name] = val
        else:
            result[section] = val

    return result
Esempio n. 45
0
def get_power_info(ip):
    try:
        child = telnet(ip)
        temp = do_some(child, 'show alarm pool')
        close(child)
    except (pexpect.EOF, pexpect.TIMEOUT) as e:
        return ('fail', None, ip)
    powerInfo = re_find(r'Alarm Code\s+:\s+(33054|53504)', temp)
    if powerInfo:
        rslt = 'alarm'
    else:
        rslt = 'normal'
    return ('success', rslt, ip)
Esempio n. 46
0
File: M6k.py Progetto: sjava/weihu
def get_bingfa(ip):
    try:
        child = telnet(ip)
        rslt = do_some(child, 'show subscriber peak')
        close(child)
    except (pexpect.EOF, pexpect.TIMEOUT) as e:
        return ('fail', None, ip)
    rslt1 = [x for x in re.split(r'\r\n-+\r\n', rslt) if 'Slot:' in x]
    rslt2 = [re_find(
        r'Slot:(\d+).*Total\s+(\d+)\s+(\d{4}/\d{2}/\d{2})', x, flags=re.S) for x in rslt1]
    rslt3 = select(bool, rslt2)
    rslt3 = [(x[0], int(x[1]), x[2]) for x in rslt3]
    return ('success', rslt3, ip)
Esempio n. 47
0
File: Zte.py Progetto: sjava/weihu
def get_power_info(ip):
    try:
        child = telnet(ip)
        temp = do_some(child, 'show alarm pool')
        close(child)
    except (pexpect.EOF, pexpect.TIMEOUT) as e:
        return ('fail', None, ip)
    powerInfo = re_find(r'Alarm Code\s+:\s+(33054|53504)', temp)
    if powerInfo:
        rslt = 'alarm'
    else:
        rslt = 'normal'
    return ('success', rslt, ip)
Esempio n. 48
0
def no_shut(ip, inf):
    try:
        child = telnet(ip)
        slot, port = inf.rsplit('/', 1)
        rslt = do_some(child, 'display board {slot}'.format(slot=slot))
        name = re_find(r'Board Name\s+:\s\w+(ETH)\w+', rslt) or 'giu'
        do_some(child, 'conf')
        do_some(child, 'interface {name} {slot}'.format(name=name, slot=slot))
        do_some(child, 'undo shutdown {port}'.format(port=port))
        do_some(child, 'quit')
        do_some(child, 'quit')
        close(child)
    except (pexpect.EOF, pexpect.TIMEOUT):
        return ('fail', ip)
    return ('success', ip)
Esempio n. 49
0
def no_shut(ip, inf):
    try:
        child = telnet(ip)
        slot, port = inf.rsplit('/', 1)
        rslt = do_some(child, 'display board {slot}'.format(slot=slot))
        name = re_find(r'Board Name\s+:\s\w+(ETH)\w+', rslt) or 'giu'
        do_some(child, 'conf')
        do_some(child, 'interface {name} {slot}'.format(name=name, slot=slot))
        do_some(child, 'undo shutdown {port}'.format(port=port))
        do_some(child, 'quit')
        do_some(child, 'quit')
        close(child)
    except (pexpect.EOF, pexpect.TIMEOUT):
        return ('fail', ip)
    return ('success', ip)
Esempio n. 50
0
File: S85.py Progetto: sjava/weihu
 def _get_traffic(child, inf):
     rslt = do_some(child, 'disp int {inf}'.format(inf=inf))
     state = re_find(
         r'{inf}\scurrent\sstate\s:\s?(\w+\s?\w+)'.format(inf=inf),
         rslt).lower()
     bw = re_find(r'(\d+[MG])bps-speed mode', rslt)
     if bw is None:
         bw = 0
     elif 'M' in bw:
         bw = int(bw.replace('M', ''))
     else:
         bw = int(bw.replace('G', '')) * 1000
     inTraffic = int(
         re_find(r'\d+ seconds input:\s+\d+\spackets/sec\s(\d+)\sbits/sec',
                 rslt)) / 1000000
     outTraffic = int(
         re_find(r'\d+ seconds output:\s+\d+\spackets/sec\s(\d+)\sbits/sec',
                 rslt)) / 1000000
     infDict = dict(name=inf,
                    state=state,
                    bw=bw,
                    inTraffic=inTraffic,
                    outTraffic=outTraffic)
     return infDict
Esempio n. 51
0
File: main.py Progetto: metaperl/mpa
    def solve_captcha(self):
        time.sleep(3)

        t = page_source(self.browser).encode("utf-8").strip()
        # print("Page source {0}".format(t))

        captcha = funcy.re_find("""ctx.strokeText\('(\d+)'""", t)

        # print("CAPTCHA = {0}".format(captcha))

        self.browser.find_by_name("codeSb").fill(captcha)

        time.sleep(6)
        button = self.browser.find_by_name("Submit")
        button.click()
Esempio n. 52
0
def use_token(request):
    """
    Implement token based authentication.
    """
    header = request.META.get('HTTP_AUTHORIZATION', '')
    key = re_find(r'^\s*token\s+([a-z0-9]+)\s*$', header, re.I)
    if not key:
        raise PermissionDenied('Invalid token header')

    model = apps.get_model(
        getattr(settings, 'DJAPI_TOKEN_MODEL', 'authtoken.token'))
    try:
        return model.objects.select_related('user').get(key=key).user
    except model.DoesNotExist:
        raise PermissionDenied('Invalid token')
Esempio n. 53
0
def get_vlans_of_port(ip, port):
    try:
        child = telnet(ip)
        rslt = do_some(child, f'disp cu interface {port}')
        eth_trunk = re_find(r'eth-trunk \d+', rslt).replace(' ', '')
        rslt = do_some(child, 'disp cu interface filter user-vlan')
        close(child)
    except Exception as e:
        raise e
    rslt = rcompose(methodcaller('split', '#'),
                    autocurry(filter)(lambda x: re_test(eth_trunk, x, re.I)),
                    autocurry(mapcat)(lambda x: x.split('\r\n')),
                    autocurry(filter)('user-vlan'),
                    autocurry(map)(lambda x: x.strip()),
                    autocurry(map)(lambda x: _item_to_vlans(x)))(rslt)
    return merge(set(), *rslt)
Esempio n. 54
0
 def duration(text):
     regexes = [
         r'()(?:(\d\d):)?(\d\d):(\d\d)(?:\s|$)',
         re.compile(
             r'''\s* (?:(\d+)\s*д[еньяй.]*)?
                        \s* (?:(\d+)\s*ч[ас.]*)?
                        \s* (?:(\d+)\s*м[инуты.]*)?
                        ()''', re.I | re.X)
     ]
     for regex in regexes:
         m = re_find(regex, text)
         if m:
             days, hours, minutes, seconds = [
                 silent(int)(p) or 0 for p in m
             ]
             if days == hours == minutes == 0:
                 return None
             return (days * 24 + hours * 60 + minutes) * 60 + seconds
Esempio n. 55
0
def get_diff_endpoints_from_commit_range(
        repo: git.Repo,
        commit_range: str) -> Tuple[git.Diffable, git.Diffable]:
    """Get endpoints of a diff given a commit range

    The resulting endpoints can be diffed directly::

        a, b = get_diff_endpoints_from_commit_range(repo, commit_range)
        a.diff(b)

    For details on specifying git diffs, see ``git diff --help``.
    For details on specifying revisions, see ``git help revisions``.

    Args:
        repo: Repo object initialized with project root
        commit_range: commit range as would be interpreted by ``git
            diff`` command. Unfortunately only patterns of the form ``a..b``
            and ``a...b`` are accepted. Note that the latter pattern finds the
            merge-base of a and b and uses it as the starting point for the
            diff.

    Returns:
        starting commit, ending commit (inclusive)

    Raises:
        ValueError: commit_range is empty or ill-formed

    See also:

        <https://stackoverflow.com/q/7251477>
    """
    if not commit_range:
        raise ValueError('commit_range cannot be empty')

    result = re_find(COMMIT_RANGE_REGEX, commit_range)
    if not result:
        raise ValueError(
            f'Expected diff str of the form \'a..b\' or \'a...b\' '
            f'(got {commit_range})')
    a, b = result['a'], result['b']
    a, b = repo.rev_parse(a), repo.rev_parse(b)
    if result['thirddot']:
        a = one_or_raise(repo.merge_base(a, b))
    return a, b
Esempio n. 56
0
def get_power_info(ip):
    try:
        child = telnet(ip)
        child.sendline('conf')
        child.expect(prompter)
        child.sendline('interface emu 0')
        child.expect(prompter)
        temp = do_some(child, 'display fan alarm')
        child.sendline('quit')
        child.expect(prompter)
        child.sendline('quit')
        child.expect(prompter)
        close(child)
    except (pexpect.EOF, pexpect.TIMEOUT) as e:
        return ('fail', None, ip)
    rslt = re_find(r'Power fault\s+(\w+)', temp)
    if rslt is None:
        rslt = "alarm"
    return ('success', rslt.lower(), ip)
Esempio n. 57
0
def findpybin(name, start):
    """For windows compatibility"""

    # normalize to the root of the environment
    rootpath = os.path.dirname(start) if os.path.isfile(start) else start
    if os.path.basename(rootpath) in ('bin', 'Scripts'):
        rootpath = os.path.dirname(rootpath)

    # special case for Ubuntu (and other?) packaged python instances
    if rootpath == '/usr':
        binpath = os.path.join('/usr/local/bin', name)
        if os.path.exists(binpath):
            return binpath

    # we're in a linux-based virtual environment
    if 'bin' in os.listdir(rootpath):
        binpath = os.path.join(rootpath, 'bin', name)
        if os.path.exists(binpath):
            return binpath

    # we're in a windows virtual environment
    elif 'Scripts' in os.listdir(rootpath):
        binpath = os.path.join(rootpath, 'Scripts', '{0}.exe'.format(name))
        if os.path.exists(binpath):
            return binpath

    # we could be in a brew environment on osx
    try:
        output = getoutputoserror('brew config')
        new_start = funcy.re_find(r'HOMEBREW_PREFIX:\s+([/\w]+)', output)
        if new_start != start:
            return findpybin(name, new_start)
    except OSError:
        pass

    raise IOError('could not find {0} relative to {1}'.format(name, start))
Esempio n. 58
0
File: S85.py Progetto: sjava/weihu
 def _inf(record):
     name = re_find(r'interface\s+(X?Gigabit\S+)', record)
     desc = re_find(r'description\s+(\S+ *\S*)', record)
     group = re_find(r'link-aggregation\s+(group\s+\d+)', record)
     return dict(name=name, desc=desc, group=group)
Esempio n. 59
0
File: S85.py Progetto: sjava/weihu
 def _vlan(record):
     if re_test(r'(Ports:\snone.*Ports:\snone)', record, re.S):
         return 0
     vlan = re_find(r'VLAN\sID:\s(\d+)', record)
     vlan = int(vlan or 0)
     return vlan