generated from caicloud/golang-template-project
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support python sdk for ormb * feat: Update gitignore and requirements Co-authored-by: robertzhu <[email protected]>
- Loading branch information
1 parent
8150ac1
commit beb0756
Showing
9 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
## python sdk for ormb | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import json | ||
import requests | ||
import platform | ||
import sys | ||
import tarfile | ||
import os | ||
|
||
|
||
REPOS = "caicloud/ormb" | ||
VERSION = "latest" | ||
BIN_PATH = './ormb/bin' | ||
|
||
OS_LIST = ["Linux", "Darwin"] | ||
ARCH_LIST = ["x86_64", "i386"] | ||
|
||
|
||
def untar(fname, dirs): | ||
t = tarfile.open(fname) | ||
t.extractall(path=dirs) | ||
|
||
|
||
def download(): | ||
url = 'https://api.github.com/repos/%s/releases/%s' % (REPOS, VERSION) | ||
r = requests.get(url) | ||
|
||
if r.status_code != 200: | ||
raise Exception("get assets info err, ret code: %s" % r.status_code) | ||
|
||
json_info = json.loads(r.text) | ||
|
||
cur_version = json_info["tag_name"][1:] | ||
|
||
asset_name = "ormb_%s_Linux_x86_64.tar.gz" % cur_version | ||
for os_name in OS_LIST: | ||
for arch_name in ARCH_LIST: | ||
if arch_name in platform.platform().lower() and os_name.lower() in sys.platform: | ||
asset_name = "ormb_%s_%s_%s.tar.gz" % (cur_version, os_name, arch_name) | ||
|
||
asset_url = "" | ||
|
||
for asset in json_info["assets"]: | ||
if asset_name in asset["browser_download_url"]: | ||
asset_url = asset["url"] | ||
|
||
# download the url contents in binary format | ||
headers = {'Accept': 'application/octet-stream'} | ||
r = requests.get(asset_url, headers=headers) | ||
|
||
# open method to open a file on your system and write the contents | ||
with open(asset_name, "wb") as code: | ||
code.write(r.content) | ||
|
||
if not os.path.exists(BIN_PATH): | ||
os.mkdir(BIN_PATH) | ||
untar(asset_name, BIN_PATH) | ||
|
||
os.remove(asset_name) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from ormb.api import * | ||
|
||
|
||
__version__ = '0.0.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from subprocess import Popen | ||
from os.path import abspath, join, dirname | ||
|
||
BIN_PATH = join(abspath(dirname(__file__)), 'bin') | ||
|
||
|
||
def login(hostname: str, username: str, password: str, insecure_opt: str): | ||
ex = Popen([join(BIN_PATH, "ormb"), "login", hostname, "--username", username, "--password", password, "--insecure", | ||
insecure_opt]) | ||
status = ex.wait() | ||
return status | ||
|
||
|
||
def push(ref: str): | ||
ex = Popen([join(BIN_PATH, "ormb"), "push", ref]) | ||
status = ex.wait() | ||
return status | ||
|
||
|
||
def pull(ref: str): | ||
ex = Popen([join(BIN_PATH, "ormb"), "pull", ref]) | ||
status = ex.wait() | ||
return status | ||
|
||
|
||
def export(ref: str, dst: str): | ||
ex = Popen([join(BIN_PATH, "ormb"), "export", ref, dst]) | ||
status = ex.wait() | ||
return status | ||
|
||
|
||
def save(src: str, ref: str): | ||
ex = Popen([join(BIN_PATH, "ormb"), "save", src, ref]) | ||
status = ex.wait() | ||
return status | ||
|
||
|
||
def remove(ref: str): | ||
ex = Popen([join(BIN_PATH, "ormb"), "remove", ref]) | ||
status = ex.wait() | ||
return status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requests==2.23.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import re | ||
import os | ||
from setuptools import find_packages | ||
from setuptools import setup | ||
|
||
from git_release import download | ||
download() | ||
|
||
|
||
def read_version(): | ||
regexp = re.compile(r"^__version__\W*=\W*'([\d.abrc]+)'") | ||
init_py = os.path.join(os.path.dirname(__file__), "ormb", "__init__.py") | ||
with open(init_py) as f: | ||
for line in f: | ||
match = regexp.match(line) | ||
if match is not None: | ||
return match.group(1) | ||
raise RuntimeError("Cannot find version in {}".format(init_py)) | ||
|
||
|
||
setup( | ||
name="ormb", | ||
version=read_version(), | ||
url="https://github.com/caicloud/ormb", | ||
project_urls={ | ||
"Documentation": "https://github.com/caicloud/ormb/wikis/home", | ||
"Code": "", | ||
"Issue tracker": "https://github.com/caicloud/ormb/issues", | ||
}, | ||
maintainer="gaocegege, ZhuYuJin", | ||
description="ormb warehouse", | ||
python_requires=">=3.6", | ||
install_requires=[ | ||
"requests" | ||
], | ||
packages=find_packages(include=("ormb", "ormb.*")), | ||
package_data={'ormb': ['bin/*']}, | ||
) |
Empty file.
Empty file.