def exportIpod(request, client, filename): """ Export 'client' to an iPod Notes folder tree 'webDir' is just read from config.webDir """ try: # filename is a directory where we will export the notes to # We assume that the user knows what they are doing # and don't check if the directory is already full or not # and we just overwrite what's already there filename = Path(filename) # Append the package name to the folder path if necessary if filename.basename() != package.name: filename /= package.name if not filename.exists(): filename.makedirs() elif not filename.isdir(): client.alert(_('Filename %s is a file, cannot replace it') % filename) log.error("Couldn't export web page: " + "Filename %s is a file, cannot replace it" % filename) return else: client.alert(_('Folder name %s already exists. ' 'Please choose another one or delete existing one then try again.') % filename) return # Now do the export ipodExport = IpodExport(self.config, filename) ipodExport.export(package) except Exception as e: client.alert(_('EXPORT FAILED!\n%s') % str(e)) raise client.alert(_('Exported to %s') % filename)
def exportIpod(request, client, filename): """ Export 'client' to an iPod Notes folder tree 'webDir' is just read from config.webDir """ try: # filename is a directory where we will export the notes to # We assume that the user knows what they are doing # and don't check if the directory is already full or not # and we just overwrite what's already there filename = Path(filename) # Append the package name to the folder path if necessary if filename.basename() != package.name: filename /= package.name if not filename.exists(): filename.makedirs() elif not filename.isdir(): client.alert( _('Filename %s is a file, cannot replace it') % filename) log.error("Couldn't export web page: " + "Filename %s is a file, cannot replace it" % filename) return else: client.alert( _('Folder name %s already exists. ' 'Please choose another one or delete existing one then try again.' ) % filename) return # Now do the export ipodExport = IpodExport(self.config, filename) ipodExport.export(package) except Exception as e: client.alert(_('EXPORT FAILED!\n%s') % str(e)) raise client.alert(_('Exported to %s') % filename)
def store_images(self, page): #for storing files local_path = Path.joinpath(settings.MEDIA_ROOT, settings.WIKI_CACHE_DIR) # creyoco/exedjango/exeapp_media/wiki_cache_images #for url global_path = Path.joinpath(settings.MEDIA_URL, settings.WIKI_CACHE_DIR) #create directory structure if not os.path.isdir(local_path): os.makedirs(local_path) soup = BeautifulSoup(page.html()) #save file and update link in content for img in soup.findAll('img'): image = "http:" + img['src'] filename = img['src'].split('/')[-1] filename = slugify(Path._get_namebase(filename)) + Path._get_ext(filename) #sanitizing filename file_path = Path.joinpath(local_path, Path(filename)) urllib.request.urlretrieve(image, file_path) img['src'] = Path.joinpath(global_path, Path.basename(filename)) #update image hyperlink to wiki for bigger version image for image_link in soup.findAll("a", {"class": "image"}): image_link['href'] = "http://wikipedia.org" + image_link['href'] for link in soup.findAll("a"): if link['href'].startswith("/wiki"): link['href'] = "http://wikipedia.org" + link['href'] link['target'] = "_blank" elif link['href'].startswith("//"): link['href'] = "http:" + link['href'] link['target'] = "_blank" page = soup.prettify() return page
def exportSinglePage(request, client, filename, webDir, stylesDir, \ printFlag): """ Export 'client' to a single web page, 'webDir' is just read from config.webDir 'stylesDir' is where to copy the style sheet information from 'printFlag' indicates whether or not this is for print (and whatever else that might mean) """ try: imagesDir = webDir.joinpath('images') scriptsDir = webDir.joinpath('scripts') templatesDir = webDir.joinpath('templates') # filename is a directory where we will export the website to # We assume that the user knows what they are doing # and don't check if the directory is already full or not # and we just overwrite what's already there filename = Path(filename) # Append the package name to the folder path if necessary if filename.basename() != package.name: filename /= package.name if not filename.exists(): filename.makedirs() elif not filename.isdir(): client.alert( _('Filename %s is a file, cannot replace it') % filename) log.error("Couldn't export web page: " + "Filename %s is a file, cannot replace it" % filename) return else: client.alert( _('Folder name %s already exists. ' 'Please choose another one or delete existing one then try again.' ) % filename) return # Now do the export singlePageExport = SinglePageExport(stylesDir, filename, \ imagesDir, scriptsDir, templatesDir) singlePageExport.export(package, printFlag) except Exception as e: client.alert(_('SAVE FAILED!\n%s' % str(e))) raise # Show the newly exported web site in a new window if not printFlag: self._startFile(client, filename) # and return a string of the actual directory name, # in case the package name was added, etc.: return filename.abspath().encode('utf-8')
def exportSinglePage(request, client, filename, webDir, stylesDir, \ printFlag): """ Export 'client' to a single web page, 'webDir' is just read from config.webDir 'stylesDir' is where to copy the style sheet information from 'printFlag' indicates whether or not this is for print (and whatever else that might mean) """ try: imagesDir = webDir.joinpath('images') scriptsDir = webDir.joinpath('scripts') templatesDir = webDir.joinpath('templates') # filename is a directory where we will export the website to # We assume that the user knows what they are doing # and don't check if the directory is already full or not # and we just overwrite what's already there filename = Path(filename) # Append the package name to the folder path if necessary if filename.basename() != package.name: filename /= package.name if not filename.exists(): filename.makedirs() elif not filename.isdir(): client.alert(_('Filename %s is a file, cannot replace it') % filename) log.error("Couldn't export web page: " + "Filename %s is a file, cannot replace it" % filename) return else: client.alert(_('Folder name %s already exists. ' 'Please choose another one or delete existing one then try again.') % filename) return # Now do the export singlePageExport = SinglePageExport(stylesDir, filename, \ imagesDir, scriptsDir, templatesDir) singlePageExport.export(package, printFlag) except Exception as e: client.alert(_('SAVE FAILED!\n%s' % str(e))) raise # Show the newly exported web site in a new window if not printFlag: self._startFile(client, filename) # and return a string of the actual directory name, # in case the package name was added, etc.: return filename.abspath().encode('utf-8')
def exportWebSite(request, client, filename, stylesDir, quick=False): """ Export 'client' to a web site, 'webDir' is just read from config.webDir 'stylesDir' is where to copy the style sheet information from """ # filename is a directory where we will export the website to filename = Path(filename) # Append the package name to the folder path if necessary if filename.basename() != package.name: filename /= package.name if filename.exists() and not quick: client.sendScript('askOverwrite("%s", "%s");' \ % (str(filename).replace("\\", "\\\\"), stylesDir.replace("\\", "\\\\"))) else: # Now do the export self.exportWebSite2(client, filename, stylesDir)
def exportWebSite(request, client, filename, stylesDir, quick=False): """ Export 'client' to a web site, 'webDir' is just read from config.webDir 'stylesDir' is where to copy the style sheet information from """ # filename is a directory where we will export the website to filename = Path(filename) # Append the package name to the folder path if necessary if filename.basename() != package.name: filename /= package.name if filename.exists() and not quick: client.sendScript('askOverwrite("%s", "%s");' \ % (str(filename).replace("\\", "\\\\"), stylesDir.replace("\\", "\\\\"))) else: # Now do the export self.exportWebSite2(client, filename, stylesDir)
def exportPresentation(request, client, filename, stylesDir): """ export client to a DOM presentation """ try: # filename is a directory where we will export the website to # We assume that the user knows what they are doing # and don't check if the directory is already full or not # and we just overwrite what's already there filename = Path(filename) # Append the package name to the folder path if necessary if filename.basename() != package.name: filename /= package.name if not filename.exists(): filename.makedirs() elif not filename.isdir(): client.alert( _('Filename %s is a file, cannot replace it') % filename) log.error("Couldn't export web page: " + "Filename %s is a file, cannot replace it" % filename) return else: client.alert( _('Folder name %s already exists. ' 'Please choose another one or delete existing one then try again.' ) % filename) return # Now do the export presentationExport = PresentationExport(self.config, stylesDir, filename) presentationExport.export(package) except Exception as e: client.alert(_('EXPORT FAILED!\n%s') % str(e)) raise # show new presentation in a new window self._startFile(client, filename)
def exportPresentation(request, client, filename, stylesDir): """ export client to a DOM presentation """ try: # filename is a directory where we will export the website to # We assume that the user knows what they are doing # and don't check if the directory is already full or not # and we just overwrite what's already there filename = Path(filename) # Append the package name to the folder path if necessary if filename.basename() != package.name: filename /= package.name if not filename.exists(): filename.makedirs() elif not filename.isdir(): client.alert(_('Filename %s is a file, cannot replace it') % filename) log.error("Couldn't export web page: " + "Filename %s is a file, cannot replace it" % filename) return else: client.alert(_('Folder name %s already exists. ' 'Please choose another one or delete existing one then try again.') % filename) return # Now do the export presentationExport = PresentationExport(self.config, stylesDir, filename) presentationExport.export(package) except Exception as e: client.alert(_('EXPORT FAILED!\n%s') % str(e)) raise # show new presentation in a new window self._startFile(client, filename)