def iceWebServer(IceCommon, options, outputWriter): iceContext = IceCommon.IceContext(options=options) iceContext.loadRepositories() settings = iceContext.settings asServiceOnly = bool( options.get("asserviceonly", settings.get("asServiceOnly", False))) enableExternalAccess = bool( options.get("enableexternalaccess", settings.get("enableExternalAccess", False))) port = int(options.get("port", options.get("p", iceContext.config.port))) settings["asServiceOnly"] = asServiceOnly settings["enableExternalAccess"] = enableExternalAccess webserver = options.get("webserver", settings.get("webServer", "default")) iceContext.isServer = options.get("server", settings.get("server", False)) settings["webserver"] = webserver iceContext.config.setPort(str(port)) if asServiceOnly: outputWriter("* asServiceOnly *\n") if enableExternalAccess: outputWriter("* external access enabled *\n") if iceContext.isServer: outputWriter("* running as a server!\n") iceServer = IceServer(iceContext, IceRequest, ServerRequestData, ServerResponseData) iceServer.serve()
def getRep(self): iceContext = IceCommon.IceContext(None) output = iceContext.output iceContext.output = None setupRep(self.fs) rep = IceRepository(iceContext, testRep, repUrl=repUrl, iceRender=MockIceRender(iceContext)) iceContext.output = output return rep
def converterAppMain(progName, options, testing=False, fs=None, output=None): if output is None: output = sys.stdout if fs is None: fs = Global.fs usageMessage = "Usage: \n %s -convert -f:odtOrDocFile -d:outputDirectory [-options]" % progName usageMessage += "\n Options:" usageMessage += "\n -pdfLink - include a link to the PDF rendition in the HTML" usageMessage += "\n -sourceLink - include a link to the source document in the HTML (including derived ODT from DOC)" usageMessage += "\n -includetitle:False - do not include the title in the body of the HTML" usageMessage += "\n -toc:False - turn off the page TOC in the HTML" usageMessage += "\n -template templateFile - use the given xhtml template file when generating the HTML" usageMessage += "\n -templateString \"templateString\" - use the given xml template string when generating the HTML" usageMessage += "\n -oooPort:# - use the given port number for communication with OpenOffice.org" usageMessage += "\n -oooPath pathToOOo - use the OpenOffice.org at the given path" usageMessage += "\n -open - to auto open the converted file" usageMessage += "\nOR to atom publish" usageMessage += "\n %s -atomPub -f:htmlFile [-options]" % progName usageMessage += "\n %s -atomConvertPub -f:odtOrDocFile -d:outputDirectory [-options]" % progName usageMessage += "\n Options:" usageMessage += "\n -atomPubUrl=url - required for first post" usageMessage += "\n -categories=\"categories\" - A list of cateogories for the post separated by ;, " usageMessage += "\n eg. \"Category1;Categor2\"(default is Uncategorized)" usageMessage += "\n -title=\"Title\" - required" usageMessage += "\n -authType=None|Basic|Blogger - (default is None)" usageMessage += "\n -username=username - required if authType is Basic or Blogger" usageMessage += "\n -password=password - required if authType is Basic or Blogger" usageMessage += "\n -author=author - required if username has not been given (default is username)" usageMessage += "\n -summary=\"summary\" - (default is title)" usageMessage += "\n -draft:True|False - (default is True)" usageMessage += "\n -new:True|False - (default is False, ignored if document has not been posted yet)" usageMessage += "\n -open - to open the publish content" convert = options.get("convert", False) atomPub = options.get("atompub", False) atomConvertPub = options.get("atomconvertpub", False) if options.get("help", False) or (not convert) and (not atomPub): output.write("%s\n" % usageMessage) return True if options.get("testing", False): output.write("%s\n" % "*** Testing Mode ***") file = "testData/test1.odt" toDir = "testData/output" if False: output.write("Testing - isWindows=%s, isLinux=%s, isMac=%s\n" % (Global.isWindows, Global.isLinux, Global.isMac)) output.write("Options=%s\n" % str(options)) output.write( "%s%s\n" % (config.settings, config.settings.get("oooPythonPath"))) else: file = options.get("file", None) toDir = options.get("directory", None) if (file is None) or ((toDir is None) and (atomPub == False)): output.write("%s\n" % usageMessage) return False if True: if not fs.isFile(file): output.write("Can not find file '%s'!\n" % file) return False if not atomPub and fs.isFile(toDir): output.write("'%s' is a filename!\n" % toDir) return False #if fs.exists(toDir): # print "'%s' already exists!" % toDir # sys.exit(1) # OpenOffice.org's python path and port # if options.get("oooport", None) is not None: config.settings["oooPort"] = options.get("oooport") if options.get("ooopath", None) is not None: oooPath = options.get("ooopath") config.settings["oooPath"] = oooPath config.settings["oooPythonPath"] = config.settings.getOooPythonPath( oooPath) # Template file if options.get("template", None) is not None: templateFile = options["template"] output.write("using template file '%s'\n" % templateFile) if fs.isFile(templateFile): template = fs.readFile(templateFile) else: output.write("Can not find template file '%s'\n" % templateFile) return False elif options.get("templatestring", None) is not None: template = options.get("templatestring") else: template = """<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Default Template</title> <style type="text/css"> .rendition-links { text-align: right; } .body table td { vertical-align: top; } </style> <style class="sub style-css" type="text/css"></style> </head> <body> <div class="rendition-links"> <span class="ins source-link"></span> <span class="ins slide-link"></span> <span class="ins pdf-rendition-link"></span> </div> <h1 class="ins title"></h1> <div class="ins page-toc"></div> <div class="ins body"></div> </body> </html>""" iceContext = IceCommon.IceContext(loadRepositories=False, loadConfig=True) oooConverterApp = iceContext.getPlugin( "ice.ooo.OdtDocConverter").pluginClass oooConverterApp = oooConverterApp(iceContext, fs, template) if atomPub or atomConvertPub: if atomConvertPub: result, htmlFile, pdfFile = oooConverterApp.convert( file, toDir, options) if htmlFile is None: return False file = htmlFile #App Publish content = fs.readFile(file) newEntry = options.get("new", False) if type(newEntry) == bool: newEntry = str(newEntry).lower() elif newEntry.strip() == "on": newEntry = "true" newEntry = newEntry.lower() == "true" if not newEntry: entryXml = fs.readFile(file + ".info") else: entryXml = None path, name, _ = fs.splitPathFileExt(file) mediaPath = "%s/%s_files" % (path, name) def getMedia(media=None): if media is None: files = fs.listFiles(mediaPath) files.append(name + ".pdf") return files else: if media.endswith(".pdf"): file = fs.join(path, media) else: file = fs.join(mediaPath, media) return fs.readFile(file) def saveResponse(entryXml, publishedCategory): fs.writeFile(file + ".info", entryXml) AtomPublish = iceContext.getPlugin("ice.atom.publish").pluginClass atomPublish = AtomPublish(iceContext, file, getMedia, saveResponse, output) try: if False: # Comment out the style data et = iceContext.ElementTree xml = et.XML(content) styles = xml.findall(".//style") for s in styles: c = et.Comment("\n" + s.text + "\n//") s.text = "//" s.append(c) content = et.tostring(xml) successes, responses, urls = atomPublish.publish( content, options, entryXml) success = True for s in successes: success = success and s if success: output.write("Published OK\n") else: output.write("Publish failed: %s\n" % responses[0]) if urls != []: for url in urls: output.write("Published URL: %s\n" % url) if options.get("open", False) and urls != []: for url in urls: iceContext.system.startFile( url, openFileBrowserIfNoAppAssociation=False) except AtomPublish.BadAuthentication, e: output.write("Publish failed: %s\n" % str(e)) except AtomPublish.RequestException, e: output.write("Publish failed: %s\n" % str(e))