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 ''
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
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
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
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)
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)
@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...')
def reject_claim(): print_success('Reject claim task running!', prefix='+ PVM:')
def accept_claim(): print_success('Accept claim task running!', prefix='+ PVM:')
def evaluate_claim(): print_success('Evaluate claim task running!', prefix='+ PVM:')
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)
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]')
def call(self): prnt('Calling opcode: "{}"'.format(self.code), '') for line in self.assembly: print_success(line, prefix='[ASSEMBLY]') divider()
def pay_claim(): print_success('Pay claim task running!', prefix='+ PVM:')
def submit_claim(): print_success('Submit claim task running!', prefix='+ PVM:')
def close_claim(): print_success('Close claim task running!', prefix='+ PVM:')
def need_more_input(): print_success('Need more input task running!', prefix='+ PVM:')
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...')
def archive_claim(): print_success('Archive claim task running!', prefix='+ PVM:')