def svncommit(body, ctype, **params): '''Commit a file. Can optionally populate the file contents from a given URL. The form parameters are: fpath - the name of the file to commit to SVN msg - the commit message q (optional) - fetch the given URL and save it to the specified file before commmiting The form must be POSTed as multipart/form-data. If the request includes the 'q' parameter then the new fetch will contain authentication forward Sample request: curl -F "msg=fixed a typo" -F fpath="/path/to/file" -F "q=http://example.org/content" http://localhost:8880/akara.svncommit ''' body = StringIO(body) form = cgi.FieldStorage(fp=body, environ=WSGI_ENVIRON) #for k in form: # print >> sys.stderr, (k, form.getvalue(k)[:100]) q = form.getvalue('q') fpath = form.getvalue('fpath') msg = form.getvalue('msg') #assert_not_equal(q, None, msg=Q_REQUIRED) if q: handler = copy_auth(WSGI_ENVIRON, q) opener = urllib2.build_opener(handler) if handler else urllib2.build_opener() req = urllib2.Request(q) with closing(opener.open(req)) as resp: result = resp.read() ctype = dict(resp.info()).get('Content-Type') with closing(open(fpath, 'w')) as f: f.write(result) cmdline = SVN_COMMIT_CMD%{'msg': msg, 'fpath': fpath} print >> sys.stderr, 'Executing subprocess in shell: ', cmdline process = Popen(cmdline, stdout=PIPE, universal_newlines=True, shell=True) output, perr = process.communicate() return 'SVN commit OK\n'
def execute(top=None): ''' Sample request: curl -F "pattern=wiki/path" -F "wiki=http://localhost:8880/moin/foo/" "http://*****:*****@class="navigation"]//@href'): link = navchild.xml_value #print >> sys.stderr, 'LINK:', link #uri = split_fragment(item.resource)[0] #relative = uri[wikibase_len:] #print >> sys.stderr, uri, relative #if rewrite: # uri = uri.replace(rewrite, wikibase) rest_uri = wrapped_uri(original_wiki_base, link) #print >> sys.stderr, 'rest uri:', rest_uri items.append(freemix(rest_uri, opener).render()) return json.dumps({'items': items}, indent=4)