Пример #1
0
 def __str__(self):
     print_success('Viewing applications in memory...')
     for node, ram_usage in self.memory_blocks.iteritems():
         print('--- {} | {} bytes @ {}'.format(
             node, sum([f[0] for f in ram_usage]),
             [f[1] for f in ram_usage]))
     return ''
Пример #2
0
 def __str__(self):
     print_success('Viewing applications in memory...')
     for node, ram_usage in self.memory_blocks.iteritems():
         print('--- {} | {} bytes @ {}'.format(
             node, sum([f[0] for f in ram_usage]),
             [f[1] for f in ram_usage]))
     return ''
Пример #3
0
 def process(self, key):
     if len(self.table1) < key:
         raise IndexError('Invalid key for first table!')
     try:
         _key = self.table2[key]
         print_success('Here is the control statement '
                       'you requested: `{}` => `{}`'.format(key, _key))
         return _key
     except IndexError:
         print_error('Could not process key: {}'.format(key))
         return None
Пример #4
0
 def process(self, key):
     if len(self.table1) < key:
         raise IndexError('Invalid key for first table!')
     try:
         _key = self.table2[key]
         print_success('Here is the control statement '
                       'you requested: `{}` => `{}`'.format(key, _key))
         return _key
     except IndexError:
         print_error('Could not process key: {}'.format(key))
         return None
Пример #5
0
def get_records(cur):
    cached = mclient.get(CACHE_KEY)
    if cached:
        print_success('Found the cached version instead')
        return cached
    else:
        print_warning('Looking up SQL Records')
        cur.execute('SELECT * FROM cache_table;')
        records = cur.fetchall()
        conn.commit()
        # Setup caching once loaded
        mclient.set(CACHE_KEY, records)
        return records
Пример #6
0
 def test(self, string):
     try:
         print_info('{}'.format(string), prefix='[TESTING]')
         chars = list(str(string))
         for char in chars:
             self.step += 1
             self.transition(char)
         self.reset()
         print_success(''.join(chars), prefix='[FOUND]')
         return True
     except InvalidTransition:
         print_error(''.join(chars), prefix='[NOT-FOUND]')
         return False
Пример #7
0
def get_records(cur):
    cached = mclient.get(CACHE_KEY)
    if cached:
        print_success('Found the cached version instead')
        return cached
    else:
        print_warning('Looking up SQL Records')
        cur.execute('SELECT * FROM cache_table;')
        records = cur.fetchall()
        conn.commit()
        # Setup caching once loaded
        mclient.set(CACHE_KEY, records)
        return records
Пример #8
0
def on_open(ch, method, properties, body):
    key = method.routing_key
    message = '* Received! {}'.format(body)
    if key == 'info':
        print_info(message)
    if key == 'warning':
        print_warning(message)
    if key == 'error':
        print_error(message)
    if key == 'success':
        print_success(message)

    if not start.USE_EXCHANGE:
        # Specify ACK to prevent failures from disappearing.
        ch.basic_ack(delivery_tag=method.delivery_tag)
Пример #9
0
def on_open(ch, method, properties, body):
    key = method.routing_key
    message = '* Received! {}'.format(body)
    if key == 'info':
        print_info(message)
    if key == 'warning':
        print_warning(message)
    if key == 'error':
        print_error(message)
    if key == 'success':
        print_success(message)

    if not start.USE_EXCHANGE:
        # Specify ACK to prevent failures from disappearing.
        ch.basic_ack(delivery_tag=method.delivery_tag)
Пример #10
0
 def test(self, scenario):
     if scenario not in self.actions:
         raise ValueError('"{}" is an invalid scenario'.format(scenario))
     else:
         success, message = self.actions[scenario]
         message = '"{}" is {}: {} was "{}"'.format(
             scenario, 'not invalid' if not success else 'valid',
             'error' if not success else 'message', message)
         print_error(message) if not success else print_success(message)
Пример #11
0
 def test(self, scenario):
     if scenario not in self.actions:
         raise ValueError('"{}" is an invalid scenario'.format(scenario))
     else:
         success, message = self.actions[scenario]
         message = '"{}" is {}: {} was "{}"'.format(
             scenario, 'not invalid' if not success else 'valid',
             'error' if not success else 'message', message)
         print_error(message) if not success else print_success(message)
Пример #12
0
@test_speed
def insert_all(max_records):
    peeps = [make_person() for n in range(max_records)]
    prnt('Records to create', peeps)
    cur.executemany("""INSERT INTO people(name, email, address)
            VALUES (%(name)s, %(email)s, %(address)s)""", peeps)


if DEBUG:
    with Section('PostgreSQL (via psycopg2)'):
        # Starting postgresql on mac:
        # `postgres -D /usr/local/var/postgres/data`
        try:
            conn = psycopg2.connect(
                dbname='ctabor', user='******', host='localhost', password='')
            print_success('Successfully connected!')
        except:
            print_error('Could not connect to PostgreSql :(')
            raise Exception

        cur = conn.cursor()
        # Always clean up DB for this demo.
        cur.execute("""DROP TABLE people""")
        cur.execute("""CREATE TABLE people(id serial PRIMARY KEY,
            name varchar, email varchar, address varchar)""")

        print_h2('Adding a bunch of records...')
        run_trials(insert_all, trials=10)
        conn.commit()

        print_h2('Reading all records...')
Пример #13
0
def reject_claim():
    print_success('Reject claim task running!', prefix='+ PVM:')
Пример #14
0
def accept_claim():
    print_success('Accept claim task running!', prefix='+ PVM:')
Пример #15
0
def evaluate_claim():
    print_success('Evaluate claim task running!', prefix='+ PVM:')
Пример #16
0
DEBUG = True if __name__ == '__main__' else False

faker = Factory.create()
redis_conn = Redis(host='localhost', port=6379, db=0)
pipe = redis_conn.pipeline()

testing = {}


def insert_name(*args, **kwargs):
    key = faker.name()
    val = faker.email()
    testing[key] = val
    pipe.set(key, val)
    pipe.get(key)


@test_speed
def insert_all(max_records):
    for n in range(max_records):
        insert_name()

if DEBUG:
    with Section('Redis (via Redis-py)'):
        run_trials(insert_all, trials=10)
        print_success('This is **too** easy!')
        # Use single pipeline for speed.
        res = pipe.execute()
        prnt('Result from Redis store pipeline execution: ', res)
Пример #17
0
DEBUG = True if __name__ == '__main__' else False

faker = Factory.create()
redis_conn = Redis(host='localhost', port=6379, db=0)
pipe = redis_conn.pipeline()

testing = {}


def insert_name(*args, **kwargs):
    key = faker.name()
    val = faker.email()
    testing[key] = val
    pipe.set(key, val)
    pipe.get(key)


@test_speed
def insert_all(max_records):
    for n in range(max_records):
        insert_name()


if DEBUG:
    with Section('Redis (via Redis-py)'):
        run_trials(insert_all, trials=10)
        print_success('This is **too** easy!')
        # Use single pipeline for speed.
        res = pipe.execute()
        prnt('Result from Redis store pipeline execution: ', res)
Пример #18
0
from MOAL.helpers.display import Section
from MOAL.helpers.display import print_success
from MOAL.helpers.display import print_error
from MOAL.helpers.display import print_simple
from itertools import permutations

DEBUG = True if __name__ == '__main__' else False


def bigrams(conditions):
    _bigrams = []
    for k, condition in enumerate(conditions):
        if k < len(conditions) - 1:
            _bigrams.append([conditions[k + 1], condition, True, False])
            _bigrams.append([conditions[k + 1], condition, True, True])
            _bigrams.append([conditions[k + 1], condition, False, True])
            _bigrams.append([conditions[k + 1], condition, False, False])
    return _bigrams


if DEBUG:
    with Section('All-pairs testing'):
        conditions = ['user', 'email', 'pass', 'pass2']
        perms = [p for p in permutations(conditions)]
        print_simple('Long way', perms, newline=False)
        print_error('Length: {}'.format(len(perms)), prefix='[LONG]')

        bgrams = bigrams(conditions)
        print_simple('Short (all-pairs) way', bgrams, newline=False)
        print_success('Length: {}'.format(len(bgrams)), prefix='[SHORT]')
Пример #19
0
def accept_claim():
    print_success('Accept claim task running!', prefix='+ PVM:')
Пример #20
0
 def call(self):
     prnt('Calling opcode: "{}"'.format(self.code), '')
     for line in self.assembly:
         print_success(line, prefix='[ASSEMBLY]')
     divider()
Пример #21
0
def pay_claim():
    print_success('Pay claim task running!', prefix='+ PVM:')
Пример #22
0
def submit_claim():
    print_success('Submit claim task running!', prefix='+ PVM:')
Пример #23
0
def close_claim():
    print_success('Close claim task running!', prefix='+ PVM:')
Пример #24
0
def need_more_input():
    print_success('Need more input task running!', prefix='+ PVM:')
Пример #25
0
def pay_claim():
    print_success('Pay claim task running!', prefix='+ PVM:')
Пример #26
0
def submit_claim():
    print_success('Submit claim task running!', prefix='+ PVM:')
Пример #27
0
def close_claim():
    print_success('Close claim task running!', prefix='+ PVM:')
Пример #28
0
    prnt('Records to create', peeps)
    cur.executemany(
        """INSERT INTO people(name, email, address)
            VALUES (%(name)s, %(email)s, %(address)s)""", peeps)


if DEBUG:
    with Section('PostgreSQL (via psycopg2)'):
        # Starting postgresql on mac:
        # `postgres -D /usr/local/var/postgres/data`
        try:
            conn = psycopg2.connect(dbname='ctabor',
                                    user='******',
                                    host='localhost',
                                    password='')
            print_success('Successfully connected!')
        except:
            print_error('Could not connect to PostgreSql :(')
            raise Exception

        cur = conn.cursor()
        # Always clean up DB for this demo.
        cur.execute("""DROP TABLE people""")
        cur.execute("""CREATE TABLE people(id serial PRIMARY KEY,
            name varchar, email varchar, address varchar)""")

        print_h2('Adding a bunch of records...')
        run_trials(insert_all, trials=10)
        conn.commit()

        print_h2('Reading all records...')
Пример #29
0
def need_more_input():
    print_success('Need more input task running!', prefix='+ PVM:')
Пример #30
0
def archive_claim():
    print_success('Archive claim task running!', prefix='+ PVM:')
Пример #31
0
def evaluate_claim():
    print_success('Evaluate claim task running!', prefix='+ PVM:')
Пример #32
0
def reject_claim():
    print_success('Reject claim task running!', prefix='+ PVM:')
Пример #33
0
def archive_claim():
    print_success('Archive claim task running!', prefix='+ PVM:')