How to use macro_parser method in dbt-osmosis

Best Python code snippet using dbt-osmosis_python

parser.py

Source:parser.py Github

copy

Full Screen

1#!/usr/bin/env python32"""remappy3Usage:4 parser.py [<config_file>]5"""6# parser.py ship <name> move <x> <y> [--speed=<kn>]7# parser.py ship shoot <x> <y>8# parser.py mine (set|remove) <x> <y> [--moored | --drifting]9# parser.py (-h | --help)10# parser.py --version11# Options:12# -h --help Show this screen.13# --version Show version.14# --speed=<kn> Speed in knots [default: 10].15# --moored Moored (anchored) mine.16# --drifting Drifting mine.17# """18import re19import sys20import json21import asyncio22import evdev23from docopt import docopt24from evdev import UInput, ecodes as e, list_devices, InputDevice25import libs.macro_parser as macro_parser26from libs.macro_parser import Converter, Map_Builder, Layer_Builder, Layer_Lexer, Short_Lexer, Macro_Lexer27fname = 'mappings/mappings.json'28out_fname = 'compiled.py'29def select_device(device_dir='/dev/input'):30 '''31 Select a device from a list of accessible input devices.32 '''33 def devicenum(device_path):34 digits = re.findall(r'\d+$', device_path)35 return [int(i) for i in digits]36 devices = sorted(list_devices(device_dir), key=devicenum)37 devices = [InputDevice(path) for path in devices]38 if not devices:39 msg = 'error: no input devices found (do you have rw permission on %s/*?)'40 print(msg % device_dir, file=sys.stderr)41 sys.exit(1)42 dev_format = '{0:<3} {1.path:<20} {1.name:<35} {1.phys:<35} {1.uniq:<4}'43 dev_lines = [dev_format.format(num, dev) for num, dev in enumerate(devices)]44 print('ID {:<20} {:<35} {:<35} {}'.format('Device', 'Name', 'Phys', 'Uniq'))45 print('-' * len(max(dev_lines, key=len)))46 print('\n'.join(dev_lines))47 print()48 choice = input('Select devices [0-%s]: ' % (len(dev_lines) - 1))49 try:50 choice = choice.strip().split()51 choice = [devices[int(num)] for num in choice]52 except ValueError:53 choice = None54 if not choice:55 msg = 'error: invalid input - please enter a number'56 print(msg, file=sys.stderr)57 sys.exit(1)58 return choice[0]59def make_func_name(in_key, layer):60 return 'keymap_for_input_' + str(in_key) + '_' + str(layer)61def get_ecode(inp):62 return inp63def create_function(keymap):64 # first we'll make the function signature65 func_sig = 'def ' + make_func_name(keymap.get('input', 'default'), keymap.get('layer', 0)) + '(' + macro_parser.names.get('uinput', 'ui') + '):'66 # next, we'll make the body of the function67 body = []68 for k, v in keymap.items():69 if k == 'short':70 c = Converter(Map_Builder(Short_Lexer(v)))71 c.convert()72 body = c.commands73 break74 elif k == 'macro':75 c = Converter(Map_Builder(Macro_Lexer(v)))76 c.convert()77 body = c.commands78 break79 elif k == 'set_layer':80 lb = Layer_Builder(Layer_Lexer(v))81 lb.build()82 body = list(lb)83 break84 body.append(macro_parser.names.get('uinput', 'ui') + '.syn()')85 # now combine them into a function86 func_str = func_sig87 bld_str = ''.join(['\n\t' + s for s in body])88 return func_str + bld_str89def get_device_by_name(name, device_dir='/dev/input'):90 devices = [InputDevice(path) for path in list_devices(device_dir)]91 dev = list(filter(lambda d: d.name == name, devices))92 if len(dev) == 0:93 return None94 elif len(dev) > 1:95 dev_format = '{0:<3} {1.path:<20} {1.name:<35} {1.phys:<35} {1.uniq:<4}'96 dev_lines = [dev_format.format(num, d) for num, d in enumerate(dev)]97 print('ID {:<20} {:<35} {:<35} {}'.format('Device', 'Name', 'Phys', 'Uniq'))98 print('-' * len(max(dev_lines, key=len)))99 print('\n'.join(dev_lines))100 print()101 choices = input('Select device [0-%s]: ' % (len(dev_lines) - 1))102 try:103 choices = dev[int(choices.strip())]104 except ValueError:105 choices = None106 if not choices:107 msg = 'error: invalid input - please enter one or more numbers separated by spaces'108 print(msg, file=sys.stderr)109 sys.exit(1)110 return choices111 else:112 # dev has just one element113 return dev[0]114if __name__ == '__main__':115 arguments = docopt(__doc__, version='remappy 0.2')116 print(arguments)117 config_file = arguments.get('<config_file>', None)118 fname = 'mappings/mappings.json' if config_file is None else config_file119 # if len(sys.argv) > 2:120 # fname = sys.argv[1]121 with open(fname, 'r') as f:122 data = json.load(f)123 maps = data.get('maps', [])124 funcs = []125 func_dict = {}126 num_layers = max(maps, key=lambda x: x.get('layer', 0)).get('layer', 0) + 1127 func_list = [{} for i in range(num_layers)]128 for m in maps:129 funcs.append(create_function(m))130 inp = m.get('input', 'default')131 fnc = make_func_name(inp, m.get('layer', 0))132 key = get_ecode(inp)133 func_list[m.get('layer', 0)][key] = fnc134 # the template135 template = """136from evdev import ecodes as e137from libs.layer import Layer138%s139def default(%s):140 print('default')141key_list = [%s]142key_dict_keys = [list(key_dict.keys()) for key_dict in key_list]143current_layer = Layer(0, len(key_list), 0)144def callback(event, ui):145 # event should already be categorized146 global key_dict147 global key_dict_keys148 if event.keystate == 1 and event.scancode in key_dict_keys[current_layer.layer]:149 # print(event.keycode, event.scancode)150 key_list[current_layer.layer][event.scancode](%s)151 else:152 ui.write_event(event)153 ui.syn()154"""155 func_block = '\n\n'.join(funcs)156 dict_block = ', '.join(['{' + (', '.join([str(k) + ': ' + str(v) for k, v in func_dict.items()])) + '}' for func_dict in func_list])157 result = template % (func_block, macro_parser.names.get('uinput', 'ui'), dict_block, macro_parser.names.get('uinput', 'ui'))158 # print(result)159 with open(out_fname, 'w') as f:160 f.write(result)161 # now load that file162 module = __import__(out_fname[:-3])163 my_class = getattr(module, 'callback')164 # dev = evdev.InputDevice('/dev/input/event19')165 name = data.get('name', None)166 if name is None:167 dev = select_device()168 else:169 dev = get_device_by_name(name)170 if dev is None:171 dev = select_device()172 else:173 print(f'Config uses {dev} is this ok [Y/N]?', end=' ')174 cont = input().strip().lower()175 if cont not in ['y', 'yes', '']:176 print(ord(cont))177 dev = select_device()178 dev.grab()179 print(dev)180 ui = UInput()181 async def print_events(device):182 async for event in device.async_read_loop():183 if event.type == e.EV_KEY:184 print(evdev.categorize(event).keycode)185 ke = evdev.categorize(event)186 my_class(ke, ui)187 asyncio.ensure_future(print_events(dev))188 loop = asyncio.get_event_loop()189 loop.run_forever()...

Full Screen

Full Screen

parsetab.py

Source:parsetab.py Github

copy

Full Screen

1# parsetab.py2# This file is automatically generated. Do not edit.3# pylint: disable=W,C,R4_tabversion = '3.10'5_lr_method = 'LALR'6_lr_signature = 'COMMA DOT EQUALS FILE ID INT LP METHOD_INQ METHOD_MoveUp PRINT RP STRING STUDENTstatement : method\n | assignment\n | empty\n assignment : stu_assignment\n | method_assignment\n method : method_moveup\n | method_print\n | method_file\n method_file : ID method_print : ID DOT PRINTmethod_moveup : ID DOT METHOD_MoveUp stu_assignment : STUDENT EQUALS ID COMMA ID COMMA ID COMMA ID COMMA IDmethod_assignment : ID DOT METHOD_INQempty : '7 8_lr_action_items = {'$end':([0,1,2,3,4,5,6,7,8,9,10,14,15,16,25,],[-14,0,-1,-2,-3,-6,-7,-8,-4,-5,-9,-11,-10,-13,-12,]),'ID':([0,13,18,20,22,24,],[10,17,19,21,23,25,]),'STUDENT':([0,],[11,]),'DOT':([10,],[12,]),'EQUALS':([11,],[13,]),'METHOD_MoveUp':([12,],[14,]),'PRINT':([12,],[15,]),'METHOD_INQ':([12,],[16,]),'COMMA':([17,19,21,23,],[18,20,22,24,]),}9_lr_action = {}10for _k, _v in _lr_action_items.items():11 for _x,_y in zip(_v[0],_v[1]):12 if not _x in _lr_action: _lr_action[_x] = {}13 _lr_action[_x][_k] = _y14del _lr_action_items15_lr_goto_items = {'statement':([0,],[1,]),'method':([0,],[2,]),'assignment':([0,],[3,]),'empty':([0,],[4,]),'method_moveup':([0,],[5,]),'method_print':([0,],[6,]),'method_file':([0,],[7,]),'stu_assignment':([0,],[8,]),'method_assignment':([0,],[9,]),}16_lr_goto = {}17for _k, _v in _lr_goto_items.items():18 for _x, _y in zip(_v[0], _v[1]):19 if not _x in _lr_goto: _lr_goto[_x] = {}20 _lr_goto[_x][_k] = _y21del _lr_goto_items22_lr_productions = [23 ("S' -> statement","S'",1,None,None,None),24 ('statement -> method','statement',1,'p_statement','Macro_parser.py',17),25 ('statement -> assignment','statement',1,'p_statement','Macro_parser.py',18),26 ('statement -> empty','statement',1,'p_statement','Macro_parser.py',19),27 ('assignment -> stu_assignment','assignment',1,'p_assignment','Macro_parser.py',25),28 ('assignment -> method_assignment','assignment',1,'p_assignment','Macro_parser.py',26),29 ('method -> method_moveup','method',1,'p_method','Macro_parser.py',32),30 ('method -> method_print','method',1,'p_method','Macro_parser.py',33),31 ('method -> method_file','method',1,'p_method','Macro_parser.py',34),32 ('method_file -> ID','method_file',1,'p_method_file','Macro_parser.py',40),33 ('method_print -> ID DOT PRINT','method_print',3,'p_method_print','Macro_parser.py',46),34 ('method_moveup -> ID DOT METHOD_MoveUp','method_moveup',3,'p_method_moveup','Macro_parser.py',66),35 ('stu_assignment -> STUDENT EQUALS ID COMMA ID COMMA ID COMMA ID COMMA ID','stu_assignment',11,'p_stu_assignment','Macro_parser.py',83),36 ('method_assignment -> ID DOT METHOD_INQ','method_assignment',3,'p_method_assignment','Macro_parser.py',93),37 ('empty -> <empty>','empty',0,'p_empty','Macro_parser.py',113),...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run dbt-osmosis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful