示例#1
0
    def write_all(self, tasks_ftype=None, tasks_fname=None,
                  log_ftype=None, log_fname=None):
        """Writes out projects, tasks, task groupings, and working slots to
        files as dictated by configuration settings.

        """
        self.write_projects()
        if tasks_ftype is None:
            tasks_ftype = self.config['TASKS_FTYPE_OUT']
        if log_ftype is None:
            log_ftype = self.config['LOG_FTYPE_OUT']
        if tasks_fname is None:
            tasks_fname = self.config['TASKS_FNAME_OUT']
        if log_fname is None:
            log_fname = self.config['LOG_FNAME_OUT']
        # The only special case so far.
        if (tasks_ftype == FTYPE_XML and log_ftype == FTYPE_XML
                and tasks_fname == log_fname):
            from backend.xml import XmlBackend
            # TODO: Use the context manager at other places too.
            with open_backed_up(tasks_fname,
                                'wb',
                                suffix=self.config['BACKUP_SUFFIX']) \
                    as outfile:
                XmlBackend.write_all(self.tasks, self.groups, self.wslots,
                                     outfile)
        else:
            # FIXME: The type of file is not looked at, unless the file name is
            # supplied too. Provide some default filename for the supported
            # file types.
            self.write_log(outftype=log_ftype, outfname=log_fname)
            self.write_tasks(outftype=tasks_ftype, outfname=tasks_fname)