How to use itemize method in localstack

Best Python code snippet using localstack_python

beamer_gen.py

Source:beamer_gen.py Github

copy

Full Screen

1#!/usr/bin/env python32import sys3import re4import argparse5import pathlib # python 3.46__version__ = '1.3.0'7def process_file(filename_in, filename_out):8 """Actual processing of a file."""9 # regular expressions for various directives10 frame_re = re.compile(r'^(\s*)\+((?:<[^>]*>)?)((?:\[[^\]]*\])?) ?(.*)$')11 section_re = re.compile(r'^s (.*)$')12 block_re = re.compile(r'^(\s*)b((?:<[^>]*>)?) (.*)$')13 item_re = re.compile(r'^(\s*)-((?:<[^>]*>)?)((?:\[[^\]]*\])?) (.*)$')14 enumitem_re = re.compile(r'^(\s*)#((?:<[^>]*>)?)((?:\[[^\]]*\])?) (.*)$')15 column_re = re.compile(r'^(\s*)c((?:\[[^\]]*\])?)\{([^}]*)\}(.*)$')16 figure_re = re.compile(r'^(\s*)f((?:<[^>]*>)?)\{([^}]*)\}\{([^}]*)\}(.*)$')17 empty_re = re.compile(r'^\s*$')18 end_re = re.compile(r'^\s*\\end\{[^}]*\}.*$')19 non_empty_re = re.compile(r'(\s*)\S.*$')20 # environments21 itemize_re = re.compile(r'^(\s*)\{itemize\}((?:<[^>]*>)?) ?(.*)$')22 columns_re = re.compile(r'^(\s*)\{columns\}((?:\[[^\]]*\])?)(.*)$')23 enumerate_re = re.compile(r'^(\s*)\{enumerate\}((?:<[^>]*>)?) ?(.*)$')24 def indent():25 """Return current indentation prefix."""26 try:27 return ' ' + ' ' * current_envs[-1][1]28 except IndexError:29 return ''30 def close_envs(n=0, strict=False):31 """Close currently opened environments."""32 if strict:33 n += 0.534 while current_envs:35 if n <= current_envs[-1][1]:36 env = current_envs.pop()37 lines.append(indent() + '\\end{{{}}}\n'.format(env[0]))38 else:39 break40 lines = []41 current_envs = []42 for line in open(filename_in):43 if frame_re.match(line): # new frame44 frame = frame_re.match(line)45 frame_title = frame.group(4)46 frame_indent = frame.group(1)47 frame_overlay = frame.group(2)48 frame_option = frame.group(3)49 close_envs() # frame is always top-level environment50 lines.append(frame_indent + '\\begin{{frame}}{}{}\n'.format(51 frame_overlay, frame_option))52 current_envs.append(('frame', len(frame_indent)))53 if frame_title:54 lines.append(indent() + '\\frametitle{{{}}}\n'.format(55 frame_title))56 elif section_re.match(line): # new section57 section = section_re.match(line)58 close_envs()59 lines.append('\\section{{{}}}\n'.format(section.group(1)))60 elif block_re.match(line): # new block61 block = block_re.match(line)62 block_name = block.group(3)63 block_overlay = block.group(2)64 block_indent = len(block.group(1))65 close_envs(block_indent)66 lines.append(indent() + '\\begin{{block}}{}{{{}}}\n'.format(67 block_overlay, block_name))68 current_envs.append(('block', block_indent))69 elif item_re.match(line): # new item70 item = item_re.match(line)71 item_content = item.group(4)72 item_label = item.group(3)73 item_overlay = item.group(2)74 item_indent = len(item.group(1))75 close_envs(item_indent, strict=True)76 if current_envs:77 if current_envs[-1] != ('itemize', item_indent):78 close_envs(item_indent)79 lines.append(indent() + '\\begin{itemize}\n')80 current_envs.append(('itemize', item_indent))81 else:82 current_envs.append(('itemize', item_indent))83 lines.append(indent() + '\\item{}{} {}\n'.format(item_overlay,84 item_label,85 item_content))86 elif enumitem_re.match(line): # new item from enumerate87 item = enumitem_re.match(line)88 item_content = item.group(4)89 item_label = item.group(3)90 item_overlay = item.group(2)91 item_indent = len(item.group(1))92 close_envs(item_indent, strict=True)93 if current_envs:94 if current_envs[-1] != ('enumerate', item_indent):95 close_envs(item_indent)96 lines.append(indent() + '\\begin{enumerate}\n')97 current_envs.append(('enumerate', item_indent))98 else:99 current_envs.append(('enumerate', item_indent))100 lines.append(indent() + '\\item{}{} {}\n'.format(item_overlay,101 item_label,102 item_content))103 elif column_re.match(line): # new column104 column = column_re.match(line)105 column_indent = len(column.group(1))106 column_align = column.group(2)107 column_ratio = column.group(3)108 column_rest = column.group(4)109 close_envs(column_indent, strict=True)110 if current_envs:111 if current_envs[-1] != ('columns', column_indent):112 close_envs(column_indent)113 lines.append(indent() + '\\begin{columns}\n')114 current_envs.append(('columns', column_indent))115 else:116 current_envs.append(('columns', column_indent))117 lines.append(indent() + '\\column{}{{{}\\columnwidth}}{}\n'.format(118 column_align, column_ratio, column_rest))119 elif figure_re.match(line): # figure120 figure = figure_re.match(line)121 figure_ratio = figure.group(3)122 figure_fname = figure.group(4)123 figure_rest = figure.group(5)124 figure_overlay = figure.group(2)125 lines.append(126 indent() +127 '\\includegraphics{}[width={}\\columnwidth]{{{}}}{}\n'.format(128 figure_overlay, figure_ratio, figure_fname, figure_rest))129 elif itemize_re.match(line): # itemize environment130 itemize = itemize_re.match(line)131 itemize_indent = len(itemize.group(1))132 itemize_overlay = itemize.group(2)133 itemize_content = itemize.group(3)134 close_envs(itemize_indent)135 lines.append(indent() + '\\begin{{itemize}}{} {}\n'.format(136 itemize_overlay,137 itemize_content))138 current_envs.append(('itemize', itemize_indent))139 elif enumerate_re.match(line): # enumerate environment140 enumerate = enumerate_re.match(line)141 enumerate_indent = len(enumerate.group(1))142 enumerate_overlay = enumerate.group(2)143 enumerate_content = enumerate.group(3)144 close_envs(enumerate_indent)145 lines.append(indent() + '\\begin{{enumerate}}{} {}\n'.format(146 enumerate_overlay,147 enumerate_content))148 current_envs.append(('enumerate', enumerate_indent))149 elif columns_re.match(line): # columns environment150 columns = columns_re.match(line)151 columns_indent = len(columns.group(1))152 columns_options = columns.group(2)153 columns_rest = columns.group(3)154 close_envs(columns_indent)155 lines.append(indent() + '\\begin{{columns}}{} {}\n'.format(156 columns_options, columns_rest))157 current_envs.append(('columns', columns_indent))158 else: # default: passthrough159 non_empty = non_empty_re.match(line)160 if non_empty:161 non_empty_indent = len(non_empty.group(1))162 close_envs(non_empty_indent)163 lines.append(line)164 # close all remaining environments165 close_envs()166 # TODO handle comments at the correct indentation level167 # reorder all closing environments and empty lines168 i, N = 0, len(lines) - 1169 while i < N:170 if empty_re.match(lines[i]) and end_re.match(lines[i+1]):171 tmp = lines[i+1]172 lines[i+1] = lines[i]173 lines[i] = tmp174 i = max(0, i-1)175 else:176 i += 1177 with open(filename_out, 'w') as f_out:178 f_out.writelines(lines)179def main():180 """Command line parsing."""181 parser = argparse.ArgumentParser(182 description='Generate LaTeX/beamer files from more compact files.')183 parser.add_argument('filenames', metavar='filename', type=str, nargs='+',184 help='name of the file to be processed.')185 args = parser.parse_args(sys.argv[1:])186 for fn in args.filenames:187 process_file(fn, str(pathlib.Path(fn).with_suffix('.tex')))188if __name__ == '__main__':...

Full Screen

Full Screen

create_pdf.py

Source:create_pdf.py Github

copy

Full Screen

1import numpy as np2import os, glob3from pylatex import Document, Section, Subsection, Tabular, Command4from pylatex import Math, TikZ, Axis, Plot, Figure, Matrix, Alignat5from main import exp_output_pdf, iter_output_pdf6from pylatex import PageStyle, Head, Foot, MiniPage, \7 StandAloneGraphic, MultiColumn, Tabu, LongTabu, LargeText, MediumText, \8 LineBreak, NewPage, Tabularx, TextColor, simple_page_number, Itemize, Hyperref, Package9from pylatex.utils import italic, bold, NoEscape, escape_latex10import os11import pandas as pd12def hyperlink(url,text):13 text = escape_latex(text)14 return NoEscape(r'\href{' + url + '}{' + text + '}')15event_info_dir = 'events_station_info'16all_station_info_files = glob.glob(f"{event_info_dir}/*.txt")17event_maps_dir = 'events_station_maps'18iteration=019if __name__ == '__main__':20 geometry_options = {"tmargin": "1cm", "lmargin": "1cm", "margin": "1cm"}21 doc = Document(geometry_options=geometry_options, 22 documentclass="beamer",23 )24 doc.packages.append(Package('hyperref'))25 26 with doc.create(Section('Titlepage')):27 doc.preamble.append(Command('title', 'Algoritmo Quine McCluskey'))28 doc.preamble.append(Command('author', 'Fabián Chacón, Johanel Álvarez, William Sánchez'))29 doc.preamble.append(Command('date', "8 setiembre 2022"))30 doc.append(NoEscape(r'\maketitle'))31 with doc.create(Section('Section')):32 with doc.create(Itemize()) as itemize:33 for i in range(0,len(iter_output_pdf)-1,2):34 iteration+=135 itemize.add_item("ITERACIÓN: "+str(iteration))36 for j in iter_output_pdf[i]:37 itemize.add_item("Cantidad de 1: "+str(j))38 for k in iter_output_pdf[i][j]: 39 if iteration>=3:40 itemize.add_item(k[1])41 elif i>1:42 itemize.add_item(k[1][1:len(k[1])])43 else:44 itemize.add_item(k[1:len(k)])45 doc.append(NewPage())46 itemize.add_item("RELACIONES CON OTRAS EXPRESIONES")47 for l in iter_output_pdf[i+1]:48 if iteration==1:49 itemize.add_item([l[0],l[1][1:len(l[1])]])50 else:51 itemize.add_item(l)52 doc.append(NewPage())53 with doc.create(Section('Slide')):54 with doc.create(Itemize()) as itemize:55 itemize.add_item("La expresión final es:")56 itemize.add_item(exp_output_pdf)57 totstationslist = []58 for ff in glob.glob(f"{event_maps_dir}/*.png"):59 numstation = int(os.path.basename(ff).split('.png')[0].split("_")[-1])60 totstationslist.append(numstation)61 totstationsinds = np.argsort(totstationslist)62 totstationsinds = totstationsinds[::-1] #reverse order63 for ind in totstationsinds:64 ff = all_station_info_files[ind]65 dff_events = pd.read_csv(ff, nrows=1)66 evname = dff_events.loc[0,'eventorig']67 eventbrk = dff_events.loc[0,'eventbrk']68 # print(evname)69 station_map_file_list = glob.glob(f"{event_maps_dir}/*{evname}_*.png")70 if len(station_map_file_list):71 station_map_file = station_map_file_list[0]72 print(station_map_file)73 with doc.create(Section('Slide')):74 with doc.create(Itemize()) as itemize:75 itemize.add_item(f"{evname}, Dep: {dff_events.loc[0,'eventdepth']}, Mag: {dff_events.loc[0,'eventmag']}")76 with doc.create(Subsection('Figure')):77 with doc.create(Figure(position='h!')) as fig_map:78 fig_map.add_image(station_map_file, width='230px')79 fig_map.add_caption(f'Station Map for {evname}')80 doc.append(NewPage())81 # Creating a pdf...

Full Screen

Full Screen

firewall.py

Source:firewall.py Github

copy

Full Screen

...12import sh13from . import files, network, output14def backup_config():15 backup_file = os.path.join(tempfile.mkdtemp(), 'iptables.cfg.bak')16 output.itemize(17 'Backing up firewall configuration to \'{}\''.format(backup_file)18 )19 sh.iptables_save(_out=backup_file)20 return backup_file21def restore_config(config_file):22 output.itemize(23 'Restoring firewall configuration from \'{}\''.format(config_file)24 )25 sh.iptables_restore(sh.cat(config_file))26 files.remove(os.path.dirname(config_file), _output_level=1)27def block_traffic(tunnel_device):28 output.itemize('Blocking relatable traffic...')29 output.itemize('Resetting config', level=1)30 sh.iptables('-P', 'INPUT', 'ACCEPT')31 sh.iptables('-P', 'FORWARD', 'ACCEPT')32 sh.iptables('-P', 'OUTPUT', 'ACCEPT')33 sh.iptables('-F')34 sh.iptables('-X')35 output.itemize('Allowing traffic over loopback interface', level=1)36 sh.iptables('-I', 'INPUT', '-i', 'lo', '-j', 'ACCEPT')37 sh.iptables('-I', 'OUTPUT', '-o', 'lo', '-j', 'ACCEPT')38 output.itemize('Allowing traffic over local networks', level=1)39 lans = network.get_local_networks(tunnel_device)40 for lan in lans:41 output.itemize(42 'Allowing traffic over {} for {}'.format(lan[0], lan[1]), level=243 )44 sh.iptables('-I', 'INPUT', '-i', lan[0], '-s', lan[1], '-j', 'ACCEPT')45 sh.iptables('-I', 'OUTPUT', '-o', lan[0], '-d', lan[1], '-j', 'ACCEPT')46 output.itemize('Allowing traffic over VPN interface', level=1)47 sh.iptables('-I', 'INPUT', '-i', tunnel_device, '-j', 'ACCEPT')48 sh.iptables('-I', 'OUTPUT', '-o', tunnel_device, '-j', 'ACCEPT')49 output.itemize('Allowing traffic to VPN gateway', level=1)50 vpn_gate = network.get_vpn_gateway()51 sh.iptables(52 '-I', 'INPUT',53 '-i', vpn_gate[0],54 '-p', 'udp',55 '-s', vpn_gate[1],56 '--sport', '1301',57 '-j', 'ACCEPT'58 )59 sh.iptables(60 '-I', 'OUTPUT',61 '-o', vpn_gate[0],62 '-p', 'udp',63 '-d', vpn_gate[1],64 '--dport', '1301',65 '-j', 'ACCEPT'66 )67 output.itemize('Logging dropped traffic', level=1)68 sh.iptables(69 '-A', 'INPUT',70 '-m', 'limit',71 '--limit', '1/min',72 '-j', 'LOG',73 '--log-prefix', 'iptables:dropped input: ',74 '--log-level', '4',75 )76 sh.iptables(77 '-A', 'OUTPUT',78 '-m', 'limit',79 '--limit', '1/min',80 '-j', 'LOG',81 '--log-prefix', 'iptables:dropped output: ',82 '--log-level', '4',83 )84 sh.iptables(85 '-A', 'FORWARD',86 '-m', 'limit',87 '--limit', '1/min',88 '-j', 'LOG',89 '--log-prefix', 'iptables:dropped forward: ',90 '--log-level', '4',91 )92 output.itemize('Dropping all other traffic', level=1)93 sh.iptables('-P', 'INPUT', 'DROP')94 sh.iptables('-P', 'OUTPUT', 'DROP')95 sh.iptables('-P', 'FORWARD', 'DROP')96 for line in sh.iptables('-vnL', _iter=True):97 print(line.rstrip())98def abort_prompt():99 security_code = ''.join(random.choice(string.lowercase) for i in range(4))100 output.itemize(101 'Enter \'{}\' to terminate protection'.format(security_code)102 )103 entered_code = raw_input('Security code: ')104 if entered_code != security_code:105 output.error('Invalid code')...

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