Beispiel #1
0
    def create_file(self, name, contents):
        """
        Creates a gzip file
        :param name: (str) name of the file to be created
        :param contents: (str) contents to be written in the file
        :return: (str or False) path of the created file
        """

        # write a tmp file
        tmp = mkstemp()[1]
        with gzip.open(tmp, 'wb') as handler:
            handler.write(contents)

        # send it to the FTP server
        if self.ftp:
            self.ftp.storbinary('STOR {}'.format(name), open(tmp, 'rb'))
            return '{}{}'.format(self.path, name)

        # or save it locally
        else:
            new_path = Path(self.path).child(name)
            tmp_path = Path(tmp)
            tmp_path.copy(new_path)
            if new_path.exists():
                return new_path.absolute()
            return False
Beispiel #2
0
    def create_file(self, name, contents):
        """
        Creates a gzip file
        :param name: (str) name of the file to be created
        :param contents: (str) contents to be written in the file
        :return: (str or False) path of the created file
        """

        # write a tmp file
        tmp = mkstemp()[1]
        with gzip.open(tmp, 'wb') as handler:
            handler.write(contents)

        # send it to the FTP server
        if self.ftp:
            self.ftp.storbinary('STOR {}'.format(name), open(tmp, 'rb'))
            return '{}{}'.format(self.path, name)

        # or save it locally
        else:
            new_path = Path(self.path).child(name)
            tmp_path = Path(tmp)
            tmp_path.copy(new_path)
            if new_path.exists():
                return new_path.absolute()
            return False
Beispiel #3
0
def objects():
    Mailbox = rt.models.django_mailbox.Mailbox
    mp = rt.settings.SITE.cache_dir.child("media", "mailbox")
    rt.settings.SITE.makedirs_if_missing(mp)
    dd.logger.info("Mailbox path is %s", mp)

    for (protocol, name, origin) in dd.plugins.mailbox.mailbox_templates:
        filename = mp.child(name)
        origin.copy(filename)
        yield Mailbox(name=name, uri=protocol + "://" + filename)

    name = 'team.mbox'
    origin = Path(__file__).parent.child(name)
    filename = mp.child(name)
    origin.copy(filename)
    mbx = Mailbox(name=name, uri="mbox://" + filename)
    yield mbx
    get_new_mail()
    def start(self):
        from unipath import Path
        self.setup()
        self.status = JOB_RUNNING

        current = 0.0
        from_files = self.cmd.get('from_files', [])
        to_files = self.cmd.get('to_files', [])
        for file_pair in zip(from_files, to_files):
            self.update_status(current)
            yield

            from_file = Path(file_pair[0])
            to_file = Path(file_pair[1])
            to_files.parent.mkdir(parents=True)
            from_file.copy(to_file)
            current += 1
        else:
            self.status = JOB_FINISHED
            yield