def generate_blotter(queue): dirpath = canonical_path(queue) if dirpath != None: names = map(lambda t: dirpath + t, os.listdir(dirpath)) #names.sort(lambda a, b: cmp(os.stat(a)[stat.ST_MTIME], os.stat(b)[stat.ST_MTIME])) names.sort(lambda a, b: cmp(os.stat(b).st_mtime, os.stat(a).st_mtime)) news_items = map(lambda f: wgo_news.news(f, False), names) news_items = filter(lambda n: n.valid, news_items) news_blotter = file_path(queue, news_config.news_blotter) fp_out = open(news_blotter, "w") print >>fp_out, '<!-- this data is automatically generated by wgo_queue.generate_blotter $Revision$ and friends -->' print >>fp_out, "<!-- begin chartae -->" map(lambda n: fp_out.write(n.as_news_item()), news_items) print >>fp_out, "<!-- end chartae -->" fp_out.close() os.chmod(news_blotter, 0666) # this is not the best way to handle this XXX if queue == news_config.current_queue: os.system("/bin/cp %s %s" % (news_blotter, wgo.config.DocumentRoot_path + "/includes/news.inc")) pass pass generate_rdf(queue) return (news_blotter)
def main(argv): fpin = sys.stdin if len(argv) > 1: fpin = open(argv[1], "r") mbox = mailbox.PortableUnixMailbox(fpin, email.message_from_file) else: mbox = [ email.message_from_file(fpin) ] pass directory = wgo_queue.canonical_path(wgo_news.config.pending_queue) if not os.path.exists(directory): os.makedirs(directory, 0777) pass for m in mbox: n = wgo_news.news(m) if n["message-id"] != None and n["message-id"] != "": s = wgo_news.re_substr("News:[ \t]*(.+)", n["subject"]) if s != None: n["subject"] = cgi.escape(s) n["body"] = cgi.escape(n["body"]) n.to_queue(wgo_news.config.pending_queue) pass pass pass return (0)
def main(): wgo_news.header() form = cgi.FieldStorage() if not (form.has_key("message-id") and form.has_key("queue")): wgo_news.footer(wgo.error("Malformed Request")) return (1) queue = form["queue"].value if queue in ["pending", wgo_news.config.pending_queue]: this_queue = wgo_news.config.pending_queue other_queue = wgo_news.config.current_queue elif queue in ["current", wgo_news.config.current_queue]: this_queue = wgo_news.config.current_queue other_queue = wgo_news.config.pending_queue elif queue in ["archive", wgo_news.config.archive_queue]: this_queue = wgo_news.config.archive_queue other_queue = wgo_news.config.archive_queue else: wgo_news.footer(wgo.error("Malformed request")) return (1) message_id = xhtml.unescape(form["message-id"].value) try: m = wgo_news.news(wgo_queue.message_path(this_queue, message_id)) except: m = wgo_news.news() m["message-id"] = message_id m["date"] = rfc822.formatdate() pass if os.environ.has_key("REMOTE_USER"): editor = os.environ["REMOTE_USER"] else: editor = "*****@*****.**" pass html_news_edit(this_queue, other_queue, m, editor) wgo_news.footer() return (0)
def main(queue): wgo_news.header() if queue in [wgo_news.config.pending_queue, wgo_news.config.current_queue, wgo_news.config.archive_queue]: dirpath = wgo.config.spool_path + queue names = map(lambda t: dirpath + "/" + t, os.listdir(dirpath)) names.sort(lambda a, b: cmp(os.stat(a).st_mtime, os.stat(b).st_mtime)) news = map(lambda f: wgo_news.news(f, False), names) news = filter(lambda n: n.valid, news) print xhtml.include('%s%s_header.html' % (wgo_news.config.news_path, queue)) # If this is the pending queue, then create one initialised news article for display. if queue == wgo_news.config.pending_queue: n = wgo_news.news() n["Subject"] = "NEW NEWS" html_index_page(queue, n) pass map(lambda n: html_index_page(queue, n), news) control_panel(queue) print xhtml.include('%s/%s_footer.html' % (wgo_news.config.news_path, queue)) if 0: print xhtml.hyperlink("XML", { "class" : "faux-button", "style" : "background: #ff6600 none; color: white; font-weight: bold; padding: 0 .5em 0 .5em; font-size: medium;", "href" : wgo_news.config.news_dir + queue + "/news.rdf"}) pass print xhtml.include(wgo_queue.generate_blotter(queue)) else: print wgo.error("Malformed Request") pass wgo_news.footer() return (0)
def generate_rdf(queue): http_host = news_config.default_http_host if os.environ.has_key("HTTP_HOST"): http_host = os.environ["HTTP_HOST"] pass rdf_file = file_path(queue, "news.rdf") dirpath = canonical_path(queue) names = map(lambda t: dirpath + t, os.listdir(dirpath)) #names.sort(lambda a, b: cmp(os.stat(a)[stat.ST_MTIME], os.stat(b)[stat.ST_MTIME])) names.sort(lambda a, b: cmp(os.stat(a).st_mtime, os.stat(b).st_mtime)) news_items = map(lambda f: wgo_news.news(f, False), names) news_items = filter(lambda n: n.valid, news_items) news_blotter = file_path(queue, news_config.news_blotter) fp = open(rdf_file, "w") print >>fp, '<?xml version="1.0" ?>' print >>fp, '<?xml-stylesheet href="/style/rdf-news.css" type="text/css" ?>' print >>fp, rdf.rss.init() print >>fp, rdf.channel.init() print >>fp, rdf.title('GIMP News') print >>fp, rdf.link('http://' + http_host) print >>fp, rdf.description(rdf.quote('Recent gimp.org ' + queue)) print >>fp, rdf.pubDate(str(rfc822.formatdate(time.time()))) #+ string.join(map(lambda n: rdf.item({"resource" : "http://" + http_host}) + "\n", news_items)) + "\n") map(lambda n: fp.write(str(n.as_rdf())), news_items) print >>fp, rdf.channel.fini() print >>fp, rdf.rss.fini() fp.close() os.chmod(news_blotter, 0666) # this is not the best way to handle this XXX if queue == news_config.current_queue: os.system("/bin/cp %s %s" % (rdf_file, wgo.config.DocumentRoot_path + "/news.rdf")) pass return (rdf_file)
def main(): form = cgi.FieldStorage() #wgo.config.debug = True if wgo.config.debug: xhtml.print_form(form) if not (form.has_key("message-id") and form.has_key("action") and form.has_key("queue")) and not (form.has_key("subject") and form.has_key("body")): wgo_news.header() wgo_news.footer(wgo.error("Malformed http request.")) return (-1) action = string.lower(xhtml.unescape(form["action"].value)) queue = xhtml.unescape(form["queue"].value) if queue in ["pending", wgo_news.config.pending_queue]: queue = wgo_news.config.pending_queue elif queue in ["current", wgo_news.config.current_queue]: queue = wgo_news.config.current_queue elif queue in ["archive", wgo_news.config.archive_queue]: queue = wgo_news.config.archive_queue else: action = "" queue = "" pass try: news = wgo_news.news(form) except: wgo_news.header() wgo_news.footer(wgo.error("The news article is malformed. Check the date, it should be <i>day month year hour:minute:seconds</i> GMT Perhaps it is missing a subject line, or it has no body. ")) return (-1) if action == "save": news.to_queue(queue) link = xhtml.hyperlink("Continue", { "href" : "news-edit.cgi?message-id=%s&queue=%s" % (news["message-id"], queue)}) status = "success" goto = ["Location: news-edit.cgi?message-id=%s&queue=%s" % (xhtml.escape(news["message-id"]), queue)] elif action == "approve": news.to_queue(wgo_news.config.current_queue) if os.path.exists(wgo_queue.message_path(queue, news["message-id"])): os.remove(wgo_queue.message_path(queue, news["message-id"])) pass link = xhtml.hyperlink("Continue", { "href" : "news-index.cgi?%s" % (queue)}) status = "success" goto = ["Location: news-index.cgi?%s" % (queue)] elif action == "disapprove": news.to_queue(wgo_news.config.pending_queue) if os.path.exists(wgo_queue.message_path(queue, news["message-id"])): os.remove(wgo_queue.message_path(queue, news["message-id"])) pass link = xhtml.hyperlink("Continue", {"href" : "news-index.cgi?%s" % (queue)}) status = "success" goto = ["Location: news-index.cgi?%s" % (queue)] elif action == "archive": news.to_queue(wgo_news.config.archive_queue) if os.path.exists(wgo_queue.message_path(queue, news["message-id"])): os.remove(wgo_queue.message_path(queue, news["message-id"])) pass link = xhtml.hyperlink("Continue", {"href" : "news-index.cgi?%s" % (queue)}) status = "success" goto = ["Location: news-index.cgi?%s" % (queue)] elif action == "delete": if os.path.exists(wgo_queue.message_path(queue, news["message-id"])): os.remove(wgo_queue.message_path(queue, news["message-id"])) pass link = xhtml.hyperlink("Continue", {"href" : "news-index.cgi?%s" % (queue)}) status = "success" goto = ["Location: news-index.cgi?%s" % (queue)] else: link = xhtml.hyperlink("Restart", {"href" : "index.html"}) queue = "" status = "failed" pass if status == "success": print goto[0] print else: wgo_news.header() wgo_news.footer(wgo.error(string.capitalize(action) + " " + string.capitalize(status))) pass return (0)