Commit 06d6b6ab authored by Marcel's avatar Marcel
Browse files

Add convenience functions to fs.

parent fdc734ff
......@@ -263,27 +263,27 @@ class FileSystem(object):
if cut:
os.remove(target)
def save_file_content(self, path, content, force=True):
#check if file already exists
path = os.path.expandvars(os.path.expanduser(path))
# check if file already exists
if os.path.exists(path) and not force:
return False, "The file '%s' already exists!" % path
out = open(path, "w")
for line in content.data:
out.write(line)
return False
out = open(path, "wb")
out.write(content)
out.close()
return True, "File saved!"
return True
def get_file_content(self, path):
path = os.path.expandvars(os.path.expanduser(path))
f = open(path, "r")
content = f.read()
f.close()
if content == '':
content = ' '
return content
def get_mtime(self, path):
path = os.path.expandvars(os.path.expanduser(path))
return os.path.getmtime(path)
def is_browser_file(self, path):
extension = path.split(".")[-1]
return extension in FileSystem.BROWSER_EXTENSIONS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment