# Path: dput/core.py
# CONFIG_LOCATIONS = {
#     "/usr/share/dput-ng/": 30,
#     "/etc/dput.d/": 20,
#     os.path.expanduser("~/.dput.d"): 10,
#     "skel/": 100
# }
# DPUT_CONFIG_LOCATIONS = {
#     "/etc/dput.cf": 15,
#     os.path.expanduser("~/.dput.cf"): 5
# }
# SCHEMA_DIRS = [
#     "/usr/share/dput-ng/schemas",
#     "skel/schemas"
# ]
# def _write_upload_log(logfile, full_log):
# def _enable_debugging(level):
# def mangle_sys():
# def maybe_print_traceback(debug_level, stack):
# def get_local_username():
# 
# Path: dput/uploader.py
# class AbstractUploader(object):
#     """
#     Abstract base class for all concrete uploader implementations.
#     """
# 
#     __metaclass__ = abc.ABCMeta
# 
#     def __init__(self, profile):
#         self._config = profile
#         interface = 'cli'
#         if 'interface' in profile:
#             interface = profile['interface']
#         logger.trace("Using interface %s" % (interface))
#         interface_obj = get_obj('interfaces', interface)
#         if interface_obj is None:
#             raise DputConfigurationError("No such interface: `%s'" % (
#                 interface
#             ))
#         self.interface = interface_obj()
#         self.interface.initialize()
# 
#     def _pre_hook(self):
#         self._run_hook("pre_upload_command")
# 
#     def _post_hook(self):
#         self._run_hook("post_upload_command")
# 
#     def _run_hook(self, hook):
#         if hook in self._config and self._config[hook] != "":
#             cmd = self._config[hook]
#             (output, stderr, ret) = run_command(cmd)
#             if ret == -1:
#                 if not os.path.exists(cmd):
#                     logger.warning(
#                         "Error: You've set a hook (%s) to run (`%s`), "
#                         "but it can't be found (and doesn't appear to exist)."
#                         " Please verify the path and correct it." % (
#                             hook,
#                             self._config[hook]
#                         )
#                     )
#                     return
# 
#             sys.stdout.write(output)  # XXX: Fixme
#             sys.stdout.flush()
#             if ret != 0:
#                 raise DputError(
#                     "Command `%s' returned an error: %s [err=%d]" % (
#                         self._config[hook],
#                         stderr,
#                         ret
#                     )
#                 )
# 
#     def __del__(self):
#         self.interface.shutdown()
# 
#     def upload_write_error(self, e):
#         """
#         .. warning::
#            don't call this.
# 
#         please don't call this
#         """
#         # XXX: Refactor this, please god, refactor this.
#         logger.warning("""Upload permissions error
# 
# You either don't have the rights to upload a file, or, if this is on
# ftp-master, you may have tried to overwrite a file already on the server.
# 
# Continuing anyway in case you want to recover from an incomplete upload.
# No file was uploaded, however.""")
# 
#     @abc.abstractmethod
#     def initialize(self, **kwargs):
#         """
#         Setup the things needed to upload a file. Usually this means creating
#         a network connection & authenticating.
#         """
#         pass
# 
#     @abc.abstractmethod
#     def upload_file(self, filename, upload_filename=None):
#         """
#         Upload a single file (``filename``) to the server.
#         """
#         pass
# 
#     @abc.abstractmethod
#     def shutdown(self):
#         """
#         Disconnect and shutdown.
#         """
#         pass
# 
# Path: dput/exceptions.py
# class UploadException(DputError):
#     """
#     Thrown when there's an error uploading, or creating an uploader. Usually
#     thrown by a subclass of the :class:`dput.uploader.AbstractUploader`
#     """
#     pass


import ftplib
import os.path
from dput.core import logger
from dput.uploader import AbstractUploader
from dput.exceptions import UploadException
# This program 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.
#
# 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
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""
FTP Uploader implementation.
"""




class FtpUploadException(UploadException):
    """
    Thrown in the event of a problem connecting, uploading to or
    terminating the connection with the remote server. This is
    a subclass of :class:`dput.exceptions.UploadException`.
    """
    pass



# Path: dput/core.py
# CONFIG_LOCATIONS = {
#     "/usr/share/dput-ng/": 30,
#     "/etc/dput.d/": 20,
#     os.path.expanduser("~/.dput.d"): 10,
#     "skel/": 100
# }
# DPUT_CONFIG_LOCATIONS = {
#     "/etc/dput.cf": 15,
#     os.path.expanduser("~/.dput.cf"): 5
# }
# SCHEMA_DIRS = [
#     "/usr/share/dput-ng/schemas",
#     "skel/schemas"
# ]
# def _write_upload_log(logfile, full_log):
# def _enable_debugging(level):
# def mangle_sys():
# def maybe_print_traceback(debug_level, stack):
# def get_local_username():
# 
# Path: dput/uploader.py
# class AbstractUploader(object):
#     """
#     Abstract base class for all concrete uploader implementations.
#     """
# 
#     __metaclass__ = abc.ABCMeta
# 
#     def __init__(self, profile):
#         self._config = profile
#         interface = 'cli'
#         if 'interface' in profile:
#             interface = profile['interface']
#         logger.trace("Using interface %s" % (interface))
#         interface_obj = get_obj('interfaces', interface)
#         if interface_obj is None:
#             raise DputConfigurationError("No such interface: `%s'" % (
#                 interface
#             ))
#         self.interface = interface_obj()
#         self.interface.initialize()
# 
#     def _pre_hook(self):
#         self._run_hook("pre_upload_command")
# 
#     def _post_hook(self):
#         self._run_hook("post_upload_command")
# 
#     def _run_hook(self, hook):
#         if hook in self._config and self._config[hook] != "":
#             cmd = self._config[hook]
#             (output, stderr, ret) = run_command(cmd)
#             if ret == -1:
#                 if not os.path.exists(cmd):
#                     logger.warning(
#                         "Error: You've set a hook (%s) to run (`%s`), "
#                         "but it can't be found (and doesn't appear to exist)."
#                         " Please verify the path and correct it." % (
#                             hook,
#                             self._config[hook]
#                         )
#                     )
#                     return
# 
#             sys.stdout.write(output)  # XXX: Fixme
#             sys.stdout.flush()
#             if ret != 0:
#                 raise DputError(
#                     "Command `%s' returned an error: %s [err=%d]" % (
#                         self._config[hook],
#                         stderr,
#                         ret
#                     )
#                 )
# 
#     def __del__(self):
#         self.interface.shutdown()
# 
#     def upload_write_error(self, e):
#         """
#         .. warning::
#            don't call this.
# 
#         please don't call this
#         """
#         # XXX: Refactor this, please god, refactor this.
#         logger.warning("""Upload permissions error
# 
# You either don't have the rights to upload a file, or, if this is on
# ftp-master, you may have tried to overwrite a file already on the server.
# 
# Continuing anyway in case you want to recover from an incomplete upload.
# No file was uploaded, however.""")
# 
#     @abc.abstractmethod
#     def initialize(self, **kwargs):
#         """
#         Setup the things needed to upload a file. Usually this means creating
#         a network connection & authenticating.
#         """
#         pass
# 
#     @abc.abstractmethod
#     def upload_file(self, filename, upload_filename=None):
#         """
#         Upload a single file (``filename``) to the server.
#         """
#         pass
# 
#     @abc.abstractmethod
#     def shutdown(self):
#         """
#         Disconnect and shutdown.
#         """
#         pass
# 
# Path: dput/exceptions.py
# class UploadException(DputError):
#     """
#     Thrown when there's an error uploading, or creating an uploader. Usually
#     thrown by a subclass of the :class:`dput.uploader.AbstractUploader`
#     """
#     pass


# Path: dput/uploaders/ftp.py
import ftplib
import os.path
from dput.core import logger
from dput.uploader import AbstractUploader
from dput.exceptions import UploadException

# This program 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.
#
# 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
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""
FTP Uploader implementation.
"""




class FtpUploadException(UploadException):
    """
    Thrown in the event of a problem connecting, uploading to or
    terminating the connection with the remote server. This is
    a subclass of :class:`dput.exceptions.UploadException`.
    """
    pass



class FtpUploader(AbstractUploader):