[pitivi] preset: Allow presets with slash chars in the name
- From: Jean-FranÃois Fortin Tam <jfft src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] preset: Allow presets with slash chars in the name
- Date: Tue, 13 Nov 2012 04:32:28 +0000 (UTC)
commit d9f3034333290a358625f5bae8c64c01cb4a27c0
Author: Alex BÄluÈ <alexandru balut gmail com>
Date: Mon Nov 12 16:57:06 2012 +0100
preset: Allow presets with slash chars in the name
pitivi/preset.py | 4 +++-
pitivi/utils/system.py | 8 ++++++++
tests/test_preset.py | 17 +++++++++++++++++
tests/test_system.py | 9 +++++++++
4 files changed, 37 insertions(+), 1 deletions(-)
---
diff --git a/pitivi/preset.py b/pitivi/preset.py
index dc453f2..c0006d4 100644
--- a/pitivi/preset.py
+++ b/pitivi/preset.py
@@ -31,6 +31,7 @@ from pitivi.render import available_muxers, available_video_encoders, available_
from pitivi.settings import xdg_data_home
from pitivi.utils.misc import isWritable
from pitivi.configure import get_renderpresets_dir, get_audiopresets_dir, get_videopresets_dir
+from pitivi.utils import system
class DuplicatePresetNameException(Exception):
@@ -65,6 +66,7 @@ class PresetManager(object):
self.cur_preset = None
# Whether to ignore the updateValue calls.
self._ignore_update_requests = False
+ self.system = system.getSystem()
def loadAll(self):
filepaths = []
@@ -99,7 +101,7 @@ class PresetManager(object):
try:
file_path = self.presets[preset_name]["filepath"]
except KeyError:
- file_name = preset_name + ".json"
+ file_name = self.system.getUniqueFilename(preset_name + ".json")
file_path = os.path.join(self.user_path, file_name)
self.presets[preset_name]["filepath"] = file_path
try:
diff --git a/pitivi/utils/system.py b/pitivi/utils/system.py
index eb404c8..3c70ea8 100644
--- a/pitivi/utils/system.py
+++ b/pitivi/utils/system.py
@@ -165,6 +165,14 @@ class System(Signallable, Loggable):
self.debug("desktopMessage(): %s, %s" % title % message)
pass
+ def getUniqueFilename(self, string):
+ """Get a filename which can only be obtained from the specified string.
+ @ivar string: the string to be translated.
+ @type string: str
+ @return: A filename which looks like the specified string.
+ """
+ return string.replace("%", "%37").replace("/", "%47")
+
class FreedesktopOrgSystem(System):
"""provides messaging capabilites for desktops that implement fd.o specs"""
diff --git a/tests/test_preset.py b/tests/test_preset.py
index c78bb1a..80dbff1 100644
--- a/tests/test_preset.py
+++ b/tests/test_preset.py
@@ -168,6 +168,23 @@ class TestAudioPresetsIO(TestCase):
other_manager = self.createOtherManager()
other_manager.loadAll()
+ self.assertEquals(1 + countDefaultPresets(other_manager), len(other_manager.presets))
snaaaake = other_manager.presets[non_ascii_preset_name]
self.assertEqual(snake, snaaaake)
+
+ def testInvalidFilenamesSaveAndLoad(self):
+ # This would be an invalid file name as is.
+ preset_name = " / % "
+ self.manager.addPreset(preset_name,
+ {"channels": 2,
+ "depth": 16,
+ "sample-rate": 44100})
+ values = self.manager.presets[preset_name]
+ self.assertEqual(3, len(values))
+ self.manager.saveAll()
+
+ other_manager = self.createOtherManager()
+ other_manager.loadAll()
self.assertEquals(1 + countDefaultPresets(other_manager), len(other_manager.presets))
+ other_values = other_manager.presets[preset_name]
+ self.assertEqual(values, other_values)
diff --git a/tests/test_system.py b/tests/test_system.py
index 40756fa..d23cd9e 100644
--- a/tests/test_system.py
+++ b/tests/test_system.py
@@ -6,6 +6,15 @@ class TestSystem(TestCase):
def setUp(self):
self.system = System()
+ def testGetUniqueFilename(self):
+ self.assertNotEqual(self.system.getUniqueFilename("a/b"),
+ self.system.getUniqueFilename("a%47b"))
+ self.assertNotEqual(self.system.getUniqueFilename("a%b"),
+ self.system.getUniqueFilename("a%37b"))
+ self.assertNotEqual(self.system.getUniqueFilename("a%/b"),
+ self.system.getUniqueFilename("a%37%3747b"))
+ self.assertEqual("a b", self.system.getUniqueFilename("a b"))
+
def testScreensaverInhibit(self):
#check that we start of uninhibited
self.assertTrue(not self.system.screensaverIsInhibited())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]