[Assorted-commits] SF.net SVN: assorted: [652] configs/trunk/src/topcoder
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-04-02 05:41:46
|
Revision: 652 http://assorted.svn.sourceforge.net/assorted/?rev=652&view=rev Author: yangzhang Date: 2008-04-01 22:41:52 -0700 (Tue, 01 Apr 2008) Log Message: ----------- fixed string escaping; added support for setting up the user project dir Modified Paths: -------------- configs/trunk/src/topcoder/contestapplet.conf.template configs/trunk/src/topcoder/setup.py Modified: configs/trunk/src/topcoder/contestapplet.conf.template =================================================================== --- configs/trunk/src/topcoder/contestapplet.conf.template 2008-04-02 05:21:28 UTC (rev 651) +++ configs/trunk/src/topcoder/contestapplet.conf.template 2008-04-02 05:41:52 UTC (rev 652) @@ -165,7 +165,7 @@ com.topcoder.jmaContestApplet.frames.codingframe.size=1024\:746 com.topcoder.jmaContestApplet.frames.codingframe.dividerloc=319 com.topcoder.jmaContesntApplet.ContestApplet.enableTimestamps=true -fileeditor.config.dirName=C\:\\Documents and Settings\\Yang\\My Documents\\Visual Studio 2008\\Projects\\TopCoderCS\\TopCoderCS +fileeditor.config.dirName=`USERDIR` fileeditor.config.fileName=Program fileeditor.config.beginCut=// BEGIN CUT HERE fileeditor.config.endCut=// END CUT HERE Modified: configs/trunk/src/topcoder/setup.py =================================================================== --- configs/trunk/src/topcoder/setup.py 2008-04-02 05:21:28 UTC (rev 651) +++ configs/trunk/src/topcoder/setup.py 2008-04-02 05:41:52 UTC (rev 652) @@ -1,6 +1,10 @@ #!/usr/bin/env python # vim:et:sw=2:ts=2 +""" +Set up topcoder configuration. +""" + from __future__ import with_statement from contextlib import * from os import * @@ -9,6 +13,13 @@ from sys import * from urllib import * +# Utilities. +def esc( s ): return sub( r'([\\:])', r'\\\1', s ) +def mkdirp( path ): + try: makedirs( path ) + except OSError, ex: + if ex.errno != 17: raise + # Source URLs to the plugin jars. urls = """ http://www.topcoder.com/contest/classes/ExampleBuilder/ExampleBuilder.jar @@ -18,12 +29,19 @@ # Figure out and setup paths. homedir = environ[ 'HOME' if platform != 'win32' else 'HOMEPATH' ] + sep -plugindir = ( argv[1] if len(argv) < 1 else homedir + '.topcoder' ) + sep -try: makedirs( plugindir ) -except OSError, ex: - if ex.errno != 17: raise +userdir = argv[1] +plugindir = ( argv[2] if len(argv) < 2 else homedir + '.topcoder' ) + sep +mkdirp( userdir ) +mkdirp( plugindir ) paths = [ plugindir + basename(url) for url in urls ] +# Sample default user directories, where the file will be placed. +# TODO parse command line options. +# if platform == 'win32': +# userdir = homedir + 'My Documents\\Visual Studio 2008\\Projects\\TopCoderCS\\TopCoderCS\\' +# else: +# userdir = homedir + 'work/topcoder/' + # Download jars if necessary. for url, path in zip( urls, paths ): if not exists( path ): @@ -31,7 +49,8 @@ # Generate the final configuration file from the template. with file( 'contestapplet.conf.template' ) as template: - with file( homedir + 'contestapplet.conf', 'w' ) as output: - output.write( sub( '`CLASSPATH`', - pathsep.join( paths ), - template.read() ) ) + contents = template.read() +contents = sub( '`CLASSPATH`', esc( pathsep.join( paths ) ), contents ) +contents = sub( '`USERDIR`', esc( userdir ), contents ) +with file( homedir + 'contestapplet.conf', 'w' ) as output: + output.write( contents ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |