Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add support for twine
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:15e453b6ab00e462af4b388f5d02c1d563f6da4a
User & Date: brandon 2018-10-13 19:15:07
Context
2018-10-13
19:19
Fix test failures check-in: 99400a7ff0 user: brandon tags: trunk
19:15
Add support for twine check-in: 15e453b6ab user: brandon tags: trunk
17:14
Fix extraction of PNG cover files from blorbs check-in: 0c718f8c4f user: brandon tags: trunk
Changes

Changes to tests/test_storyformat.py.

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
..
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class StoryTest(unittest.TestCase):
    def setUp(self, story_file_dir):
        self.test_stories = []
        self.babel_override = {}
        for story in os.listdir(story_file_dir):
            story_path = os.path.join(story_file_dir, story)
            self.test_stories.append(story_path)
    
    def test_format(self):
        for story_path in self.test_stories:
            story_override = self.babel_override.get(story_path)
            if story_override is not None:
                CBabel_format = story_override.get("format")
            else:
                babel_format_res = subprocess.check_output(['babel',
................................................................................
                                                          '-format',
                                                          story_path])
                CBabel_format = babel_format_res.split(':')[1].strip()
            ifformat = babel.deduce_format(story_path)
            self.assertEqual(ifformat, CBabel_format,
                             format_error(story_path, 'format',
                                          ifformat, CBabel_format))
    
    def test_ifid(self):
        for story_path in self.test_stories:
            story_override = self.babel_override.get(story_path)
            if story_override is not None:
                CBabel_ifids = story_override.get("ifids")
            else:
                babel_ifid_res = subprocess.check_output(['babel',







|







 







|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
..
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class StoryTest(unittest.TestCase):
    def setUp(self, story_file_dir):
        self.test_stories = []
        self.babel_override = {}
        for story in os.listdir(story_file_dir):
            story_path = os.path.join(story_file_dir, story)
            self.test_stories.append(story_path)

    def test_format(self):
        for story_path in self.test_stories:
            story_override = self.babel_override.get(story_path)
            if story_override is not None:
                CBabel_format = story_override.get("format")
            else:
                babel_format_res = subprocess.check_output(['babel',
................................................................................
                                                          '-format',
                                                          story_path])
                CBabel_format = babel_format_res.split(':')[1].strip()
            ifformat = babel.deduce_format(story_path)
            self.assertEqual(ifformat, CBabel_format,
                             format_error(story_path, 'format',
                                          ifformat, CBabel_format))

    def test_ifid(self):
        for story_path in self.test_stories:
            story_override = self.babel_override.get(story_path)
            if story_override is not None:
                CBabel_ifids = story_override.get("ifids")
            else:
                babel_ifid_res = subprocess.check_output(['babel',

Added tests/test_twine.py.



























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
#
#       test_twine.py
#
#       Copyright © 2018 Brandon Invergo <brandon@invergo.net>
#
#       This file is part of pyIFBable.
#
#       pyIFBabel is free software: you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation, either version 3 of the License, or
#       (at your option) any later version.
#
#       pyIFBabel is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with pyIFBabel.  If not, see <http://www.gnu.org/licenses/>.


import test_storyformat


class TwineTest(test_storyformat.StoryTest):
    def setUp(self):
        super(TwineTest, self).setUp('twine')
        self.babel_override = {
            "twine/abbess-otilias.html": {
                "format": 'twine',
                "ifids": ["94D68358-2F2B-4E24-825B-5558DD4EEC9E"]
            },
            "twine/Adventures_with_Fido.html": {
                "format": 'twine',
                "ifids": ["859229BD-CE3A-49F5-ABA3-D0C3FA572595"]
            },
            "twine/Animalia.html": {
                "format": 'twine',
                "ifids": ["AEA8DA1E-46F5-4C0E-BB7F-5E8ECC3C95E6"]
            }}


if __name__ == "__main__":
    unittest.main()

Changes to treatyofbabel/__init__.py.

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os.path
import xml.dom.minidom

import ifiction
from babelerrors import BabelError
from formats import (adrift, advsys, agt, alan, executable, glulx,
                     hugo, level9, magscrolls, quest, tads2, tads3,
                     zcode)
from wrappers import blorb

PYIFBABEL_VERSION = u"0.4"
TREATY_VERSION = u"9"
HANDLERS = [adrift, advsys, agt, alan, executable, glulx, hugo,
            level9, magscrolls, quest, tads2, tads3, zcode]
EXTENSION_MAP = {}


for h in HANDLERS:
    for ext in h.get_file_extensions():
        EXTENSION_MAP[ext] = h








|





|







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os.path
import xml.dom.minidom

import ifiction
from babelerrors import BabelError
from formats import (adrift, advsys, agt, alan, executable, glulx,
                     hugo, level9, magscrolls, quest, tads2, tads3,
                     twine, zcode)
from wrappers import blorb

PYIFBABEL_VERSION = u"0.4"
TREATY_VERSION = u"9"
HANDLERS = [adrift, advsys, agt, alan, executable, glulx, hugo,
            level9, magscrolls, quest, tads2, tads3, twine, zcode]
EXTENSION_MAP = {}


for h in HANDLERS:
    for ext in h.get_file_extensions():
        EXTENSION_MAP[ext] = h

Added treatyofbabel/formats/twine.py.





































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
#
#       twine.py
#
#       Copyright © 2018 Brandon Invergo <brandon@invergo.net>
#
#       This file is part of pyifbabel.
#
#       pyifbabel is free software: you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation, either version 3 of the License, or
#       (at your option) any later version.
#
#       pyifbabel is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with pyifbabel.  If not, see <http://www.gnu.org/licenses/>.

import re

FORMAT = "twine"
FORMAT_EXT = [".html", ".htm"]
HOME_PAGE = "http://www.twinery.org"
HAS_COVER = False
HAS_META = False


def get_format_name():
    return FORMAT


def get_story_file_extension(file_buffer):
    if claim_story_file(file_buffer):
        return ".html"
    else:
        return None


def get_home_page():
    return HOME_PAGE


def get_file_extensions():
    return FORMAT_EXT


def claim_story_file(file_buffer):
    return "tw-story" in file_buffer


def get_story_file_meta(file_buffer, truncate=False):
    return None


def get_story_file_cover(file_buffer):
    return None


def get_story_file_ifid(file_buffer):
    m = re.search(r'ifid="([A-Z0-9-]+)"', file_buffer)
    if m is None:
        return None
    return m.group(1)

Changes to treatyofbabel/ifiction.py.

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
BIBLIO_ATTR = ['title', 'author', 'language', 'headline',
               'firstpublished', 'genre', 'group', 'description',
               'series', 'seriesnumber', 'forgiveness']


IF_FORMATS = ["zcode", "glulx", "tads", "tads2", "tads3", "hugo", "alan",
              "adrift", "level9", "agt", "magscrolls", "advsys", "executable",
              "quest", "html"]


TOP_LEVELS = ["identification", "bibliographic", "resources", "contact",
              "cover art", "zcode", "tads2", "tads3", "glulx", "hugo",
              "adrift", "releases", "colophon", "annotation"]









|







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
BIBLIO_ATTR = ['title', 'author', 'language', 'headline',
               'firstpublished', 'genre', 'group', 'description',
               'series', 'seriesnumber', 'forgiveness']


IF_FORMATS = ["zcode", "glulx", "tads", "tads2", "tads3", "hugo", "alan",
              "adrift", "level9", "agt", "magscrolls", "advsys", "executable",
              "quest", "html", "twine"]


TOP_LEVELS = ["identification", "bibliographic", "resources", "contact",
              "cover art", "zcode", "tads2", "tads3", "glulx", "hugo",
              "adrift", "releases", "colophon", "annotation"]