Skip to content

Commit

Permalink
Don't import * from helpers
Browse files Browse the repository at this point in the history
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 <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
  • Loading branch information
rlbdv committed Jan 17, 2016
1 parent 3b470fc commit 7e1f05f
Show file tree
Hide file tree
Showing 37 changed files with 167 additions and 61 deletions.
7 changes: 5 additions & 2 deletions cmd/bloom-cmd.py
Expand Up @@ -4,9 +4,12 @@
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...]
Expand Down
6 changes: 4 additions & 2 deletions cmd/cat-file-cmd.py
Expand Up @@ -4,9 +4,11 @@
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]
Expand Down
4 changes: 3 additions & 1 deletion cmd/damage-cmd.py
Expand Up @@ -4,9 +4,11 @@
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):
Expand Down
5 changes: 4 additions & 1 deletion cmd/drecurse-cmd.py
Expand Up @@ -6,8 +6,11 @@
# 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 <path>
Expand Down
6 changes: 4 additions & 2 deletions cmd/fsck-cmd.py
Expand Up @@ -4,9 +4,11 @@
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')
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion cmd/ftp-cmd.py
Expand Up @@ -4,9 +4,12 @@
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()

Expand Down
5 changes: 4 additions & 1 deletion cmd/fuse-cmd.py
Expand Up @@ -4,9 +4,12 @@
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:
Expand Down
5 changes: 4 additions & 1 deletion cmd/index-cmd.py
Expand Up @@ -6,9 +6,12 @@
# 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):
Expand Down
3 changes: 2 additions & 1 deletion cmd/init-cmd.py
Expand Up @@ -4,10 +4,11 @@
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 = """
Expand Down
4 changes: 3 additions & 1 deletion cmd/join-cmd.py
Expand Up @@ -4,9 +4,11 @@
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 = """
Expand Down
5 changes: 4 additions & 1 deletion cmd/list-idx-cmd.py
Expand Up @@ -4,9 +4,12 @@
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=<prefix>] <idxfilenames...>
Expand Down
3 changes: 2 additions & 1 deletion cmd/ls-cmd.py
Expand Up @@ -4,9 +4,10 @@
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()
Expand Down
4 changes: 3 additions & 1 deletion cmd/margin-cmd.py
Expand Up @@ -4,9 +4,11 @@
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

Expand Down
6 changes: 5 additions & 1 deletion cmd/memtest-cmd.py
Expand Up @@ -4,12 +4,16 @@
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
Expand Down
10 changes: 7 additions & 3 deletions cmd/midx-cmd.py
Expand Up @@ -4,10 +4,14 @@
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.
Expand Down
5 changes: 4 additions & 1 deletion cmd/mux-cmd.py
Expand Up @@ -4,9 +4,12 @@
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)
Expand Down
5 changes: 4 additions & 1 deletion cmd/on-cmd.py
Expand Up @@ -4,10 +4,13 @@
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 <hostname> index ...
Expand Down
7 changes: 5 additions & 2 deletions cmd/random-cmd.py
Expand Up @@ -4,9 +4,12 @@
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] <numbytes>
Expand Down
9 changes: 7 additions & 2 deletions cmd/restore-cmd.py
Expand Up @@ -4,10 +4,15 @@
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] </branch/revision/path/to/dir ...>
Expand Down
8 changes: 6 additions & 2 deletions cmd/save-cmd.py
Expand Up @@ -4,13 +4,17 @@
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 = """
Expand Down
5 changes: 4 additions & 1 deletion cmd/server-cmd.py
Expand Up @@ -4,9 +4,12 @@
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
Expand Down
5 changes: 4 additions & 1 deletion cmd/split-cmd.py
Expand Up @@ -4,9 +4,12 @@
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 = """
Expand Down
5 changes: 2 additions & 3 deletions cmd/tag-cmd.py
Expand Up @@ -5,11 +5,10 @@
"""
# 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.

Expand Down
9 changes: 6 additions & 3 deletions cmd/web-cmd.py
Expand Up @@ -4,10 +4,12 @@
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
Expand All @@ -16,6 +18,7 @@
log('error: cannot find the python "tornado" module; please install it\n')
sys.exit(1)


handle_ctrl_c()


Expand Down
8 changes: 6 additions & 2 deletions lib/bup/bloom.py
Expand Up @@ -79,9 +79,13 @@
Brandon Low <lostlogic@lostlogicx.com> 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
Expand Down
8 changes: 6 additions & 2 deletions 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

Expand Down

0 comments on commit 7e1f05f

Please sign in to comment.