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