Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Fixed problems related with hardcoded forward slashes #9

Merged
merged 2 commits into from
Jul 31, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions flask_alchemydumps/helpers/backup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# coding: utf-8

import os
from os.path import abspath
import gzip
import re
from datetime import datetime
Expand All @@ -9,7 +11,6 @@
from time import gmtime, strftime
from unipath import Path


class Backup(object):
"""Manages backup files through local or FTP file systems"""

Expand Down Expand Up @@ -147,14 +148,18 @@ def __get_path(self):
:return: Unipath if local, string if FTP
"""
if self.ftp:
return 'ftp://{}{}'.format(self.ftp_server,
self.__slashes(self.ftp_path))
return 'ftp://{}/{}/'.format(self.ftp_server, re.sub(r'/$', '', self.ftp_path))
else:
basedir = current_app.extensions['alchemydumps'].basedir
backup_dir = basedir.child('alchemydumps')
if not backup_dir.exists():
backup_dir.mkdir()
return self.__slashes(str(backup_dir.absolute()))

path = abspath(str(backup_dir.absolute()))
if path.endswith(os.sep):
return path
else:
return path + os.sep

def __get_ftp(self):

Expand Down Expand Up @@ -184,11 +189,9 @@ def __get_ftp(self):
return False

@staticmethod
def __slashes(string):
"""Adds, if needed, a slash to the beginning and ending of a string"""
if string and len(string) > 1:
if string[0:1] != '/':
string = '/{}'.format(string)
if string[-1] != '/':
string = '{}/'.format(string)
return string
def __ensure_os_absolute_path(path):
"""Ensure the selected path is a folder path
"""
if path and len(path) > 1:
return abspath(path) + os.sep
return path