[PATCH] Scripts in contrib/ and relative paths

Jon Foster <[email protected]> Thu, 25 Mar 2010 17:59:42 -0000
Newsgroups gmane.comp.version-control.subversion.cvs2svn.devel
Message-ID <[email protected]>
Hi,

I came across this minor bug:

> ~/cvs2svn-trunk/contrib$ ./destroy_repository.py
> Traceback (most recent call last):
>   File "./destroy_repository.py", line 113, in <module>
>     from cvs2svn_lib.key_generator import KeyGenerator
> ImportError: No module named cvs2svn_lib.key_generator

It works if I specify the absolute path:

> ~/cvs2svn-trunk/contrib$ `pwd`/destroy_repository.py
> [...usage message, as expected...]

The problem is that destroy_repository.py automatically finds the
cvs2svn libraries by taking the script path, then chopping off the
last directory component.  But because I didn't specify the full
path, there wasn't a "last directory component" to chop off.  The
fix is just to insert a call to abspath() in the appropriate place.

After fixing that, there's a similar-but-different bug when using
pychecker:

> ~/cvs2svn-trunk/contrib$ pychecker destroy_repository.py
> Processing destroy_repository...
> ImportError: No module named cvs2svn_lib.key_generator 

In this case, the problem is that sys.argv[0] points to pychecker,
not destroy_repository.py.  This can be fixed by using __file__
instead, which is a special Python variable that gives the path
to the current source file.

Patch attached, that fixes all the occurances of this code.

Kind regards,

Jon

--


**********************************************************************
This email and its attachments may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of Cabot Communications Ltd.

If you are not the intended recipient of this email and its attachments, you must take no action based upon them, nor must you copy or show them to anyone.

Cabot Communications Limited
Verona House, Filwood Road, Bristol BS16 3RY, UK
+44 (0) 1179584232

Co. Registered in England number 02817269

Please contact the sender if you believe you have received this email in error.

**********************************************************************


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

------------------------------------------------------
http://cvs2svn.tigris.org/ds/viewMessage.do?dsForumId=1667&dsMessageId=2465056

To unsubscribe from this discussion, e-mail: [[email protected]].
cvs2svn_contrib_path_fix_patch.txt (text/plain, 2.3 KB)
Index: contrib/shrink_test_case.py
===================================================================
--- contrib/shrink_test_case.py	(revision 5080)
+++ contrib/shrink_test_case.py	(working copy)
@@ -38,7 +38,7 @@
 import optparse
 from cStringIO import StringIO
 
-sys.path.insert(0, os.path.dirname(os.path.dirname(sys.argv[0])))
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
 from cvs2svn_lib.key_generator import KeyGenerator
 
Index: contrib/destroy_repository.py
===================================================================
--- contrib/destroy_repository.py	(revision 5080)
+++ contrib/destroy_repository.py	(working copy)
@@ -108,7 +108,7 @@
 import shutil
 import re
 
-sys.path.insert(0, os.path.dirname(os.path.dirname(sys.argv[0])))
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
 from cvs2svn_lib.key_generator import KeyGenerator
 import cvs2svn_rcsparse
Index: contrib/rcs_file_filter.py
===================================================================
--- contrib/rcs_file_filter.py	(revision 5080)
+++ contrib/rcs_file_filter.py	(working copy)
@@ -22,7 +22,7 @@
 import os
 import time
 
-sys.path.insert(0, os.path.dirname(os.path.dirname(sys.argv[0])))
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
 import cvs2svn_rcsparse
 
Index: contrib/find_illegal_filenames.py
===================================================================
--- contrib/find_illegal_filenames.py	(revision 5080)
+++ contrib/find_illegal_filenames.py	(working copy)
@@ -27,7 +27,7 @@
 import sys
 import os
 
-sys.path.insert(0, os.path.dirname(os.path.dirname(sys.argv[0])))
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
 from cvs2svn_lib.common import FatalError
 from cvs2svn_lib.collect_data import verify_filename_legal
Index: contrib/show_db.py
===================================================================
--- contrib/show_db.py	(revision 5080)
+++ contrib/show_db.py	(working copy)
@@ -8,7 +8,7 @@
 import cPickle as pickle
 from cStringIO import StringIO
 
-sys.path.insert(0, os.path.dirname(os.path.dirname(sys.argv[0])))
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
 from cvs2svn_lib import config
 from cvs2svn_lib.context import Ctx