From 5b42f9341a92344245dd503d2c128670d8097e22 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Sat, 16 Jul 2016 09:44:21 +0000 Subject: Removed dependence on absolute path for editing --- mediagoblin/plugins/custom_subtitles/tools.py | 47 +++++++++++++++++++-------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'mediagoblin/plugins/custom_subtitles/tools.py') diff --git a/mediagoblin/plugins/custom_subtitles/tools.py b/mediagoblin/plugins/custom_subtitles/tools.py index efafbeec..2cc5157f 100644 --- a/mediagoblin/plugins/custom_subtitles/tools.py +++ b/mediagoblin/plugins/custom_subtitles/tools.py @@ -1,20 +1,41 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from mediagoblin import mg_globals 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 + path = eval(path) # Converting string to a tuple + return 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 + subtitle_public_filepath = get_path(path) + subtitle_public_file = mg_globals.public_store.get_file( + subtitle_public_filepath, 'rb') + try: + text = subtitle_public_file.read().decode('utf-8') + return text + finally: + subtitle_public_file.close() 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 + subtitle_public_filepath = get_path(path) + subtitle_public_file = mg_globals.public_store.get_file( + subtitle_public_filepath, 'wb') + try: + subtitle_public_file.write(text) + finally: + subtitle_public_file.close() \ No newline at end of file -- cgit v1.2.3