def parse_args(): parser = argparse.ArgumentParser() parser.add_argument( "launch_info", help="Path to the launch file to analyze and optional arguments", nargs="+") parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true") parser.add_argument("-q", "--quiet", help="decrease output verbosity", action="store_true") parser.add_argument("-np", "--noplot", help="don't plot the generated html", action="store_true") args = parser.parse_args() return args
import os import sys import glob import json import subprocess from collections import defaultdict from utils import UnicodeReader, slugify, count_pages, combine_pdfs, parser import addresscleaner from click2mail import Click2MailBatch parser.add_argument("directory", help="Path to downloaded mail batch") parser.add_argument("--skip-letters", action='store_true', default=False) parser.add_argument("--skip-postcards", action='store_true', default=False) def fix_lines(address): """ Click2Mail screws up addresses with 3 lines. If we have only one address line, put it in "address1". If we have more, put the first in "organization", and subsequent ones in "addressN". """ lines = [ a for a in [ address.get('organization', None), address.get('address1', None), address.get('address2', None), address.get('address3', None) ] if a ] if len(lines) == 1:
import os import sys import glob import json import subprocess from collections import defaultdict from utils import UnicodeReader, slugify, count_pages, combine_pdfs, parser import addresscleaner from click2mail import Click2MailBatch parser.add_argument("directory", help="Path to downloaded mail batch") parser.add_argument("--skip-letters", action='store_true', default=False) parser.add_argument("--skip-postcards", action='store_true', default=False) def fix_lines(address): """ Click2Mail screws up addresses with 3 lines. If we have only one address line, put it in "address1". If we have more, put the first in "organization", and subsequent ones in "addressN". """ lines = [a for a in [ address.get('organization', None), address.get('address1', None), address.get('address2', None), address.get('address3', None)] if a] if len(lines) == 1: address['organization'] = '' address['address1'] = lines[0] address['address2'] = '' address['address3'] = ''
import yaml from utils import parser def update(d, u): for k, v in u.items(): dv = d.get(k, {}) if not isinstance(dv, Mapping): d[k] = v elif isinstance(v, Mapping): d[k] = update(dv, v) else: d[k] = v return d parser.add_argument('-m', dest='merge') args = parser.parse_args() with open(args.input, 'r') as input_yaml,\ open(args.merge, 'r') as merge_in_yaml: openapi = yaml.load(input_yaml, Loader=yaml.SafeLoader) merge_in = yaml.safe_load(merge_in_yaml) updated_openapi = update(openapi, merge_in) with open(args.output, 'w') as output_yaml: yaml.safe_dump(updated_openapi, output_yaml, indent=2)
import os import sys import glob import json from collections import defaultdict from utils import UnicodeReader, slugify, count_pages, combine_pdfs, parser import addresscleaner from click2mail import Click2MailBatch parser.add_argument("directory", help="Path to downloaded mail batch") def fix_lines(address): """ Click2Mail screws up addresses with 3 lines. If we have only one address line, put it in "address1". If we have more, put the first in "organization", and subsequent ones in "addressN". """ lines = [a for a in [ address.get('organization', None), address.get('address1', None), address.get('address2', None), address.get('address3', None)] if a] if len(lines) == 1: address['organization'] = '' address['address1'] = lines[0] address['address2'] = '' address['address3'] = '' if len(lines) >= 2: address['organization'] = lines[0] address['address1'] = lines[1]
import os import sys import glob import json from collections import defaultdict from utils import UnicodeReader, slugify, count_pages, combine_pdfs, parser import addresscleaner from click2mail import Click2MailBatch parser.add_argument("directory", help="Path to downloaded mail batch") def fix_lines(address): """ Click2Mail screws up addresses with 3 lines. If we have only one address line, put it in "address1". If we have more, put the first in "organization", and subsequent ones in "addressN". """ lines = [ a for a in [ address.get('organization', None), address.get('address1', None), address.get('address2', None), address.get('address3', None) ] if a ] if len(lines) == 1: address['organization'] = '' address['address1'] = lines[0] address['address2'] = ''
import jsonpatch import yaml from utils import parser parser.add_argument('-d', dest='diff') args = parser.parse_args() with open(args.diff, 'r') as patch_file, \ open(args.input, 'r') as input_yaml: openapi = yaml.load(input_yaml, Loader=yaml.SafeLoader) json_patch = jsonpatch.JsonPatch.from_string(patch_file.read()) json_patch.apply(openapi, in_place=True) with open(args.output, 'w') as output_yaml: yaml.safe_dump(openapi, output_yaml, indent=2)