<commit_before>import datetime
import os

from exporters.default_retries import retry_long
from exporters.progress_callback import FtpUploadProgress
from exporters.writers.filebase_base_writer import FilebaseBaseWriter


class FtpCreateDirsException(Exception):
    pass


class FTPWriter(FilebaseBaseWriter):
    """
    Writes items to FTP server. It is a File Based writer, so it has filebase
    option available

        - host (str)
            Ftp server ip

        - port (int)
            Ftp port

        - ftp_user (str)
            Ftp user

        - ftp_password (str)
            Ftp password

        - filebase (str)
            Path to store the exported files
    """
    supported_options = {
        'host': {'type': basestring},
        'ftp_user': {'type': basestring, 'env_fallback': 'EXPORTERS_FTP_USER'},
        'ftp_password': {'type': basestring, 'env_fallback': 'EXPORTERS_FTP_PASSWORD'},
        'port': {'type': int, 'default': 21},
    }

    def __init__(self, options):
        super(FTPWriter, self).__init__(options)

        self.ftp_host = self.read_option('host')
        self.ftp_port = self.read_option('port')
        self.ftp_user = self.read_option('ftp_user')
        self.ftp_password = self.read_option('ftp_password')
        self.filebase = self.read_option('filebase').format(datetime.datetime.now())
        self.logger.info(
            'FTPWriter has been initiated. host: {}. port: {}. filebase: {}'.format(
                self.ftp_host, self.ftp_port,
                self.filebase))

    def _create_target_dir_if_needed(self, target, depth_limit=20):
        """Creates the directory for the path given, recursively creating
        parent directories when needed"""

        if depth_limit <= 0:
            raise FtpCreateDirsException('Depth limit exceeded')
        if not target:
            return
        target_dir = os.path.dirname(target)
        parent_dir, dir_name = os.path.split(target_dir)

        parent_dir_ls = []
        try:
            parent_dir_ls = self.ftp.nlst(parent_dir)<commit_msg>Removed filebase formatting in constructor<commit_after>import datetime
import os

from exporters.default_retries import retry_long
from exporters.progress_callback import FtpUploadProgress
from exporters.writers.filebase_base_writer import FilebaseBaseWriter


class FtpCreateDirsException(Exception):
    pass


class FTPWriter(FilebaseBaseWriter):
    """
    Writes items to FTP server. It is a File Based writer, so it has filebase
    option available

        - host (str)
            Ftp server ip

        - port (int)
            Ftp port

        - ftp_user (str)
            Ftp user

        - ftp_password (str)
            Ftp password

        - filebase (str)
            Path to store the exported files
    """
    supported_options = {
        'host': {'type': basestring},
        'ftp_user': {'type': basestring, 'env_fallback': 'EXPORTERS_FTP_USER'},
        'ftp_password': {'type': basestring, 'env_fallback': 'EXPORTERS_FTP_PASSWORD'},
        'port': {'type': int, 'default': 21},
    }

    def __init__(self, options):
        super(FTPWriter, self).__init__(options)

        self.ftp_host = self.read_option('host')
        self.ftp_port = self.read_option('port')
        self.ftp_user = self.read_option('ftp_user')
        self.ftp_password = self.read_option('ftp_password')
        self.logger.info(
            'FTPWriter has been initiated. host: {}. port: {}. filebase: {}'.format(
                self.ftp_host, self.ftp_port,
                self.filebase))

    def _create_target_dir_if_needed(self, target, depth_limit=20):
        """Creates the directory for the path given, recursively creating
        parent directories when needed"""

        if depth_limit <= 0:
            raise FtpCreateDirsException('Depth limit exceeded')
        if not target:
            return
        target_dir = os.path.dirname(target)
        parent_dir, dir_name = os.path.split(target_dir)

        parent_dir_ls = []
        try:
            parent_dir_ls = self.ftp.nlst(parent_dir)
{'fraction_non_alphanumeric': 0.09926650366748166, 'fraction_numerical': 0.0024449877750611247, 'mean_word_length': 2.499572284003422, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2245633', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1187, 'n_words': 293}