~ubuntu-branches/ubuntu/trusty/pitivi/trusty

« back to all changes in this revision

Viewing changes to pitivi/formatters/format.py

* New upstream pre-release:
  + debian/control:
    - Update dependencies.
* debian/control:
  + Update Standards-Version to 3.8.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
High-level tools for using Formatters
24
24
"""
25
25
 
 
26
from gettext import gettext as _
 
27
 
26
28
# FIXME : We need a registry of all available formatters
27
29
 
28
 
def load_project(uri, formatter=None, missinguricallback=None):
29
 
    """
30
 
    Load the project from the given location.
31
 
 
32
 
    If specified, use the given formatter.
33
 
 
34
 
    @type uri: L{str}
35
 
    @param uri: The location of the project. Needs to be an
36
 
    absolute URI.
37
 
    @type formatter: L{Formatter}
38
 
    @param formatter: If specified, try loading the project with that
39
 
    L{Formatter}. If not specified, will try all available L{Formatter}s.
40
 
    @raise FormatterLoadError: If the location couldn't be properly loaded.
41
 
    @param missinguricallback: A callback that will be used if some
42
 
    files to load can't be found anymore. The callback shall call the
43
 
    formatter's addMapping() method with the moved location.
44
 
    @type missinguricallback: C{callable}
45
 
    @return: The project. The caller needs to ensure the loading is
46
 
    finished before using it. See the 'loaded' property and signal of
47
 
    L{Project}.
48
 
    @rtype: L{Project}.
49
 
    """
50
 
    raise NotImplementedError
51
 
 
52
 
def save_project(project, uri, formatter=None, overwrite=False):
53
 
    """
54
 
    Save the L{Project} to the given location.
55
 
 
56
 
    If specified, use the given formatter.
57
 
 
58
 
    @type project: L{Project}
59
 
    @param project: The L{Project} to save.
60
 
    @type uri: L{str}
61
 
    @param uri: The location to store the project to. Needs to
62
 
    be an absolute URI.
63
 
    @type formatter: L{Formatter}
64
 
    @param formatter: The L{Formatter} to use to store the project if specified.
65
 
    If it is not specified, then it will be saved at its original format.
66
 
    @param overwrite: Whether to overwrite existing location.
67
 
    @type overwrite: C{bool}
68
 
    @raise FormatterSaveError: If the file couldn't be properly stored.
69
 
 
70
 
    @see: L{Formatter.saveProject}
71
 
    """
72
 
    if formatter == None:
73
 
        if project.format:
74
 
            formatter == project.format
75
 
        else:
76
 
            from pitivi.formatters.etree import ElementTreeFormatter
77
 
            formatter = ElementTreeFormatter()
78
 
    formatter.saveProject(project, uri, overwrite)
 
30
_formatters = []
79
31
 
80
32
def can_handle_location(uri):
81
33
    """
88
40
    @rtype: L{bool}
89
41
    """
90
42
 
91
 
    for klass, name, exts in list_formats():
 
43
    for klass, name, exts in _formatters:
92
44
        if klass.canHandle(uri):
93
45
            return True
94
46
 
100
52
    file formats, where name is a user-readable name, and extensions is a
101
53
    sequence of extensions for this format ('.' omitted).
102
54
    """
103
 
    from pitivi.formatters.etree import ElementTreeFormatter
104
 
    from pitivi.formatters.playlist import PlaylistFormatter
105
 
    return [
106
 
        (ElementTreeFormatter, "PiTiVi Native (XML)", ('xptv',)),
107
 
        (PlaylistFormatter, "Playlist format", ('pls', ))
108
 
        ]
 
55
    return _formatters
109
56
 
110
57
def get_formatter_for_uri(uri):
111
58
    """
115
62
    @param uri: The location of the project file
116
63
    @return: an instance of a Formatter, or None
117
64
    """
118
 
    from pitivi.formatters.etree import ElementTreeFormatter
119
 
 
120
 
    for klass, name, exts in list_formats():
 
65
    for klass, name, exts in _formatters:
121
66
        if klass.canHandle(uri):
122
67
            return klass()
 
68
 
 
69
def register_formatter(klass, name, extensions):
 
70
    _formatters.append((klass, name, extensions))
 
71
 
 
72
# register known formatters
 
73
 
 
74
from pitivi.formatters.etree import ElementTreeFormatter
 
75
from pitivi.formatters.playlist import PlaylistFormatter
 
76
 
 
77
register_formatter(ElementTreeFormatter, _("PiTiVi Native (XML)"), ('xptv',))
 
78
register_formatter(PlaylistFormatter, _("Playlist format"), ('pls', 'm3u'))