From 99decd8eface9cd38ddd70542aa28a2773810526 Mon Sep 17 00:00:00 2001 From: Joshua McKenzie Date: Thu, 23 Jul 2015 13:21:10 -0400 Subject: [PATCH 1/2] Fix handling of incorrect %z cqlshlib output on Windows Patch by jmckenzie; reviewed by aweisberg for CASSANDRA-9418 --- bin/cqlsh.py | 2 +- pylib/cqlshlib/formatting.py | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/bin/cqlsh.py b/bin/cqlsh.py index 999ddc42f8..6df1d75ab1 100644 --- a/bin/cqlsh.py +++ b/bin/cqlsh.py @@ -945,7 +945,7 @@ class Shell(cmd.Cmd): try: import readline except ImportError: - if platform.system() == 'Windows': + if myplatform == 'Windows': print "WARNING: pyreadline dependency missing. Install to enable tab completion." pass else: diff --git a/pylib/cqlshlib/formatting.py b/pylib/cqlshlib/formatting.py index ff5b118fa9..00d5b405df 100644 --- a/pylib/cqlshlib/formatting.py +++ b/pylib/cqlshlib/formatting.py @@ -16,16 +16,20 @@ import calendar import math +import platform import re import sys import platform import time from collections import defaultdict + from . import wcwidth from .displaying import colorme, FormattedValue, DEFAULT_VALUE_COLORS from datetime import datetime, timedelta from cassandra.cqltypes import EMPTY +is_win = platform.system() == 'Windows' + unicode_controlchars_re = re.compile(r'[\x00-\x31\x7f-\xa0]') controlchars_re = re.compile(r'[\x00-\x31\x7f-\xff]') @@ -193,15 +197,24 @@ def strftime(time_format, seconds): offset = -time.altzone else: offset = -time.timezone - if formatted[-4:] != '0000' or time_format[-2:] != '%z' or offset == 0: + if not is_win and (formatted[-4:] != '0000' or time_format[-2:] != '%z' or offset == 0): return formatted + elif is_win and time_format[-2:] != '%z': + return formatted + # deal with %z on platforms where it isn't supported. see CASSANDRA-4746. if offset < 0: sign = '-' else: sign = '+' hours, minutes = divmod(abs(offset) / 60, 60) - return formatted[:-5] + sign + '{0:0=2}{1:0=2}'.format(hours, minutes) + # Need to strip out invalid %z output on Windows. C libs give us 'Eastern Standard Time' instead of +/- GMT + if is_win and time_format[-2:] == '%z': + # Remove chars and strip trailing spaces left behind + formatted = re.sub('[A-Za-z]', '', formatted).rstrip() + return formatted + sign + '{0:0=2}{1:0=2}'.format(hours, minutes) + else: + return formatted[:-5] + sign + '{0:0=2}{1:0=2}'.format(hours, minutes) @formatter_for('Date') def format_value_date(val, colormap, **_): From 9ad133097b5120fc6838b62f649c4d058639215e Mon Sep 17 00:00:00 2001 From: Joshua McKenzie Date: Thu, 23 Jul 2015 13:23:55 -0400 Subject: [PATCH 2/2] Add logdir and storagedir to nodetool.bat Patch by jmckenzie; reviewed by pthompson for CASSANDRA-9696 --- bin/nodetool.bat | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/nodetool.bat b/bin/nodetool.bat index ec64db0499..92d5c05a2d 100644 --- a/bin/nodetool.bat +++ b/bin/nodetool.bat @@ -23,8 +23,11 @@ call cassandra.in.bat if NOT DEFINED CASSANDRA_HOME set CASSANDRA_HOME=%~dp0.. if NOT DEFINED JAVA_HOME goto :err +set CASSANDRA_PARAMS=%CASSANDRA_PARAMS% -Dcassandra.logdir="%CASSANDRA_HOME%\logs" +set CASSANDRA_PARAMS=%CASSANDRA_PARAMS% -Dcassandra.storagedir="%CASSANDRA_HOME%\data" + echo Starting NodeTool -"%JAVA_HOME%\bin\java" -cp %CASSANDRA_CLASSPATH% -Dlogback.configurationFile=logback-tools.xml org.apache.cassandra.tools.NodeTool %* +"%JAVA_HOME%\bin\java" -cp %CASSANDRA_CLASSPATH% %CASSANDRA_PARAMS% -Dlogback.configurationFile=logback-tools.xml org.apache.cassandra.tools.NodeTool %* goto finally :err