diff options
Diffstat (limited to 'mediagoblin/tools')
-rw-r--r-- | mediagoblin/tools/files.py | 7 | ||||
-rw-r--r-- | mediagoblin/tools/subtitles.py | 20 |
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 |