How to use _print_diff method in localstack

Best Python code snippet using localstack_python

signaldiff

Source:signaldiff Github

copy

Full Screen

...15def run(args):16 file1 = args.LOG_FILE117 file2 = args.LOG_FILE218 print_sep = False19 def _print_diff(signalnum, filename, linenum, line, header=True):20 nonlocal print_sep21 if header:22 if print_sep:23 print()24 print('Signal', signalnum)25 print('{}:{}:'.format(filename, linenum), line)26 print_sep = True27 with open(file1) as f1, open(file2) as f2:28 signal_count = 029 i = 030 lines2 = f2.readlines()31 lines2_length = len(lines2)32 line1_count = line2_count = 033 for line1 in f1.readlines():34 line1_count += 135 line1_s = line1.strip()36 if len(line1_s) == 0:37 continue38 line1_match = signal_pattern.match(line1_s)39 if not line1_match:40 continue41 signal_count += 142 while i < lines2_length:43 line2_s = lines2[i].strip()44 line2_count += 145 i += 146 if len(line2_s) == 0:47 continue48 line2_match = signal_pattern.match(line2_s)49 if line2_match:50 notime_line1 = '{} {}'.format(line1_match.group('direction'),51 line1_match.group('signal'))52 notime_line2 = '{} {}'.format(line2_match.group('direction'),53 line2_match.group('signal'))54 if args.ignore_time:55 cmp_line1 = notime_line156 cmp_line2 = notime_line257 else:58 if args.time_deviation:59 time1 = line1_match.group('time')60 time2 = line2_match.group('time')61 deviate = abs(float(time1) - float(time2)) > \62 args.time_deviation63 if not deviate and (notime_line1 == notime_line2):64 break65 cmp_line1 = line1_s66 cmp_line2 = line2_s67 if cmp_line1 != cmp_line2:68 _print_diff(signal_count, file1, line1_count, line1_s)69 _print_diff(signal_count, file2, line2_count, line2_s, False)70 break71 else:72 # Remaining lines for File 1 (if any).73 _print_diff(signal_count, file1, line1_count, line1_s)74 # Remaining lines for File 2 (if any).75 while i < lines2_length:76 line2_s = lines2[i].strip()77 line2_count += 178 i += 179 if len(line2_s) == 0:80 continue81 line2_match = signal_pattern.match(line2_s)82 if line2_match:83 signal_count += 184 _print_diff(signal_count, file2, line2_count, line2_s)85if __name__ == '__main__':86 parser = argparse.ArgumentParser()87 parser.add_argument('LOG_FILE1', type=str, help="Log file 1")88 parser.add_argument('LOG_FILE2', type=str, help="Log file 2")89 parser.add_argument('-i', '--ignore-time', action='store_true',90 help='Ignore timestamps')91 parser.add_argument('-t', '--time-deviation', type=float,92 help='Time deviation specified as a decimal number in '93 'milliseconds (ms)')94 args = parser.parse_args()...

Full Screen

Full Screen

config.py

Source:config.py Github

copy

Full Screen

...18 19 with open(output_file, 'w') as output_file:20 for line in diff(diff1.splitlines(), diff2.splitlines(), tofile=tofile, fromfile=fromfile, lineterm=''):21 output_file.write(line + '\n')22def _print_diff(switch, remote_switch, diff1, diff2):23 tofile = '{} running configuration'.format(switch)24 fromfile = '{} running configuration'.format(remote_switch)25 26 print ''27 28 for line in diff(diff1.splitlines(), diff2.splitlines(), tofile=tofile, fromfile=fromfile, lineterm=''):29 if line[0] == '+':30 print '\033[32m' + line + '\033[0m'31 elif line[0] == '-':32 print '\033[31m' + line + '\033[0m'33 else:34 print line35 36 print ''37def get_running_config(switch, output_file):38 running_config = _get_config(switch)39 if output_file:40 log.info('Writing running config to file {}'.format(output_file))41 with open(output_file, 'w') as config_file:42 config_file.write(running_config)43 else:44 print ''45 print running_config46 print ''47def diff_config_file(switch, diff_file, output_file):48 running_config = _get_config(switch)49 with open(diff_file, 'r') as read_diff_file:50 file_to_diff = read_diff_file.read()51 log.info('Diffing {} running configuration against {}'.format(switch, diff_file))52 if output_file:53 _send_diff_to_file(switch, diff_file, running_config, file_to_diff, output_file)54 else:55 _print_diff(switch, diff_file, running_config, file_to_diff)56def diff_config_switch(switch, remote_switch, output_file):57 local_running_config = _get_config(switch)58 remote_running_config = _get_config(remote_switch)59 log.info('Getting config differences between {} and {}'.format(switch, remote_switch))60 if output_file:61 _send_diff_to_file(switch, remote_switch, local_running_config, remote_running_config, output_file)62 else:63 _print_diff(switch, remote_switch, local_running_config, remote_running_config)64 65 66def reload(switch):67 session = Session().ssh(switch)68 reload_output = session.send_command('/etc/init.d/quagga force-reload')69 70 log.info('Command sent. Waiting 5 seconds to check status')71 time.sleep(5)72 confirmation_output = session.send_command('ps -ef | grep quagga')73 74 result = confirmation_output.splitlines()75 76 if len(result) < 2:77 log.error('Restart of Quagga on {} was unsuccessful!'.format(target))...

Full Screen

Full Screen

diff.py

Source:diff.py Github

copy

Full Screen

...25 mem[x][y] = result26 return mem27def print_diff(p, q):28 mem = _lcs(p, q)29 yield from _print_diff(p, q, mem, len(p), len(q))30def _print_diff(p, q, mem, x, y):31 if x > 0 and y > 0 and p[x - 1] == q[y - 1]:32 yield from _print_diff(p, q, mem, x - 1, y - 1)33 yield (' ', p[x - 1])34 elif y > 0 and (x == 0 or mem[x][y - 1] >= mem[x - 1][y]):35 yield from _print_diff(p, q, mem, x, y - 1)36 yield ('+', q[y - 1])37 elif x > 0 and (y == 0 or mem[x][y - 1] < mem[x - 1][y]):38 yield from _print_diff(p, q, mem, x - 1, y)...

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 localstack 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