Robert Pluim wrote:
>Query to black-belt pythoners (pythonistas?): is there a more
>pythonesque way of doing this? According to my docs, os.system
>doesn't throw exceptions, so checking the return code is the only
>way to do this.
>
>* define run_external as an error checking wrapper around os.system,
> and use it in pass3, pass4 & pass5.
>
>
>
>------------------------------------------------------------------------
>
>Index: tools/cvs2svn/cvs2svn.py
>===================================================================
>--- tools/cvs2svn/cvs2svn.py (revision 5932)
>+++ tools/cvs2svn/cvs2svn.py (working copy)
>@@ -272,6 +272,10 @@
> gen_key_base = gen_key_base + 1
> return key
>
>+def run_external(command):
>+ if os.system(command):
>+ print 'Error running "%s"' % command
>+ sys.exit(1)
>
Micro-optimization: sys.exit('Error running "%s"' % command)
> def pass3(ctx):
> # sort the log files
>- os.system('sort %s > %s' % (ctx.log_fname_base + CLEAN_REVS_SUFFIX,
>- ctx.log_fname_base + SORTED_REVS_SUFFIX))
>+ run_external('sort %s > %s' % (ctx.log_fname_base + CLEAN_REVS_SUFFIX,
>+ ctx.log_fname_base + SORTED_REVS_SUFFIX))
>
>
Unrelated to your patch, but does sort exist for non-unix systems? If
not, the following fairly obvious code might work:
def sort_file(dst, src):
lines = open(src).readlines()
lines.sort()
open(dst, 'w').writelines(lines)
/Tobias
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed May 14 15:57:15 2003