Not logged in

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

Overview
Comment:Move error checking to pyifbabel tool
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:7cc6c3a772f77da89cb713e0401fc061d1357104
User & Date: brandon 2018-10-09 19:37:38
Context
2018-10-13
16:38
Catch possible malformed XML check-in: 6dede47dbd user: brandon tags: trunk
2018-10-09
19:37
Move error checking to pyifbabel tool check-in: 7cc6c3a772 user: brandon tags: trunk
2018-10-06
20:35
Fix bug in which a handler initially chosen for the file extension is kept even if it does not claim the file. check-in: de5fe86a8e user: brandon tags: trunk
Changes

Changes to pyifbabel.in.

1
2
3
4
5
6
7
8
9
10
11
12
13
..
70
71
72
73
74
75
76

77


78
79
80
81
82
83
84
85
86
...
111
112
113
114
115
116
117

118


119
120
121
122
123
124
125
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!@PYTHON@
# -*- coding: utf-8 -*-
#
#       pyifbabel
#       
#       Copyright © 2012, 2013, 2014 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.
................................................................................
def print_ifids(in_file):
    ifids = babel.get_ifids(in_file)
    for ifid in ifids:
        print "IFID: {0}".format(ifid)


def print_format(in_file):

    ifformat = babel.deduce_format(in_file)


    print "Format: {0}".format(ifformat)
    

def extract_ifiction(in_file, to_dir):
    ifids = babel.get_ifids(in_file)
    if ifids is None:
        ifid = "UNKNOWN"
    else:
        ifid = ifids[0]
................................................................................
def identify_file(in_file):
    meta = babel.get_meta(in_file, True)
    ifids = babel.get_ifids(in_file)
    if ifids is None:
        ifid = "UNKNOWN"
    else:
        ifid = ifids[0]

    ifformat = babel.deduce_format(in_file)


    warning_line = ""
    if ifformat is None:
        warning_line_a = "Warning: Story format could not be positively "
        warning_line_b = "identified. Guessing executable"
        warning_line = "".join([warning_line_a, warning_line_b])
        ifformat = "executable"
    size = os.path.getsize(in_file) / 1024
................................................................................
        ifid = "UNKNOWN"
    else:
        ifid = ifids[0]
    story = babel.get_story(in_file)
    handler = babel.deduce_handler(in_file, story)
    ext = handler.get_story_file_extension(story)
    basename = "".join([ifid, ext])
    if to_dir is not None:    
        out_path = os.path.join(to_dir, basename)
    else:
        out_path = basename
    with open(out_path, 'wb') as out_handle:
        out_handle.write(story)







|







 







>
|
>
>

|







 







>
|
>
>







 







|







1
2
3
4
5
6
7
8
9
10
11
12
13
..
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
...
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
...
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!@PYTHON@
# -*- coding: utf-8 -*-
#
#       pyifbabel
#       
#       Copyright © 2012, 2013, 2014, 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.
................................................................................
def print_ifids(in_file):
    ifids = babel.get_ifids(in_file)
    for ifid in ifids:
        print "IFID: {0}".format(ifid)


def print_format(in_file):
    try:
        ifformat = babel.deduce_format(in_file)
    except:
        ifformat = "unknown"
    print "Format: {0}".format(ifformat)


def extract_ifiction(in_file, to_dir):
    ifids = babel.get_ifids(in_file)
    if ifids is None:
        ifid = "UNKNOWN"
    else:
        ifid = ifids[0]
................................................................................
def identify_file(in_file):
    meta = babel.get_meta(in_file, True)
    ifids = babel.get_ifids(in_file)
    if ifids is None:
        ifid = "UNKNOWN"
    else:
        ifid = ifids[0]
    try:
        ifformat = babel.deduce_format(in_file)
    except BabelError:
        ifformat = None
    warning_line = ""
    if ifformat is None:
        warning_line_a = "Warning: Story format could not be positively "
        warning_line_b = "identified. Guessing executable"
        warning_line = "".join([warning_line_a, warning_line_b])
        ifformat = "executable"
    size = os.path.getsize(in_file) / 1024
................................................................................
        ifid = "UNKNOWN"
    else:
        ifid = ifids[0]
    story = babel.get_story(in_file)
    handler = babel.deduce_handler(in_file, story)
    ext = handler.get_story_file_extension(story)
    basename = "".join([ifid, ext])
    if to_dir is not None:
        out_path = os.path.join(to_dir, basename)
    else:
        out_path = basename
    with open(out_path, 'wb') as out_handle:
        out_handle.write(story)


Changes to treatyofbabel/__init__.py.

1
2
3
4
5
6
7
8
9
10
...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# __init__.py ---

# Copyright (C) 2014 Brandon Invergo <brandon@invergo.net>

# Author: Brandon Invergo <brandon@invergo.net>

# This program 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.
................................................................................
        The name of the formt of the story, which could be blorbed

    """
    story_data = _get_story_data(story_file)
    if blorb.claim_story_file(story_data):
        story_format = blorb.get_story_format(story_data)
        return "blorbed {0}".format(story_format)
    try:
        handler = deduce_handler(story_file, story_data)
    except BabelError:
        return "unknown"
    return handler.get_format_name()


def get_ifids(story_file):
    """Get the IFID from a story file or from an ifiction file.

    Args:


|







 







<
|
<
<







1
2
3
4
5
6
7
8
9
10
...
122
123
124
125
126
127
128

129


130
131
132
133
134
135
136
# __init__.py ---

# Copyright (C) 2014, 2018 Brandon Invergo <brandon@invergo.net>

# Author: Brandon Invergo <brandon@invergo.net>

# This program 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.
................................................................................
        The name of the formt of the story, which could be blorbed

    """
    story_data = _get_story_data(story_file)
    if blorb.claim_story_file(story_data):
        story_format = blorb.get_story_format(story_data)
        return "blorbed {0}".format(story_format)

    handler = deduce_handler(story_file, story_data)


    return handler.get_format_name()


def get_ifids(story_file):
    """Get the IFID from a story file or from an ifiction file.

    Args: