#!/usr/bin/env python # -*- coding: utf-8 -*- import cgi import cgitb cgitb.enable() from urllib import unquote import sys, os # Modify this to point to where you usually run planet. BASE_DIR = '..' # Modify this to point to your venus installation dir, relative to planet dir above. VENUS_INSTALL = "venus" # Config file, relative to planet dir above CONFIG_FILE = "config/live" # Admin page URL, relative to this script's URL ADMIN_URL = "admin.html" # chdir to planet dir - config may be relative from there os.chdir(os.path.abspath(BASE_DIR)) # Add venus to path. sys.path.append(VENUS_INSTALL) # Add shell dir to path - auto detection does not work sys.path.append(os.path.join(VENUS_INSTALL, "planet", "shell")) # import necessary planet items from planet import config from planet.spider import filename # Load config config.load(CONFIG_FILE) # parse query parameters form = cgi.FieldStorage() # Start HTML output at once print "Content-Type: text/html;charset=utf-8" # HTML is following print # blank line, end of headers print '' print '
Unknown command
" elif form['command'].value == "blacklist": # Create the blacklist dir if it does not exist if not os.path.exists(blacklist): os.mkdir(blacklist) print "Created directory %s
" % blacklist # find list of urls, in the form bl[n]=url for key in form.keys(): if not key.startswith("bl"): continue url = unquote(form[key].value) # find corresponding files cache_file = filename(cache, url) blacklist_file = filename(blacklist, url) # move to blacklist if found if os.path.exists(cache_file): os.rename(cache_file, blacklist_file) print "Blacklisted %s
" % (url, url) else: print "Unknown file: %s
" % cache_file print """Note that blacklisting does not automatically refresh the planet. You will need to either wait for a scheduled planet run, or refresh manually from the admin interface.
""" elif form['command'].value == "run": # run spider and refresh from planet import spider, splice try: spider.spiderPlanet(only_if_new=False) print "Successfully ran spider
" except Exception, e: print e doc = splice.splice() splice.apply(doc.toxml('utf-8')) elif form['command'].value == "refresh": # only refresh from planet import splice doc = splice.splice() splice.apply(doc.toxml('utf-8')) print "Successfully refreshed
" elif form['command'].value == "expunge": # only expunge from planet import expunge expunge.expungeCache() print "Successfully expunged
" print "Return to admin interface
" print ""