~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/externalcommand.py

  • Committer: Robert Collins
  • Date: 2006-01-05 22:30:59 UTC
  • mto: (1534.1.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1536.
  • Revision ID: robertc@robertcollins.net-20060105223059-a8b64f7b47cf12fb
 * bzrlib.osutils.safe_unicode now exists to provide parameter coercion
   for functions that need unicode strings. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import os
23
23
import sys
 
24
 
24
25
from bzrlib.commands import Command
 
26
from bzrlib.osutils import pathjoin
25
27
 
26
28
 
27
29
class ExternalCommand(Command):
33
35
        bzrpath = os.environ.get('BZRPATH', '')
34
36
 
35
37
        for dir in bzrpath.split(os.pathsep):
 
38
            ## Empty directories are not real paths
 
39
            if not dir:
 
40
                continue
 
41
            # This needs to be os.path.join() or windows cannot
 
42
            # find the batch file that you are wanting to execute
36
43
            path = os.path.join(dir, cmd)
37
44
            if os.path.isfile(path):
38
45
                return ExternalCommand(path)
43
50
    def __init__(self, path):
44
51
        self.path = path
45
52
 
46
 
 
47
53
    def name(self):
48
 
        return self.path.split(os.sep)[-1]
49
 
 
 
54
        return os.path.basename(self.path)
50
55
 
51
56
    def run(self, *args, **kwargs):
52
57
        raise NotImplementedError('should not be called on %r' % self)
53
58
 
54
 
 
55
59
    def run_argv(self, argv):
56
60
        return os.spawnv(os.P_WAIT, self.path, [self.path] + argv)
57
61
 
58
 
 
59
62
    def help(self):
60
63
        m = 'external command from %s\n\n' % self.path
61
64
        pipe = os.popen('%s --help' % self.path)
62
65
        return m + pipe.read()
 
66