[pitivi] preset: Reuse serialization logic
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] preset: Reuse serialization logic
- Date: Wed, 25 Nov 2015 09:55:37 +0000 (UTC)
commit 554b065ff4e62ff83d63cb09d06870e4985b8f59
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Wed Nov 25 01:04:13 2015 +0100
preset: Reuse serialization logic
Differential Revision: https://phabricator.freedesktop.org/D364
Reviewed-by: Thibault Saunier <tsaunier gnome org>
pitivi/preset.py | 77 ++++++++++++++++++++------------------------------
tests/test_preset.py | 4 +-
2 files changed, 33 insertions(+), 48 deletions(-)
---
diff --git a/pitivi/preset.py b/pitivi/preset.py
index ca6842f..6afe933 100644
--- a/pitivi/preset.py
+++ b/pitivi/preset.py
@@ -108,7 +108,11 @@ class PresetManager(Loggable):
file_path = os.path.join(self.user_path, file_name)
self.presets[preset_name]["filepath"] = file_path
with open(file_path, "w") as fout:
- self._saveSection(fout, preset_name)
+ values = self.presets[preset_name]
+ raw = self._serializePreset(values)
+ raw["name"] = preset_name
+ serialized = json.dumps(raw, indent=4)
+ fout.write(serialized)
def getUniqueName(self, first=_("Custom"), second=_("Custom %d")):
name = first
@@ -310,16 +314,6 @@ class PresetManager(Loggable):
return False
return True
- def _saveSection(self, fout, section):
- """Save the specified section into the specified file.
-
- @param fout: The file where to save the section.
- @type parser: file
- @param section: The name of the section to be saved.
- @type section: string
- """
- raise NotImplementedError()
-
def _projectToPreset(self, project):
raise NotImplementedError()
@@ -367,18 +361,15 @@ class VideoPresetManager(PresetManager):
"filepath": filepath,
})
- def _saveSection(self, fout, section):
- values = self.presets[section]
- data = json.dumps({
- "name": section,
- "width": int(values["width"]),
- "height": int(values["height"]),
- "framerate-num": values["frame-rate"].num,
- "framerate-denom": values["frame-rate"].denom,
- "par-num": values["par"].num,
- "par-denom": values["par"].denom,
- }, indent=4)
- fout.write(data)
+ def _serializePreset(self, preset):
+ return {
+ "width": int(preset["width"]),
+ "height": int(preset["height"]),
+ "framerate-num": preset["frame-rate"].num,
+ "framerate-denom": preset["frame-rate"].denom,
+ "par-num": preset["par"].num,
+ "par-denom": preset["par"].denom,
+ }
def _projectToPreset(self, project):
return {
@@ -409,14 +400,11 @@ class AudioPresetManager(PresetManager):
"filepath": filepath,
})
- def _saveSection(self, fout, section):
- values = self.presets[section]
- data = json.dumps({
- "name": section,
- "channels": values["channels"],
- "sample-rate": int(values["sample-rate"]),
- }, indent=4)
- fout.write(data)
+ def _serializePreset(self, preset):
+ return {
+ "channels": preset["channels"],
+ "sample-rate": int(preset["sample-rate"]),
+ }
def _projectToPreset(self, project):
return {
@@ -473,18 +461,15 @@ class RenderPresetManager(PresetManager):
"filepath": filepath,
})
- def _saveSection(self, fout, section):
- values = self.presets[section]
- data = json.dumps({
- "name": section,
- "container": str(values["container"]),
- "acodec": str(values["acodec"]),
- "vcodec": str(values["vcodec"]),
- "width": int(values["width"]),
- "height": int(values["height"]),
- "framerate-num": values["frame-rate"].num,
- "framerate-denom": values["frame-rate"].denom,
- "channels": values["channels"],
- "sample-rate": int(values["sample-rate"]),
- }, indent=4)
- fout.write(data)
+ def _serializePreset(self, preset):
+ return {
+ "container": str(preset["container"]),
+ "acodec": str(preset["acodec"]),
+ "vcodec": str(preset["vcodec"]),
+ "width": int(preset["width"]),
+ "height": int(preset["height"]),
+ "framerate-num": preset["frame-rate"].num,
+ "framerate-denom": preset["frame-rate"].denom,
+ "channels": preset["channels"],
+ "sample-rate": int(preset["sample-rate"]),
+ }
diff --git a/tests/test_preset.py b/tests/test_preset.py
index 7e56d3e..8fff9bf 100644
--- a/tests/test_preset.py
+++ b/tests/test_preset.py
@@ -38,8 +38,8 @@ class FakePresetManager(PresetManager):
def __init__(self, default_path):
PresetManager.__init__(self, default_path, tempfile.mkdtemp())
- def _saveSection(self, fout, section):
- pass
+ def _serializePreset(self, preset):
+ return dict(preset.items())
def clearPresetManagerPaths(preset_manager):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]