23
23
High-level tools for using Formatters
26
from gettext import gettext as _
26
28
# FIXME : We need a registry of all available formatters
28
def load_project(uri, formatter=None, missinguricallback=None):
30
Load the project from the given location.
32
If specified, use the given formatter.
35
@param uri: The location of the project. Needs to be an
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
50
raise NotImplementedError
52
def save_project(project, uri, formatter=None, overwrite=False):
54
Save the L{Project} to the given location.
56
If specified, use the given formatter.
58
@type project: L{Project}
59
@param project: The L{Project} to save.
61
@param uri: The location to store the project to. Needs to
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.
70
@see: L{Formatter.saveProject}
74
formatter == project.format
76
from pitivi.formatters.etree import ElementTreeFormatter
77
formatter = ElementTreeFormatter()
78
formatter.saveProject(project, uri, overwrite)
80
32
def can_handle_location(uri):
100
52
file formats, where name is a user-readable name, and extensions is a
101
53
sequence of extensions for this format ('.' omitted).
103
from pitivi.formatters.etree import ElementTreeFormatter
104
from pitivi.formatters.playlist import PlaylistFormatter
106
(ElementTreeFormatter, "PiTiVi Native (XML)", ('xptv',)),
107
(PlaylistFormatter, "Playlist format", ('pls', ))
110
57
def get_formatter_for_uri(uri):
115
62
@param uri: The location of the project file
116
63
@return: an instance of a Formatter, or None
118
from pitivi.formatters.etree import ElementTreeFormatter
120
for klass, name, exts in list_formats():
65
for klass, name, exts in _formatters:
121
66
if klass.canHandle(uri):
69
def register_formatter(klass, name, extensions):
70
_formatters.append((klass, name, extensions))
72
# register known formatters
74
from pitivi.formatters.etree import ElementTreeFormatter
75
from pitivi.formatters.playlist import PlaylistFormatter
77
register_formatter(ElementTreeFormatter, _("PiTiVi Native (XML)"), ('xptv',))
78
register_formatter(PlaylistFormatter, _("Playlist format"), ('pls', 'm3u'))