From: Rob Browning Date: Sun, 17 Jan 2016 16:11:22 +0000 (-0600) Subject: Don't import * from helpers X-Git-Tag: 0.28-rc1~31 X-Git-Url: https://arthur.barton.de/gitweb/?p=bup.git;a=commitdiff_plain;h=7e1f05fe8b8d580d61c6a233ec1440adc248c97c Don't import * from helpers So we're not pulling access to random other namespaces through helpers (like errno, subprocess, etc.), and so it's obvious what's coming from where. Thanks to Greg Troxel for help evaluating the changes. Signed-off-by: Rob Browning Tested-by: Rob Browning --- diff --git a/cmd/bloom-cmd.py b/cmd/bloom-cmd.py index b2f909b..f968fa0 100755 --- a/cmd/bloom-cmd.py +++ b/cmd/bloom-cmd.py @@ -4,9 +4,12 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -import sys, glob, tempfile + +import glob, os, sys, tempfile + from bup import options, git, bloom -from bup.helpers import * +from bup.helpers import (debug1, handle_ctrl_c, log, progress, qprogress, + saved_errors) optspec = """ bup bloom [options...] diff --git a/cmd/cat-file-cmd.py b/cmd/cat-file-cmd.py index d8a3dc5..3247e4f 100755 --- a/cmd/cat-file-cmd.py +++ b/cmd/cat-file-cmd.py @@ -4,9 +4,11 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -import sys, stat + +import re, stat, sys + from bup import options, git, vfs -from bup.helpers import * +from bup.helpers import chunkyreader, handle_ctrl_c, log, saved_errors optspec = """ bup cat-file [--meta|--bupm] /branch/revision/[path] diff --git a/cmd/damage-cmd.py b/cmd/damage-cmd.py index 22bc8f0..669148a 100755 --- a/cmd/damage-cmd.py +++ b/cmd/damage-cmd.py @@ -4,9 +4,11 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + import sys, os, random + from bup import options -from bup.helpers import * +from bup.helpers import log def randblock(n): diff --git a/cmd/drecurse-cmd.py b/cmd/drecurse-cmd.py index 611bfdb..bc537cb 100755 --- a/cmd/drecurse-cmd.py +++ b/cmd/drecurse-cmd.py @@ -6,8 +6,11 @@ exec "$bup_python" "$0" ${1+"$@"} # end of bup preamble from os.path import relpath +import sys + from bup import options, drecurse -from bup.helpers import * +from bup.helpers import log, parse_excludes, parse_rx_excludes, saved_errors + optspec = """ bup drecurse diff --git a/cmd/fsck-cmd.py b/cmd/fsck-cmd.py index 94eeb89..8c4d0b7 100755 --- a/cmd/fsck-cmd.py +++ b/cmd/fsck-cmd.py @@ -4,9 +4,11 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + import sys, os, glob, subprocess + from bup import options, git -from bup.helpers import * +from bup.helpers import Sha1, chunkyreader, istty2, log, progress par2_ok = 0 nullf = open('/dev/null') @@ -77,7 +79,7 @@ def git_verify(base): try: quick_verify(base) except Exception as e: - debug('error: %s\n' % e) + log('error: %s\n' % e) return 1 return 0 else: diff --git a/cmd/ftp-cmd.py b/cmd/ftp-cmd.py index 908932b..44fe68c 100755 --- a/cmd/ftp-cmd.py +++ b/cmd/ftp-cmd.py @@ -4,9 +4,12 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + import sys, os, stat, fnmatch + from bup import options, git, shquote, vfs, ls -from bup.helpers import * +from bup.helpers import chunkyreader, handle_ctrl_c, log + handle_ctrl_c() diff --git a/cmd/fuse-cmd.py b/cmd/fuse-cmd.py index 3708692..df9bf56 100755 --- a/cmd/fuse-cmd.py +++ b/cmd/fuse-cmd.py @@ -4,9 +4,12 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + import sys, os, errno + from bup import options, git, vfs, xstat -from bup.helpers import * +from bup.helpers import log + try: import fuse except ImportError: diff --git a/cmd/index-cmd.py b/cmd/index-cmd.py index 73ef558..8390452 100755 --- a/cmd/index-cmd.py +++ b/cmd/index-cmd.py @@ -6,9 +6,12 @@ exec "$bup_python" "$0" ${1+"$@"} # end of bup preamble import sys, stat, time, os, errno, re + from bup import metadata, options, git, index, drecurse, hlinkdb -from bup.helpers import * from bup.hashsplit import GIT_MODE_TREE, GIT_MODE_FILE +from bup.helpers import (handle_ctrl_c, log, parse_excludes, parse_rx_excludes, + progress, qprogress, saved_errors) + class IterHelper: def __init__(self, l): diff --git a/cmd/init-cmd.py b/cmd/init-cmd.py index fabd98c..f2c0052 100755 --- a/cmd/init-cmd.py +++ b/cmd/init-cmd.py @@ -4,10 +4,11 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + import sys from bup import git, options, client -from bup.helpers import * +from bup.helpers import log, saved_errors optspec = """ diff --git a/cmd/join-cmd.py b/cmd/join-cmd.py index 8ad322d..33935d2 100755 --- a/cmd/join-cmd.py +++ b/cmd/join-cmd.py @@ -4,9 +4,11 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + import sys + from bup import git, options, client -from bup.helpers import * +from bup.helpers import linereader, log optspec = """ diff --git a/cmd/list-idx-cmd.py b/cmd/list-idx-cmd.py index 3bab6b3..0d5e9ac 100755 --- a/cmd/list-idx-cmd.py +++ b/cmd/list-idx-cmd.py @@ -4,9 +4,12 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + import sys, os + from bup import git, options -from bup.helpers import * +from bup.helpers import handle_ctrl_c, log, qprogress, saved_errors + optspec = """ bup list-idx [--find=] diff --git a/cmd/ls-cmd.py b/cmd/ls-cmd.py index 031fbae..377d275 100755 --- a/cmd/ls-cmd.py +++ b/cmd/ls-cmd.py @@ -4,9 +4,10 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + import sys + from bup import git, vfs, ls -from bup.helpers import * git.check_repo_or_die() diff --git a/cmd/margin-cmd.py b/cmd/margin-cmd.py index ac25ed0..ca502b9 100755 --- a/cmd/margin-cmd.py +++ b/cmd/margin-cmd.py @@ -4,9 +4,11 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + import sys, struct, math + from bup import options, git, _helpers -from bup.helpers import * +from bup.helpers import log POPULATION_OF_EARTH=6.7e9 # as of September, 2010 diff --git a/cmd/memtest-cmd.py b/cmd/memtest-cmd.py index 245bfc9..c4c531e 100755 --- a/cmd/memtest-cmd.py +++ b/cmd/memtest-cmd.py @@ -4,12 +4,16 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + import sys, re, struct, time, resource + from bup import git, bloom, midx, options, _helpers -from bup.helpers import * +from bup.helpers import handle_ctrl_c + handle_ctrl_c() + _linux_warned = 0 def linux_memstat(): global _linux_warned diff --git a/cmd/midx-cmd.py b/cmd/midx-cmd.py index d867ad6..1879550 100755 --- a/cmd/midx-cmd.py +++ b/cmd/midx-cmd.py @@ -4,10 +4,14 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -import sys, math, struct, glob, resource -import tempfile + +import glob, math, os, resource, struct, sys, tempfile + from bup import options, git, midx, _helpers, xstat -from bup.helpers import * +from bup.helpers import (Sha1, atomically_replaced_file, debug1, fdatasync, + handle_ctrl_c, log, mmap_readwrite, qprogress, + saved_errors, unlink) + PAGE_SIZE=4096 SHA_PER_PAGE=PAGE_SIZE/20. diff --git a/cmd/mux-cmd.py b/cmd/mux-cmd.py index 7a8a9ea..b7a6db1 100755 --- a/cmd/mux-cmd.py +++ b/cmd/mux-cmd.py @@ -4,9 +4,12 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + import os, sys, subprocess, struct + from bup import options -from bup.helpers import * +from bup.helpers import debug1, debug2, mux + # Give the subcommand exclusive access to stdin. orig_stdin = os.dup(0) diff --git a/cmd/on-cmd.py b/cmd/on-cmd.py index f76ad3e..10b1e3f 100755 --- a/cmd/on-cmd.py +++ b/cmd/on-cmd.py @@ -4,10 +4,13 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + import sys, os, struct, getopt, subprocess, signal + from subprocess import PIPE from bup import options, ssh, path -from bup.helpers import * +from bup.helpers import DemuxConn, log + optspec = """ bup on index ... diff --git a/cmd/random-cmd.py b/cmd/random-cmd.py index 7d4c007..868c3af 100755 --- a/cmd/random-cmd.py +++ b/cmd/random-cmd.py @@ -4,9 +4,12 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -import sys + +import os, sys + from bup import options, _helpers -from bup.helpers import * +from bup.helpers import atoi, handle_ctrl_c, log, parse_num + optspec = """ bup random [-S seed] diff --git a/cmd/restore-cmd.py b/cmd/restore-cmd.py index afcc3a4..d1ff9b5 100755 --- a/cmd/restore-cmd.py +++ b/cmd/restore-cmd.py @@ -4,10 +4,15 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -import copy, errno, sys, stat, re + +import copy, errno, os, sys, stat, re + from bup import options, git, metadata, vfs -from bup.helpers import * from bup._helpers import write_sparsely +from bup.helpers import (chunkyreader, handle_ctrl_c, log, mkdirp, + parse_rx_excludes, progress, qprogress, saved_errors, + should_rx_exclude_path, unlink) + optspec = """ bup restore [-C outdir] diff --git a/cmd/save-cmd.py b/cmd/save-cmd.py index 961d7f3..4fa6dca 100755 --- a/cmd/save-cmd.py +++ b/cmd/save-cmd.py @@ -4,13 +4,17 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -import sys, stat, time, math + from errno import EACCES from io import BytesIO +import os, sys, stat, time, math from bup import hashsplit, git, options, index, client, metadata, hlinkdb -from bup.helpers import * from bup.hashsplit import GIT_MODE_TREE, GIT_MODE_FILE, GIT_MODE_SYMLINK +from bup.helpers import (add_error, grafted_path_components, handle_ctrl_c, + istty2, log, parse_date_or_fatal, parse_num, + path_components, progress, qprogress, resolve_parent, + saved_errors, stripped_path_components) optspec = """ diff --git a/cmd/server-cmd.py b/cmd/server-cmd.py index 520ea64..0de6694 100755 --- a/cmd/server-cmd.py +++ b/cmd/server-cmd.py @@ -4,9 +4,12 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + import os, sys, struct + from bup import options, git -from bup.helpers import * +from bup.helpers import Conn, debug1, debug2, linereader, log + suspended_w = None dumb_server_mode = False diff --git a/cmd/split-cmd.py b/cmd/split-cmd.py index 2ad5721..abf3737 100755 --- a/cmd/split-cmd.py +++ b/cmd/split-cmd.py @@ -4,9 +4,12 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + import os, sys, time + from bup import hashsplit, git, options, client -from bup.helpers import * +from bup.helpers import (handle_ctrl_c, log, parse_num, qprogress, reprogress, + saved_errors) optspec = """ diff --git a/cmd/tag-cmd.py b/cmd/tag-cmd.py index f065904..492c3ba 100755 --- a/cmd/tag-cmd.py +++ b/cmd/tag-cmd.py @@ -5,11 +5,10 @@ exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -import sys -import os +import os, sys from bup import git, options -from bup.helpers import * +from bup.helpers import debug1, handle_ctrl_c, log # FIXME: review for safe writes. diff --git a/cmd/web-cmd.py b/cmd/web-cmd.py index 640e4ae..9d5d8a1 100755 --- a/cmd/web-cmd.py +++ b/cmd/web-cmd.py @@ -4,10 +4,12 @@ bup_python="$(dirname "$0")/bup-python" || exit $? exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -import sys, stat, urllib, mimetypes, posixpath, time, webbrowser -import urllib + +import mimetypes, os, posixpath, stat, sys, time, urllib, webbrowser + from bup import options, git, vfs -from bup.helpers import * +from bup.helpers import debug1, handle_ctrl_c, log, resource_path + try: import tornado.httpserver import tornado.ioloop @@ -16,6 +18,7 @@ except ImportError: log('error: cannot find the python "tornado" module; please install it\n') sys.exit(1) + handle_ctrl_c() diff --git a/lib/bup/bloom.py b/lib/bup/bloom.py index c90a1fd..ef896f5 100644 --- a/lib/bup/bloom.py +++ b/lib/bup/bloom.py @@ -79,9 +79,13 @@ None of this tells us what max_pfalse_positive to choose. Brandon Low 2011-02-04 """ -import sys, os, math, mmap + +import sys, os, math, mmap, struct + from bup import _helpers -from bup.helpers import * +from bup.helpers import (debug1, debug2, log, mmap_read, mmap_readwrite, + mmap_readwrite_private) + BLOOM_VERSION = 2 MAX_BITS_EACH = 32 # Kinda arbitrary, but 4 bytes per entry is pretty big diff --git a/lib/bup/client.py b/lib/bup/client.py index d819e70..a57254b 100644 --- a/lib/bup/client.py +++ b/lib/bup/client.py @@ -1,6 +1,10 @@ -import re, struct, errno, time, zlib + +import errno, os, re, struct, time, zlib + from bup import git, ssh -from bup.helpers import * +from bup.helpers import (Conn, atomically_replaced_file, chunkyreader, debug1, + debug2, linereader, mkdirp, progress, qprogress) + bwlimit = None diff --git a/lib/bup/drecurse.py b/lib/bup/drecurse.py index 90b7f26..37e189a 100644 --- a/lib/bup/drecurse.py +++ b/lib/bup/drecurse.py @@ -1,7 +1,10 @@ + import stat, os -from bup.helpers import * + +from bup.helpers import should_rx_exclude_path, debug1 import bup.xstat as xstat + try: O_LARGEFILE = os.O_LARGEFILE except AttributeError: diff --git a/lib/bup/git.py b/lib/bup/git.py index a79b9bd..fd0f3c9 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -2,12 +2,17 @@ bup repositories are in Git format. This library allows us to interact with the Git data structures. """ -import os, sys, zlib, time, subprocess, struct, stat, re, tempfile, glob + +import errno, os, sys, zlib, time, subprocess, struct, stat, re, tempfile, glob from collections import namedtuple from itertools import islice -from bup.helpers import * from bup import _helpers, path, midx, bloom, xstat +from bup.helpers import (Sha1, add_error, chunkyreader, debug1, debug2, + hostname, log, merge_iter, mmap_read, mmap_readwrite, + progress, qprogress, unlink, username, userfullname, + utc_offset_str) + max_pack_size = 1000*1000*1000 # larger packs will slow down pruning max_pack_objects = 200*1000 # cache memory usage is about 83 bytes per object diff --git a/lib/bup/index.py b/lib/bup/index.py index d4dbc55..0829764 100644 --- a/lib/bup/index.py +++ b/lib/bup/index.py @@ -1,6 +1,9 @@ -import metadata, os, stat, struct, tempfile +import errno, metadata, os, stat, struct, tempfile + from bup import xstat -from bup.helpers import * +from bup.helpers import (add_error, log, merge_iter, mmap_readwrite, + progress, qprogress, resolve_parent, slashappend) + EMPTY_SHA = '\0'*20 FAKE_SHA = '\x01'*20 diff --git a/lib/bup/ls.py b/lib/bup/ls.py index df299e5..6e66be5 100644 --- a/lib/bup/ls.py +++ b/lib/bup/ls.py @@ -1,7 +1,9 @@ """Common code for listing files from a bup repository.""" + import copy, os.path, stat, xstat + from bup import metadata, options, vfs -from helpers import * +from helpers import istty1, log def node_info(n, name, diff --git a/lib/bup/midx.py b/lib/bup/midx.py index 57a4787..99c47a2 100644 --- a/lib/bup/midx.py +++ b/lib/bup/midx.py @@ -1,6 +1,9 @@ -import mmap + +import mmap, struct + from bup import _helpers -from bup.helpers import * +from bup.helpers import log, mmap_read + MIDX_VERSION = 4 diff --git a/lib/bup/t/tbloom.py b/lib/bup/t/tbloom.py index 25ef661..43ee2d3 100644 --- a/lib/bup/t/tbloom.py +++ b/lib/bup/t/tbloom.py @@ -1,8 +1,12 @@ -import errno, platform, tempfile + +import errno, platform, subprocess, tempfile + from bup import bloom -from bup.helpers import * +from bup.helpers import mkdirp + from wvtest import * + bup_tmp = os.path.realpath('../../../t/tmp') mkdirp(bup_tmp) diff --git a/lib/bup/t/tgit.py b/lib/bup/t/tgit.py index c57e8cd..8665e80 100644 --- a/lib/bup/t/tgit.py +++ b/lib/bup/t/tgit.py @@ -1,7 +1,9 @@ -import struct, os, tempfile, time from subprocess import check_call +import struct, os, subprocess, tempfile, time + from bup import git -from bup.helpers import * +from bup.helpers import log, mkdirp, readpipe + from wvtest import * diff --git a/lib/bup/t/thelpers.py b/lib/bup/t/thelpers.py index ee8df51..865ad5d 100644 --- a/lib/bup/t/thelpers.py +++ b/lib/bup/t/thelpers.py @@ -4,10 +4,17 @@ import os import os.path import tempfile import stat +import subprocess + +from bup.helpers import (atomically_replaced_file, batchpipe, detect_fakeroot, + grafted_path_components, mkdirp, parse_num, + path_components, readpipe, stripped_path_components, + utc_offset_str) import bup._helpers as _helpers -from bup.helpers import * + from wvtest import * + bup_tmp = os.path.realpath('../../../t/tmp') mkdirp(bup_tmp) diff --git a/lib/bup/t/tindex.py b/lib/bup/t/tindex.py index 14a8d4a..c0276c5 100644 --- a/lib/bup/t/tindex.py +++ b/lib/bup/t/tindex.py @@ -1,13 +1,13 @@ -import os -import time, tempfile + +import os, subprocess, time, tempfile from bup import index, metadata -from bup.helpers import * -import bup.helpers as helpers +from bup.helpers import mkdirp, resolve_parent import bup.xstat as xstat from wvtest import * + lib_t_dir = os.getcwd() bup_tmp = os.path.realpath('../../../t/tmp') mkdirp(bup_tmp) @@ -17,11 +17,11 @@ def index_basic(): cd = os.path.realpath('../../../t') WVPASS(cd) sd = os.path.realpath(cd + '/sampledata') - WVPASSEQ(helpers.resolve_parent(cd + '/sampledata'), sd) + WVPASSEQ(resolve_parent(cd + '/sampledata'), sd) WVPASSEQ(os.path.realpath(cd + '/sampledata/x'), sd + '/x') WVPASSEQ(os.path.realpath(cd + '/sampledata/var/abs-symlink'), sd + '/var/abs-symlink-target') - WVPASSEQ(helpers.resolve_parent(cd + '/sampledata/var/abs-symlink'), + WVPASSEQ(resolve_parent(cd + '/sampledata/var/abs-symlink'), sd + '/var/abs-symlink') diff --git a/lib/bup/vfs.py b/lib/bup/vfs.py index fbe5bd6..00e1b8d 100644 --- a/lib/bup/vfs.py +++ b/lib/bup/vfs.py @@ -3,9 +3,11 @@ The vfs.py library makes it possible to expose contents from bup's repository and abstracts internal name mangling and storage from the exposition layer. """ + import os, re, stat, time + from bup import git, metadata -from helpers import * +from helpers import debug1, debug2 from bup.git import BUP_NORMAL, BUP_CHUNKED, cp from bup.hashsplit import GIT_MODE_TREE, GIT_MODE_FILE diff --git a/main.py b/main.py index b149bba..ecc975f 100755 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ exec "$bup_python" "$0" ${1+"$@"} import sys, os, subprocess, signal, getopt + argv = sys.argv exe = os.path.realpath(argv[0]) exepath = os.path.split(exe)[0] or '.' @@ -29,8 +30,10 @@ os.environ['PYTHONPATH'] = libpath + ':' + os.environ.get('PYTHONPATH', '') os.environ['BUP_MAIN_EXE'] = os.path.abspath(exe) os.environ['BUP_RESOURCE_PATH'] = resourcepath + from bup import helpers -from bup.helpers import * +from bup.helpers import atoi, columnate, debug1, log, tty_width + # after running 'bup newliner', the tty_width() ioctl won't work anymore os.environ['WIDTH'] = str(tty_width())