-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
revol.cai
committed
Feb 18, 2018
1 parent
e124a44
commit 2287f30
Showing
13 changed files
with
182 additions
and
65 deletions.
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
class BaseAPI(object): | ||
def call_rpc(self, method, data=None, stream=False, **kwargs): | ||
raise NotImplementedError | ||
from base import BaseAPI | ||
from maintenance import MaintenanceAPI | ||
|
||
__all__ = ['BaseAPI', 'MaintenanceAPI'] |
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,3 @@ | ||
class BaseAPI(object): | ||
def call_rpc(self, method, data=None, stream=False, **kwargs): | ||
raise NotImplementedError |
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
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,33 @@ | ||
ENUM_FILE_TPL = '''\ | ||
# Models generated from rpc.swagger.json, do not edit | ||
import enum | ||
{% for e in enums %} | ||
class {{e._path | last}}(enum.Enum): | ||
""" | ||
ref: {{ e._ref }} | ||
default: {{ e.default }} | ||
""" | ||
{% for prop in e.enum %}{{ prop.name }} = '{{ prop.value }}' | ||
{% endfor %} | ||
{% endfor %} | ||
__all__ = [{% for e in enums %} | ||
'{{e._path | last}}',{% endfor %} | ||
] | ||
''' | ||
|
||
if __name__ == '__main__': | ||
import os | ||
import jinja2 | ||
from swagger_helper import SwaggerSpec | ||
|
||
rpc_swagger_json = os.path.join(os.path.dirname(__file__), 'rpc.swagger.json') | ||
swaggerSpec = SwaggerSpec(rpc_swagger_json) | ||
|
||
enums = [i for i in swaggerSpec.definitions if i._is_enum] | ||
enum_tpl = jinja2.Template(ENUM_FILE_TPL) | ||
with open(os.path.join(os.path.dirname(__file__), 'models.py'), 'w') as f: | ||
s = enum_tpl.render(enums=enums) | ||
f.write(s) | ||
print(s) |
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,106 @@ | ||
# Models generated from rpc.swagger.json, do not edit | ||
import enum | ||
|
||
|
||
class AlarmRequestAlarmAction(enum.Enum): | ||
""" | ||
ref: #/definitions/AlarmRequestAlarmAction | ||
default: GET | ||
""" | ||
GET = 'GET' | ||
ACTIVATE = 'ACTIVATE' | ||
DEACTIVATE = 'DEACTIVATE' | ||
|
||
|
||
class EventEventType(enum.Enum): | ||
""" | ||
ref: #/definitions/EventEventType | ||
default: PUT | ||
""" | ||
PUT = 'PUT' | ||
DELETE = 'DELETE' | ||
|
||
|
||
class RangeRequestSortTarget(enum.Enum): | ||
""" | ||
ref: #/definitions/RangeRequestSortTarget | ||
default: KEY | ||
""" | ||
KEY = 'KEY' | ||
VERSION = 'VERSION' | ||
CREATE = 'CREATE' | ||
MOD = 'MOD' | ||
VALUE = 'VALUE' | ||
|
||
|
||
class CompareCompareTarget(enum.Enum): | ||
""" | ||
ref: #/definitions/CompareCompareTarget | ||
default: VERSION | ||
""" | ||
VERSION = 'VERSION' | ||
CREATE = 'CREATE' | ||
MOD = 'MOD' | ||
VALUE = 'VALUE' | ||
|
||
|
||
class authpbPermissionType(enum.Enum): | ||
""" | ||
ref: #/definitions/authpbPermissionType | ||
default: READ | ||
""" | ||
READ = 'READ' | ||
WRITE = 'WRITE' | ||
READWRITE = 'READWRITE' | ||
|
||
|
||
class CompareCompareResult(enum.Enum): | ||
""" | ||
ref: #/definitions/CompareCompareResult | ||
default: EQUAL | ||
""" | ||
EQUAL = 'EQUAL' | ||
GREATER = 'GREATER' | ||
LESS = 'LESS' | ||
NOT_EQUAL = 'NOT_EQUAL' | ||
|
||
|
||
class RangeRequestSortOrder(enum.Enum): | ||
""" | ||
ref: #/definitions/RangeRequestSortOrder | ||
default: NONE | ||
""" | ||
NONE = 'NONE' | ||
ASCEND = 'ASCEND' | ||
DESCEND = 'DESCEND' | ||
|
||
|
||
class etcdserverpbAlarmType(enum.Enum): | ||
""" | ||
ref: #/definitions/etcdserverpbAlarmType | ||
default: NONE | ||
""" | ||
NONE = 'NONE' | ||
NOSPACE = 'NOSPACE' | ||
|
||
|
||
class WatchCreateRequestFilterType(enum.Enum): | ||
""" | ||
ref: #/definitions/WatchCreateRequestFilterType | ||
default: NOPUT | ||
""" | ||
NOPUT = 'NOPUT' | ||
NODELETE = 'NODELETE' | ||
|
||
|
||
__all__ = [ | ||
'AlarmRequestAlarmAction', | ||
'EventEventType', | ||
'RangeRequestSortTarget', | ||
'CompareCompareTarget', | ||
'authpbPermissionType', | ||
'CompareCompareResult', | ||
'RangeRequestSortOrder', | ||
'etcdserverpbAlarmType', | ||
'WatchCreateRequestFilterType', | ||
] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,29 +1 @@ | ||
import base64 | ||
import enum | ||
import six | ||
|
||
bytes_types = (bytes, bytearray) | ||
|
||
|
||
def encode(data): | ||
""" | ||
Encode the given data using base-64 | ||
:param data: | ||
:return: base-64 encoded string | ||
""" | ||
if isinstance(data, enum.Enum): | ||
data = enum.value | ||
if not isinstance(data, bytes_types): | ||
data = six.b(str(data)) | ||
return base64.b64encode(data).decode("utf-8") | ||
|
||
|
||
def decode(data): | ||
""" | ||
Decode the base-64 encoded string | ||
:param data: | ||
:return: decoded string | ||
""" | ||
if not isinstance(data, bytes_types): | ||
data = six.b(str(data)) | ||
return base64.b64decode(data.decode("utf-8")) |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pip>=8.1.2 | ||
bumpversion>=0.5.3 | ||
Jinja2==2.10 | ||
wheel>=0.29.0 | ||
watchdog>=0.8.3 | ||
flake8>=2.6.0 | ||
|