def exportIndex(self, name, dir="."): if self.indexes.has_section(name): print "Exporting index properties for %s" % name global tempdir global tarName global extension tempdir = tempfile.mkdtemp() exportConfig = ConfigParser.ConfigParser() exportConfig.add_section(name) for opt in self.indexes.options(name): exportConfig.set(name, opt, self.getIndexProp(name, opt)) exportConfig.set(name, INDEX_DIR, "indexes") exportConfig.set(name, CONTENT_DIR, "contents") exportConfig.write(open(os.path.join(tempdir, "indexes.cfg"), "w")) print "Copying index files (this may take a while)..." import shutil shutil.copytree(self.getIndexProp(name, INDEX_DIR), os.path.join(tempdir, INDEX_DIR)) print "Copying content files (this may take a while)..." shutil.copytree(self.getIndexProp(name, INDEX_DIR), os.path.join(tempdir, CONTENT_DIR)) tarName = utils.createSafeFilename(name) archive = tarfile.open(os.path.join(dir, tarName + extension), "w:bz2") os.path.walk(tempdir, walker, archive) archive.close() shutil.rmtree(tempdir)
def OnCopyTheme(self, event): dialog = wx.TextEntryDialog(self, _("Please type a name for your new theme"), _("New Theme"), "") if dialog.ShowModal() == wx.ID_OK: themedir = os.path.join(settings.AppDir, "themes") filename = string.replace(fileutils.MakeFileName2(dialog.GetValue()) + ".py", " ", "_") otherfilename = string.replace(fileutils.MakeFileName2(self.lstThemeList.GetStringSelection()) + ".py", " ", "_") otherfilename = string.replace(otherfilename, "(", "") otherfilename = string.replace(otherfilename, ")", "") foldername = utils.createSafeFilename(dialog.GetValue()) try: os.mkdir(os.path.join(themedir, foldername)) except: message = _("Cannot create theme. Check that a theme with this name does not already exist, and that you have write access to the '%(themedir)s' directory.") % {"themedir":os.path.join(settings.AppDir, "themes")} self.parent.log.error(message) wx.MessageBox(message) return copyfile = utils.openFile(os.path.join(themedir, otherfilename), "r") data = copyfile.read() copyfile.close() oldthemeline = 'themename = "%s"' % (string.replace(self.lstThemeList.GetStringSelection(), "\"", "\\\"")) newthemeline = 'themename = "%s"' % (string.replace(dialog.GetValue(), "\"", "\\\"")) data = string.replace(data, oldthemeline, newthemeline) myfile = utils.openFile(os.path.join(themedir, filename), "w") myfile.write(data) myfile.close() #copy support files from Default (no frames) fileutils.CopyFiles(os.path.join(themedir, self.lstThemeList.GetStringSelection()), os.path.join(themedir, foldername), 1) self.parent.themes.LoadThemes() self.ReloadThemes() dialog.Destroy()
def btnOKClicked(self, event): self.eclassdir = os.path.join(settings.AppSettings["EClass3Folder"], utils.createSafeFilename(self.txtTitle.GetValue())) if not os.path.exists(self.eclassdir): self.EndModal(wx.ID_OK) else: wx.MessageDialog(self, _("A publication with this name already exists. Please choose another name."), _("Publication exists!"), wx.OK).ShowModal()
def MakeFileName2(mytext): """ Function: MakeFileName2(mydir, mytext) Last Updated: 10/21/02 Description: Returns a filename valid on supported operating systems. Also checks for existing files and renames if necessary. Replacement for MakeFileName which oddly is designed only for .ecp files... """ mytext = utils.createSafeFilename(mytext) mytext = mytext.replace(" ", "_") return mytext
def ExportTheme(self, event=None): import zipfile themename = fileutils.MakeFileName2(self.lstThemeList.GetStringSelection()) dialog = wx.FileDialog(self, _("Export Theme File"), "", themename + ".theme", _("Theme Files") + " (*.theme)|*.theme", wxSAVE|wxOVERWRITE_PROMPT) if dialog.ShowModal() == wx.ID_OK: filename = dialog.GetPath() themezip = zipfile.ZipFile(filename, "w") themepyfile = string.replace(themename + ".py", " ", "_") themezip.write(os.path.join(settings.AppDir, "themes", themepyfile), themepyfile) themefolder = utils.createSafeFilename(self.lstThemeList.GetStringSelection()) self.AddDirToZip(themefolder, themezip) themezip.close() wx.MessageBox(_("Theme successfully exported.")) dialog.Destroy()
def addIndex(self, name, contentDir): if not self.indexes.has_section(name): self.indexes.add_section(name) self.indexes.set(name, CONTENT_DIR, contentDir) indexdir = self.indexesDir if not os.path.exists(indexdir): os.makedirs(indexdir) thisindexdir = os.path.join(indexdir, utils.createSafeFilename(name)) if not os.path.exists(thisindexdir): os.makedirs(thisindexdir) self.setIndexProp(name, INDEX_DIR, thisindexdir) self.saveChanges() else: raise IndexExistsError(name)
def OnNewTheme(self, event): dialog = wx.TextEntryDialog(self, _("Please type a name for your new theme"), _("New Theme"), _("New Theme")) if dialog.ShowModal() == wx.ID_OK: themedir = os.path.join(settings.AppDir, "themes") filename = string.replace(fileutils.MakeFileName2(dialog.GetValue()) + ".py", "-", "_") foldername = utils.createSafeFilename(dialog.GetValue()) try: os.mkdir(os.path.join(themedir, foldername)) except: message = _("Cannot create theme. Check that a theme with this name does not already exist, and that you have write access to the '%(themedir)s' directory.") % {"themedir":os.path.join(settings.AppDir, "themes")} self.parent.log.error(message) wx.MessageBox(message) return myfile = utils.openFile(os.path.join(themedir, filename), "w") data = """ from BaseTheme import * themename = "%s" import settings class HTMLPublisher(BaseHTMLPublisher): def __init__(self, parent): BaseHTMLPublisher.__init__(self, parent) self.themedir = os.path.join(settings.AppDir, "themes", themename) """ % (string.replace(dialog.GetValue(), "\"", "\\\"")) myfile.write(data) myfile.close() #copy support files from Default (no frames) fileutils.CopyFiles(os.path.join(themedir, "Default (no frames)"), os.path.join(themedir, foldername), 1) self.parent.themes.LoadThemes() self.ReloadThemes() dialog.Destroy()