[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] make cvs2svn check the exit status of commands

From: Tobias Ringstrom <tobias_at_ringstrom.mine.nu>
Date: 2003-05-14 15:56:19 CEST

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

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.