kyuubi/python/generate.py
Cheng Pan f8c7b93f55
[KYUUBI #5686][FOLLOWUP] Rename pyhive to python
# 🔍 Description

This is the follow-up of #5686, renaming `./pyhive` to `./python`, and also adding `**/python/*` to RAT exclusion list temporarily.

"PyHive" may not be a suitable name after being part of Apache Kyuubi, let's use a generic dir name `python`, and discuss the official name later(we probably keep the code at `./python` eventually).

## Types of changes 🔖

- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Test Plan 🧪

Recover RAT checked.

---

# Checklist 📝

- [x] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html)

**Be nice. Be informative.**

Closes #6279 from pan3793/pyhive-1.

Closes #5686

42d338e71 [Cheng Pan] [KYUUBI #5686][FOLLOWUP] Rename pyhive to python

Authored-by: Cheng Pan <chengpan@apache.org>
Signed-off-by: Cheng Pan <chengpan@apache.org>
2024-04-09 20:30:02 +08:00

53 lines
1.3 KiB
Python

"""
This file can be used to generate a new version of the TCLIService package
using a TCLIService.thrift URL.
If no URL is specified, the file for Hive 2.3 will be downloaded.
Usage:
python generate.py THRIFT_URL
or
python generate.py
"""
import shutil
import sys
from os import path
from urllib.request import urlopen
import subprocess
here = path.abspath(path.dirname(__file__))
PACKAGE = 'TCLIService'
GENERATED = 'gen-py'
HIVE_SERVER2_URL = \
'https://raw.githubusercontent.com/apache/hive/branch-2.3/service-rpc/if/TCLIService.thrift'
def save_url(url):
data = urlopen(url).read()
file_path = path.join(here, url.rsplit('/', 1)[-1])
with open(file_path, 'wb') as f:
f.write(data)
def main(hive_server2_url):
save_url(hive_server2_url)
hive_server2_path = path.join(here, hive_server2_url.rsplit('/', 1)[-1])
subprocess.call(['thrift', '-r', '--gen', 'py', hive_server2_path])
shutil.move(path.join(here, PACKAGE), path.join(here, PACKAGE + '.old'))
shutil.move(path.join(here, GENERATED, PACKAGE), path.join(here, PACKAGE))
shutil.rmtree(path.join(here, PACKAGE + '.old'))
if __name__ == '__main__':
if len(sys.argv) > 1:
url = sys.argv[1]
else:
url = HIVE_SERVER2_URL
main(url)