phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joshelser <...@git.apache.org>
Subject [GitHub] phoenix pull request #186: cleanup sqlline-thin.py using python idioms.
Date Mon, 01 Aug 2016 18:06:44 GMT
Github user joshelser commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/186#discussion_r73024268
  
    --- Diff: bin/sqlline-thin.py ---
    @@ -86,73 +80,83 @@ def get_serialization():
             return default_serialization
         return stdout
     
    -if len(sys.argv) == 1:
    -    pass
    -elif len(sys.argv) == 2:
    -    if os.path.isfile(sys.argv[1]):
    -        sqlfile = sys.argv[1]
    -    else:
    +
    +def main():
    +    url = 'localhost:8765'
    +    sqlfile = ''
    +    if len(sys.argv) == 1:
    +        pass
    +    elif len(sys.argv) == 2:
    +        if os.path.isfile(sys.argv[1]):
    +            sqlfile = sys.argv[1]
    +        else:
    +            url = sys.argv[1]
    +    elif len(sys.argv) == 3:
             url = sys.argv[1]
    -elif len(sys.argv) == 3:
    -    url = sys.argv[1]
    -    sqlfile = sys.argv[2]
    -else:
    -    usage_and_exit()
    -
    -url = cleanup_url(url)
    -
    -if sqlfile != "":
    -    sqlfile = "--run=" + sqlfile
    -
    -colorSetting = "true"
    -# disable color setting for windows OS
    -if os.name == 'nt':
    -    colorSetting = "false"
    -
    -# HBase configuration folder path (where hbase-site.xml reside) for
    -# HBase/Phoenix client side property override
    -hbase_config_path = os.getenv('HBASE_CONF_DIR', phoenix_utils.current_dir)
    -
    -serialization = get_serialization()
    -
    -java_home = os.getenv('JAVA_HOME')
    -
    -# load hbase-env.??? to extract JAVA_HOME, HBASE_PID_DIR, HBASE_LOG_DIR
    -hbase_env_path = None
    -hbase_env_cmd  = None
    -if os.name == 'posix':
    -    hbase_env_path = os.path.join(hbase_config_path, 'hbase-env.sh')
    -    hbase_env_cmd = ['bash', '-c', 'source %s && env' % hbase_env_path]
    -elif os.name == 'nt':
    -    hbase_env_path = os.path.join(hbase_config_path, 'hbase-env.cmd')
    -    hbase_env_cmd = ['cmd.exe', '/c', 'call %s & set' % hbase_env_path]
    -if not hbase_env_path or not hbase_env_cmd:
    -    print >> sys.stderr, "hbase-env file unknown on platform %s" % os.name
    -    sys.exit(-1)
    -
    -hbase_env = {}
    -if os.path.isfile(hbase_env_path):
    -    p = subprocess.Popen(hbase_env_cmd, stdout = subprocess.PIPE)
    -    for x in p.stdout:
    -        (k, _, v) = x.partition('=')
    -        hbase_env[k.strip()] = v.strip()
    -
    -if hbase_env.has_key('JAVA_HOME'):
    -    java_home = hbase_env['JAVA_HOME']
    -
    -if java_home:
    -    java = os.path.join(java_home, 'bin', 'java')
    -else:
    -    java = 'java'
    -
    -java_cmd = java + ' $PHOENIX_OPTS ' + \
    -    ' -cp "' + phoenix_utils.hbase_conf_dir + os.pathsep + phoenix_utils.phoenix_thin_client_jar
+ \
    -    os.pathsep + phoenix_utils.hadoop_conf + os.pathsep + phoenix_utils.hadoop_classpath
+ '" -Dlog4j.configuration=file:' + \
    -    os.path.join(phoenix_utils.current_dir, "log4j.properties") + \
    -    " org.apache.phoenix.queryserver.client.SqllineWrapper -d org.apache.phoenix.queryserver.client.Driver
" + \
    -    " -u \"jdbc:phoenix:thin:url=" + url + ";serialization=" + serialization + "\"" +
\
    -    " -n none -p none --color=" + colorSetting + " --fastConnect=false --verbose=true
" + \
    -    " --incremental=false --isolation=TRANSACTION_READ_COMMITTED " + sqlfile
    -
    -exitcode = subprocess.call(java_cmd, shell=True)
    -sys.exit(exitcode)
    +        sqlfile = sys.argv[2]
    +    else:
    +        sys.exit('usage: sqlline-thin.py [host[:port]] [sql_file]')
    +
    +    # disable color setting for windows OS
    +    color_setting = 'false' if os.name == 'nt' else 'true'
    +
    +    # HBase configuration folder path (where hbase-site.xml reside) for
    +    # HBase/Phoenix client side property override
    +    hbase_config_path = os.getenv('HBASE_CONF_DIR', phoenix_utils.current_dir)
    +    serialization = get_serialization()
    +    java_home = os.getenv('JAVA_HOME')
    +
    +    # load hbase-env.??? to extract JAVA_HOME, HBASE_PID_DIR, HBASE_LOG_DIR
    +    hbase_env_path = None
    +    hbase_env_cmd = None
    +    if os.name == 'posix':
    +        hbase_env_path = os.path.join(hbase_config_path, 'hbase-env.sh')
    +        hbase_env_cmd = ['bash', '-c', 'source %s && env' % hbase_env_path]
    +    elif os.name == 'nt':
    +        hbase_env_path = os.path.join(hbase_config_path, 'hbase-env.cmd')
    +        hbase_env_cmd = ['cmd.exe', '/c', 'call %s & set' % hbase_env_path]
    +
    +    if not hbase_env_path:
    +        print("hbase-env script unknown on platform %s" % (os.name, ),
    +              file=sys.stderr)
    +        sys.exit(-1)
    +
    +    hbase_env = {}
    +    if os.path.isfile(hbase_env_path):
    +        p = subprocess.Popen(hbase_env_cmd, stdout=subprocess.PIPE)
    +        for x in p.stdout:
    +            (k, _, v) = x.partition('=')
    +            hbase_env[k.strip()] = v.strip()
    +
    +    if 'JAVA_HOME' in hbase_env:
    +        java_home = hbase_env['JAVA_HOME']
    +
    +    java = os.path.join(java_home, 'bin', 'java') if java_home else 'java'
    +    print ('java is ', java)
    --- End diff --
    
    Nit, please remove the print statement.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message