#!/usr/bin/env python
import sys, os, glob
-from bup import options
+from bup import options, path
optspec = """
bup help <command>
os.execvp(os.environ['BUP_MAIN_EXE'], ['bup'])
elif len(extra) == 1:
docname = (extra[0]=='bup' and 'bup' or ('bup-%s' % extra[0]))
- exe = sys.argv[0]
- (exepath, exefile) = os.path.split(exe)
- manpath = os.path.join(exepath, '../Documentation/' + docname + '.[1-9]')
+ manpath = os.path.join(path.exedir(),
+ '../Documentation/' + docname + '.[1-9]')
g = glob.glob(manpath)
if g:
os.execvp('man', ['man', '-l', g[0]])
#!/usr/bin/env python
import sys, os, struct, getopt, subprocess, signal
-from bup import options, ssh
+from bup import options, ssh, path
from bup.helpers import *
optspec = """
p.stdin.write(struct.pack('!I', len(argvs)) + argvs)
p.stdin.flush()
- main_exe = os.environ.get('BUP_MAIN_EXE') or sys.argv[0]
- sp = subprocess.Popen([main_exe, 'server'], stdin=p.stdout, stdout=p.stdin)
-
+ sp = subprocess.Popen([path.exe(), 'server'],
+ stdin=p.stdout, stdout=p.stdin)
p.stdin.close()
p.stdout.close()
"""
import os, sys, zlib, time, subprocess, struct, stat, re, tempfile, heapq
from bup.helpers import *
-from bup import _helpers
+from bup import _helpers, path
MIDX_VERSION = 2
def auto_midx(objdir):
- main_exe = os.environ.get('BUP_MAIN_EXE') or sys.argv[0]
- args = [main_exe, 'midx', '--auto', '--dir', objdir]
+ args = [path.exe(), 'midx', '--auto', '--dir', objdir]
try:
rv = subprocess.call(args, stdout=open('/dev/null', 'w'))
except OSError, e:
--- /dev/null
+"""This is a separate module so we can cleanly getcwd() before anyone
+ does chdir().
+"""
+import sys, os
+
+startdir = os.getcwd()
+
+def exe():
+ return (os.environ.get('BUP_MAIN_EXE') or
+ os.path.join(startdir, sys.argv[0]))
+
+def exedir():
+ return os.path.split(exe())[0]
+
+def exefile():
+ return os.path.split(exe())[1]
"""SSH connection.
Connect to a remote host via SSH and execute a command on the host.
"""
-import os
-import sys
-import re
-import subprocess
-
-from bup import helpers
+import sys, os, re, subprocess
+from bup import helpers, path
def connect(rhost, port, subcmd):
"""Connect to 'rhost' and execute the bup subcommand 'subcmd' on it."""
assert(not re.search(r'[^\w-]', subcmd))
- main_exe = os.environ.get('BUP_MAIN_EXE') or sys.argv[0]
- nicedir = os.path.split(os.path.abspath(main_exe))[0]
- nicedir = re.sub(r':', "_", nicedir)
+ nicedir = re.sub(r':', "_", path.exedir())
if rhost == '-':
rhost = None
if not rhost: