diff --git a/bin/cqlsh.py b/bin/cqlsh.py index 57c47ab2f1..500ba38ddd 100644 --- a/bin/cqlsh.py +++ b/bin/cqlsh.py @@ -155,7 +155,7 @@ cqlshlibdir = os.path.join(CASSANDRA_PATH, 'pylib') if os.path.isdir(cqlshlibdir): sys.path.insert(0, cqlshlibdir) -from cqlshlib import cql3handling, cqlhandling, pylexotron, sslhandling, copy +from cqlshlib import cql3handling, cqlhandling, copyutil, pylexotron, sslhandling from cqlshlib.displaying import (ANSI_RESET, BLUE, COLUMN_NAME_COLORS, CYAN, RED, FormattedValue, colorme) from cqlshlib.formatting import (DEFAULT_DATE_FORMAT, DEFAULT_NANOTIME_FORMAT, @@ -1843,7 +1843,7 @@ class Shell(cmd.Cmd): print "\n%d rows %s in %s." % (rows, verb, describe_interval(timeend - timestart)) def perform_csv_import(self, ks, cf, columns, fname, opts): - csv_options, dialect_options, unrecognized_options = copy.parse_options(self, opts) + csv_options, dialect_options, unrecognized_options = copyutil.parse_options(self, opts) if unrecognized_options: self.printerr('Unrecognized COPY FROM options: %s' % ', '.join(unrecognized_options.keys())) @@ -1869,7 +1869,7 @@ class Shell(cmd.Cmd): linesource.next() reader = csv.reader(linesource, **dialect_options) - num_processes = copy.get_num_processes(cap=4) + num_processes = copyutil.get_num_processes(cap=4) for i in range(num_processes): parent_conn, child_conn = mp.Pipe() @@ -1879,7 +1879,7 @@ class Shell(cmd.Cmd): for process in processes: process.start() - meter = copy.RateMeter(10000) + meter = copyutil.RateMeter(10000) for current_record, row in enumerate(reader, start=1): # write to the child process pipes[current_record % num_processes].send((current_record, row)) @@ -1953,13 +1953,13 @@ class Shell(cmd.Cmd): return True def perform_csv_export(self, ks, cf, columns, fname, opts): - csv_options, dialect_options, unrecognized_options = copy.parse_options(self, opts) + csv_options, dialect_options, unrecognized_options = copyutil.parse_options(self, opts) if unrecognized_options: self.printerr('Unrecognized COPY TO options: %s' % ', '.join(unrecognized_options.keys())) return 0 - return copy.ExportTask(self, ks, cf, columns, fname, csv_options, dialect_options, - DEFAULT_PROTOCOL_VERSION, CONFIG_FILE).run() + return copyutil.ExportTask(self, ks, cf, columns, fname, csv_options, dialect_options, + DEFAULT_PROTOCOL_VERSION, CONFIG_FILE).run() def do_show(self, parsed): """ diff --git a/pylib/cqlshlib/copy.py b/pylib/cqlshlib/copyutil.py similarity index 99% rename from pylib/cqlshlib/copy.py rename to pylib/cqlshlib/copyutil.py index 8ff474f8f8..a2fab00681 100644 --- a/pylib/cqlshlib/copy.py +++ b/pylib/cqlshlib/copyutil.py @@ -19,7 +19,6 @@ import json import multiprocessing as mp import os import Queue -import random import sys import time import traceback diff --git a/pylib/cqlshlib/test/basecase.py b/pylib/cqlshlib/test/basecase.py index 93a64f6015..d3937690ed 100644 --- a/pylib/cqlshlib/test/basecase.py +++ b/pylib/cqlshlib/test/basecase.py @@ -18,7 +18,7 @@ import os import sys import logging from itertools import izip -from os.path import dirname, join, normpath, islink +from os.path import dirname, join, normpath cqlshlog = logging.getLogger('test_cqlsh') @@ -31,21 +31,15 @@ except ImportError: import unittest rundir = dirname(__file__) -path_to_cqlsh = normpath(join(rundir, '..', '..', '..', 'bin', 'cqlsh.py')) +cqlshdir = normpath(join(rundir, '..', '..', '..', 'bin')) +path_to_cqlsh = normpath(join(cqlshdir, 'cqlsh.py')) -# symlink a ".py" file to cqlsh main script, so we can load it as a module -modulepath = join(rundir, 'cqlsh.py') -try: - if islink(modulepath): - os.unlink(modulepath) -except OSError: - pass -os.symlink(path_to_cqlsh, modulepath) +sys.path.append(cqlshdir) -sys.path.append(rundir) import cqlsh cql = cqlsh.cassandra.cluster.Cluster policy = cqlsh.cassandra.policies.RoundRobinPolicy() +quote_name = cqlsh.cassandra.metadata.maybe_escape_name TEST_HOST = os.environ.get('CQL_TEST_HOST', '127.0.0.1') TEST_PORT = int(os.environ.get('CQL_TEST_PORT', 9042)) diff --git a/pylib/cqlshlib/test/cassconnect.py b/pylib/cqlshlib/test/cassconnect.py index ac0b31b4b8..a93647a471 100644 --- a/pylib/cqlshlib/test/cassconnect.py +++ b/pylib/cqlshlib/test/cassconnect.py @@ -19,9 +19,8 @@ from __future__ import with_statement import contextlib import tempfile import os.path -from .basecase import cql, cqlsh, cqlshlog, TEST_HOST, TEST_PORT, rundir, policy +from .basecase import cql, cqlsh, cqlshlog, TEST_HOST, TEST_PORT, rundir, policy, quote_name from .run_cqlsh import run_cqlsh, call_cqlsh -from cassandra.metadata import maybe_escape_name test_keyspace_init = os.path.join(rundir, 'test_keyspace_init.cql') @@ -126,9 +125,6 @@ def cassandra_cursor(cql_version=None, ks=''): def cql_rule_set(): return cqlsh.cql3handling.CqlRuleSet -def quote_name(name): - return maybe_escape_name(name) - class DEFAULTVAL: pass def testrun_cqlsh(keyspace=DEFAULTVAL, **kwargs):