From fd02d962d00ab35b1cd4091e61b984c4a34ac661 Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Fri, 21 Jul 2023 13:45:47 -0700 Subject: [PATCH] flake8 --- ptulsconv/docparser/generic_entity.py | 2 +- ptulsconv/docparser/tag_mapping.py | 3 +- .../docparser/tagged_string_parser_visitor.py | 7 +- ptulsconv/footage.py | 4 +- ptulsconv/movie_export.py | 8 +- ptulsconv/pdf/__init__.py | 89 ++++++++++++------- 6 files changed, 71 insertions(+), 42 deletions(-) diff --git a/ptulsconv/docparser/generic_entity.py b/ptulsconv/docparser/generic_entity.py index 4caf46c..c215642 100644 --- a/ptulsconv/docparser/generic_entity.py +++ b/ptulsconv/docparser/generic_entity.py @@ -1 +1 @@ -from dataclasses import dataclass +# from dataclasses import dataclass diff --git a/ptulsconv/docparser/tag_mapping.py b/ptulsconv/docparser/tag_mapping.py index 012f85b..bf5c6c1 100644 --- a/ptulsconv/docparser/tag_mapping.py +++ b/ptulsconv/docparser/tag_mapping.py @@ -48,7 +48,8 @@ class TagMapping: for rule in rules: if rule.target in done: continue - if rule.apply(tags, clip_content, track_content, session_content, to): + if rule.apply(tags, clip_content, track_content, session_content, + to): done.update(rule.target) def __init__(self, source: str, diff --git a/ptulsconv/docparser/tagged_string_parser_visitor.py b/ptulsconv/docparser/tagged_string_parser_visitor.py index d1d5385..44dd4cc 100644 --- a/ptulsconv/docparser/tagged_string_parser_visitor.py +++ b/ptulsconv/docparser/tagged_string_parser_visitor.py @@ -1,5 +1,5 @@ from parsimonious import NodeVisitor, Grammar -from typing import Dict, Union +from typing import Dict from enum import Enum @@ -52,8 +52,9 @@ class TagListVisitor(NodeVisitor): modifier_opt, line_opt, _, tag_list_opt = visited_children return TaggedStringResult(content=next(iter(line_opt), None), - tag_dict=next(iter(tag_list_opt), dict()), - mode=TagPreModes(next(iter(modifier_opt), 'Normal')) + tag_dict=next(iter(tag_list_opt), dict()), + mode=TagPreModes( + next(iter(modifier_opt), 'Normal')) ) @staticmethod diff --git a/ptulsconv/footage.py b/ptulsconv/footage.py index 53eed2f..a0f7f8b 100644 --- a/ptulsconv/footage.py +++ b/ptulsconv/footage.py @@ -8,8 +8,8 @@ from typing import Optional def footage_to_seconds(footage: str) -> Optional[Fraction]: """ - Converts a string representation of a footage (35mm, 24fps) - into a :class:`Fraction`, this fraction being a some number of + Converts a string representation of a footage (35mm, 24fps) + into a :class:`Fraction`, this fraction being a some number of seconds. :param footage: A string reprenentation of a footage of the form diff --git a/ptulsconv/movie_export.py b/ptulsconv/movie_export.py index c0f4fa3..dfc8192 100644 --- a/ptulsconv/movie_export.py +++ b/ptulsconv/movie_export.py @@ -1,12 +1,14 @@ -#import ffmpeg # ffmpeg-python +# import ffmpeg # ffmpeg-python # TODO: Implement movie export # def create_movie(event): # start = event['Movie.Start_Offset_Seconds'] -# duration = event['PT.Clip.Finish_Seconds'] - event['PT.Clip.Start_Seconds'] +# duration = event['PT.Clip.Finish_Seconds'] - +# event['PT.Clip.Start_Seconds'] # input_movie = event['Movie.Filename'] -# print("Will make movie starting at {}, dur {} from movie {}".format(start, duration, input_movie)) +# print("Will make movie starting at {}, dur {} from movie {}" +# .format(start, duration, input_movie)) # # # def export_movies(events): diff --git a/ptulsconv/pdf/__init__.py b/ptulsconv/pdf/__init__.py index cf17a3a..ea106de 100644 --- a/ptulsconv/pdf/__init__.py +++ b/ptulsconv/pdf/__init__.py @@ -17,6 +17,8 @@ from typing import List # This is from https://code.activestate.com/recipes/576832/ for # generating page count messages + + class ReportCanvas(canvas.Canvas): def __init__(self, *args, **kwargs): canvas.Canvas.__init__(self, *args, **kwargs) @@ -38,10 +40,12 @@ class ReportCanvas(canvas.Canvas): def draw_page_number(self, page_count): self.saveState() - self.setFont('Helvetica', 10) #FIXME make this customizable - self.drawString(0.5 * inch, 0.5 * inch, "Page %d of %d" % (self._pageNumber, page_count)) + self.setFont('Helvetica', 10) # FIXME make this customizable + self.drawString(0.5 * inch, 0.5 * inch, + "Page %d of %d" % (self._pageNumber, page_count)) right_edge = self._pagesize[0] - 0.5 * inch - self.drawRightString(right_edge, 0.5 * inch, self._report_date.strftime("%m/%d/%Y %H:%M")) + self.drawRightString(right_edge, 0.5 * inch, + self._report_date.strftime("%m/%d/%Y %H:%M")) top_line = self.beginPath() top_line.moveTo(0.5 * inch, 0.75 * inch) @@ -74,16 +78,18 @@ def make_doc_template(page_size, filename, document_title, footer_box, page_box = page_box.split_y(0.25 * inch, direction='u') header_box, page_box = page_box.split_y(0.75 * inch, direction='d') title_box, report_box = header_box.split_x(3.5 * inch, direction='r') - - on_page_lambda = (lambda c, _: - draw_header_footer(c, report_box, title_box, - footer_box,title=title, - supervisor=supervisor, - document_subheader=document_subheader, - client=client, doc_title=document_header)) - - frames = [Frame(page_box.min_x, page_box.min_y, page_box.width, page_box.height)] - + + on_page_lambda = (lambda c, _: + draw_header_footer(c, report_box, title_box, + footer_box, title=title, + supervisor=supervisor, + document_subheader=document_subheader, + client=client, + doc_title=document_header)) + + frames = [Frame(page_box.min_x, page_box.min_y, + page_box.width, page_box.height)] + page_template = PageTemplate(id="Main", frames=frames, onPage=on_page_lambda) @@ -119,12 +125,17 @@ def time_format(mins, zero_str="-"): return "%i:%02i" % (hh, mm) -def draw_header_footer(a_canvas: ReportCanvas, left_box, right_box, footer_box, title: str, supervisor: str, - document_subheader: str, client: str, doc_title="", font_name='Helvetica'): +def draw_header_footer(a_canvas: ReportCanvas, left_box, right_box, + footer_box, title: str, supervisor: str, + document_subheader: str, client: str, doc_title="", + font_name='Helvetica'): - (_supervisor_box, client_box,), title_box = right_box.divide_y([16., 16., ]) - title_box.draw_text_cell(a_canvas, title, font_name, 18, inset_y=2., inset_x=5.) - client_box.draw_text_cell(a_canvas, client, font_name, 11, inset_y=2., inset_x=5.) + (_supervisor_box, client_box,), title_box = \ + right_box.divide_y([16., 16., ]) + title_box.draw_text_cell(a_canvas, title, font_name, 18, + inset_y=2., inset_x=5.) + client_box.draw_text_cell(a_canvas, client, font_name, 11, + inset_y=2., inset_x=5.) a_canvas.saveState() a_canvas.setLineWidth(0.5) @@ -139,16 +150,20 @@ def draw_header_footer(a_canvas: ReportCanvas, left_box, right_box, footer_box, a_canvas.drawPath(tline2) a_canvas.restoreState() - (doc_title_cell, spotting_version_cell,), _ = left_box.divide_y([18., 14], direction='d') + (doc_title_cell, spotting_version_cell,), _ = \ + left_box.divide_y([18., 14], direction='d') - doc_title_cell.draw_text_cell(a_canvas, doc_title, font_name, 14., inset_y=2.) + doc_title_cell.draw_text_cell(a_canvas, doc_title, font_name, 14., + inset_y=2.) if document_subheader is not None: - spotting_version_cell.draw_text_cell(a_canvas, document_subheader, font_name, 12., inset_y=2.) + spotting_version_cell.draw_text_cell(a_canvas, document_subheader, + font_name, 12., inset_y=2.) if supervisor is not None: a_canvas.setFont(font_name, 11.) - a_canvas.drawCentredString(footer_box.min_x + footer_box.width / 2., footer_box.min_y, supervisor) + a_canvas.drawCentredString(footer_box.min_x + footer_box.width / 2., + footer_box.min_y, supervisor) class GRect: @@ -201,10 +216,12 @@ class GRect: else: if direction == 'l': return (GRect(self.min_x, self.min_y, at, self.height), - GRect(self.min_x + at, self.y, self.width - at, self.height)) + GRect(self.min_x + at, self.y, + self.width - at, self.height)) else: return (GRect(self.max_x - at, self.y, at, self.height), - GRect(self.min_x, self.y, self.width - at, self.height)) + GRect(self.min_x, self.y, + self.width - at, self.height)) def split_y(self, at, direction='u'): if at >= self.height: @@ -214,19 +231,23 @@ class GRect: else: if direction == 'u': return (GRect(self.x, self.y, self.width, at), - GRect(self.x, self.y + at, self.width, self.height - at)) + GRect(self.x, self.y + at, + self.width, self.height - at)) else: return (GRect(self.x, self.max_y - at, self.width, at), - GRect(self.x, self.y, self.width, self.height - at)) + GRect(self.x, self.y, + self.width, self.height - at)) def inset_xy(self, dx, dy): - return GRect(self.x + dx, self.y + dy, self.width - dx * 2, self.height - dy * 2) + return GRect(self.x + dx, self.y + dy, + self.width - dx * 2, self.height - dy * 2) def inset(self, d): return self.inset_xy(d, d) def __repr__(self): - return "" % (self.x, self.y, self.width, self.height) + return "" % \ + (self.x, self.y, self.width, self.height) def divide_x(self, x_list, direction='l'): ret_list = list() @@ -259,13 +280,17 @@ class GRect: def draw_border_impl(en): if en == 'min_x': - coordinates = ((self.min_x, self.min_y), (self.min_x, self.max_y)) + coordinates = ((self.min_x, self.min_y), + (self.min_x, self.max_y)) elif en == 'max_x': - coordinates = ((self.max_x, self.min_y), (self.max_x, self.max_y)) + coordinates = ((self.max_x, self.min_y), + (self.max_x, self.max_y)) elif en == 'min_y': - coordinates = ((self.min_x, self.min_y), (self.max_x, self.min_y)) + coordinates = ((self.min_x, self.min_y), + (self.max_x, self.min_y)) elif en == 'max_y': - coordinates = ((self.min_x, self.max_y), (self.max_x, self.max_y)) + coordinates = ((self.min_x, self.max_y), + (self.max_x, self.max_y)) else: return