From 1b04790e5fd83e129526808ca923b811b00e48fc Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 28 Feb 2010 16:17:35 -0500 Subject: [PATCH 1/1] Move python library files to lib/bup/ ...and update other programs so that they import them correctly from their new location. This is necessary so that the bup library files can eventually be installed somewhere other than wherever the 'bup' executable ends up. Plus it's clearer and safer to say 'from bup import options' instead of just 'import options', in case someone else writes an 'options' module. I wish I could have named the directory just 'bup', but I can't; there's already a program with that name. Also, in the name of sanity, rename memtest.py to 'bup memtest' so that it can get the new paths automatically. --- Makefile | 17 +++++++++-------- cmd-damage.py | 4 ++-- cmd-drecurse.py | 4 ++-- cmd-fsck.py | 4 ++-- cmd-ftp.py | 4 ++-- cmd-fuse.py | 4 ++-- cmd-index.py | 4 ++-- cmd-init.py | 4 ++-- cmd-join.py | 4 ++-- cmd-ls.py | 4 ++-- cmd-margin.py | 4 ++-- memtest.py => cmd-memtest.py | 5 +++-- cmd-midx.py | 4 ++-- cmd-newliner.py | 2 +- cmd-random.py | 4 ++-- cmd-save.py | 4 ++-- cmd-server.py | 4 ++-- cmd-split.py | 4 ++-- cmd-tick.py | 2 +- lib/bup/__init__.py | 0 _hashsplit.c => lib/bup/_hashsplit.c | 0 client.py => lib/bup/client.py | 4 ++-- csetup.py => lib/bup/csetup.py | 0 drecurse.py => lib/bup/drecurse.py | 2 +- git.py => lib/bup/git.py | 2 +- hashsplit.py => lib/bup/hashsplit.py | 4 ++-- helpers.py => lib/bup/helpers.py | 0 index.py => lib/bup/index.py | 2 +- options.py => lib/bup/options.py | 2 +- shquote.py => lib/bup/shquote.py | 0 vfs.py => lib/bup/vfs.py | 2 +- bup.py => main.py | 9 +++++++-- t/__init__.py | 2 ++ t/tgit.py | 5 +++-- t/thelpers.py | 2 +- t/tindex.py | 4 ++-- t/toptions.py | 2 +- t/tshquote.py | 2 +- 38 files changed, 70 insertions(+), 60 deletions(-) rename memtest.py => cmd-memtest.py (95%) create mode 100644 lib/bup/__init__.py rename _hashsplit.c => lib/bup/_hashsplit.c (100%) rename client.py => lib/bup/client.py (99%) rename csetup.py => lib/bup/csetup.py (100%) rename drecurse.py => lib/bup/drecurse.py (99%) rename git.py => lib/bup/git.py (99%) rename hashsplit.py => lib/bup/hashsplit.py (98%) rename helpers.py => lib/bup/helpers.py (100%) rename index.py => lib/bup/index.py (99%) rename options.py => lib/bup/options.py (99%) rename shquote.py => lib/bup/shquote.py (100%) rename vfs.py => lib/bup/vfs.py (99%) rename bup.py => main.py (89%) diff --git a/Makefile b/Makefile index eacedd0..b47dad6 100644 --- a/Makefile +++ b/Makefile @@ -21,8 +21,8 @@ default: all all: bup-split bup-join bup-save bup-init bup-server bup-index bup-tick \ bup-midx bup-fuse bup-ls bup-damage bup-fsck bup-margin bup-drecurse \ - bup-random bup-ftp bup-newliner \ - bup memtest _hashsplit$(SOEXT) \ + bup-random bup-ftp bup-newliner bup-memtest \ + bup lib/bup/_hashsplit$(SOEXT) \ Documentation/all %/all: @@ -31,10 +31,10 @@ all: bup-split bup-join bup-save bup-init bup-server bup-index bup-tick \ %/clean: $(MAKE) -C $* clean -_hashsplit$(SOEXT): _hashsplit.c csetup.py +lib/bup/_hashsplit$(SOEXT): lib/bup/_hashsplit.c lib/bup/csetup.py @rm -f $@ - python csetup.py build - cp build/*/_hashsplit$(SOEXT) . + cd lib/bup && python csetup.py build + cp lib/bup/build/*/_hashsplit$(SOEXT) lib/bup/ runtests: all runtests-python runtests-cmdline @@ -53,7 +53,7 @@ test: all %: %.o $(CC) $(CFLAGS) (LDFLAGS) -o $@ $^ $(LIBS) -bup: bup.py +bup: main.py rm -f $@ ln -s $< $@ @@ -73,7 +73,8 @@ bup-%: cmd-%.sh gcc -c -o $@ $< $(CPPFLAGS) $(CFLAGS) clean: Documentation/clean - rm -f *.o *.so *.dll *.exe *~ .*~ *.pyc */*.pyc */*~ \ + rm -f *.o *.so */*/*.so *.dll *.exe .*~ *~ */*~ */*/*~ \ + *.pyc */*.pyc */*/*.pyc\ bup bup-* randomgen memtest \ out[12] out2[tc] tags[12] tags2[tc] - rm -rf *.tmp build + rm -rf *.tmp build lib/bup/build diff --git a/cmd-damage.py b/cmd-damage.py index 685a109..6f630fd 100755 --- a/cmd-damage.py +++ b/cmd-damage.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys, os, random -import options -from helpers import * +from bup import options +from bup.helpers import * def randblock(n): diff --git a/cmd-drecurse.py b/cmd-drecurse.py index c2b7079..99780af 100755 --- a/cmd-drecurse.py +++ b/cmd-drecurse.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import options, drecurse -from helpers import * +from bup import options, drecurse +from bup.helpers import * optspec = """ bup drecurse diff --git a/cmd-fsck.py b/cmd-fsck.py index 30f9b07..36c8a35 100755 --- a/cmd-fsck.py +++ b/cmd-fsck.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys, os, glob, subprocess, time, sha -import options, git -from helpers import * +from bup import options, git +from bup.helpers import * par2_ok = 0 nullf = open('/dev/null') diff --git a/cmd-ftp.py b/cmd-ftp.py index 9594b39..b59cf44 100755 --- a/cmd-ftp.py +++ b/cmd-ftp.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys, os, re, stat, readline, fnmatch -import options, git, shquote, vfs -from helpers import * +from bup import options, git, shquote, vfs +from bup.helpers import * def print_node(text, n): if stat.S_ISDIR(n.mode): diff --git a/cmd-fuse.py b/cmd-fuse.py index 0b0bab6..ffcd036 100755 --- a/cmd-fuse.py +++ b/cmd-fuse.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys, os, stat, errno, fuse, re, time, tempfile -import options, git, vfs -from helpers import * +from bup import options, git, vfs +from bup.helpers import * class Stat(fuse.Stat): diff --git a/cmd-index.py b/cmd-index.py index fe1acb1..6839890 100755 --- a/cmd-index.py +++ b/cmd-index.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import os, sys, stat, time -import options, git, index, drecurse -from helpers import * +from bup import options, git, index, drecurse +from bup.helpers import * def merge_indexes(out, r1, r2): diff --git a/cmd-init.py b/cmd-init.py index 8dca178..04f3248 100755 --- a/cmd-init.py +++ b/cmd-init.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import git, options, client -from helpers import * +from bup import git, options, client +from bup.helpers import * optspec = """ [BUP_DIR=...] bup init [-r host:path] diff --git a/cmd-join.py b/cmd-join.py index 26f390c..0e1e1ff 100755 --- a/cmd-join.py +++ b/cmd-join.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys, time, struct -import hashsplit, git, options, client -from helpers import * +from bup import hashsplit, git, options, client +from bup.helpers import * from subprocess import PIPE diff --git a/cmd-ls.py b/cmd-ls.py index 2ce6bb0..5a22c1d 100755 --- a/cmd-ls.py +++ b/cmd-ls.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys, os, stat -import options, git, vfs -from helpers import * +from bup import options, git, vfs +from bup.helpers import * def print_node(text, n): prefix = '' diff --git a/cmd-margin.py b/cmd-margin.py index 05f7d2b..85b3289 100755 --- a/cmd-margin.py +++ b/cmd-margin.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys -import options, git, _hashsplit -from helpers import * +from bup import options, git, _hashsplit +from bup.helpers import * optspec = """ diff --git a/memtest.py b/cmd-memtest.py similarity index 95% rename from memtest.py rename to cmd-memtest.py index 7595259..cf106e4 100755 --- a/memtest.py +++ b/cmd-memtest.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys, re, struct, mmap -import git, options -from helpers import * +from bup import git, options +from bup.helpers import * def s_from_bytes(bytes): @@ -21,6 +21,7 @@ def report(count): else: e1 = '' print ('%9s ' + ('%10s ' * len(fields))) % tuple([e1] + fields) + sys.stdout.flush() optspec = """ diff --git a/cmd-midx.py b/cmd-midx.py index 36907eb..8711111 100755 --- a/cmd-midx.py +++ b/cmd-midx.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys, math, struct, glob, sha -import options, git -from helpers import * +from bup import options, git +from bup.helpers import * PAGE_SIZE=4096 SHA_PER_PAGE=PAGE_SIZE/200. diff --git a/cmd-newliner.py b/cmd-newliner.py index 0b665aa..6c4e60f 100755 --- a/cmd-newliner.py +++ b/cmd-newliner.py @@ -1,6 +1,6 @@ #!/usr/bin/env python import sys, os, re -import options +from bup import options optspec = """ bup newliner diff --git a/cmd-random.py b/cmd-random.py index 518cea8..91820a8 100755 --- a/cmd-random.py +++ b/cmd-random.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys, mmap -import options, _hashsplit -from helpers import * +from bup import options, _hashsplit +from bup.helpers import * optspec = """ bup random [-S seed] diff --git a/cmd-save.py b/cmd-save.py index e2b1f47..0350fff 100755 --- a/cmd-save.py +++ b/cmd-save.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys, re, errno, stat, time, math -import hashsplit, git, options, index, client -from helpers import * +from bup import hashsplit, git, options, index, client +from bup.helpers import * optspec = """ diff --git a/cmd-server.py b/cmd-server.py index 92aa8c1..59459d1 100755 --- a/cmd-server.py +++ b/cmd-server.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys, struct, mmap -import options, git -from helpers import * +from bup import options, git +from bup.helpers import * suspended_w = None diff --git a/cmd-split.py b/cmd-split.py index ae7b380..0f8408c 100755 --- a/cmd-split.py +++ b/cmd-split.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys, time, struct -import hashsplit, git, options, client -from helpers import * +from bup import hashsplit, git, options, client +from bup.helpers import * from subprocess import PIPE diff --git a/cmd-tick.py b/cmd-tick.py index 12bd97e..8375dee 100755 --- a/cmd-tick.py +++ b/cmd-tick.py @@ -1,6 +1,6 @@ #!/usr/bin/env python import sys, time -import options +from bup import options optspec = """ bup tick diff --git a/lib/bup/__init__.py b/lib/bup/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/_hashsplit.c b/lib/bup/_hashsplit.c similarity index 100% rename from _hashsplit.c rename to lib/bup/_hashsplit.c diff --git a/client.py b/lib/bup/client.py similarity index 99% rename from client.py rename to lib/bup/client.py index a9e9c95..6df1358 100644 --- a/client.py +++ b/lib/bup/client.py @@ -1,6 +1,6 @@ import re, struct, errno, select -import git -from helpers import * +from bup import git +from bup.helpers import * from subprocess import Popen, PIPE diff --git a/csetup.py b/lib/bup/csetup.py similarity index 100% rename from csetup.py rename to lib/bup/csetup.py diff --git a/drecurse.py b/lib/bup/drecurse.py similarity index 99% rename from drecurse.py rename to lib/bup/drecurse.py index 33bcca4..c3daaa8 100644 --- a/drecurse.py +++ b/lib/bup/drecurse.py @@ -1,5 +1,5 @@ import stat, heapq -from helpers import * +from bup.helpers import * try: O_LARGEFILE = os.O_LARGEFILE diff --git a/git.py b/lib/bup/git.py similarity index 99% rename from git.py rename to lib/bup/git.py index c5381f0..77e90bf 100644 --- a/git.py +++ b/lib/bup/git.py @@ -1,6 +1,6 @@ import os, errno, zlib, time, sha, subprocess, struct, stat, re, tempfile import heapq -from helpers import * +from bup.helpers import * verbose = 0 ignore_midx = 0 diff --git a/hashsplit.py b/lib/bup/hashsplit.py similarity index 98% rename from hashsplit.py rename to lib/bup/hashsplit.py index f9bc48d..f85011d 100644 --- a/hashsplit.py +++ b/lib/bup/hashsplit.py @@ -1,6 +1,6 @@ import sys, math -import git, _hashsplit -from helpers import * +from bup import git, _hashsplit +from bup.helpers import * BLOB_LWM = 8192*2 BLOB_MAX = BLOB_LWM*2 diff --git a/helpers.py b/lib/bup/helpers.py similarity index 100% rename from helpers.py rename to lib/bup/helpers.py diff --git a/index.py b/lib/bup/index.py similarity index 99% rename from index.py rename to lib/bup/index.py index 536af8f..39cae88 100644 --- a/index.py +++ b/lib/bup/index.py @@ -1,5 +1,5 @@ import os, stat, time, struct, tempfile -from helpers import * +from bup.helpers import * EMPTY_SHA = '\0'*20 FAKE_SHA = '\x01'*20 diff --git a/options.py b/lib/bup/options.py similarity index 99% rename from options.py rename to lib/bup/options.py index 165016c..7ae529f 100644 --- a/options.py +++ b/lib/bup/options.py @@ -1,5 +1,5 @@ import textwrap, getopt, re -from helpers import * +from bup.helpers import * class OptDict: def __init__(self): diff --git a/shquote.py b/lib/bup/shquote.py similarity index 100% rename from shquote.py rename to lib/bup/shquote.py diff --git a/vfs.py b/lib/bup/vfs.py similarity index 99% rename from vfs.py rename to lib/bup/vfs.py index a97d4f5..efa0947 100644 --- a/vfs.py +++ b/lib/bup/vfs.py @@ -1,5 +1,5 @@ import os, re, stat, time -import git +from bup import git from helpers import * EMPTY_SHA='\0'*20 diff --git a/bup.py b/main.py similarity index 89% rename from bup.py rename to main.py index 56f3afe..d5fab14 100755 --- a/bup.py +++ b/main.py @@ -1,12 +1,17 @@ #!/usr/bin/env python import sys, os, subprocess -import git -from helpers import * argv = sys.argv exe = argv[0] exepath = os.path.split(exe)[0] or '.' +# fix the PYTHONPATH to include our lib dir +libpath = os.path.join(exepath, 'lib') +sys.path[:0] = [libpath] +os.environ['PYTHONPATH'] = libpath + ':' + os.environ.get('PYTHONPATH', '') + +from bup.helpers import * + def usage(): log('Usage: bup \n\n') log('Available subcommands:\n') diff --git a/t/__init__.py b/t/__init__.py index e69de29..cb95e53 100644 --- a/t/__init__.py +++ b/t/__init__.py @@ -0,0 +1,2 @@ +import sys +sys.path[:0] = ['lib'] diff --git a/t/tgit.py b/t/tgit.py index 321a343..f43ab53 100644 --- a/t/tgit.py +++ b/t/tgit.py @@ -1,6 +1,7 @@ -import git, time +import time +from bup import git +from bup.helpers import * from wvtest import * -from helpers import * @wvtest diff --git a/t/thelpers.py b/t/thelpers.py index 5e59bca..9f24962 100644 --- a/t/thelpers.py +++ b/t/thelpers.py @@ -1,4 +1,4 @@ -from helpers import * +from bup.helpers import * from wvtest import * @wvtest diff --git a/t/tindex.py b/t/tindex.py index e5c043b..330b444 100644 --- a/t/tindex.py +++ b/t/tindex.py @@ -1,7 +1,7 @@ import os -import index +from bup import index +from bup.helpers import * from wvtest import * -from helpers import * @wvtest def index_basic(): diff --git a/t/toptions.py b/t/toptions.py index 937cf70..4596e8b 100644 --- a/t/toptions.py +++ b/t/toptions.py @@ -1,4 +1,4 @@ -import options +from bup import options from wvtest import * @wvtest diff --git a/t/tshquote.py b/t/tshquote.py index 9f9c8cc..15b06ec 100644 --- a/t/tshquote.py +++ b/t/tshquote.py @@ -1,5 +1,5 @@ +from bup import shquote from wvtest import * -import shquote def qst(line): return [s[1] for s in shquote.quotesplit(line)] -- 2.39.2