def compare_diff(self, pre_snap_file, post_snap_file, check_from_sqlite): """ This function is called when --diff is used """ if check_from_sqlite: lines_a = pre_snap_file.splitlines(True) lines_b = post_snap_file.splitlines(True) headers = ("Snap_1", "Snap_2") options = get_options()[0] cd = ConsoleDiff(cols=int(options.cols), show_all_spaces=options.show_all_spaces, highlight=options.highlight, no_bold=options.no_bold, line_numbers=options.line_numbers, tabsize=int(options.tabsize)) for line in cd.make_table(lines_a, lines_b, headers[0], headers[1], context=(not options.whole_file), numlines=int(options.unified)): codec_print(line, options) sys.stdout.flush() else: if os.path.isfile(pre_snap_file) and os.path.isfile( post_snap_file): diff(pre_snap_file, post_snap_file) else: self.logger_check.info( colorama.Fore.RED + "ERROR!!! Files are not present in given path", extra=self.log_detail)
def start(): if len(sys.argv) < 3: raise Exception('USAGE: pdfdiff a.pdf b.df') file_1 = sys.argv[-2] file_2 = sys.argv[-1] if not os.path.isfile(file_1) or not os.path.isfile(file_2): raise Exception('Input file cant be located') file_1_split = os.path.splitext(file_1) file_2_split = os.path.splitext(file_2) if file_1_split[-1].lower() != '.pdf' and file_2_split[-1].lower( ) != '.pdf': raise Exception('file is not a pdf type') file_1_txt = file_1_split[0] + '.txt' file_2_txt = file_2_split[0] + '.txt' with open(file_1_txt, 'w') as fd1: fd1.write(convert_pdf_to_txt(file_1)) with open(file_2_txt, 'w') as fd2: fd2.write(convert_pdf_to_txt(file_2)) diff(file_1_txt, file_2_txt) os.remove(file_1_txt) os.remove(file_2_txt)