Ejemplo n.º 1
0
    def saveData(self, filePath, imageX=None):
        """Save all the data to a zip file.
        If imageX is a directory path, get the images from there
        instead of from the source file
        """
        dest = CfgZip(filePath, write=True)
        for f, spec in self.fileDict.items():
            if f.endswith('/'):
                continue
            if (spec[1] == 'i'):
                if not imageX:
                    # Image file, copy it from the source
                    dest.addFile(f, self.source.getFile(f))
            else:
                # Information file, write it in 'sini'-format
                dest.addFile(f, self.writeSection(f, spec[4], spec[3]))

        if imageX:
            # Copy in all files ending .svg and .jpg from the given folder
            try:
                tlist = ["teachers/" + i
                        for i in os.listdir(imageX + "/teachers")]
            except:
                tlist = []
            try:
                ilist = os.listdir(imageX)
            except:
                ilist = []
            imlist = ilist + tlist
            for i in imlist:
                if i.endswith(".svg") or i.endswith(".jpg"):
                    fpath = [imageX] + i.split('/')
                    dest.addFromFile(os.path.join(*fpath), "imagefiles/" + i)
        dest.close()
Ejemplo n.º 2
0
    def restoreConfigFile(self, db):
        """Get a parent directory for the creation of a data file.
        The file to be created may not exist already.
        Returns the file-name if successful, otherwise 'None'.
        """
        # put up directory dialog, starting one up from dir0
        dir = getDirectory(_("Parent Folder"))
        if not dir: return None
        datapath = os.path.join(dir, self.dbname + '.zip')
        if os.path.exists(datapath):
            message(_("'%1' already exists"), (datapath, ))
            return None
        dest = CfgZip(datapath, True)  # open for writing
        if not dest.isOpen():
            message(_("Couldn't open '%s' for writing") % datapath)
            return None

        for path, data in db.getAllData():
            dest.addFile(path, data)
        dest.close()
        message(_("Configuration saved to '%s'") % datapath)
        return datapath
Ejemplo n.º 3
0
    def restoreConfigFile(self, db):
        """Get a parent directory for the creation of a data file.
        The file to be created may not exist already.
        Returns the file-name if successful, otherwise 'None'.
        """
        # put up directory dialog, starting one up from dir0
        dir = getDirectory(_("Parent Folder"))
        if not dir: return None
        datapath = os.path.join(dir, self.dbname + '.zip')
        if os.path.exists(datapath):
            message(_("'%1' already exists"), (datapath,))
            return None
        dest = CfgZip(datapath, True)   # open for writing
        if not dest.isOpen():
            message(_("Couldn't open '%s' for writing") % datapath)
            return None

        for path, data in db.getAllData():
            dest.addFile(path, data)
        dest.close()
        message(_("Configuration saved to '%s'") % datapath)
        return datapath