Example #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 ''
Example #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 ''
Example #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
Example #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
Example #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
Example #6
0
File: fsm.py Project: terry07/MoAL
 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
Example #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
Example #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)
Example #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)
Example #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)
Example #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)
Example #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...')
Example #13
0
def reject_claim():
    print_success('Reject claim task running!', prefix='+ PVM:')
Example #14
0
def accept_claim():
    print_success('Accept claim task running!', prefix='+ PVM:')
Example #15
0
def evaluate_claim():
    print_success('Evaluate claim task running!', prefix='+ PVM:')
Example #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)
Example #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)
Example #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]')
Example #19
0
def accept_claim():
    print_success('Accept claim task running!', prefix='+ PVM:')
Example #20
0
 def call(self):
     prnt('Calling opcode: "{}"'.format(self.code), '')
     for line in self.assembly:
         print_success(line, prefix='[ASSEMBLY]')
     divider()
Example #21
0
def pay_claim():
    print_success('Pay claim task running!', prefix='+ PVM:')
Example #22
0
def submit_claim():
    print_success('Submit claim task running!', prefix='+ PVM:')
Example #23
0
def close_claim():
    print_success('Close claim task running!', prefix='+ PVM:')
Example #24
0
def need_more_input():
    print_success('Need more input task running!', prefix='+ PVM:')
Example #25
0
def pay_claim():
    print_success('Pay claim task running!', prefix='+ PVM:')
Example #26
0
def submit_claim():
    print_success('Submit claim task running!', prefix='+ PVM:')
Example #27
0
def close_claim():
    print_success('Close claim task running!', prefix='+ PVM:')
Example #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...')
Example #29
0
def need_more_input():
    print_success('Need more input task running!', prefix='+ PVM:')
Example #30
0
def archive_claim():
    print_success('Archive claim task running!', prefix='+ PVM:')
Example #31
0
def evaluate_claim():
    print_success('Evaluate claim task running!', prefix='+ PVM:')
Example #32
0
def reject_claim():
    print_success('Reject claim task running!', prefix='+ PVM:')
Example #33
0
def archive_claim():
    print_success('Archive claim task running!', prefix='+ PVM:')