#!/usr/bin/env python """ run py.test with the --apigen option and rsync the results to a host rsyncs the whole package (with all the ReST docs converted to HTML) as well as the apigen docs to a given remote host and path """ import _fixpythonpath import py print "using py lib", py.__file__ import sys def rsync(pkgpath, gateway, remotepath): """ copy the code and docs to the remote host """ # copy to a temp dir first, even though both paths (normally) share the # same parent dir, that may contain other stuff that we don't want to # copy... tempdir = py.test.ensuretemp('update_website_rsync_temp') pkgpath.copy(tempdir.ensure(pkgpath.basename, dir=True)) apidocspath.copy(tempdir.ensure(apidocspath.basename, dir=True)) rs = py.execnet.RSync(tempdir) rs.add_target(gateway, remotepath, delete=True) rs.send() def gendoc(pkgpath, args='', captureouterr=False): """ generate docs """ pypath = py.__pkg__.getpath() pytestpath = pypath.join('bin/gendoc.py') cmd = "python py/bin/gendoc.py" if captureouterr: cmd += ' > /dev/null 2>&1' try: old = pypath.dirpath().chdir() try: output = py.process.cmdexec(cmd) finally: old.chdir() except py.error.Error, e: return e.err or str(e) return None def main(pkgpath, rhost, rpath): print 'running gendoc', pkgpath errors = gendoc(pkgpath) if errors: print >>sys.stderr, \ 'Errors while running the unit tests: %s' % (errors,) if not ignorefail: print >>sys.stderr, ('if you want to continue the update ' 'regardless of failures, use --ignorefail') sys.exit(1) print 'rsyncing to %s:%s' %(rhost, rpath) gateway = py.execnet.SshGateway(rhost) errors = rsync(gateway, pkgpath, rpath) if errors: print >>sys.stderr, 'Errors while rsyncing: %s' sys.exit(1) if __name__ == '__main__': host = "codespeak.net" location = "/www/codespeak.net/htdocs/py" baselocation = "%s:%s" % (host, location) args = sys.argv[1:] if not args or '--help' in args or '-h' in args: print "usage: update_website.py [directory]" print print "generate py lib docs and send it to the website. " print "the 'directory' must contain the 'py' package." print "remote location will be %s/BASENAME_OF_DIRECTORY" % baselocation sys.exit() path = py.path.local(args[0]) assert path.join("py").check() pkgpath = py.__pkg__.getpath() main(pkgpath, host, "%s/%s" % (baselocation, path.basename))