Best Python code snippet using avocado_python
mdpe.py
Source:mdpe.py
1#!/usr/bin/env python32# -*- coding: utf-8 -*-3"""4Program to convert papers in markdown format to each other5"""6import sys, signal7sys.dont_write_bytecode = True8signal.signal(signal.SIGINT, signal.SIG_DFL)9import argparse10import re11from mods.func_prompt_io import check_exist, check_overwrite12# =============== constant =============== #13LINE_START_WITH = "*"14COMMENT_START = "<!--"15COMMENT_END = "-->"16SKIP_LINE_START = ["####"]17RE_LINE_START_WITH = re.compile(r"^[\s\t]*\*")18# =============== function =============== #19def swap_main_and_comment(input_file):20 """21 Function to swap main text and comment22 Args:23 input_file (str): input file path24 Returns:25 list: [line_val(str), ...]26 """27 output_line_vals = []28 with open(input_file, "r") as obj_input:29 for line_val in obj_input:30 if RE_LINE_START_WITH.search(line_val) and "<!--" in line_val:31 indent, line_val = line_val.split(LINE_START_WITH, maxsplit=1)32 line_val = line_val.replace(COMMENT_END, "", 1)33 line_val = line_val.strip()34 elems = [v.strip() for v in line_val.split(COMMENT_START, 1)]35 output_line_vals.append("{0}* {1} <!-- {2} -->\n".format(indent, elems[1], elems[0]))36 else:37 output_line_vals.append(line_val)38 return output_line_vals39def formatting(input_file, enable_region):40 """41 Function to format to paper (remove main text or comment)42 Args:43 input_file (str): input file path44 enable_region (str): remain region: `main` or `comment`45 Returns:46 list: [line_val(str), ...]47 """48 output_line_vals = []49 is_continued_list_bullet = False50 with open(input_file, "r") as obj_input:51 for line_val in obj_input:52 if any([line_val.startswith(v) for v in SKIP_LINE_START]):53 continue54 if RE_LINE_START_WITH.search(line_val) and COMMENT_START in line_val:55 line_val = line_val.split(LINE_START_WITH, maxsplit=1)[1]56 line_val = line_val.replace(COMMENT_END, "", 1)57 line_val = line_val.strip()58 elems = [v.strip() for v in line_val.split(COMMENT_START, 1)]59 elem = None60 if enable_region == "main":61 elem = elems[0]62 else:63 elem = elems[1]64 if is_continued_list_bullet:65 output_line_vals[-1] += " {0}".format(elem)66 else:67 output_line_vals.append(elem)68 is_continued_list_bullet = True69 else:70 output_line_vals.append(line_val)71 is_continued_list_bullet = False72 return [v if v.endswith("\n") else v + "\n" for v in output_line_vals]73# =============== main =============== #74if __name__ == '__main__':75 parser = argparse.ArgumentParser(description="Program to convert papers in markdown format to each other", formatter_class=argparse.RawTextHelpFormatter)76 parser.add_argument("TYPE", metavar="OPERATION", choices=["swap", "main", "comment"], help="operation type (`swap`, `main`, or `comment`)")77 parser.add_argument("INPUT_FILE", metavar="INPUT.md", help="source markdown paper file")78 parser.add_argument("OUTPUT_FILE", metavar="OUTPUT.md", nargs="?", help="output markdown paper file (Default: `-i`)")79 parser.add_argument("-O", dest="FLAG_OVERWRITE", action="store_true", default=False, help="overwrite forcibly")80 args = parser.parse_args()81 check_exist(args.INPUT_FILE, 2)82 output_file = args.INPUT_FILE83 if args.OUTPUT_FILE is not None:84 output_file = args.OUTPUT_FILE85 output_line_vals = []86 if args.TYPE == "swap":87 output_line_vals = swap_main_and_comment(args.INPUT_FILE)88 else:89 output_line_vals = formatting(args.INPUT_FILE, args.TYPE)90 if args.FLAG_OVERWRITE == False:91 check_overwrite(output_file)92 with open(output_file, "w") as obj_output:93 for line_val in output_line_vals:...
enable_config.py
Source:enable_config.py
...14 print "No entries found."15 elif 'aws-config' not in recorders[0]['name']:16 print(recorders[0]['name'])17 delete_recorder(config, recorders[0]['name'])18def enable_region(region):19 config = boto3.client('config',region)20 recorder = config.put_configuration_recorder(21 ConfigurationRecorder={22 'name': 'aws-config',23 'roleARN': 'arn:aws:iam::039522162354:role/service-role/kfc-config-role',24 'recordingGroup': {25 'allSupported': True,26 'includeGlobalResourceTypes': True,27 }28 }29 )30 channel = config.put_delivery_channel(31 DeliveryChannel={32 'name': 'default',33 's3BucketName': 'kfc-config',34 'configSnapshotDeliveryProperties': {35 'deliveryFrequency': 'One_Hour'36 }37 }38 )39 state = config.start_configuration_recorder(40 ConfigurationRecorderName='aws-config'41 )42for region in regions:43 print("Enabling Config for: {}".format(region['RegionName']))44 clean_config(region['RegionName'])...
res_country.py
Source:res_country.py
1# -*- encoding: utf-8 -*-2##############################################################################3#4# Copyright (C) 2014 Didotech Srl - OpenERP 7 migration by Matmoz d.o.o. 5# $Id$6#7# This program is free software: you can redistribute it and/or modify8# it under the terms of the GNU Affero General Public License as published by9# the Free Software Foundation, either version 3 of the License, or10# (at your option) any later version.11#12# This program is distributed in the hope that it will be useful,13# but WITHOUT ANY WARRANTY; without even the implied warranty of14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15# GNU General Public License for more details.16#17# You should have received a copy of the GNU General Public License18# along with this program. If not, see <http://www.gnu.org/licenses/>.19#20##############################################################################21from osv import osv22from osv import fields23from tools.translate import _24class res_country(osv.osv):25 _inherit = 'res.country'26 _columns = {27 'enable_province': fields.boolean('Show Province?'),28 'enable_region': fields.boolean('Show Region?'),29 'enable_state': fields.boolean('Show State?'),...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!