# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2002 Ben Escoto <ben@emerose.org>
# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
#
# This file is part of duplicity.
#
# Duplicity is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# Duplicity 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
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with duplicity; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

import sys, os
testing = os.path.dirname(sys.argv[0])
newpath = os.path.abspath(os.path.join(testing, "../../."))
sys.path.insert(0, newpath)

import gettext
gettext.install('duplicity', codeset='utf8')

from duplicity import globals
from duplicity import log
from duplicity import backend
from duplicity.backends import localbackend

# config for duplicity unit tests

# verbosity, default is log.WARNING
verbosity = log.WARNING

# to test GPG and friends
# these must be without passwords
encrypt_key1 = ""
encrypt_key2 = ""

# password required on this one
sign_key = ""
sign_passphrase = ""

# URLs for testing
# NOTE: if the ***_url is None or "" the test
# is skipped and is noted in the test results.

file_url = "file:///tmp/testdup"
file_password = None

# To set up rsyncd for test:
# /etc/rsyncd.conf contains
# [testdup]
# path = /tmp/testdup
# comment = Test area for duplicity
# read only = false
#
# NOTE: chmod 777 /tmp/testdup

ftp_url = None
ftp_password = None

gs_url = None
gs_access_key = None
gs_secret_key = None

rsync_abspath_url = None
rsync_relpath_url = None
rsync_module_url = None
rsync_password = None

ssh_url = None
ssh_password = None

s3_url = None
s3_access_key = None
s3_secret_key = None

webdav_url = None
webdav_password = None

webdavs_url = None
webdavs_password = None

gdocs_url = None
gdocs_password = None

def setup():
    """ setup for unit tests """
    # The following is for starting remote debugging in Eclipse with Pydev.
    # Adjust the path to your location and version of Eclipse and Pydev.  Comment out
    # to run normally, or this process will hang at pydevd.settrace() waiting for the
    # remote debugger to start.
#    pysrc = "/opt/Aptana Studio 2/plugins/org.python.pydev.debug_2.1.0.2011052613/pysrc/"
#    sys.path.append(pysrc)
#    import pydevd #@UnresolvedImport
#    pydevd.settrace()
    # end remote debugger startup

    log.setup()
    log.setverbosity(verbosity)
    globals.print_statistics = 0

    globals.num_retries = 2

    backend.import_backends()

    set_environ("FTP_PASSWORD", None)
    set_environ("PASSPHRASE", None)
    if gs_access_key:
        set_environ("GS_ACCESS_KEY_ID", gs_access_key)
        set_environ("GS_SECRET_ACCESS_KEY", gs_secret_key)
    else:
        set_environ("GS_ACCESS_KEY_ID", None)
        set_environ("GS_SECRET_ACCESS_KEY", None)
    if s3_access_key:
        set_environ("AWS_ACCESS_KEY_ID", s3_access_key)
        set_environ("AWS_SECRET_ACCESS_KEY", s3_secret_key)
    else:
        set_environ("AWS_ACCESS_KEY_ID", None)
        set_environ("AWS_SECRET_ACCESS_KEY", None)


def set_environ(varname, value):
    if value is not None:
        os.environ[varname] = value
    else:
        try:
            del os.environ[varname]
        except Exception:
            pass
