aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools
diff options
context:
space:
mode:
authorBoris Bobrov <breton@cynicmansion.ru>2018-07-10 18:29:30 +0200
committerBoris Bobrov <breton@cynicmansion.ru>2018-07-10 18:29:30 +0200
commite08de70757b6f973bc2955f1b3292d383a19b21d (patch)
treef60ad20e55538e1945cbc61284b09540dd601975 /mediagoblin/tools
parent588162b861f4993ee8412b14601b215505134bfc (diff)
parent7ab18019782b285a5bf9fc79227e0d0d4896398a (diff)
downloadmediagoblin-e08de70757b6f973bc2955f1b3292d383a19b21d.tar.lz
mediagoblin-e08de70757b6f973bc2955f1b3292d383a19b21d.tar.xz
mediagoblin-e08de70757b6f973bc2955f1b3292d383a19b21d.zip
Merge remote-tracking branch 'gsoc2016/Subtitle-1'
Diffstat (limited to 'mediagoblin/tools')
-rw-r--r--mediagoblin/tools/files.py7
-rw-r--r--mediagoblin/tools/subtitles.py20
2 files changed, 27 insertions, 0 deletions
diff --git a/mediagoblin/tools/files.py b/mediagoblin/tools/files.py
index 2c486ac8..0509a387 100644
--- a/mediagoblin/tools/files.py
+++ b/mediagoblin/tools/files.py
@@ -41,5 +41,12 @@ def delete_media_files(media):
except OSError:
no_such_files.append("/".join(attachment['filepath']))
+ for subtitle in media.subtitle_files:
+ try:
+ mg_globals.public_store.delete_file(
+ subtitle['filepath'])
+ except OSError:
+ no_such_files.append("/".join(subtitle['filepath']))
+
if no_such_files:
raise OSError(", ".join(no_such_files))
diff --git a/mediagoblin/tools/subtitles.py b/mediagoblin/tools/subtitles.py
new file mode 100644
index 00000000..efafbeec
--- /dev/null
+++ b/mediagoblin/tools/subtitles.py
@@ -0,0 +1,20 @@
+import os
+
+def get_path(path):
+ temp = ['user_dev','media','public']
+ path = list(eval(path))
+ file_path = os.path.abspath(__file__).split('/') # Path of current file as dictionary
+ subtitle_path = file_path[:-3] + temp + path # Creating the absolute path for the subtitle file
+ subtitle_path = "/" + os.path.join(*subtitle_path)
+ return subtitle_path
+
+def open_subtitle(path):
+ subtitle_path = get_path(path)
+ subtitle = open(subtitle_path,"r") # Opening the file using the absolute path
+ text = subtitle.read()
+ return text
+
+def save_subtitle(path,text):
+ subtitle_path = get_path(path)
+ subtitle = open(subtitle_path,"w") # Opening the file using the absolute path
+ subtitle.write(text) \ No newline at end of file