mirror of
https://github.com/iluvcapra/ptulsconv.git
synced 2025-12-31 08:50:48 +00:00
Implementation
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from .doc_entity import SessionDescriptor, TrackDescriptor, TrackClipDescriptor
|
from .doc_entity import SessionDescriptor, TrackDescriptor, TrackClipDescriptor
|
||||||
|
from .tag_compiler import Event
|
||||||
from typing import Optional, Generator
|
from typing import Optional, Generator
|
||||||
|
|
||||||
# field_map maps tags in the text export to fields in FMPXMLRESULT
|
# field_map maps tags in the text export to fields in FMPXMLRESULT
|
||||||
@@ -72,7 +73,7 @@ class ADRLine:
|
|||||||
adlib: bool
|
adlib: bool
|
||||||
optional: bool
|
optional: bool
|
||||||
|
|
||||||
adr_tag_to_line_map = (
|
adr_tag_to_line_map = [
|
||||||
TagMapping(source='Title', target="title", alt=TagMapping.ContentSource.Session),
|
TagMapping(source='Title', target="title", alt=TagMapping.ContentSource.Session),
|
||||||
TagMapping(source="Supv", target="supervisor"),
|
TagMapping(source="Supv", target="supervisor"),
|
||||||
TagMapping(source="Client", target="client"),
|
TagMapping(source="Client", target="client"),
|
||||||
@@ -104,18 +105,12 @@ class ADRLine:
|
|||||||
formatter=(lambda x: len(x) > 0)),
|
formatter=(lambda x: len(x) > 0)),
|
||||||
TagMapping(source="OPT", target="optional",
|
TagMapping(source="OPT", target="optional",
|
||||||
formatter=(lambda x: len(x) > 0))
|
formatter=(lambda x: len(x) > 0))
|
||||||
)
|
]
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def from_clip(clip: TrackClipDescriptor,
|
def from_event(cls, event: Event) -> Optional['ADRLine']:
|
||||||
track: TrackDescriptor,
|
new = cls()
|
||||||
session: SessionDescriptor) -> Optional['ADRLine']:
|
TagMapping.apply_rules(cls.adr_tag_to_line_map, event.tags,
|
||||||
pass
|
event.clip_name, event.track_name, event.session_name, new)
|
||||||
|
return new
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def generate_lines(session: SessionDescriptor) -> Generator['ADRLine']:
|
|
||||||
for track in session.tracks:
|
|
||||||
for track_clip in track.clips:
|
|
||||||
line = ADRLine.from_clip(track_clip, track, session)
|
|
||||||
if line is not None:
|
|
||||||
yield line
|
|
||||||
|
|||||||
@@ -4,10 +4,13 @@ from typing import Iterator, Tuple
|
|||||||
|
|
||||||
from ptulsconv.docparser import apply_appends
|
from ptulsconv.docparser import apply_appends
|
||||||
from ptulsconv.docparser.doc_entity import SessionDescriptor
|
from ptulsconv.docparser.doc_entity import SessionDescriptor
|
||||||
from ptulsconv.docparser.tag_mapping import Event
|
|
||||||
from ptulsconv.docparser.tagged_string_parser_visitor import parse_tags, TagPreModes
|
from ptulsconv.docparser.tagged_string_parser_visitor import parse_tags, TagPreModes
|
||||||
|
|
||||||
|
|
||||||
|
class Event(namedtuple('Event', 'clip_name track_name session_name tags start finish')):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TagCompiler:
|
class TagCompiler:
|
||||||
session: SessionDescriptor
|
session: SessionDescriptor
|
||||||
|
|
||||||
@@ -117,3 +120,4 @@ class TagCompiler:
|
|||||||
session_tags=session_parsed.tag_dict)
|
session_tags=session_parsed.tag_dict)
|
||||||
|
|
||||||
yield event.clip_content, event.track_content, session_parsed.content, tags, event.start, event.finish
|
yield event.clip_content, event.track_content, session_parsed.content, tags, event.start, event.finish
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Optional, Callable, Any, List
|
from typing import Optional, Callable, Any, List
|
||||||
from collections import namedtuple
|
|
||||||
|
|
||||||
|
|
||||||
class Event(namedtuple('Event', 'clip_name track_name session_name tags start finish')):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TagMapping:
|
class TagMapping:
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ def parse_tags(prompt) -> "TaggedStringResult":
|
|||||||
class TaggedStringResult:
|
class TaggedStringResult:
|
||||||
content: Optional[str]
|
content: Optional[str]
|
||||||
tag_dict: Optional[Dict[str, str]]
|
tag_dict: Optional[Dict[str, str]]
|
||||||
mode: str
|
mode: TagPreModes
|
||||||
|
|
||||||
def __init__(self, content, tag_dict, mode):
|
def __init__(self, content, tag_dict, mode):
|
||||||
self.content = content
|
self.content = content
|
||||||
@@ -52,7 +52,7 @@ class TagListVisitor(NodeVisitor):
|
|||||||
|
|
||||||
return TaggedStringResult(content=next(iter(line_opt), None),
|
return TaggedStringResult(content=next(iter(line_opt), None),
|
||||||
tag_dict=next(iter(tag_list_opt), None),
|
tag_dict=next(iter(tag_list_opt), None),
|
||||||
mode=next(iter(modifier_opt), 'Normal')
|
mode=TagPreModes(next(iter(modifier_opt), 'Normal'))
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -1,41 +1,39 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from ptulsconv.transformations import TagInterpreter
|
|
||||||
|
from ptulsconv.docparser.tagged_string_parser_visitor import parse_tags, TagPreModes
|
||||||
|
|
||||||
|
|
||||||
class TestTagInterpreter(unittest.TestCase):
|
class TestTagInterpreter(unittest.TestCase):
|
||||||
def test_line(self):
|
def test_line(self):
|
||||||
ti = TagInterpreter()
|
s1 = parse_tags("this is a test")
|
||||||
s1 = ti.parse_tags("this is a test")
|
|
||||||
self.assertEqual(s1.content, "this is a test")
|
self.assertEqual(s1.content, "this is a test")
|
||||||
self.assertEqual(s1.mode, 'Normal')
|
self.assertEqual(s1.mode, TagPreModes.NORMAL)
|
||||||
self.assertEqual(len(s1.tag_dict), 0)
|
self.assertEqual(len(s1.tag_dict), 0)
|
||||||
|
|
||||||
s2 = ti.parse_tags("this! IS! Me! ** Typing! 123 <> |||")
|
s2 = parse_tags("this! IS! Me! ** Typing! 123 <> |||")
|
||||||
self.assertEqual(s2.content, "this! IS! Me! ** Typing! 123 <> |||")
|
self.assertEqual(s2.content, "this! IS! Me! ** Typing! 123 <> |||")
|
||||||
self.assertEqual(s2.mode, 'Normal')
|
self.assertEqual(s2.mode, TagPreModes.NORMAL)
|
||||||
self.assertEqual(len(s2.tag_dict), 0)
|
self.assertEqual(len(s2.tag_dict), 0)
|
||||||
|
|
||||||
def test_tags(self):
|
def test_tags(self):
|
||||||
ti = TagInterpreter()
|
s1 = parse_tags("{a=100}")
|
||||||
s1 = ti.parse_tags("{a=100}")
|
|
||||||
self.assertEqual(s1.tag_dict['a'], "100")
|
self.assertEqual(s1.tag_dict['a'], "100")
|
||||||
|
|
||||||
s2 = ti.parse_tags("{b=This is a test} [option] $X=9")
|
s2 = parse_tags("{b=This is a test} [option] $X=9")
|
||||||
self.assertEqual(s2.tag_dict['b'], 'This is a test')
|
self.assertEqual(s2.tag_dict['b'], 'This is a test')
|
||||||
self.assertEqual(s2.tag_dict['option'], 'option')
|
self.assertEqual(s2.tag_dict['option'], 'option')
|
||||||
self.assertEqual(s2.tag_dict['X'], "9")
|
self.assertEqual(s2.tag_dict['X'], "9")
|
||||||
|
|
||||||
def test_modes(self):
|
def test_modes(self):
|
||||||
ti = TagInterpreter()
|
s1 = parse_tags("@ Monday Tuesday {a=1}")
|
||||||
s1 = ti.parse_tags("@ Monday Tuesday {a=1}")
|
self.assertEqual(s1.mode, TagPreModes.TIMESPAN)
|
||||||
self.assertEqual(s1.mode, 'Timespan')
|
|
||||||
|
|
||||||
s2 = ti.parse_tags("Monday Tuesday {a=1}")
|
s2 = parse_tags("Monday Tuesday {a=1}")
|
||||||
self.assertEqual(s2.mode, 'Normal')
|
self.assertEqual(s2.mode, TagPreModes.NORMAL)
|
||||||
|
|
||||||
s3 = ti.parse_tags("&Monday Tuesday {a=1}")
|
s3 = parse_tags("&Monday Tuesday {a=1}")
|
||||||
self.assertEqual(s3.mode, 'Append')
|
self.assertEqual(s3.mode, TagPreModes.APPEND)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import unittest
|
|||||||
import ptulsconv.docparser.tag_compiler
|
import ptulsconv.docparser.tag_compiler
|
||||||
from ptulsconv.docparser import doc_entity
|
from ptulsconv.docparser import doc_entity
|
||||||
from fractions import Fraction
|
from fractions import Fraction
|
||||||
import pprint
|
|
||||||
|
|
||||||
|
|
||||||
class TestTagCompiler(unittest.TestCase):
|
class TestTagCompiler(unittest.TestCase):
|
||||||
|
|||||||
Reference in New Issue
Block a user