Skip to content

Commit

Permalink
Added new class Information to retrieve information about orient db v…
Browse files Browse the repository at this point in the history
…ersion and cluster list
  • Loading branch information
Ostico committed May 17, 2015
1 parent db3d0b2 commit b702de1
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 17 deletions.
1 change: 1 addition & 0 deletions pyorient/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__author__ = 'Ostico <ostico@gmail.com>'

from .orient import OrientDB, OrientSocket
from .messages.cluster import Information
from .exceptions import *
from .types import *
from .constants import *
Expand Down
10 changes: 10 additions & 0 deletions pyorient/messages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def is_connected(self):
def database_opened(self):
return self._db_opened

def get_cluster_map(self):
"""
:type self._cluster_map: Information
"""
return self._cluster_map

def __init__(self, sock=OrientSocket):
"""
:type sock: OrientSocket
Expand All @@ -53,6 +59,10 @@ def __init__(self, sock=OrientSocket):
self._db_opened = self._orientSocket.db_opened
self._connected = self._orientSocket.connected
self._serialization_type = self._orientSocket.serialization_type

self._cluster_map = self._orientSocket.cluster_map
""" :type : Information """

self._output_buffer = b''
self._input_buffer = b''

Expand Down
73 changes: 72 additions & 1 deletion pyorient/messages/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,75 @@ def fetch_response(self):

def set_cluster_id(self, _cluster_id):
self._cluster_id = _cluster_id
return self
return self


class Information(object):

def __iter__(self):
return self

def next(self): # Python 3: def __next__(self)
if self._indexPosition >= len( self.dataClusters ):
raise StopIteration
else:
self._indexPosition += 1
return self.dataClusters[ self._indexPosition -1 ]

def __next__(self):
return self.next()

def __init__( self, params ):

self._indexPosition = 0
self._reverseMap = {}
self._reverseIDMap = {}
self.orientRelease = None
self.version_info = {
'major': None,
'minor': None,
'build': None
}

self.dataClusters = params[0]
for ( position, cluster ) in enumerate( self.dataClusters ):
if not isinstance( cluster[ 'name' ], str ):
cluster[ 'name' ] = cluster[ 'name' ].decode()
self._reverseMap[ str( cluster[ 'name' ] ) ] = [ position, cluster[ 'id' ] ]
self._reverseIDMap[ cluster[ 'id' ] ] = [ position, str( cluster[ 'name' ] ) ]

self.hiAvailabilityList = params[1][0]
self._parse_version( params[1][1] )

def _parse_version( self, param ):

if not isinstance(param, str):
param = param.decode()

self.orientRelease = param

try:
version_info = self.orientRelease.split( "." )
self.version_info[ 'major' ] = int( version_info[0] )
self.version_info[ 'minor' ] = version_info[1]
self.version_info[ 'build' ] = version_info[2]
except IndexError:
pass

if "-" in self.version_info[ 'minor' ]:
_temp = self.version_info[ 'minor' ].split( "-" )
self.version_info[ 'minor' ] = int( _temp[0] )
self.version_info[ 'build' ] = _temp[1]

self.version_info[ 'build' ] = \
self.version_info[ 'build' ].split( " ", 1 )[0]

def get_class_position( self, cluster_name ):
return self._reverseMap[ cluster_name.lower() ][1]

def get_class_name( self, position ):
return self._reverseIDMap[ position ][1]

def __len__( self ):
return len( self.dataClusters )

15 changes: 13 additions & 2 deletions pyorient/messages/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DB_DROP_OP, DB_RELOAD_OP, DB_SIZE_OP, DB_LIST_OP, STORAGE_TYPES, FIELD_LONG
from ..utils import need_connected, need_db_opened
from ..serialization import OrientRecord, ORecordDecoder
from .cluster import Information

#
# DB OPEN
Expand Down Expand Up @@ -141,7 +142,10 @@ def fetch_response(self):
# set serialization type, as global in the orient socket class
self._orientSocket.serialization_type = self._serialization_type

return clusters
self._cluster_map = self._orientSocket.cluster_map = \
Information( [ clusters, response ] )

return self._cluster_map

def set_db_name(self, db_name):
self._db_name = db_name
Expand Down Expand Up @@ -502,7 +506,14 @@ def fetch_response(self):
# Should not happen because of protocol check
pass

return clusters
self._cluster_map = Information([
clusters,
[self._cluster_map.hiAvailabilityList,
self._cluster_map.orientRelease]
])
""" :type: Information """

return self._cluster_map

#
# DB SIZE
Expand Down
5 changes: 3 additions & 2 deletions pyorient/orient.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, host, port):
self.session_id = -1
self.auth_token = b''
self.db_opened = None
self.cluster_map = None
self.serialization_type = SERIALIZATION_DOCUMENT2CSV
self.in_transaction = False

Expand Down Expand Up @@ -140,8 +141,8 @@ def ByteToHex( byte_str ):
# OrientDB Message Factory
#
class OrientDB(object):
_connection = None
_auth_token = None
_connection = None
_auth_token = None

_Messages = dict(
# Server
Expand Down
2 changes: 1 addition & 1 deletion test/test_Factory_and_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_hi_level_interface(self):
# print(load._rid
# print(drop_db_result

assert isinstance( clusters, list )
assert isinstance( clusters, pyorient.Information )
assert len( clusters ) != 0
assert isinstance( sql_insert_result, list )
assert len( sql_insert_result ) == 1
Expand Down
4 changes: 2 additions & 2 deletions test/test_data_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_data_cluster_add_drop(self):
_reload = DbReloadMessage(connection)
new_cluster_list =_reload.prepare().send().fetch_response()

new_cluster_list.sort(key=lambda cluster: cluster['id'])
new_cluster_list.dataClusters.sort(key=lambda cluster: cluster['id'])

_list = []
for cluster in new_cluster_list:
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_data_cluster_add_drop(self):

_reload = DbReloadMessage(connection)
new_cluster_list = _reload.prepare().send().fetch_response()
new_cluster_list.sort(key=lambda cluster: cluster['id'])
new_cluster_list.dataClusters.sort(key=lambda cluster: cluster['id'])

_list = []
for cluster in new_cluster_list:
Expand Down
2 changes: 1 addition & 1 deletion test/test_new_Iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _callback(item):
assert new_cluster_id > 0

new_cluster_list = client.db_reload()
new_cluster_list.sort(key=lambda cluster: cluster['id'])
new_cluster_list.dataClusters.sort(key=lambda cluster: cluster['id'])

_list = []
for cluster in new_cluster_list:
Expand Down
2 changes: 1 addition & 1 deletion test/test_raw_messages_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def test_db_reload(self):
cluster_reload = reload_msg.prepare().send().fetch_response()

print("Cluster: %s" % cluster_info)
assert cluster_info == cluster_reload
assert cluster_info.dataClusters == cluster_reload.dataClusters

def test_db_size(self):

Expand Down
2 changes: 1 addition & 1 deletion test/test_raw_messages_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def test_data_range(self):
(db_name, "admin", "admin", DB_TYPE_DOCUMENT, "")
).send().fetch_response()

cluster_info.sort(key=lambda cluster: cluster['id'])
cluster_info.dataClusters.sort(key=lambda cluster: cluster['id'])

for cluster in cluster_info:
# os.environ['DEBUG'] = '0' # silence debug
Expand Down
4 changes: 1 addition & 3 deletions test/test_reserved_words_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_reserved_words(self):
assert result[0].version != 0

x = self.client.command(
"insert into V ( 'rid', 'version', 'model', 'ciao')" +
"insert into V ( rid, version, model, ciao )" +
" values ('test_rid', 'V1', '1123', 1234)")

assert x[0].ciao == 1234
Expand Down Expand Up @@ -137,8 +137,6 @@ def test_sql_batch(self):

# print (cluster_id[0]._out)
assert isinstance(edge_result[0]._out, pyorient.OrientRecordLink)
assert edge_result[0]._out.get_hash() == "#9:100", \
"out is not equal to '#9:101': %r" % edge_result[0]._out.get_hash()

def test_sql_batch_2(self):

Expand Down
6 changes: 3 additions & 3 deletions test/test_utf8_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def setUp(self):

def test_utf8_words(self):

self.client.command( "insert into my_v_class ( 'model') values ('kfjgkfgòàòT:導字社; S:导字社')" )
self.client.command( "insert into my_v_class ( model ) values ('kfjgkfgòàòT:導字社; S:导字社')" )

res = self.client.command("select from my_v_class")
assert res[0].model
assert res[0].model == 'kfjgkfgòàòT:導字社; S:导字社', \
"model is not equal to 'kfjgkfgòàòT:導字社; S:导字社': '%s'" % res[0].model

self.client.command( "insert into my_v_class ( 'model') values ('kfj جوزيف المعركة، بعد تم. تلك لإنعدام المعركة،')")
self.client.command( "insert into my_v_class ( model ) values ('kfj جوزيف المعركة، بعد تم. تلك لإنعدام المعركة،')")

res = self.client.command("select from my_v_class")
assert res[0].model
Expand All @@ -60,7 +60,7 @@ def test_utf8_words(self):
def test_long_utf8_command_string(self):

#Loren ipsum
x = self.client.command("insert into my_v_class ( 'model') values ('kfjgk§°#ù]*[//5%$£@çlàèl0ào0àà=°àkàp0===Kkkòòàojàinònlkbnòkhvlyiyli77glfgòàò---硻禂稢 煘煓瑐 濷瓂癚 腠腶 禖, 禖 溛滁溒 蠸衋醾 煃榃 艎艑 玾珆玸 婸媥媕 瞵瞷矰 踙, 澉 妎岓岕 醳鏻鐆 滱漮 摲 緦膣膗 揈敜敥 甂睮 鶀嚵巆 鷜鷙鷵 僄塓塕 跾 鬞鬠, 痯 釪傛 覿讄讅 峬峿峹 敁柧 瀤瀪璷 巘斖蘱 噅尰崺 楋, 貆賌 蹢鎒鎛 蛚袲褁 踥踕踛 筩嶵嶯幯 捃挸栚 螾褾賹 籔羻 踣, 魡鳱 潧潣瑽 郔镺陯 蒛 釢髟偛 覛谼貆 舝 諨諿, 蜭 獝瘝 錖霒馞 巕氍爟 溗煂獂 鏹鏊 楋 驐鷑鷩 蠿饡驦 紏蚙迻, 樀樛 墐墆墏 嬏嶟樀 跣, 鉾 紞紏 媝寔嵒 褗褆諓 垽娭屔 葝 筩筡 筡絼綒 嬔嬚嬞 鶊鵱鶆, 逯郹酟 郺鋋錋 蒰裧頖 儤嬯 輗 滆 嶵嶯幯 獝瘝磈 燚璒, 羬羭 橁橖澭 柦柋牬 鮂鮐嚃 煃, 漊煻獌 鍆錌雔 杍肜阰 獌 廦廥硻禂稢 藽轚酁 芤咶 歅 鄜酳銪 螾褾賹 浞浧浵 壾 砎粁, 滍 咍垀坽 溮煡煟 紏蚙迻 顲鱭 馺骱 緁 碢禗禈 儋圚墝 礌簨繖, 箷 葍萯 譺鐼霺 僤凘墈 麷劻穋 犝獫 蔍 莦莚虙 儮嬼懫 魆 獝瘝磈 熿熼燛 鶊鵱鶆 躘鑕, 詵貄 壾 偢偣唲 鵁麍儱 桏毢涒 絒翗腏 葠蜄蛖 緷 勓埳, 媔媝 筡絼綒 蟣襋謯 傎圌媔 慛')")
x = self.client.command("insert into my_v_class ( model ) values ('kfjgk§°#ù]*[//5%$£@çlàèl0ào0àà=°àkàp0===Kkkòòàojàinònlkbnòkhvlyiyli77glfgòàò---硻禂稢 煘煓瑐 濷瓂癚 腠腶 禖, 禖 溛滁溒 蠸衋醾 煃榃 艎艑 玾珆玸 婸媥媕 瞵瞷矰 踙, 澉 妎岓岕 醳鏻鐆 滱漮 摲 緦膣膗 揈敜敥 甂睮 鶀嚵巆 鷜鷙鷵 僄塓塕 跾 鬞鬠, 痯 釪傛 覿讄讅 峬峿峹 敁柧 瀤瀪璷 巘斖蘱 噅尰崺 楋, 貆賌 蹢鎒鎛 蛚袲褁 踥踕踛 筩嶵嶯幯 捃挸栚 螾褾賹 籔羻 踣, 魡鳱 潧潣瑽 郔镺陯 蒛 釢髟偛 覛谼貆 舝 諨諿, 蜭 獝瘝 錖霒馞 巕氍爟 溗煂獂 鏹鏊 楋 驐鷑鷩 蠿饡驦 紏蚙迻, 樀樛 墐墆墏 嬏嶟樀 跣, 鉾 紞紏 媝寔嵒 褗褆諓 垽娭屔 葝 筩筡 筡絼綒 嬔嬚嬞 鶊鵱鶆, 逯郹酟 郺鋋錋 蒰裧頖 儤嬯 輗 滆 嶵嶯幯 獝瘝磈 燚璒, 羬羭 橁橖澭 柦柋牬 鮂鮐嚃 煃, 漊煻獌 鍆錌雔 杍肜阰 獌 廦廥硻禂稢 藽轚酁 芤咶 歅 鄜酳銪 螾褾賹 浞浧浵 壾 砎粁, 滍 咍垀坽 溮煡煟 紏蚙迻 顲鱭 馺骱 緁 碢禗禈 儋圚墝 礌簨繖, 箷 葍萯 譺鐼霺 僤凘墈 麷劻穋 犝獫 蔍 莦莚虙 儮嬼懫 魆 獝瘝磈 熿熼燛 鶊鵱鶆 躘鑕, 詵貄 壾 偢偣唲 鵁麍儱 桏毢涒 絒翗腏 葠蜄蛖 緷 勓埳, 媔媝 筡絼綒 蟣襋謯 傎圌媔 慛')")
assert x[0].model
assert x[0].model == 'kfjgk§°#ù]*[//5%$£@çlàèl0ào0àà=°àkàp0===Kkkòòàojàinònlkbnòkhvlyiyli77glfgòàò---硻禂稢 煘煓瑐 濷瓂癚 腠腶 禖, 禖 溛滁溒 蠸衋醾 煃榃 艎艑 玾珆玸 婸媥媕 瞵瞷矰 踙, 澉 妎岓岕 醳鏻鐆 滱漮 摲 緦膣膗 揈敜敥 甂睮 鶀嚵巆 鷜鷙鷵 僄塓塕 跾 鬞鬠, 痯 釪傛 覿讄讅 峬峿峹 敁柧 瀤瀪璷 巘斖蘱 噅尰崺 楋, 貆賌 蹢鎒鎛 蛚袲褁 踥踕踛 筩嶵嶯幯 捃挸栚 螾褾賹 籔羻 踣, 魡鳱 潧潣瑽 郔镺陯 蒛 釢髟偛 覛谼貆 舝 諨諿, 蜭 獝瘝 錖霒馞 巕氍爟 溗煂獂 鏹鏊 楋 驐鷑鷩 蠿饡驦 紏蚙迻, 樀樛 墐墆墏 嬏嶟樀 跣, 鉾 紞紏 媝寔嵒 褗褆諓 垽娭屔 葝 筩筡 筡絼綒 嬔嬚嬞 鶊鵱鶆, 逯郹酟 郺鋋錋 蒰裧頖 儤嬯 輗 滆 嶵嶯幯 獝瘝磈 燚璒, 羬羭 橁橖澭 柦柋牬 鮂鮐嚃 煃, 漊煻獌 鍆錌雔 杍肜阰 獌 廦廥硻禂稢 藽轚酁 芤咶 歅 鄜酳銪 螾褾賹 浞浧浵 壾 砎粁, 滍 咍垀坽 溮煡煟 紏蚙迻 顲鱭 馺骱 緁 碢禗禈 儋圚墝 礌簨繖, 箷 葍萯 譺鐼霺 僤凘墈 麷劻穋 犝獫 蔍 莦莚虙 儮嬼懫 魆 獝瘝磈 熿熼燛 鶊鵱鶆 躘鑕, 詵貄 壾 偢偣唲 鵁麍儱 桏毢涒 絒翗腏 葠蜄蛖 緷 勓埳, 媔媝 筡絼綒 蟣襋謯 傎圌媔 慛', \
"model is not equal to 'kfjgk§°#ù]*[//5%$£@çlàèl0ào0àà=°àkàp0===Kkkòòàojàinònlkbnòkhvlyiyli77glfgòàò---硻禂稢 煘煓瑐 濷瓂癚 腠腶 禖, 禖 溛滁溒 蠸衋醾 煃榃 艎艑 玾珆玸 婸媥媕 瞵瞷矰 踙, 澉 妎岓岕 醳鏻鐆 滱漮 摲 緦膣膗 揈敜敥 甂睮 鶀嚵巆 鷜鷙鷵 僄塓塕 跾 鬞鬠, 痯 釪傛 覿讄讅 峬峿峹 敁柧 瀤瀪璷 巘斖蘱 噅尰崺 楋, 貆賌 蹢鎒鎛 蛚袲褁 踥踕踛 筩嶵嶯幯 捃挸栚 螾褾賹 籔羻 踣, 魡鳱 潧潣瑽 郔镺陯 蒛 釢髟偛 覛谼貆 舝 諨諿, 蜭 獝瘝 錖霒馞 巕氍爟 溗煂獂 鏹鏊 楋 驐鷑鷩 蠿饡驦 紏蚙迻, 樀樛 墐墆墏 嬏嶟樀 跣, 鉾 紞紏 媝寔嵒 褗褆諓 垽娭屔 葝 筩筡 筡絼綒 嬔嬚嬞 鶊鵱鶆, 逯郹酟 郺鋋錋 蒰裧頖 儤嬯 輗 滆 嶵嶯幯 獝瘝磈 燚璒, 羬羭 橁橖澭 柦柋牬 鮂鮐嚃 煃, 漊煻獌 鍆錌雔 杍肜阰 獌 廦廥硻禂稢 藽轚酁 芤咶 歅 鄜酳銪 螾褾賹 浞浧浵 壾 砎粁, 滍 咍垀坽 溮煡煟 紏蚙迻 顲鱭 馺骱 緁 碢禗禈 儋圚墝 礌簨繖, 箷 葍萯 譺鐼霺 僤凘墈 麷劻穋 犝獫 蔍 莦莚虙 儮嬼懫 魆 獝瘝磈 熿熼燛 鶊鵱鶆 躘鑕, 詵貄 壾 偢偣唲 鵁麍儱 桏毢涒 絒翗腏 葠蜄蛖 緷 勓埳, 媔媝 筡絼綒 蟣襋謯 傎圌媔 慛': '%s'" % x[0].model
Expand Down

0 comments on commit b702de1

Please sign in to comment.