[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: Robert Pluim <rpluim_at_bigfoot.com>
Date: 2003-05-14 16:15:06 CEST

Tobias Ringstrom writes:
> Robert Pluim wrote:
> >+def run_external(command):
> >+ if os.system(command):
> >+ print 'Error running "%s"' % command
> >+ sys.exit(1)
> >
> Micro-optimization: sys.exit('Error running "%s"' % command)
>

Ahh, the joys of a proper object-oriented language! Patch mark II
attached.

> > 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?

Well, if you install cygwin on your windows box, yes. You mean you
don't? ;-)

> 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)

I assume that would work, but it might consume a large chunk of
memory. People who know more about python than I will have to
comment.

Robert

Index: tools/cvs2svn/cvs2svn.py
===================================================================
--- tools/cvs2svn/cvs2svn.py (revision 5932)
+++ tools/cvs2svn/cvs2svn.py (working copy)
@@ -272,6 +272,9 @@
   gen_key_base = gen_key_base + 1
   return key
 
+def run_external(command):
+ if os.system(command):
+ sys.exit('Error running "%s"' % command)
 
 class TreeMirror:
   def __init__(self):
@@ -960,14 +963,14 @@
 
 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))
 
 def pass4(ctx):
   # create the target repository
   if not ctx.dry_run:
     if ctx.create_repos:
- os.system('%s create %s' % (ctx.svnadmin, ctx.target))
+ run_external('%s create %s' % (ctx.svnadmin, ctx.target))
   else:
     t_fs = t_repos = None
 
@@ -1052,8 +1055,8 @@
     # ### FIXME: Er, does this "<" stuff work under Windows?
     # ### If not, then in general how do we load dumpfiles under Windows?
     print 'loading %s into %s' % (ctx.dumpfile, ctx.target)
- os.system('%s load --ignore-uuid %s < %s'
- % (ctx.svnadmin, ctx.target, ctx.dumpfile))
+ run_external('%s load --ignore-uuid %s < %s'
+ % (ctx.svnadmin, ctx.target, ctx.dumpfile))
 
 _passes = [
   pass1,

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed May 14 16:12:45 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.