[pitivi] settings: Allow xdg_* methods to receive subdirs
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] settings: Allow xdg_* methods to receive subdirs
- Date: Fri, 7 Feb 2020 15:42:45 +0000 (UTC)
commit 71b26de1b45dd9735dbaa9d5be46d8fcd375f493
Author: Vivek R <123vivekr gmail com>
Date: Sat Feb 1 10:48:27 2020 +0530
settings: Allow xdg_* methods to receive subdirs
Since each xdg_* method already calls get_dir, there is no need to call
it separately.
pitivi/application.py | 3 +--
pitivi/preset.py | 4 ++--
pitivi/project.py | 4 +---
pitivi/settings.py | 27 +++++++++++++++------------
pitivi/shortcuts.py | 3 +--
pitivi/timeline/previewers.py | 5 ++---
6 files changed, 22 insertions(+), 24 deletions(-)
---
diff --git a/pitivi/application.py b/pitivi/application.py
index c6d85097..86079e4b 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -32,7 +32,6 @@ from pitivi.effects import EffectsManager
from pitivi.mainwindow import MainWindow
from pitivi.pluginmanager import PluginManager
from pitivi.project import ProjectManager
-from pitivi.settings import get_dir
from pitivi.settings import GlobalSettings
from pitivi.settings import xdg_cache_home
from pitivi.shortcuts import ShortcutsManager
@@ -247,7 +246,7 @@ class Pitivi(Gtk.Application, Loggable):
if 'PITIVI_SCENARIO_FILE' in os.environ:
scenario_path = os.environ['PITIVI_SCENARIO_FILE']
else:
- cache_dir = get_dir(os.path.join(xdg_cache_home(), "scenarios"))
+ cache_dir = xdg_cache_home("scenarios")
scenario_name = str(time.strftime("%Y%m%d-%H%M%S"))
if project_path:
scenario_name += os.path.splitext(project_path.replace(os.sep, "_"))[0]
diff --git a/pitivi/preset.py b/pitivi/preset.py
index 81cb0ea4..d0db955e 100644
--- a/pitivi/preset.py
+++ b/pitivi/preset.py
@@ -425,7 +425,7 @@ class VideoPresetManager(PresetManager):
def __init__(self, system):
default_path = get_videopresets_dir()
- user_path = os.path.join(xdg_data_home(), 'video_presets')
+ user_path = xdg_data_home("video_presets")
PresetManager.__init__(self, default_path, user_path, system)
def _deserialize_preset(self, parser):
@@ -461,7 +461,7 @@ class AudioPresetManager(PresetManager):
def __init__(self, system):
default_path = get_audiopresets_dir()
- user_path = os.path.join(xdg_data_home(), 'audio_presets')
+ user_path = xdg_data_home("audio_presets")
PresetManager.__init__(self, default_path, user_path, system)
def _deserialize_preset(self, parser):
diff --git a/pitivi/project.py b/pitivi/project.py
index 1b930a96..bcff66df 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -41,7 +41,6 @@ from pitivi.medialibrary import AssetThumbnail
from pitivi.preset import AudioPresetManager
from pitivi.preset import VideoPresetManager
from pitivi.render import Encoders
-from pitivi.settings import get_dir
from pitivi.settings import xdg_cache_home
from pitivi.timeline.previewers import Previewer
from pitivi.timeline.previewers import ThumbnailCache
@@ -826,8 +825,7 @@ class Project(Loggable, GES.Project):
def get_thumb_path(uri, resolution):
"""Returns path of thumbnail of specified resolution in the cache."""
thumb_hash = md5(quote_uri(uri).encode()).hexdigest()
- thumbs_cache_dir = get_dir(os.path.join(xdg_cache_home(),
- "project_thumbs", resolution))
+ thumbs_cache_dir = xdg_cache_home("project_thumbs", resolution)
return os.path.join(thumbs_cache_dir, thumb_hash) + ".png"
@classmethod
diff --git a/pitivi/settings.py b/pitivi/settings.py
index 43469e01..fbbc042b 100644
--- a/pitivi/settings.py
+++ b/pitivi/settings.py
@@ -64,25 +64,28 @@ def get_dir(path, autocreate=True):
return path
-def xdg_config_home(autocreate=True):
+def xdg_config_home(*subdirs):
"""Gets the directory for storing the user's Pitivi configuration."""
- default = os.path.join(GLib.get_user_config_dir(), "pitivi")
- path = os.getenv("PITIVI_USER_CONFIG_DIR", default)
- return get_dir(path, autocreate)
+ default_base = os.path.join(GLib.get_user_config_dir(), "pitivi")
+ base = os.getenv("PITIVI_USER_CONFIG_DIR", default_base)
+ path = os.path.join(base, *subdirs)
+ return get_dir(path, autocreate=True)
-def xdg_data_home(autocreate=True):
+def xdg_data_home(*subdirs):
"""Gets the directory for storing the user's data: presets, plugins, etc."""
- default = os.path.join(GLib.get_user_data_dir(), "pitivi")
- path = os.getenv("PITIVI_USER_DATA_DIR", default)
- return get_dir(path, autocreate)
+ default_base = os.path.join(GLib.get_user_data_dir(), "pitivi")
+ base = os.getenv("PITIVI_USER_DATA_DIR", default_base)
+ path = os.path.join(base, *subdirs)
+ return get_dir(path, autocreate=True)
-def xdg_cache_home(autocreate=True):
+def xdg_cache_home(*subdirs):
"""Gets the Pitivi cache directory."""
- default = os.path.join(GLib.get_user_cache_dir(), "pitivi")
- path = os.getenv("PITIVI_USER_CACHE_DIR", default)
- return get_dir(path, autocreate)
+ default_base = os.path.join(GLib.get_user_cache_dir(), "pitivi")
+ base = os.getenv("PITIVI_USER_CACHE_DIR", default_base)
+ path = os.path.join(base, *subdirs)
+ return get_dir(path, autocreate=True)
class ConfigError(Exception):
diff --git a/pitivi/shortcuts.py b/pitivi/shortcuts.py
index c4445eec..454de6ed 100644
--- a/pitivi/shortcuts.py
+++ b/pitivi/shortcuts.py
@@ -39,8 +39,7 @@ class ShortcutsManager(GObject.Object):
self.group_actions = {}
self.default_accelerators = {}
self.titles = {}
- self.config_path = os.path.sep.join([xdg_config_home(),
- "shortcuts.conf"])
+ self.config_path = os.path.join(xdg_config_home(), "shortcuts.conf")
self.__loaded_actions = list(self.__load())
@property
diff --git a/pitivi/timeline/previewers.py b/pitivi/timeline/previewers.py
index c6b6e822..0660df63 100644
--- a/pitivi/timeline/previewers.py
+++ b/pitivi/timeline/previewers.py
@@ -30,7 +30,6 @@ from gi.repository import GObject
from gi.repository import Gst
from gi.repository import Gtk
-from pitivi.settings import get_dir
from pitivi.settings import GlobalSettings
from pitivi.settings import xdg_cache_home
from pitivi.utils.loggable import Loggable
@@ -942,7 +941,7 @@ class ThumbnailCache(Loggable):
def dbfile_name(uri):
"""Returns the cache file path for the specified URI."""
filename = hash_file(Gst.uri_get_location(uri))
- thumbs_cache_dir = get_dir(os.path.join(xdg_cache_home(), "thumbs"))
+ thumbs_cache_dir = xdg_cache_home("thumbs")
return os.path.join(thumbs_cache_dir, filename)
@classmethod
@@ -1076,7 +1075,7 @@ def get_wavefile_location_for_uri(uri):
if ProxyManager.is_proxy_asset(uri):
uri = ProxyManager.get_target_uri(uri)
filename = hash_file(Gst.uri_get_location(uri)) + ".wave.npy"
- cache_dir = get_dir(os.path.join(xdg_cache_home(), "waves"))
+ cache_dir = xdg_cache_home("waves")
return os.path.join(cache_dir, filename)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]