nwo
stringlengths
6
76
sha
stringlengths
40
40
path
stringlengths
5
118
language
stringclasses
1 value
identifier
stringlengths
1
89
parameters
stringlengths
2
5.4k
argument_list
stringclasses
1 value
return_statement
stringlengths
0
51.1k
docstring
stringlengths
1
17.6k
docstring_summary
stringlengths
0
7.02k
docstring_tokens
sequence
function
stringlengths
30
51.1k
function_tokens
sequence
url
stringlengths
85
218
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/utils/services.py
python
Service.unMapTarget
(self, target)
Remove a target from the service.
Remove a target from the service.
[ "Remove", "a", "target", "from", "the", "service", "." ]
def unMapTarget(self, target): """Remove a target from the service.""" key = target.__name__ if key in self._targets: del self._targets[key]
[ "def", "unMapTarget", "(", "self", ",", "target", ")", ":", "key", "=", "target", ".", "__name__", "if", "key", "in", "self", ".", "_targets", ":", "del", "self", ".", "_targets", "[", "key", "]" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/utils/services.py#L40-L44
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/utils/services.py
python
Service.unMapTargetByKey
(self,targetKey)
Remove a target from the service.
Remove a target from the service.
[ "Remove", "a", "target", "from", "the", "service", "." ]
def unMapTargetByKey(self,targetKey): """Remove a target from the service.""" del self._targets[targetKey]
[ "def", "unMapTargetByKey", "(", "self", ",", "targetKey", ")", ":", "del", "self", ".", "_targets", "[", "targetKey", "]" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/utils/services.py#L46-L48
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/utils/services.py
python
Service.getTarget
(self, targetKey)
return target
Get a target from the service by name.
Get a target from the service by name.
[ "Get", "a", "target", "from", "the", "service", "by", "name", "." ]
def getTarget(self, targetKey): """Get a target from the service by name.""" target = self._targets.get(targetKey, None) return target
[ "def", "getTarget", "(", "self", ",", "targetKey", ")", ":", "target", "=", "self", ".", "_targets", ".", "get", "(", "targetKey", ",", "None", ")", "return", "target" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/utils/services.py#L50-L53
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/utils/services.py
python
Service.callTarget
(self,targetKey,*args,**kw)
return response
call Target @param conn: client connection @param targetKey: target ID @param data: client data
call Target
[ "call", "Target" ]
def callTarget(self,targetKey,*args,**kw): '''call Target @param conn: client connection @param targetKey: target ID @param data: client data ''' target = self.getTarget(targetKey) if not target: log.err('the command '+str(targetKey)+' not Found on service') return None if targetKey not in self.unDisplay: log.msg("call method %s on service[single]"%target.__name__) response = target(*args,**kw) return response
[ "def", "callTarget", "(", "self", ",", "targetKey", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "target", "=", "self", ".", "getTarget", "(", "targetKey", ")", "if", "not", "target", ":", "log", ".", "err", "(", "'the command '", "+", "str", "(", "targetKey", ")", "+", "' not Found on service'", ")", "return", "None", "if", "targetKey", "not", "in", "self", ".", "unDisplay", ":", "log", ".", "msg", "(", "\"call method %s on service[single]\"", "%", "target", ".", "__name__", ")", "response", "=", "target", "(", "*", "args", ",", "*", "*", "kw", ")", "return", "response" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/utils/services.py#L55-L68
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/utils/services.py
python
CommandService.mapTarget
(self, target)
Add a target to the service.
Add a target to the service.
[ "Add", "a", "target", "to", "the", "service", "." ]
def mapTarget(self, target): """Add a target to the service. """ key = int((target.__name__).split('_')[-1]) if self._targets.has_key(key): exist_target = self._targets.get(key) raise "target [%d] Already exists,\ Conflict between the %s and %s"%(key,exist_target.__name__,target.__name__) self._targets[key] = target
[ "def", "mapTarget", "(", "self", ",", "target", ")", ":", "key", "=", "int", "(", "(", "target", ".", "__name__", ")", ".", "split", "(", "'_'", ")", "[", "-", "1", "]", ")", "if", "self", ".", "_targets", ".", "has_key", "(", "key", ")", ":", "exist_target", "=", "self", ".", "_targets", ".", "get", "(", "key", ")", "raise", "\"target [%d] Already exists,\\\n Conflict between the %s and %s\"", "%", "(", "key", ",", "exist_target", ".", "__name__", ",", "target", ".", "__name__", ")", "self", ".", "_targets", "[", "key", "]", "=", "target" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/utils/services.py#L75-L83
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/utils/services.py
python
CommandService.unMapTarget
(self, target)
Remove a target from the service.
Remove a target from the service.
[ "Remove", "a", "target", "from", "the", "service", "." ]
def unMapTarget(self, target): """Remove a target from the service. """ key = int((target.__name__).split('_')[-1]) if key in self._targets: del self._targets[key]
[ "def", "unMapTarget", "(", "self", ",", "target", ")", ":", "key", "=", "int", "(", "(", "target", ".", "__name__", ")", ".", "split", "(", "'_'", ")", "[", "-", "1", "]", ")", "if", "key", "in", "self", ".", "_targets", ":", "del", "self", ".", "_targets", "[", "key", "]" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/utils/services.py#L85-L90
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/utils/version.py
python
get_version
(version=None)
return str(main + sub)
Returns a PEP 386-compliant version number from VERSION.
Returns a PEP 386-compliant version number from VERSION.
[ "Returns", "a", "PEP", "386", "-", "compliant", "version", "number", "from", "VERSION", "." ]
def get_version(version=None): "Returns a PEP 386-compliant version number from VERSION." if version is None: from gfirefly import VERSION as version else: assert len(version) == 5 assert version[3] in ('alpha', 'beta', 'rc', 'final') parts = 2 if version[2] == 0 else 3 main = '.'.join(str(x) for x in version[:parts]) sub = '' if version[3] == 'alpha' and version[4] == 0: git_changeset = get_git_changeset() if git_changeset: sub = '.dev%s' % git_changeset elif version[3] != 'final': mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'} sub = mapping[version[3]] + str(version[4]) return str(main + sub)
[ "def", "get_version", "(", "version", "=", "None", ")", ":", "if", "version", "is", "None", ":", "from", "gfirefly", "import", "VERSION", "as", "version", "else", ":", "assert", "len", "(", "version", ")", "==", "5", "assert", "version", "[", "3", "]", "in", "(", "'alpha'", ",", "'beta'", ",", "'rc'", ",", "'final'", ")", "parts", "=", "2", "if", "version", "[", "2", "]", "==", "0", "else", "3", "main", "=", "'.'", ".", "join", "(", "str", "(", "x", ")", "for", "x", "in", "version", "[", ":", "parts", "]", ")", "sub", "=", "''", "if", "version", "[", "3", "]", "==", "'alpha'", "and", "version", "[", "4", "]", "==", "0", ":", "git_changeset", "=", "get_git_changeset", "(", ")", "if", "git_changeset", ":", "sub", "=", "'.dev%s'", "%", "git_changeset", "elif", "version", "[", "3", "]", "!=", "'final'", ":", "mapping", "=", "{", "'alpha'", ":", "'a'", ",", "'beta'", ":", "'b'", ",", "'rc'", ":", "'c'", "}", "sub", "=", "mapping", "[", "version", "[", "3", "]", "]", "+", "str", "(", "version", "[", "4", "]", ")", "return", "str", "(", "main", "+", "sub", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/utils/version.py#L13-L34
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/utils/version.py
python
get_git_changeset
()
return timestamp.strftime('%Y%m%d%H%M%S')
Returns a numeric identifier of the latest git changeset. The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format. This value isn't guaranteed to be unique, but collisions are very unlikely, so it's sufficient for generating the development version numbers.
Returns a numeric identifier of the latest git changeset.
[ "Returns", "a", "numeric", "identifier", "of", "the", "latest", "git", "changeset", "." ]
def get_git_changeset(): """Returns a numeric identifier of the latest git changeset. The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format. This value isn't guaranteed to be unique, but collisions are very unlikely, so it's sufficient for generating the development version numbers. """ repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) git_log = subprocess.Popen('git log --pretty=format:%ct --quiet -1 HEAD', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=repo_dir, universal_newlines=True) timestamp = git_log.communicate()[0] try: timestamp = datetime.datetime.utcfromtimestamp(int(timestamp)) except ValueError: return None return timestamp.strftime('%Y%m%d%H%M%S')
[ "def", "get_git_changeset", "(", ")", ":", "repo_dir", "=", "os", ".", "path", ".", "dirname", "(", "os", ".", "path", ".", "dirname", "(", "os", ".", "path", ".", "abspath", "(", "__file__", ")", ")", ")", "git_log", "=", "subprocess", ".", "Popen", "(", "'git log --pretty=format:%ct --quiet -1 HEAD'", ",", "stdout", "=", "subprocess", ".", "PIPE", ",", "stderr", "=", "subprocess", ".", "PIPE", ",", "shell", "=", "True", ",", "cwd", "=", "repo_dir", ",", "universal_newlines", "=", "True", ")", "timestamp", "=", "git_log", ".", "communicate", "(", ")", "[", "0", "]", "try", ":", "timestamp", "=", "datetime", ".", "datetime", ".", "utcfromtimestamp", "(", "int", "(", "timestamp", ")", ")", "except", "ValueError", ":", "return", "None", "return", "timestamp", ".", "strftime", "(", "'%Y%m%d%H%M%S'", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/utils/version.py#L37-L53
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/management/__init__.py
python
Command.__init__
(self,subcommond,*args)
工具类指令
工具类指令
[ "工具类指令" ]
def __init__(self,subcommond,*args): '''工具类指令 ''' self.subcommond = subcommond self.args = args
[ "def", "__init__", "(", "self", ",", "subcommond", ",", "*", "args", ")", ":", "self", ".", "subcommond", "=", "subcommond", "self", ".", "args", "=", "args" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/management/__init__.py#L18-L22
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/util.py
python
FormatCondition
(props)
return sqlstr[:-4]
生成查询条件字符串
生成查询条件字符串
[ "生成查询条件字符串" ]
def FormatCondition(props): """生成查询条件字符串 """ items = props.items() itemstrlist = [] for _item in items: if isinstance(_item[1],Number): sqlstr = " `%s`=%s AND"%_item else: sqlstr = " `%s`='%s' AND "%(_item[0],str(_item[1]).replace("'", "\\'")) itemstrlist.append(sqlstr) sqlstr = ''.join(itemstrlist) return sqlstr[:-4]
[ "def", "FormatCondition", "(", "props", ")", ":", "items", "=", "props", ".", "items", "(", ")", "itemstrlist", "=", "[", "]", "for", "_item", "in", "items", ":", "if", "isinstance", "(", "_item", "[", "1", "]", ",", "Number", ")", ":", "sqlstr", "=", "\" `%s`=%s AND\"", "%", "_item", "else", ":", "sqlstr", "=", "\" `%s`='%s' AND \"", "%", "(", "_item", "[", "0", "]", ",", "str", "(", "_item", "[", "1", "]", ")", ".", "replace", "(", "\"'\"", ",", "\"\\\\'\"", ")", ")", "itemstrlist", ".", "append", "(", "sqlstr", ")", "sqlstr", "=", "''", ".", "join", "(", "itemstrlist", ")", "return", "sqlstr", "[", ":", "-", "4", "]" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/util.py#L57-L69
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/util.py
python
FormatUpdateStr
(props)
return sqlstr[:-1]
生成更新语句
生成更新语句
[ "生成更新语句" ]
def FormatUpdateStr(props): """生成更新语句 """ items = props.items() itemstrlist = [] for _item in items: if isinstance(_item[1],Number): sqlstr = " `%s`=%s,"%_item else: sqlstr = " `%s`='%s',"%(_item[0],str(_item[1]).replace("'", "\\'")) itemstrlist.append(sqlstr) sqlstr = ''.join(itemstrlist) return sqlstr[:-1]
[ "def", "FormatUpdateStr", "(", "props", ")", ":", "items", "=", "props", ".", "items", "(", ")", "itemstrlist", "=", "[", "]", "for", "_item", "in", "items", ":", "if", "isinstance", "(", "_item", "[", "1", "]", ",", "Number", ")", ":", "sqlstr", "=", "\" `%s`=%s,\"", "%", "_item", "else", ":", "sqlstr", "=", "\" `%s`='%s',\"", "%", "(", "_item", "[", "0", "]", ",", "str", "(", "_item", "[", "1", "]", ")", ".", "replace", "(", "\"'\"", ",", "\"\\\\'\"", ")", ")", "itemstrlist", ".", "append", "(", "sqlstr", ")", "sqlstr", "=", "''", ".", "join", "(", "itemstrlist", ")", "return", "sqlstr", "[", ":", "-", "1", "]" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/util.py#L71-L83
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/util.py
python
forEachUpdateProps
(tablename,props,prere)
return sqlstr
遍历所要修改的属性,以生成sql语句
遍历所要修改的属性,以生成sql语句
[ "遍历所要修改的属性,以生成sql语句" ]
def forEachUpdateProps(tablename,props,prere): '''遍历所要修改的属性,以生成sql语句''' assert isinstance(props, dict) pro = FormatUpdateStr(props) pre = FormatCondition(prere) sqlstr = """UPDATE `%s` SET %s WHERE %s;"""%(tablename,pro,pre) return sqlstr
[ "def", "forEachUpdateProps", "(", "tablename", ",", "props", ",", "prere", ")", ":", "assert", "isinstance", "(", "props", ",", "dict", ")", "pro", "=", "FormatUpdateStr", "(", "props", ")", "pre", "=", "FormatCondition", "(", "prere", ")", "sqlstr", "=", "\"\"\"UPDATE `%s` SET %s WHERE %s;\"\"\"", "%", "(", "tablename", ",", "pro", ",", "pre", ")", "return", "sqlstr" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/util.py#L85-L91
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/util.py
python
EachQueryProps
(props)
遍历字段列表生成sql语句
遍历字段列表生成sql语句
[ "遍历字段列表生成sql语句" ]
def EachQueryProps(props): '''遍历字段列表生成sql语句 ''' sqlstr = "" if props == '*': return '*' elif type(props) == type([0]): for prop in props: sqlstr = sqlstr + prop +',' sqlstr = sqlstr[:-1] return sqlstr else: raise Exception('props to query must be dict') return
[ "def", "EachQueryProps", "(", "props", ")", ":", "sqlstr", "=", "\"\"", "if", "props", "==", "'*'", ":", "return", "'*'", "elif", "type", "(", "props", ")", "==", "type", "(", "[", "0", "]", ")", ":", "for", "prop", "in", "props", ":", "sqlstr", "=", "sqlstr", "+", "prop", "+", "','", "sqlstr", "=", "sqlstr", "[", ":", "-", "1", "]", "return", "sqlstr", "else", ":", "raise", "Exception", "(", "'props to query must be dict'", ")", "return" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/util.py#L93-L106
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/util.py
python
forEachQueryProps
(sqlstr, props)
return sqlstr
遍历所要查询属性,以生成sql语句
遍历所要查询属性,以生成sql语句
[ "遍历所要查询属性,以生成sql语句" ]
def forEachQueryProps(sqlstr, props): '''遍历所要查询属性,以生成sql语句''' if props == '*': sqlstr += ' *' elif type(props) == type([0]): i = 0 for prop in props: if(i == 0): sqlstr += ' ' + prop else: sqlstr += ', ' + prop i += 1 else: raise Exception('props to query must be list') return return sqlstr
[ "def", "forEachQueryProps", "(", "sqlstr", ",", "props", ")", ":", "if", "props", "==", "'*'", ":", "sqlstr", "+=", "' *'", "elif", "type", "(", "props", ")", "==", "type", "(", "[", "0", "]", ")", ":", "i", "=", "0", "for", "prop", "in", "props", ":", "if", "(", "i", "==", "0", ")", ":", "sqlstr", "+=", "' '", "+", "prop", "else", ":", "sqlstr", "+=", "', '", "+", "prop", "i", "+=", "1", "else", ":", "raise", "Exception", "(", "'props to query must be list'", ")", "return", "return", "sqlstr" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/util.py#L108-L123
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/util.py
python
DeleteFromDB
(tablename,props)
return bool(count)
从数据库中删除
从数据库中删除
[ "从数据库中删除" ]
def DeleteFromDB(tablename,props): '''从数据库中删除 ''' prers = FormatCondition(props) sql = """DELETE FROM %s WHERE %s ;"""%(tablename,prers) conn = dbpool.connection(write=True,tablename=tablename) cursor = conn.cursor() count = 0 try: count = cursor.execute(sql) conn.commit() except Exception,e: log.err(e,traceback.format_exc()) log.err(sql) cursor.close() conn.close() return bool(count)
[ "def", "DeleteFromDB", "(", "tablename", ",", "props", ")", ":", "prers", "=", "FormatCondition", "(", "props", ")", "sql", "=", "\"\"\"DELETE FROM %s WHERE %s ;\"\"\"", "%", "(", "tablename", ",", "prers", ")", "conn", "=", "dbpool", ".", "connection", "(", "write", "=", "True", ",", "tablename", "=", "tablename", ")", "cursor", "=", "conn", ".", "cursor", "(", ")", "count", "=", "0", "try", ":", "count", "=", "cursor", ".", "execute", "(", "sql", ")", "conn", ".", "commit", "(", ")", "except", "Exception", ",", "e", ":", "log", ".", "err", "(", "e", ",", "traceback", ".", "format_exc", "(", ")", ")", "log", ".", "err", "(", "sql", ")", "cursor", ".", "close", "(", ")", "conn", ".", "close", "(", ")", "return", "bool", "(", "count", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/util.py#L153-L169
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/util.py
python
InsertIntoDBAndReturnID
(tablename,data)
return result
写入数据库,并返回ID
写入数据库,并返回ID
[ "写入数据库", "并返回ID" ]
def InsertIntoDBAndReturnID(tablename,data): """写入数据库,并返回ID """ sql = forEachPlusInsertProps(tablename,data) conn = dbpool.connection(write=True,tablename=tablename) cursor = conn.cursor() cursor.execute(sql) conn.commit() cursor.execute("SELECT LAST_INSERT_ID();") result=cursor.fetchall()[0] cursor.close() conn.close() return result
[ "def", "InsertIntoDBAndReturnID", "(", "tablename", ",", "data", ")", ":", "sql", "=", "forEachPlusInsertProps", "(", "tablename", ",", "data", ")", "conn", "=", "dbpool", ".", "connection", "(", "write", "=", "True", ",", "tablename", "=", "tablename", ")", "cursor", "=", "conn", ".", "cursor", "(", ")", "cursor", ".", "execute", "(", "sql", ")", "conn", ".", "commit", "(", ")", "cursor", ".", "execute", "(", "\"SELECT LAST_INSERT_ID();\"", ")", "result", "=", "cursor", ".", "fetchall", "(", ")", "[", "0", "]", "cursor", ".", "close", "(", ")", "conn", ".", "close", "(", ")", "return", "result" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/util.py#L171-L183
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/util.py
python
InsertIntoDB
(tablename,data)
return bool(count)
写入数据库
写入数据库
[ "写入数据库" ]
def InsertIntoDB(tablename,data): """写入数据库 """ sql = forEachPlusInsertProps(tablename,data) conn = dbpool.connection(write=True,tablename=tablename) cursor = conn.cursor() count = cursor.execute(sql) conn.commit() cursor.close() conn.close() return bool(count)
[ "def", "InsertIntoDB", "(", "tablename", ",", "data", ")", ":", "sql", "=", "forEachPlusInsertProps", "(", "tablename", ",", "data", ")", "conn", "=", "dbpool", ".", "connection", "(", "write", "=", "True", ",", "tablename", "=", "tablename", ")", "cursor", "=", "conn", ".", "cursor", "(", ")", "count", "=", "cursor", ".", "execute", "(", "sql", ")", "conn", ".", "commit", "(", ")", "cursor", ".", "close", "(", ")", "conn", ".", "close", "(", ")", "return", "bool", "(", "count", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/util.py#L185-L195
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/util.py
python
UpdateWithDict
(tablename,props,prere)
return False
更新记录
更新记录
[ "更新记录" ]
def UpdateWithDict(tablename,props,prere): """更新记录 """ sql = forEachUpdateProps(tablename, props, prere) conn = dbpool.connection(write=True,tablename=tablename) cursor = conn.cursor() count = 0 try: count = cursor.execute(sql) conn.commit() except Exception,e: log.err(e,traceback.format_exc()) log.err(sql) cursor.close() conn.close() if(count >= 1): return True return False
[ "def", "UpdateWithDict", "(", "tablename", ",", "props", ",", "prere", ")", ":", "sql", "=", "forEachUpdateProps", "(", "tablename", ",", "props", ",", "prere", ")", "conn", "=", "dbpool", ".", "connection", "(", "write", "=", "True", ",", "tablename", "=", "tablename", ")", "cursor", "=", "conn", ".", "cursor", "(", ")", "count", "=", "0", "try", ":", "count", "=", "cursor", ".", "execute", "(", "sql", ")", "conn", ".", "commit", "(", ")", "except", "Exception", ",", "e", ":", "log", ".", "err", "(", "e", ",", "traceback", ".", "format_exc", "(", ")", ")", "log", ".", "err", "(", "sql", ")", "cursor", ".", "close", "(", ")", "conn", ".", "close", "(", ")", "if", "(", "count", ">=", "1", ")", ":", "return", "True", "return", "False" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/util.py#L202-L219
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/util.py
python
getAllPkByFkInDB
(tablename,pkname,props)
return [key[0] for key in result]
根据所有的外键获取主键ID
根据所有的外键获取主键ID
[ "根据所有的外键获取主键ID" ]
def getAllPkByFkInDB(tablename,pkname,props): """根据所有的外键获取主键ID """ props = FormatCondition(props) sql = """select `%s` from `%s` where %s;"""%(pkname,tablename,props) conn = dbpool.connection(write=False,tablename=tablename) cursor = conn.cursor() cursor.execute(sql) result = cursor.fetchall() cursor.close() conn.close() return [key[0] for key in result]
[ "def", "getAllPkByFkInDB", "(", "tablename", ",", "pkname", ",", "props", ")", ":", "props", "=", "FormatCondition", "(", "props", ")", "sql", "=", "\"\"\"select `%s` from `%s` where %s;\"\"\"", "%", "(", "pkname", ",", "tablename", ",", "props", ")", "conn", "=", "dbpool", ".", "connection", "(", "write", "=", "False", ",", "tablename", "=", "tablename", ")", "cursor", "=", "conn", ".", "cursor", "(", ")", "cursor", ".", "execute", "(", "sql", ")", "result", "=", "cursor", ".", "fetchall", "(", ")", "cursor", ".", "close", "(", ")", "conn", ".", "close", "(", ")", "return", "[", "key", "[", "0", "]", "for", "key", "in", "result", "]" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/util.py#L221-L232
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/util.py
python
GetOneRecordInfo
(tablename,props)
return result
获取单条数据的信息
获取单条数据的信息
[ "获取单条数据的信息" ]
def GetOneRecordInfo(tablename,props): '''获取单条数据的信息 ''' props = FormatCondition(props) sql = """Select * from `%s` where %s;"""%(tablename,props) conn = dbpool.connection(write=False,tablename=tablename) cursor = conn.cursor(cursorclass = DictCursor) cursor.execute(sql) result = cursor.fetchone() cursor.close() conn.close() return result
[ "def", "GetOneRecordInfo", "(", "tablename", ",", "props", ")", ":", "props", "=", "FormatCondition", "(", "props", ")", "sql", "=", "\"\"\"Select * from `%s` where %s;\"\"\"", "%", "(", "tablename", ",", "props", ")", "conn", "=", "dbpool", ".", "connection", "(", "write", "=", "False", ",", "tablename", "=", "tablename", ")", "cursor", "=", "conn", ".", "cursor", "(", "cursorclass", "=", "DictCursor", ")", "cursor", ".", "execute", "(", "sql", ")", "result", "=", "cursor", ".", "fetchone", "(", ")", "cursor", ".", "close", "(", ")", "conn", ".", "close", "(", ")", "return", "result" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/util.py#L234-L245
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/mmode.py
python
DBPub._run
(self)
执行协议
执行协议
[ "执行协议" ]
def _run(self): """执行协议 """ address = 'tcp://%s:%s'%self.to_db_address self.sock.connect(address) while True: try: message = self.inbox.get() self.sock.send_pyobj(message) except Exception as e: log.err(_stuff=e,_why=traceback.format_exc()) log.msg(str(message))
[ "def", "_run", "(", "self", ")", ":", "address", "=", "'tcp://%s:%s'", "%", "self", ".", "to_db_address", "self", ".", "sock", ".", "connect", "(", "address", ")", "while", "True", ":", "try", ":", "message", "=", "self", ".", "inbox", ".", "get", "(", ")", "self", ".", "sock", ".", "send_pyobj", "(", "message", ")", "except", "Exception", "as", "e", ":", "log", ".", "err", "(", "_stuff", "=", "e", ",", "_why", "=", "traceback", ".", "format_exc", "(", ")", ")", "log", ".", "msg", "(", "str", "(", "message", ")", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/mmode.py#L51-L62
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/mmode.py
python
MMode.getData
(self)
return None
获取data数据
获取data数据
[ "获取data数据" ]
def getData(self): """获取data数据 """ data = self.get('data') if data: return data tablename,pk_value = self._name.split(':') props = {self._pk:int(pk_value)} record = util.GetOneRecordInfo(tablename,props) if record: self.data = record self.insert() return self.data return None
[ "def", "getData", "(", "self", ")", ":", "data", "=", "self", ".", "get", "(", "'data'", ")", "if", "data", ":", "return", "data", "tablename", ",", "pk_value", "=", "self", ".", "_name", ".", "split", "(", "':'", ")", "props", "=", "{", "self", ".", "_pk", ":", "int", "(", "pk_value", ")", "}", "record", "=", "util", ".", "GetOneRecordInfo", "(", "tablename", ",", "props", ")", "if", "record", ":", "self", ".", "data", "=", "record", "self", ".", "insert", "(", ")", "return", "self", ".", "data", "return", "None" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/mmode.py#L127-L140
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/mmode.py
python
MMode.delete
(self)
清理对象
清理对象
[ "清理对象" ]
def delete(self): """清理对象 """ self.syncDB(state=MMODE_STATE_DEL) if self._fk: data = self.getData() if data: fk = data.get(self._fk,"") pk = data.get(self._pk) self._update_fk(pk, fk, None) self.mdelete()
[ "def", "delete", "(", "self", ")", ":", "self", ".", "syncDB", "(", "state", "=", "MMODE_STATE_DEL", ")", "if", "self", ".", "_fk", ":", "data", "=", "self", ".", "getData", "(", ")", "if", "data", ":", "fk", "=", "data", ".", "get", "(", "self", ".", "_fk", ",", "\"\"", ")", "pk", "=", "data", ".", "get", "(", "self", ".", "_pk", ")", "self", ".", "_update_fk", "(", "pk", ",", "fk", ",", "None", ")", "self", ".", "mdelete", "(", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/mmode.py#L142-L152
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/mmode.py
python
MMode.IsEffective
(self)
return True
检测对象是否有效
检测对象是否有效
[ "检测对象是否有效" ]
def IsEffective(self): '''检测对象是否有效 ''' return True
[ "def", "IsEffective", "(", "self", ")", ":", "return", "True" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/mmode.py#L154-L157
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/mmode.py
python
MMode.syncDB
(self,state=MMODE_STATE_UPDATE)
return result
同步到数据库
同步到数据库
[ "同步到数据库" ]
def syncDB(self,state=MMODE_STATE_UPDATE): """同步到数据库 """ tablename = self._name.split(':')[0] if state==MMODE_STATE_NEW: props = self.getData() pk = self._pk result = util.InsertIntoDB(tablename, props) elif state==MMODE_STATE_UPDATE: props = self.getData() pk = self._pk prere = {pk:props.get(pk)} sql = util.UpdateWithDictSQL(tablename, props, prere) DBPub().send((tablename,sql)) result = True else: pk = self._pk props = self.getData() prere = {pk:props.get(pk)} result = util.DeleteFromDB(tablename,prere) return result
[ "def", "syncDB", "(", "self", ",", "state", "=", "MMODE_STATE_UPDATE", ")", ":", "tablename", "=", "self", ".", "_name", ".", "split", "(", "':'", ")", "[", "0", "]", "if", "state", "==", "MMODE_STATE_NEW", ":", "props", "=", "self", ".", "getData", "(", ")", "pk", "=", "self", ".", "_pk", "result", "=", "util", ".", "InsertIntoDB", "(", "tablename", ",", "props", ")", "elif", "state", "==", "MMODE_STATE_UPDATE", ":", "props", "=", "self", ".", "getData", "(", ")", "pk", "=", "self", ".", "_pk", "prere", "=", "{", "pk", ":", "props", ".", "get", "(", "pk", ")", "}", "sql", "=", "util", ".", "UpdateWithDictSQL", "(", "tablename", ",", "props", ",", "prere", ")", "DBPub", "(", ")", ".", "send", "(", "(", "tablename", ",", "sql", ")", ")", "result", "=", "True", "else", ":", "pk", "=", "self", ".", "_pk", "props", "=", "self", ".", "getData", "(", ")", "prere", "=", "{", "pk", ":", "props", ".", "get", "(", "pk", ")", "}", "result", "=", "util", ".", "DeleteFromDB", "(", "tablename", ",", "prere", ")", "return", "result" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/mmode.py#L159-L179
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/mmode.py
python
MAdmin.load
(self)
读取数据到数据库中
读取数据到数据库中
[ "读取数据到数据库中" ]
def load(self): '''读取数据到数据库中 ''' mmname = self._name recordlist = util.ReadDataFromDB(mmname) for record in recordlist: pk = record[self.pk] mm = MMode(self._name+':%s'%pk,self.pk,data=record,fk=self._fk,timeout=self.timeout) mm.insert()
[ "def", "load", "(", "self", ")", ":", "mmname", "=", "self", ".", "_name", "recordlist", "=", "util", ".", "ReadDataFromDB", "(", "mmname", ")", "for", "record", "in", "recordlist", ":", "pk", "=", "record", "[", "self", ".", "pk", "]", "mm", "=", "MMode", "(", "self", ".", "_name", "+", "':%s'", "%", "pk", ",", "self", ".", "pk", ",", "data", "=", "record", ",", "fk", "=", "self", ".", "_fk", ",", "timeout", "=", "self", ".", "timeout", ")", "mm", ".", "insert", "(", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/mmode.py#L200-L208
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/mmode.py
python
MAdmin.getAllPkByFk
(self,fk)
return dbkeylist
根据外键获取主键列表
根据外键获取主键列表
[ "根据外键获取主键列表" ]
def getAllPkByFk(self,fk): '''根据外键获取主键列表 ''' name = '%s_fk:%s'%(self._name,fk) fkmm = MFKMode(name) pklist = fkmm.get('pklist') if pklist is not None: return pklist props = {self._fk:fk} dbkeylist = util.getAllPkByFkInDB(self._name, self.pk, props) name = '%s_fk:%s'%(self._name,fk) fkmm = MFKMode(name, pklist = dbkeylist) fkmm.insert() return dbkeylist
[ "def", "getAllPkByFk", "(", "self", ",", "fk", ")", ":", "name", "=", "'%s_fk:%s'", "%", "(", "self", ".", "_name", ",", "fk", ")", "fkmm", "=", "MFKMode", "(", "name", ")", "pklist", "=", "fkmm", ".", "get", "(", "'pklist'", ")", "if", "pklist", "is", "not", "None", ":", "return", "pklist", "props", "=", "{", "self", ".", "_fk", ":", "fk", "}", "dbkeylist", "=", "util", ".", "getAllPkByFkInDB", "(", "self", ".", "_name", ",", "self", ".", "pk", ",", "props", ")", "name", "=", "'%s_fk:%s'", "%", "(", "self", ".", "_name", ",", "fk", ")", "fkmm", "=", "MFKMode", "(", "name", ",", "pklist", "=", "dbkeylist", ")", "fkmm", ".", "insert", "(", ")", "return", "dbkeylist" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/mmode.py#L210-L223
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/mmode.py
python
MAdmin.getObj
(self,pk)
return mm
根据主键,可以获得mmode对象的实例.\n >>> m = madmin.getObj(1)
根据主键,可以获得mmode对象的实例.\n >>> m = madmin.getObj(1)
[ "根据主键,可以获得mmode对象的实例", ".", "\\", "n", ">>>", "m", "=", "madmin", ".", "getObj", "(", "1", ")" ]
def getObj(self,pk): '''根据主键,可以获得mmode对象的实例.\n >>> m = madmin.getObj(1) ''' mm = MMode(self._name+':%s'%pk,self.pk,fk=self._fk,timeout=self.timeout) if mm.get('data'): return mm props = {self.pk:pk} record = util.GetOneRecordInfo(self._name,props) if not record: return None mm = MMode(self._name+':%s'%pk,self.pk,data = record,fk=self._fk,timeout=self.timeout) mm.insert() return mm
[ "def", "getObj", "(", "self", ",", "pk", ")", ":", "mm", "=", "MMode", "(", "self", ".", "_name", "+", "':%s'", "%", "pk", ",", "self", ".", "pk", ",", "fk", "=", "self", ".", "_fk", ",", "timeout", "=", "self", ".", "timeout", ")", "if", "mm", ".", "get", "(", "'data'", ")", ":", "return", "mm", "props", "=", "{", "self", ".", "pk", ":", "pk", "}", "record", "=", "util", ".", "GetOneRecordInfo", "(", "self", ".", "_name", ",", "props", ")", "if", "not", "record", ":", "return", "None", "mm", "=", "MMode", "(", "self", ".", "_name", "+", "':%s'", "%", "pk", ",", "self", ".", "pk", ",", "data", "=", "record", ",", "fk", "=", "self", ".", "_fk", ",", "timeout", "=", "self", ".", "timeout", ")", "mm", ".", "insert", "(", ")", "return", "mm" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/mmode.py#L225-L238
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/mmode.py
python
MAdmin.getObjData
(self,pk)
return record
根据主键,可以获得mmode对象的实例的数据.\n >>> m = madmin.getObjData(1)
根据主键,可以获得mmode对象的实例的数据.\n >>> m = madmin.getObjData(1)
[ "根据主键,可以获得mmode对象的实例的数据", ".", "\\", "n", ">>>", "m", "=", "madmin", ".", "getObjData", "(", "1", ")" ]
def getObjData(self,pk): '''根据主键,可以获得mmode对象的实例的数据.\n >>> m = madmin.getObjData(1) ''' mm = MMode(self._name+':%s'%pk,self.pk,fk=self._fk,timeout=self.timeout) if not mm.IsEffective(): return None data = mm.get('data') if data: return data props = {self.pk:pk} record = util.GetOneRecordInfo(self._name,props) if not record: return None mm = MMode(self._name+':%s'%pk,self.pk,data = record,fk=self._fk,timeout=self.timeout) mm.insert() return record
[ "def", "getObjData", "(", "self", ",", "pk", ")", ":", "mm", "=", "MMode", "(", "self", ".", "_name", "+", "':%s'", "%", "pk", ",", "self", ".", "pk", ",", "fk", "=", "self", ".", "_fk", ",", "timeout", "=", "self", ".", "timeout", ")", "if", "not", "mm", ".", "IsEffective", "(", ")", ":", "return", "None", "data", "=", "mm", ".", "get", "(", "'data'", ")", "if", "data", ":", "return", "data", "props", "=", "{", "self", ".", "pk", ":", "pk", "}", "record", "=", "util", ".", "GetOneRecordInfo", "(", "self", ".", "_name", ",", "props", ")", "if", "not", "record", ":", "return", "None", "mm", "=", "MMode", "(", "self", ".", "_name", "+", "':%s'", "%", "pk", ",", "self", ".", "pk", ",", "data", "=", "record", ",", "fk", "=", "self", ".", "_fk", ",", "timeout", "=", "self", ".", "timeout", ")", "mm", ".", "insert", "(", ")", "return", "record" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/mmode.py#L240-L256
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/mmode.py
python
MAdmin.getObjList
(self,pklist)
return objlist
根据主键列表获取mmode对象的列表.\n >>> m = madmin.getObjList([1,2,3,4,5])
根据主键列表获取mmode对象的列表.\n >>> m = madmin.getObjList([1,2,3,4,5])
[ "根据主键列表获取mmode对象的列表", ".", "\\", "n", ">>>", "m", "=", "madmin", ".", "getObjList", "(", "[", "1", "2", "3", "4", "5", "]", ")" ]
def getObjList(self,pklist): '''根据主键列表获取mmode对象的列表.\n >>> m = madmin.getObjList([1,2,3,4,5]) ''' _pklist = [] objlist = [] for pk in pklist: mm = MMode(self._name+':%s'%pk,self.pk,fk=self._fk,timeout=self.timeout) if not mm.IsEffective(): continue if mm.get('data'): objlist.append(mm) else: _pklist.append(pk) if _pklist: recordlist = util.GetRecordList(self._name, self.pk,_pklist) for record in recordlist: pk = record[self.pk] mm = MMode(self._name+':%s'%pk,self.pk,data = record,fk=self._fk,timeout=self.timeout) mm.insert() objlist.append(mm) return objlist
[ "def", "getObjList", "(", "self", ",", "pklist", ")", ":", "_pklist", "=", "[", "]", "objlist", "=", "[", "]", "for", "pk", "in", "pklist", ":", "mm", "=", "MMode", "(", "self", ".", "_name", "+", "':%s'", "%", "pk", ",", "self", ".", "pk", ",", "fk", "=", "self", ".", "_fk", ",", "timeout", "=", "self", ".", "timeout", ")", "if", "not", "mm", ".", "IsEffective", "(", ")", ":", "continue", "if", "mm", ".", "get", "(", "'data'", ")", ":", "objlist", ".", "append", "(", "mm", ")", "else", ":", "_pklist", ".", "append", "(", "pk", ")", "if", "_pklist", ":", "recordlist", "=", "util", ".", "GetRecordList", "(", "self", ".", "_name", ",", "self", ".", "pk", ",", "_pklist", ")", "for", "record", "in", "recordlist", ":", "pk", "=", "record", "[", "self", ".", "pk", "]", "mm", "=", "MMode", "(", "self", ".", "_name", "+", "':%s'", "%", "pk", ",", "self", ".", "pk", ",", "data", "=", "record", ",", "fk", "=", "self", ".", "_fk", ",", "timeout", "=", "self", ".", "timeout", ")", "mm", ".", "insert", "(", ")", "objlist", ".", "append", "(", "mm", ")", "return", "objlist" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/mmode.py#L259-L280
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/mmode.py
python
MAdmin.deleteMode
(self,pk)
return True
根据主键删除内存中的某条记录信息,\n这里只是修改内存中的记录状态_state为删除状态.\n >>> m = madmin.deleteMode(1)
根据主键删除内存中的某条记录信息,\n这里只是修改内存中的记录状态_state为删除状态.\n >>> m = madmin.deleteMode(1)
[ "根据主键删除内存中的某条记录信息,", "\\", "n这里只是修改内存中的记录状态_state为删除状态", ".", "\\", "n", ">>>", "m", "=", "madmin", ".", "deleteMode", "(", "1", ")" ]
def deleteMode(self,pk): '''根据主键删除内存中的某条记录信息,\n这里只是修改内存中的记录状态_state为删除状态.\n >>> m = madmin.deleteMode(1) ''' mm = self.getObj(pk) if mm: # if self._fk: # data = mm.get('data') # if data: # fk = data.get(self._fk,0) # name = '%s_fk:%s'%(self._name,fk) # fkmm = MFKMode(name) # pklist = fkmm.get('pklist') # if pklist and pk in pklist: # pklist.remove(pk) # fkmm.update('pklist', pklist) mm.delete() return True
[ "def", "deleteMode", "(", "self", ",", "pk", ")", ":", "mm", "=", "self", ".", "getObj", "(", "pk", ")", "if", "mm", ":", "# if self._fk:", "# data = mm.get('data')", "# if data:", "# fk = data.get(self._fk,0)", "# name = '%s_fk:%s'%(self._name,fk)", "# fkmm = MFKMode(name)", "# pklist = fkmm.get('pklist')", "# if pklist and pk in pklist:", "# pklist.remove(pk)", "# fkmm.update('pklist', pklist)", "mm", ".", "delete", "(", ")", "return", "True" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/mmode.py#L282-L299
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/mmode.py
python
MAdmin.new
(self,data)
return mm
创建一个新的对象
创建一个新的对象
[ "创建一个新的对象" ]
def new(self,data): """创建一个新的对象 """ incrkey = self.incrkey tablename = self._name if incrkey: result = util.InsertIntoDBAndReturnID(tablename, data) data[incrkey] = result[0] pk = data.get(self.pk) if pk is None: raise PKValueError(data) mm = MMode(self._name+':%s'%pk,self.pk,data=data,fk=self._fk,timeout=self.timeout) else: pk = data.get(self.pk) result = util.InsertIntoDB(tablename, data) if not result: raise util.SQLError() mm = MMode(self._name+':%s'%pk,self.pk,data=data,fk=self._fk,timeout=self.timeout) mm.insert() if self._fk: fk = data.get(self._fk,0) name = '%s_fk:%s'%(self._name,fk) fkmm = MFKMode(name) pklist = fkmm.get('pklist') pklist = self.getAllPkByFk(fk) pklist.append(pk) fkmm.update('pklist', pklist) return mm
[ "def", "new", "(", "self", ",", "data", ")", ":", "incrkey", "=", "self", ".", "incrkey", "tablename", "=", "self", ".", "_name", "if", "incrkey", ":", "result", "=", "util", ".", "InsertIntoDBAndReturnID", "(", "tablename", ",", "data", ")", "data", "[", "incrkey", "]", "=", "result", "[", "0", "]", "pk", "=", "data", ".", "get", "(", "self", ".", "pk", ")", "if", "pk", "is", "None", ":", "raise", "PKValueError", "(", "data", ")", "mm", "=", "MMode", "(", "self", ".", "_name", "+", "':%s'", "%", "pk", ",", "self", ".", "pk", ",", "data", "=", "data", ",", "fk", "=", "self", ".", "_fk", ",", "timeout", "=", "self", ".", "timeout", ")", "else", ":", "pk", "=", "data", ".", "get", "(", "self", ".", "pk", ")", "result", "=", "util", ".", "InsertIntoDB", "(", "tablename", ",", "data", ")", "if", "not", "result", ":", "raise", "util", ".", "SQLError", "(", ")", "mm", "=", "MMode", "(", "self", ".", "_name", "+", "':%s'", "%", "pk", ",", "self", ".", "pk", ",", "data", "=", "data", ",", "fk", "=", "self", ".", "_fk", ",", "timeout", "=", "self", ".", "timeout", ")", "mm", ".", "insert", "(", ")", "if", "self", ".", "_fk", ":", "fk", "=", "data", ".", "get", "(", "self", ".", "_fk", ",", "0", ")", "name", "=", "'%s_fk:%s'", "%", "(", "self", ".", "_name", ",", "fk", ")", "fkmm", "=", "MFKMode", "(", "name", ")", "pklist", "=", "fkmm", ".", "get", "(", "'pklist'", ")", "pklist", "=", "self", ".", "getAllPkByFk", "(", "fk", ")", "pklist", ".", "append", "(", "pk", ")", "fkmm", ".", "update", "(", "'pklist'", ",", "pklist", ")", "return", "mm" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/mmode.py#L327-L354
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memobject.py
python
MemObject.__init__
(self,name,**kw)
@param name: str 对象的名称\n @param _lock: int 对象锁 为1时表示对象被锁定无法进行修改\n
[]
def __init__(self,name,**kw): ''' @param name: str 对象的名称\n @param _lock: int 对象锁 为1时表示对象被锁定无法进行修改\n ''' self._name = name self._locked = False self._timestamp = 0 self._cas = kw.get("cas",False) self._cache = kw.get("cache",True) self._timeout = kw.get("timeout",CACHE_TIMEOUT) if self._cas: self.lock()
[ "def", "__init__", "(", "self", ",", "name", ",", "*", "*", "kw", ")", ":", "self", ".", "_name", "=", "name", "self", ".", "_locked", "=", "False", "self", ".", "_timestamp", "=", "0", "self", ".", "_cas", "=", "kw", ".", "get", "(", "\"cas\"", ",", "False", ")", "self", ".", "_cache", "=", "kw", ".", "get", "(", "\"cache\"", ",", "True", ")", "self", ".", "_timeout", "=", "kw", ".", "get", "(", "\"timeout\"", ",", "CACHE_TIMEOUT", ")", "if", "self", ".", "_cas", ":", "self", ".", "lock", "(", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memobject.py#L41-L53
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memobject.py
python
MemObject.produceKey
(self,keyname)
重新生成key
重新生成key
[ "重新生成key" ]
def produceKey(self,keyname): ''' 重新生成key ''' if isinstance(keyname, basestring): return str(''.join([self._name,':',keyname])) else: raise MEMKeyError()
[ "def", "produceKey", "(", "self", ",", "keyname", ")", ":", "if", "isinstance", "(", "keyname", ",", "basestring", ")", ":", "return", "str", "(", "''", ".", "join", "(", "[", "self", ".", "_name", ",", "':'", ",", "keyname", "]", ")", ")", "else", ":", "raise", "MEMKeyError", "(", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memobject.py#L55-L62
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memobject.py
python
MemObject.lock
(self)
return self._locked
锁定对象
锁定对象
[ "锁定对象" ]
def lock(self): '''锁定对象 ''' print "locked" if not self.isLocked(): key = self.produceKey('_lock') result = memclient.mclient.add(key,1,LOCK_TIMEOUT) if result: self._timestamp=time.time() self._locked = result return self._locked
[ "def", "lock", "(", "self", ")", ":", "print", "\"locked\"", "if", "not", "self", ".", "isLocked", "(", ")", ":", "key", "=", "self", ".", "produceKey", "(", "'_lock'", ")", "result", "=", "memclient", ".", "mclient", ".", "add", "(", "key", ",", "1", ",", "LOCK_TIMEOUT", ")", "if", "result", ":", "self", ".", "_timestamp", "=", "time", ".", "time", "(", ")", "self", ".", "_locked", "=", "result", "return", "self", ".", "_locked" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memobject.py#L72-L82
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memobject.py
python
MemObject.release
(self)
释放锁
释放锁
[ "释放锁" ]
def release(self): '''释放锁 ''' if self.isLocked(): print "release..." key = self.produceKey('_lock') memclient.mclient.delete(key) self._locked = False
[ "def", "release", "(", "self", ")", ":", "if", "self", ".", "isLocked", "(", ")", ":", "print", "\"release...\"", "key", "=", "self", ".", "produceKey", "(", "'_lock'", ")", "memclient", ".", "mclient", ".", "delete", "(", "key", ")", "self", ".", "_locked", "=", "False" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memobject.py#L84-L91
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memobject.py
python
MemObject.get
(self,key)
return memclient.mclient.get(key)
获取对象值
获取对象值
[ "获取对象值" ]
def get(self,key): '''获取对象值 ''' if self._cas and not self.isLocked(): for _ in xrange(10): if not self.lock(): gevent.sleep(0.2) continue break else: return None key = self.produceKey(key) return memclient.mclient.get(key)
[ "def", "get", "(", "self", ",", "key", ")", ":", "if", "self", ".", "_cas", "and", "not", "self", ".", "isLocked", "(", ")", ":", "for", "_", "in", "xrange", "(", "10", ")", ":", "if", "not", "self", ".", "lock", "(", ")", ":", "gevent", ".", "sleep", "(", "0.2", ")", "continue", "break", "else", ":", "return", "None", "key", "=", "self", ".", "produceKey", "(", "key", ")", "return", "memclient", ".", "mclient", ".", "get", "(", "key", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memobject.py#L93-L105
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memobject.py
python
MemObject.get_multi
(self,keys)
return newdict
一次获取多个key的值 @param keys: list(str) key的列表
一次获取多个key的值
[ "一次获取多个key的值" ]
def get_multi(self,keys): '''一次获取多个key的值 @param keys: list(str) key的列表 ''' if self._cas and not self.isLocked(): for _ in xrange(10): if not self.lock(): gevent.sleep(0.2) continue break else: return None keynamelist = [self.produceKey(keyname) for keyname in keys] olddict = memclient.mclient.get_multi(keynamelist) newdict = dict(zip([keyname.split(':')[-1] for keyname in olddict.keys()], olddict.values())) return newdict
[ "def", "get_multi", "(", "self", ",", "keys", ")", ":", "if", "self", ".", "_cas", "and", "not", "self", ".", "isLocked", "(", ")", ":", "for", "_", "in", "xrange", "(", "10", ")", ":", "if", "not", "self", ".", "lock", "(", ")", ":", "gevent", ".", "sleep", "(", "0.2", ")", "continue", "break", "else", ":", "return", "None", "keynamelist", "=", "[", "self", ".", "produceKey", "(", "keyname", ")", "for", "keyname", "in", "keys", "]", "olddict", "=", "memclient", ".", "mclient", ".", "get_multi", "(", "keynamelist", ")", "newdict", "=", "dict", "(", "zip", "(", "[", "keyname", ".", "split", "(", "':'", ")", "[", "-", "1", "]", "for", "keyname", "in", "olddict", ".", "keys", "(", ")", "]", ",", "olddict", ".", "values", "(", ")", ")", ")", "return", "newdict" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memobject.py#L107-L123
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memobject.py
python
MemObject.update
(self,key,values)
return memclient.mclient.set(key,values,time=self._timeout)
修改对象的值
修改对象的值
[ "修改对象的值" ]
def update(self,key,values): '''修改对象的值 ''' if self._cas and not self.isLocked(): for _ in xrange(10): if not self.lock(): gevent.sleep(0.2) continue break else: return None key = self.produceKey(key) return memclient.mclient.set(key,values,time=self._timeout)
[ "def", "update", "(", "self", ",", "key", ",", "values", ")", ":", "if", "self", ".", "_cas", "and", "not", "self", ".", "isLocked", "(", ")", ":", "for", "_", "in", "xrange", "(", "10", ")", ":", "if", "not", "self", ".", "lock", "(", ")", ":", "gevent", ".", "sleep", "(", "0.2", ")", "continue", "break", "else", ":", "return", "None", "key", "=", "self", ".", "produceKey", "(", "key", ")", "return", "memclient", ".", "mclient", ".", "set", "(", "key", ",", "values", ",", "time", "=", "self", ".", "_timeout", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memobject.py#L125-L137
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memobject.py
python
MemObject.update_multi
(self,mapping)
return memclient.mclient.set_multi(newmapping,time=self._timeout)
同时修改多个key值
同时修改多个key值
[ "同时修改多个key值" ]
def update_multi(self,mapping): '''同时修改多个key值 ''' if self._cas and not self.isLocked(): for _ in xrange(10): if not self.lock(): gevent.sleep(0.2) continue break else: return None newmapping = dict(zip([self.produceKey(keyname) for keyname in mapping.keys()], mapping.values())) return memclient.mclient.set_multi(newmapping,time=self._timeout)
[ "def", "update_multi", "(", "self", ",", "mapping", ")", ":", "if", "self", ".", "_cas", "and", "not", "self", ".", "isLocked", "(", ")", ":", "for", "_", "in", "xrange", "(", "10", ")", ":", "if", "not", "self", ".", "lock", "(", ")", ":", "gevent", ".", "sleep", "(", "0.2", ")", "continue", "break", "else", ":", "return", "None", "newmapping", "=", "dict", "(", "zip", "(", "[", "self", ".", "produceKey", "(", "keyname", ")", "for", "keyname", "in", "mapping", ".", "keys", "(", ")", "]", ",", "mapping", ".", "values", "(", ")", ")", ")", "return", "memclient", ".", "mclient", ".", "set_multi", "(", "newmapping", ",", "time", "=", "self", ".", "_timeout", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memobject.py#L139-L152
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memobject.py
python
MemObject.mdelete
(self)
删除memcache中的数据
删除memcache中的数据
[ "删除memcache中的数据" ]
def mdelete(self): '''删除memcache中的数据 ''' nowdict = dict(self.__dict__) keys = [keyname for keyname in nowdict.keys() if not keyname.startswith('_')] keys = [self.produceKey(key) for key in keys] memclient.mclient.delete_multi(keys)
[ "def", "mdelete", "(", "self", ")", ":", "nowdict", "=", "dict", "(", "self", ".", "__dict__", ")", "keys", "=", "[", "keyname", "for", "keyname", "in", "nowdict", ".", "keys", "(", ")", "if", "not", "keyname", ".", "startswith", "(", "'_'", ")", "]", "keys", "=", "[", "self", ".", "produceKey", "(", "key", ")", "for", "key", "in", "keys", "]", "memclient", ".", "mclient", ".", "delete_multi", "(", "keys", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memobject.py#L154-L160
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memobject.py
python
MemObject.insert
(self)
插入对象记录
插入对象记录
[ "插入对象记录" ]
def insert(self): '''插入对象记录 ''' nowdict = dict(self.__dict__) newmapping = dict([(self.produceKey(keyname),nowdict[keyname]) for keyname in nowdict.keys() if not keyname.startswith('_')]) memclient.mclient.set_multi(newmapping,time=self._timeout)
[ "def", "insert", "(", "self", ")", ":", "nowdict", "=", "dict", "(", "self", ".", "__dict__", ")", "newmapping", "=", "dict", "(", "[", "(", "self", ".", "produceKey", "(", "keyname", ")", ",", "nowdict", "[", "keyname", "]", ")", "for", "keyname", "in", "nowdict", ".", "keys", "(", ")", "if", "not", "keyname", ".", "startswith", "(", "'_'", ")", "]", ")", "memclient", ".", "mclient", ".", "set_multi", "(", "newmapping", ",", "time", "=", "self", ".", "_timeout", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memobject.py#L162-L167
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memobject.py
python
MemObject.__del__
(self)
在对象销毁时释放锁,避免在获取memcache数据时死锁
在对象销毁时释放锁,避免在获取memcache数据时死锁
[ "在对象销毁时释放锁,避免在获取memcache数据时死锁" ]
def __del__(self): """ 在对象销毁时释放锁,避免在获取memcache数据时死锁 """ try: if self.isLocked(): self.release() except Exception as e: print e
[ "def", "__del__", "(", "self", ")", ":", "try", ":", "if", "self", ".", "isLocked", "(", ")", ":", "self", ".", "release", "(", ")", "except", "Exception", "as", "e", ":", "print", "e" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memobject.py#L169-L177
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memfields.py
python
MemFields.__init__
(self, value=None, cache=True,timeout=CACHE_TIMEOUT)
@param name: str 字段的名称 @param cache: bool 是否本地缓存获取到的值
[]
def __init__(self, value=None, cache=True,timeout=CACHE_TIMEOUT): """ @param name: str 字段的名称 @param cache: bool 是否本地缓存获取到的值 """ self.name = "" self.value = value self.cache = cache self.timeout = timeout
[ "def", "__init__", "(", "self", ",", "value", "=", "None", ",", "cache", "=", "True", ",", "timeout", "=", "CACHE_TIMEOUT", ")", ":", "self", ".", "name", "=", "\"\"", "self", ".", "value", "=", "value", "self", ".", "cache", "=", "cache", "self", ".", "timeout", "=", "timeout" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memfields.py#L25-L33
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memfields.py
python
MemFields.getValue
(self)
获取name对应的值 当cache为True时,并且value值存在时,不再重新从memcache中获取值
获取name对应的值 当cache为True时,并且value值存在时,不再重新从memcache中获取值
[ "获取name对应的值", "当cache为True时,并且value值存在时,不再重新从memcache中获取值" ]
def getValue(self): """ 获取name对应的值 当cache为True时,并且value值存在时,不再重新从memcache中获取值 """ if self.cache and self.value: return self.value else: self.refreshValue() return self.value
[ "def", "getValue", "(", "self", ")", ":", "if", "self", ".", "cache", "and", "self", ".", "value", ":", "return", "self", ".", "value", "else", ":", "self", ".", "refreshValue", "(", ")", "return", "self", ".", "value" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memfields.py#L35-L44
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memfields.py
python
MemFields.refreshValue
(self)
return self.value
重新从memcached中获取值
重新从memcached中获取值
[ "重新从memcached中获取值" ]
def refreshValue(self): """ 重新从memcached中获取值 """ self.value = memclient.mclient.get(self.name) return self.value
[ "def", "refreshValue", "(", "self", ")", ":", "self", ".", "value", "=", "memclient", ".", "mclient", ".", "get", "(", "self", ".", "name", ")", "return", "self", ".", "value" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memfields.py#L46-L51
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memfields.py
python
MemFields.setValue
(self,value)
return result
修改对应的值
修改对应的值
[ "修改对应的值" ]
def setValue(self,value): """ 修改对应的值 """ self.value = value result = memclient.mclient.set(self.name,value,time=self.timeout) return result
[ "def", "setValue", "(", "self", ",", "value", ")", ":", "self", ".", "value", "=", "value", "result", "=", "memclient", ".", "mclient", ".", "set", "(", "self", ".", "name", ",", "value", ",", "time", "=", "self", ".", "timeout", ")", "return", "result" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memfields.py#L53-L59
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memfields.py
python
MemObj.__init__
(self, name,**kw)
@param name: str 表示对象的名称
[]
def __init__(self, name,**kw): """ @param name: str 表示对象的名称 """ self._name = name self._locked = False self._timestamp = 0 self._cas = kw.get("cas",False) self._cache = kw.get("cache",True) self._timeout = kw.get("timeout",CACHE_TIMEOUT) if self._cas: self.lock()
[ "def", "__init__", "(", "self", ",", "name", ",", "*", "*", "kw", ")", ":", "self", ".", "_name", "=", "name", "self", ".", "_locked", "=", "False", "self", ".", "_timestamp", "=", "0", "self", ".", "_cas", "=", "kw", ".", "get", "(", "\"cas\"", ",", "False", ")", "self", ".", "_cache", "=", "kw", ".", "get", "(", "\"cache\"", ",", "True", ")", "self", ".", "_timeout", "=", "kw", ".", "get", "(", "\"timeout\"", ",", "CACHE_TIMEOUT", ")", "if", "self", ".", "_cas", ":", "self", ".", "lock", "(", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memfields.py#L63-L75
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memfields.py
python
MemObj.initFields
(self)
初始化字段
初始化字段
[ "初始化字段" ]
def initFields(self): """ 初始化字段 """ nowdict = dict(self.__dict__) for item_key,item_value in nowdict.items(): if isinstance(item_value, MemFields): item_value.name = self.produceKey(item_key) item_value.timeout = self._timeout item_value.cache = self._cache
[ "def", "initFields", "(", "self", ")", ":", "nowdict", "=", "dict", "(", "self", ".", "__dict__", ")", "for", "item_key", ",", "item_value", "in", "nowdict", ".", "items", "(", ")", ":", "if", "isinstance", "(", "item_value", ",", "MemFields", ")", ":", "item_value", ".", "name", "=", "self", ".", "produceKey", "(", "item_key", ")", "item_value", ".", "timeout", "=", "self", ".", "_timeout", "item_value", ".", "cache", "=", "self", ".", "_cache" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memfields.py#L77-L86
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memfields.py
python
MemObj.produceKey
(self,keyname)
重新生成key
重新生成key
[ "重新生成key" ]
def produceKey(self,keyname): ''' 重新生成key ''' if isinstance(keyname, basestring): return ''.join([self._name,':',keyname]) else: raise MEMKeyError()
[ "def", "produceKey", "(", "self", ",", "keyname", ")", ":", "if", "isinstance", "(", "keyname", ",", "basestring", ")", ":", "return", "''", ".", "join", "(", "[", "self", ".", "_name", ",", "':'", ",", "keyname", "]", ")", "else", ":", "raise", "MEMKeyError", "(", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memfields.py#L88-L95
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memfields.py
python
MemObj.lock
(self)
return self._locked
检测对象是否被锁定
检测对象是否被锁定
[ "检测对象是否被锁定" ]
def lock(self): ''' 检测对象是否被锁定 ''' print "lock" if not self.isLocked(): key = self.produceKey('_lock') result = memclient.mclient.add(key,1,LOCK_TIMEOUT) if result: self._timestamp=time.time() self._locked = result return self._locked
[ "def", "lock", "(", "self", ")", ":", "print", "\"lock\"", "if", "not", "self", ".", "isLocked", "(", ")", ":", "key", "=", "self", ".", "produceKey", "(", "'_lock'", ")", "result", "=", "memclient", ".", "mclient", ".", "add", "(", "key", ",", "1", ",", "LOCK_TIMEOUT", ")", "if", "result", ":", "self", ".", "_timestamp", "=", "time", ".", "time", "(", ")", "self", ".", "_locked", "=", "result", "return", "self", ".", "_locked" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memfields.py#L105-L116
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memfields.py
python
MemObj.release
(self)
释放锁
释放锁
[ "释放锁" ]
def release(self): '''释放锁 ''' if self.isLocked(): key = self.produceKey('_lock') memclient.mclient.delete(key) self._locked = False
[ "def", "release", "(", "self", ")", ":", "if", "self", ".", "isLocked", "(", ")", ":", "key", "=", "self", ".", "produceKey", "(", "'_lock'", ")", "memclient", ".", "mclient", ".", "delete", "(", "key", ")", "self", ".", "_locked", "=", "False" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memfields.py#L118-L124
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memfields.py
python
MemObj.insert
(self)
插入对象记录
插入对象记录
[ "插入对象记录" ]
def insert(self): ''' 插入对象记录 ''' nowdict = dict(self.__dict__) newmapping = dict([(self.produceKey(item_key), item_value.value) for item_key,item_value in\ nowdict.items() if isinstance(item_value, MemFields) and item_value.value]) memclient.mclient.set_multi(newmapping,time=self._timeout)
[ "def", "insert", "(", "self", ")", ":", "nowdict", "=", "dict", "(", "self", ".", "__dict__", ")", "newmapping", "=", "dict", "(", "[", "(", "self", ".", "produceKey", "(", "item_key", ")", ",", "item_value", ".", "value", ")", "for", "item_key", ",", "item_value", "in", "nowdict", ".", "items", "(", ")", "if", "isinstance", "(", "item_value", ",", "MemFields", ")", "and", "item_value", ".", "value", "]", ")", "memclient", ".", "mclient", ".", "set_multi", "(", "newmapping", ",", "time", "=", "self", ".", "_timeout", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memfields.py#L126-L133
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memfields.py
python
MemObj.mdelete
(self)
return memclient.mclient.delete_multi(keys)
删除缓存中的对象
删除缓存中的对象
[ "删除缓存中的对象" ]
def mdelete(self): """ 删除缓存中的对象 """ nowdict = dict(self.__dict__) keys = [self.produceKey(item_key) for item_key,item_value in\ nowdict.items() if isinstance(item_value, MemFields)] return memclient.mclient.delete_multi(keys)
[ "def", "mdelete", "(", "self", ")", ":", "nowdict", "=", "dict", "(", "self", ".", "__dict__", ")", "keys", "=", "[", "self", ".", "produceKey", "(", "item_key", ")", "for", "item_key", ",", "item_value", "in", "nowdict", ".", "items", "(", ")", "if", "isinstance", "(", "item_value", ",", "MemFields", ")", "]", "return", "memclient", ".", "mclient", ".", "delete_multi", "(", "keys", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memfields.py#L135-L142
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memfields.py
python
MemObj.__getattribute__
(self,attr)
return value
封装了获取字段值的过程
封装了获取字段值的过程
[ "封装了获取字段值的过程" ]
def __getattribute__(self,attr): """ 封装了获取字段值的过程 """ value = object.__getattribute__(self,attr) if isinstance(value, MemFields): print 'locked',self.isLocked() if self._cas and not self.isLocked(): for _ in xrange(10): if not self.lock(): time.sleep(0.2) continue break else: return None return value.getValue() return value
[ "def", "__getattribute__", "(", "self", ",", "attr", ")", ":", "value", "=", "object", ".", "__getattribute__", "(", "self", ",", "attr", ")", "if", "isinstance", "(", "value", ",", "MemFields", ")", ":", "print", "'locked'", ",", "self", ".", "isLocked", "(", ")", "if", "self", ".", "_cas", "and", "not", "self", ".", "isLocked", "(", ")", ":", "for", "_", "in", "xrange", "(", "10", ")", ":", "if", "not", "self", ".", "lock", "(", ")", ":", "time", ".", "sleep", "(", "0.2", ")", "continue", "break", "else", ":", "return", "None", "return", "value", ".", "getValue", "(", ")", "return", "value" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memfields.py#L144-L160
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memfields.py
python
MemObj.__del__
(self)
在对象销毁时释放锁,避免在获取memcache数据时死锁
在对象销毁时释放锁,避免在获取memcache数据时死锁
[ "在对象销毁时释放锁,避免在获取memcache数据时死锁" ]
def __del__(self): """ 在对象销毁时释放锁,避免在获取memcache数据时死锁 """ try: if self.isLocked(): self.release() except Exception as e: print e
[ "def", "__del__", "(", "self", ")", ":", "try", ":", "if", "self", ".", "isLocked", "(", ")", ":", "self", ".", "release", "(", ")", "except", "Exception", "as", "e", ":", "print", "e" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memfields.py#L177-L185
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/madminanager.py
python
MAdminManager.__init__
(self)
初始化所有管理的的madmin的集合,放在self.admins中
初始化所有管理的的madmin的集合,放在self.admins中
[ "初始化所有管理的的madmin的集合,放在self", ".", "admins中" ]
def __init__(self): """初始化所有管理的的madmin的集合,放在self.admins中 """ self.isStart = False self.to_db_port = None
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "isStart", "=", "False", "self", ".", "to_db_port", "=", "None" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/madminanager.py#L21-L25
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/madminanager.py
python
MAdminManager.registe
(self,admin)
注册一个madmin对象到管理中. >>> madmin = MAdmin('tb_registe','characterId',incrkey='id') >>> MAdminManager().registe(madmin)
注册一个madmin对象到管理中. >>> madmin = MAdmin('tb_registe','characterId',incrkey='id') >>> MAdminManager().registe(madmin)
[ "注册一个madmin对象到管理中", ".", ">>>", "madmin", "=", "MAdmin", "(", "tb_registe", "characterId", "incrkey", "=", "id", ")", ">>>", "MAdminManager", "()", ".", "registe", "(", "madmin", ")" ]
def registe(self,admin): """注册一个madmin对象到管理中. >>> madmin = MAdmin('tb_registe','characterId',incrkey='id') >>> MAdminManager().registe(madmin) """ pass
[ "def", "registe", "(", "self", ",", "admin", ")", ":", "pass" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/madminanager.py#L27-L32
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/madminanager.py
python
MAdminManager._run
(self)
执行协议
执行协议
[ "执行协议" ]
def _run(self): """执行协议 """ while True: # msg = self.sock.recv() try: pyobj = self.sock.recv_pyobj() tablename,sql = pyobj excuteSQL(tablename, sql) except Exception,e: log.err(_stuff=e,_why=traceback.format_exc())
[ "def", "_run", "(", "self", ")", ":", "while", "True", ":", "# msg = self.sock.recv()", "try", ":", "pyobj", "=", "self", ".", "sock", ".", "recv_pyobj", "(", ")", "tablename", ",", "sql", "=", "pyobj", "excuteSQL", "(", "tablename", ",", "sql", ")", "except", "Exception", ",", "e", ":", "log", ".", "err", "(", "_stuff", "=", "e", ",", "_why", "=", "traceback", ".", "format_exc", "(", ")", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/madminanager.py#L35-L45
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/madminanager.py
python
MAdminManager.checkAdmins
(self,port=M2DB_PORT)
遍历所有的madmin,与数据库进行同步。 >>>MAdminManager().checkAdmins(port=M2DB_PORT)
遍历所有的madmin,与数据库进行同步。
[ "遍历所有的madmin,与数据库进行同步。" ]
def checkAdmins(self,port=M2DB_PORT): """遍历所有的madmin,与数据库进行同步。 >>>MAdminManager().checkAdmins(port=M2DB_PORT) """ if self.isStart: return self.isStart=True context = zmq.Context() self.sock = context.socket(zmq.SUB) if port==M2DB_PORT: port = ToDBAddress().m2db_port address = 'tcp://*:%s'%port self.sock.bind(address) self.sock.setsockopt(zmq.SUBSCRIBE, "") gevent.spawn(self._run)
[ "def", "checkAdmins", "(", "self", ",", "port", "=", "M2DB_PORT", ")", ":", "if", "self", ".", "isStart", ":", "return", "self", ".", "isStart", "=", "True", "context", "=", "zmq", ".", "Context", "(", ")", "self", ".", "sock", "=", "context", ".", "socket", "(", "zmq", ".", "SUB", ")", "if", "port", "==", "M2DB_PORT", ":", "port", "=", "ToDBAddress", "(", ")", ".", "m2db_port", "address", "=", "'tcp://*:%s'", "%", "port", "self", ".", "sock", ".", "bind", "(", "address", ")", "self", ".", "sock", ".", "setsockopt", "(", "zmq", ".", "SUBSCRIBE", ",", "\"\"", ")", "gevent", ".", "spawn", "(", "self", ".", "_run", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/madminanager.py#L47-L63
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memclient.py
python
memcached_connect
(servers,mem_lib="default",dead_retry=_DEAD_RETRY,**kw)
memcached connect @param servers: (list) memcached的地址,例如["127.0.0.1:11211","127.0.0.1:11222",] @param mem_lib: 选择性的使用memcached库,默认的使用python-memcached {'python-memcached':"memcache","python-ultramemcache":"ultramemcache","default":"memcache"}
memcached connect
[ "memcached", "connect" ]
def memcached_connect(servers,mem_lib="default",dead_retry=_DEAD_RETRY,**kw): """ memcached connect @param servers: (list) memcached的地址,例如["127.0.0.1:11211","127.0.0.1:11222",] @param mem_lib: 选择性的使用memcached库,默认的使用python-memcached {'python-memcached':"memcache","python-ultramemcache":"ultramemcache","default":"memcache"} """ global mclient memcache = __import__(MEMCS.get(mem_lib)) mclient = memcache.Client(servers,dead_retry=dead_retry,**kw) server,key = mclient._get_server("ping") if not server or not key: raise MemConnError()
[ "def", "memcached_connect", "(", "servers", ",", "mem_lib", "=", "\"default\"", ",", "dead_retry", "=", "_DEAD_RETRY", ",", "*", "*", "kw", ")", ":", "global", "mclient", "memcache", "=", "__import__", "(", "MEMCS", ".", "get", "(", "mem_lib", ")", ")", "mclient", "=", "memcache", ".", "Client", "(", "servers", ",", "dead_retry", "=", "dead_retry", ",", "*", "*", "kw", ")", "server", ",", "key", "=", "mclient", ".", "_get_server", "(", "\"ping\"", ")", "if", "not", "server", "or", "not", "key", ":", "raise", "MemConnError", "(", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memclient.py#L23-L35
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memmodel.py
python
MemModel.syncDB
(self)
return result
同步到数据库
同步到数据库
[ "同步到数据库" ]
def syncDB(self): """同步到数据库 """ tablename = self._name.split(':')[0] data_item = self.__dict__.get("data") data_item.setValue(data_item.value) if self._cas: self.release() props = self.data pk = self.pk prere = {pk:props.get(pk)} result = util.UpdateWithDict(tablename, props, prere) return result
[ "def", "syncDB", "(", "self", ")", ":", "tablename", "=", "self", ".", "_name", ".", "split", "(", "':'", ")", "[", "0", "]", "data_item", "=", "self", ".", "__dict__", ".", "get", "(", "\"data\"", ")", "data_item", ".", "setValue", "(", "data_item", ".", "value", ")", "if", "self", ".", "_cas", ":", "self", ".", "release", "(", ")", "props", "=", "self", ".", "data", "pk", "=", "self", ".", "pk", "prere", "=", "{", "pk", ":", "props", ".", "get", "(", "pk", ")", "}", "result", "=", "util", ".", "UpdateWithDict", "(", "tablename", ",", "props", ",", "prere", ")", "return", "result" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memmodel.py#L56-L68
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memmodel.py
python
MemAdmin.load
(self)
读取数据到数据库中
读取数据到数据库中
[ "读取数据到数据库中" ]
def load(self): '''读取数据到数据库中 ''' mmname = self.name recordlist = util.ReadDataFromDB(mmname) for record in recordlist: pk = record[self.pk] mm = MemModel(self.name+':%s'%pk,self.pk,data=record,**self.kw) mm.insert()
[ "def", "load", "(", "self", ")", ":", "mmname", "=", "self", ".", "name", "recordlist", "=", "util", ".", "ReadDataFromDB", "(", "mmname", ")", "for", "record", "in", "recordlist", ":", "pk", "=", "record", "[", "self", ".", "pk", "]", "mm", "=", "MemModel", "(", "self", ".", "name", "+", "':%s'", "%", "pk", ",", "self", ".", "pk", ",", "data", "=", "record", ",", "*", "*", "self", ".", "kw", ")", "mm", ".", "insert", "(", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memmodel.py#L90-L98
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memmodel.py
python
MemAdmin.new
(self,data)
return mm
创建一个新的对象
创建一个新的对象
[ "创建一个新的对象" ]
def new(self,data): """创建一个新的对象 """ incrkey = self.incrkey tablename = self.name if incrkey: result = util.InsertIntoDBAndReturnID(tablename, data) data[incrkey] = result pk = data.get(self.pk) if pk is None: raise PKValueError(data) mm = MemModel(self.name+':%s'%pk,self.pk,data=data,**self.kw) setattr(mm,incrkey,pk) else: pk = data.get(self.pk) result = util.InsertIntoDB(tablename, data) if not result: raise util.SQLError() mm = MemModel(self.name+':%s'%pk,self.pk,data=data,**self.kw) mm.insert() return mm
[ "def", "new", "(", "self", ",", "data", ")", ":", "incrkey", "=", "self", ".", "incrkey", "tablename", "=", "self", ".", "name", "if", "incrkey", ":", "result", "=", "util", ".", "InsertIntoDBAndReturnID", "(", "tablename", ",", "data", ")", "data", "[", "incrkey", "]", "=", "result", "pk", "=", "data", ".", "get", "(", "self", ".", "pk", ")", "if", "pk", "is", "None", ":", "raise", "PKValueError", "(", "data", ")", "mm", "=", "MemModel", "(", "self", ".", "name", "+", "':%s'", "%", "pk", ",", "self", ".", "pk", ",", "data", "=", "data", ",", "*", "*", "self", ".", "kw", ")", "setattr", "(", "mm", ",", "incrkey", ",", "pk", ")", "else", ":", "pk", "=", "data", ".", "get", "(", "self", ".", "pk", ")", "result", "=", "util", ".", "InsertIntoDB", "(", "tablename", ",", "data", ")", "if", "not", "result", ":", "raise", "util", ".", "SQLError", "(", ")", "mm", "=", "MemModel", "(", "self", ".", "name", "+", "':%s'", "%", "pk", ",", "self", ".", "pk", ",", "data", "=", "data", ",", "*", "*", "self", ".", "kw", ")", "mm", ".", "insert", "(", ")", "return", "mm" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memmodel.py#L100-L120
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memmodel.py
python
MemAdmin.getObj
(self,pk)
根据主键,可以获得mmode对象的实例.
根据主键,可以获得mmode对象的实例.
[ "根据主键,可以获得mmode对象的实例", "." ]
def getObj(self,pk): '''根据主键,可以获得mmode对象的实例. ''' mm = MemModel(self.name+':%s'%pk,self.pk,**self.kw) if mm.data: return mm else: return None
[ "def", "getObj", "(", "self", ",", "pk", ")", ":", "mm", "=", "MemModel", "(", "self", ".", "name", "+", "':%s'", "%", "pk", ",", "self", ".", "pk", ",", "*", "*", "self", ".", "kw", ")", "if", "mm", ".", "data", ":", "return", "mm", "else", ":", "return", "None" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memmodel.py#L122-L129
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/dbentrust/memmodel.py
python
MemAdmin.getObjList
(self,pklist)
return objlist
根据主键列表获取mmode对象的列表.\n >>> m = madmin.getObjList([1,2,3,4,5])
根据主键列表获取mmode对象的列表.\n >>> m = madmin.getObjList([1,2,3,4,5])
[ "根据主键列表获取mmode对象的列表", ".", "\\", "n", ">>>", "m", "=", "madmin", ".", "getObjList", "(", "[", "1", "2", "3", "4", "5", "]", ")" ]
def getObjList(self,pklist): '''根据主键列表获取mmode对象的列表.\n >>> m = madmin.getObjList([1,2,3,4,5]) ''' objlist = [] for pk in pklist: mm = MemModel(self.name+':%s'%pk,self.pk,**self.kw) objlist.append(mm) return objlist
[ "def", "getObjList", "(", "self", ",", "pklist", ")", ":", "objlist", "=", "[", "]", "for", "pk", "in", "pklist", ":", "mm", "=", "MemModel", "(", "self", ".", "name", "+", "':%s'", "%", "pk", ",", "self", ".", "pk", ",", "*", "*", "self", ".", "kw", ")", "objlist", ".", "append", "(", "mm", ")", "return", "objlist" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/dbentrust/memmodel.py#L137-L145
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/master/rootapp.py
python
_doChildConnect
(name,transport)
当server节点连接到master的处理
当server节点连接到master的处理
[ "当server节点连接到master的处理" ]
def _doChildConnect(name,transport): """当server节点连接到master的处理 """ server_config = GlobalObject().json_config.get('servers',{}).get(name,{}) remoteport = server_config.get('remoteport',[]) child_host = transport.transport.address[0] root_list = [rootport.get('rootname') for rootport in remoteport] GlobalObject().remote_map[name] = {"host":child_host,"root_list":root_list} #通知有需要连的node节点连接到此root节点 for servername,remote_list in GlobalObject().remote_map.items(): remote_host = remote_list.get("host","") remote_name_host = remote_list.get("root_list","") if name in remote_name_host: GlobalObject().root.callChild(servername,"remote_connect",name,remote_host) #查看当前是否有可供连接的root节点 master_node_list = GlobalObject().remote_map.keys() for root_name in root_list: if root_name in master_node_list: root_host = GlobalObject().remote_map[root_name]['host'] GlobalObject().root.callChild(name,"remote_connect",root_name,root_host)
[ "def", "_doChildConnect", "(", "name", ",", "transport", ")", ":", "server_config", "=", "GlobalObject", "(", ")", ".", "json_config", ".", "get", "(", "'servers'", ",", "{", "}", ")", ".", "get", "(", "name", ",", "{", "}", ")", "remoteport", "=", "server_config", ".", "get", "(", "'remoteport'", ",", "[", "]", ")", "child_host", "=", "transport", ".", "transport", ".", "address", "[", "0", "]", "root_list", "=", "[", "rootport", ".", "get", "(", "'rootname'", ")", "for", "rootport", "in", "remoteport", "]", "GlobalObject", "(", ")", ".", "remote_map", "[", "name", "]", "=", "{", "\"host\"", ":", "child_host", ",", "\"root_list\"", ":", "root_list", "}", "#通知有需要连的node节点连接到此root节点", "for", "servername", ",", "remote_list", "in", "GlobalObject", "(", ")", ".", "remote_map", ".", "items", "(", ")", ":", "remote_host", "=", "remote_list", ".", "get", "(", "\"host\"", ",", "\"\"", ")", "remote_name_host", "=", "remote_list", ".", "get", "(", "\"root_list\"", ",", "\"\"", ")", "if", "name", "in", "remote_name_host", ":", "GlobalObject", "(", ")", ".", "root", ".", "callChild", "(", "servername", ",", "\"remote_connect\"", ",", "name", ",", "remote_host", ")", "#查看当前是否有可供连接的root节点", "master_node_list", "=", "GlobalObject", "(", ")", ".", "remote_map", ".", "keys", "(", ")", "for", "root_name", "in", "root_list", ":", "if", "root_name", "in", "master_node_list", ":", "root_host", "=", "GlobalObject", "(", ")", ".", "remote_map", "[", "root_name", "]", "[", "'host'", "]", "GlobalObject", "(", ")", ".", "root", ".", "callChild", "(", "name", ",", "\"remote_connect\"", ",", "root_name", ",", "root_host", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/master/rootapp.py#L11-L30
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/master/webapp.py
python
stop
()
return "stop"
stop service
stop service
[ "stop", "service" ]
def stop(): '''stop service ''' for child in GlobalObject().root.childsmanager._childs.values(): child.callbackChildNotForResult('serverStop') reactor.callLater(0.5,reactor.stop) return "stop"
[ "def", "stop", "(", ")", ":", "for", "child", "in", "GlobalObject", "(", ")", ".", "root", ".", "childsmanager", ".", "_childs", ".", "values", "(", ")", ":", "child", ".", "callbackChildNotForResult", "(", "'serverStop'", ")", "reactor", ".", "callLater", "(", "0.5", ",", "reactor", ".", "stop", ")", "return", "\"stop\"" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/master/webapp.py#L12-L18
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/master/webapp.py
python
reloadmodule
()
return "reload"
reload module
reload module
[ "reload", "module" ]
def reloadmodule(): '''reload module ''' for child in GlobalObject().root.childsmanager._childs.values(): child.callbackChildNotForResult('sreload') return "reload"
[ "def", "reloadmodule", "(", ")", ":", "for", "child", "in", "GlobalObject", "(", ")", ".", "root", ".", "childsmanager", ".", "_childs", ".", "values", "(", ")", ":", "child", ".", "callbackChildNotForResult", "(", "'sreload'", ")", "return", "\"reload\"" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/master/webapp.py#L21-L26
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/reference.py
python
ProxyReference.__init__
(self)
初始化
初始化
[ "初始化" ]
def __init__(self): '''初始化''' self._service = Service('proxy')
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "_service", "=", "Service", "(", "'proxy'", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/reference.py#L13-L15
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/reference.py
python
ProxyReference.addService
(self,service)
添加一条服务通道
添加一条服务通道
[ "添加一条服务通道" ]
def addService(self,service): '''添加一条服务通道''' self._service = service
[ "def", "addService", "(", "self", ",", "service", ")", ":", "self", ".", "_service", "=", "service" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/reference.py#L17-L19
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/reference.py
python
ProxyReference.remote_callChild
(self, command,*arg,**kw)
return self._service.callTarget(command,*arg,**kw)
代理发送数据
代理发送数据
[ "代理发送数据" ]
def remote_callChild(self, command,*arg,**kw): '''代理发送数据 ''' return self._service.callTarget(command,*arg,**kw)
[ "def", "remote_callChild", "(", "self", ",", "command", ",", "*", "arg", ",", "*", "*", "kw", ")", ":", "return", "self", ".", "_service", ".", "callTarget", "(", "command", ",", "*", "arg", ",", "*", "*", "kw", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/reference.py#L21-L24
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/child.py
python
Child.__init__
(self,name)
初始化子节点对象
初始化子节点对象
[ "初始化子节点对象" ]
def __init__(self,name): '''初始化子节点对象 ''' self._name = name self._transport = None
[ "def", "__init__", "(", "self", ",", "name", ")", ":", "self", ".", "_name", "=", "name", "self", ".", "_transport", "=", "None" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/child.py#L10-L14
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/child.py
python
Child.getName
(self)
return self._name
获取子节点的名称
获取子节点的名称
[ "获取子节点的名称" ]
def getName(self): '''获取子节点的名称''' return self._name
[ "def", "getName", "(", "self", ")", ":", "return", "self", ".", "_name" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/child.py#L16-L18
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/child.py
python
Child.setTransport
(self,transport)
设置子节点的通道
设置子节点的通道
[ "设置子节点的通道" ]
def setTransport(self,transport): '''设置子节点的通道''' self._transport = transport
[ "def", "setTransport", "(", "self", ",", "transport", ")", ":", "self", ".", "_transport", "=", "transport" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/child.py#L20-L22
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/child.py
python
Child.callbackChild
(self,*args,**kw)
return self.callbackChildForResult(*args,**kw)
回调子节点的接口\n return a Defered Object (recvdata)
回调子节点的接口\n return a Defered Object (recvdata)
[ "回调子节点的接口", "\\", "n", "return", "a", "Defered", "Object", "(", "recvdata", ")" ]
def callbackChild(self,*args,**kw): '''回调子节点的接口\n return a Defered Object (recvdata) ''' return self.callbackChildForResult(*args,**kw)
[ "def", "callbackChild", "(", "self", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "return", "self", ".", "callbackChildForResult", "(", "*", "args", ",", "*", "*", "kw", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/child.py#L24-L28
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/child.py
python
Child.callbackChildNotForResult
(self,*args,**kw)
回调子节点的接口\n return a Defered Object (recvdata)
回调子节点的接口\n return a Defered Object (recvdata)
[ "回调子节点的接口", "\\", "n", "return", "a", "Defered", "Object", "(", "recvdata", ")" ]
def callbackChildNotForResult(self,*args,**kw): '''回调子节点的接口\n return a Defered Object (recvdata) ''' remote = self._transport.getRootObject() remote.callRemoteNotForResult('callChild',*args,**kw)
[ "def", "callbackChildNotForResult", "(", "self", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "remote", "=", "self", ".", "_transport", ".", "getRootObject", "(", ")", "remote", ".", "callRemoteNotForResult", "(", "'callChild'", ",", "*", "args", ",", "*", "*", "kw", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/child.py#L30-L35
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/child.py
python
Child.callbackChildForResult
(self,*args,**kw)
return recvdata
回调子节点的接口\n return a Defered Object (recvdata)
回调子节点的接口\n return a Defered Object (recvdata)
[ "回调子节点的接口", "\\", "n", "return", "a", "Defered", "Object", "(", "recvdata", ")" ]
def callbackChildForResult(self,*args,**kw): '''回调子节点的接口\n return a Defered Object (recvdata) ''' remote = self._transport.getRootObject() recvdata = remote.callRemoteForResult('callChild',*args,**kw) return recvdata
[ "def", "callbackChildForResult", "(", "self", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "remote", "=", "self", ".", "_transport", ".", "getRootObject", "(", ")", "recvdata", "=", "remote", ".", "callRemoteForResult", "(", "'callChild'", ",", "*", "args", ",", "*", "*", "kw", ")", "return", "recvdata" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/child.py#L37-L43
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/root.py
python
BilateralBroker.remote_takeProxy
(self,name)
设置代理通道 @param name: 根节点的名称
设置代理通道
[ "设置代理通道" ]
def remote_takeProxy(self,name): '''设置代理通道 @param name: 根节点的名称 ''' self.factory.root.remote_takeProxy(name,self)
[ "def", "remote_takeProxy", "(", "self", ",", "name", ")", ":", "self", ".", "factory", ".", "root", ".", "remote_takeProxy", "(", "name", ",", "self", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/root.py#L19-L23
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/root.py
python
BilateralBroker.remote_callTarget
(self,command,*args,**kw)
return data
远程调用方法 @param commandId: int 指令号 @param data: str 调用参数
远程调用方法
[ "远程调用方法" ]
def remote_callTarget(self,command,*args,**kw): '''远程调用方法 @param commandId: int 指令号 @param data: str 调用参数 ''' data = self.factory.root.remote_callTarget(command,*args,**kw) return data
[ "def", "remote_callTarget", "(", "self", ",", "command", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "data", "=", "self", ".", "factory", ".", "root", ".", "remote_callTarget", "(", "command", ",", "*", "args", ",", "*", "*", "kw", ")", "return", "data" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/root.py#L25-L31
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/root.py
python
PBRoot.__init__
(self,dnsmanager = ChildsManager())
初始化根节点
初始化根节点
[ "初始化根节点" ]
def __init__(self,dnsmanager = ChildsManager()): '''初始化根节点 ''' self.service = None self.childsmanager = dnsmanager
[ "def", "__init__", "(", "self", ",", "dnsmanager", "=", "ChildsManager", "(", ")", ")", ":", "self", ".", "service", "=", "None", "self", ".", "childsmanager", "=", "dnsmanager" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/root.py#L46-L50
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/root.py
python
PBRoot.addServiceChannel
(self,service)
添加服务通道 @param service: Service Object(In bilateral.services)
添加服务通道
[ "添加服务通道" ]
def addServiceChannel(self,service): '''添加服务通道 @param service: Service Object(In bilateral.services) ''' self.service = service
[ "def", "addServiceChannel", "(", "self", ",", "service", ")", ":", "self", ".", "service", "=", "service" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/root.py#L52-L56
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/root.py
python
PBRoot.remote_takeProxy
(self,name,transport)
设置代理通道 @param name: 根节点的名称
设置代理通道
[ "设置代理通道" ]
def remote_takeProxy(self,name,transport): '''设置代理通道 @param name: 根节点的名称 ''' log.msg('node [%s] takeProxy ready'%name) child = Child(name) self.childsmanager.addChild(child) child.setTransport(transport) self.doChildConnect(name, transport)
[ "def", "remote_takeProxy", "(", "self", ",", "name", ",", "transport", ")", ":", "log", ".", "msg", "(", "'node [%s] takeProxy ready'", "%", "name", ")", "child", "=", "Child", "(", "name", ")", "self", ".", "childsmanager", ".", "addChild", "(", "child", ")", "child", ".", "setTransport", "(", "transport", ")", "self", ".", "doChildConnect", "(", "name", ",", "transport", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/root.py#L58-L66
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/root.py
python
PBRoot.doChildConnect
(self,name,transport)
当node节点连接时的处理
当node节点连接时的处理
[ "当node节点连接时的处理" ]
def doChildConnect(self,name,transport): """当node节点连接时的处理 """ pass
[ "def", "doChildConnect", "(", "self", ",", "name", ",", "transport", ")", ":", "pass" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/root.py#L68-L71
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/root.py
python
PBRoot.remote_callTarget
(self,command,*args,**kw)
return data
远程调用方法 @param commandId: int 指令号 @param data: str 调用参数
远程调用方法
[ "远程调用方法" ]
def remote_callTarget(self,command,*args,**kw): '''远程调用方法 @param commandId: int 指令号 @param data: str 调用参数 ''' data = self.service.callTarget(command,*args,**kw) return data
[ "def", "remote_callTarget", "(", "self", ",", "command", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "data", "=", "self", ".", "service", ".", "callTarget", "(", "command", ",", "*", "args", ",", "*", "*", "kw", ")", "return", "data" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/root.py#L73-L79
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/root.py
python
PBRoot.dropChild
(self,*args,**kw)
删除子节点记录
删除子节点记录
[ "删除子节点记录" ]
def dropChild(self,*args,**kw): '''删除子节点记录''' self.childsmanager.dropChild(*args,**kw)
[ "def", "dropChild", "(", "self", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "self", ".", "childsmanager", ".", "dropChild", "(", "*", "args", ",", "*", "*", "kw", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/root.py#L81-L83
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/root.py
python
PBRoot.dropChildByID
(self,childId)
删除子节点记录
删除子节点记录
[ "删除子节点记录" ]
def dropChildByID(self,childId): '''删除子节点记录 ''' self.doChildLostConnect(childId) self.childsmanager.dropChildByID(childId)
[ "def", "dropChildByID", "(", "self", ",", "childId", ")", ":", "self", ".", "doChildLostConnect", "(", "childId", ")", "self", ".", "childsmanager", ".", "dropChildByID", "(", "childId", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/root.py#L85-L89
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/root.py
python
PBRoot.dropChildSessionId
(self, session_id)
删除子节点记录
删除子节点记录
[ "删除子节点记录" ]
def dropChildSessionId(self, session_id): '''删除子节点记录''' child = self.childsmanager.getChildBYSessionId(session_id) if not child: return childname = child.getName() self.doChildLostConnect(childname) self.childsmanager.dropChildByID(childname)
[ "def", "dropChildSessionId", "(", "self", ",", "session_id", ")", ":", "child", "=", "self", ".", "childsmanager", ".", "getChildBYSessionId", "(", "session_id", ")", "if", "not", "child", ":", "return", "childname", "=", "child", ".", "getName", "(", ")", "self", ".", "doChildLostConnect", "(", "childname", ")", "self", ".", "childsmanager", ".", "dropChildByID", "(", "childname", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/root.py#L91-L98
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/root.py
python
PBRoot.doChildLostConnect
(self,childname)
当node节点连接时的处理
当node节点连接时的处理
[ "当node节点连接时的处理" ]
def doChildLostConnect(self,childname): """当node节点连接时的处理 """ pass
[ "def", "doChildLostConnect", "(", "self", ",", "childname", ")", ":", "pass" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/root.py#L100-L103
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/root.py
python
PBRoot.callChild
(self,key,*args,**kw)
return self.childsmanager.callChild(key,*args,**kw)
调用子节点的接口 @param childId: int 子节点的id return Defered Object
调用子节点的接口
[ "调用子节点的接口" ]
def callChild(self,key,*args,**kw): '''调用子节点的接口 @param childId: int 子节点的id return Defered Object ''' return self.childsmanager.callChild(key,*args,**kw)
[ "def", "callChild", "(", "self", ",", "key", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "return", "self", ".", "childsmanager", ".", "callChild", "(", "key", ",", "*", "args", ",", "*", "*", "kw", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/root.py#L105-L110
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/root.py
python
PBRoot.callChildNotForResult
(self,childname,*args,**kw)
调用子节点的接口 @param childId: int 子节点的id return Defered Object
调用子节点的接口
[ "调用子节点的接口" ]
def callChildNotForResult(self,childname,*args,**kw): '''调用子节点的接口 @param childId: int 子节点的id return Defered Object ''' self.childsmanager.callChildNotForResult(childname,*args,**kw)
[ "def", "callChildNotForResult", "(", "self", ",", "childname", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "self", ".", "childsmanager", ".", "callChildNotForResult", "(", "childname", ",", "*", "args", ",", "*", "*", "kw", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/root.py#L112-L117
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/manager.py
python
ChildsManager.__init__
(self)
初始化子节点管理器
初始化子节点管理器
[ "初始化子节点管理器" ]
def __init__(self): '''初始化子节点管理器''' self._childs = {}
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "_childs", "=", "{", "}" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/manager.py#L12-L14
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/manager.py
python
ChildsManager.getChild
(self,childname)
return None
根据节点的名称获取节点实例
根据节点的名称获取节点实例
[ "根据节点的名称获取节点实例" ]
def getChild(self,childname): '''根据节点的名称获取节点实例''' for key,child in self._childs.items(): if child.getName() == childname: return self._childs[key] return None
[ "def", "getChild", "(", "self", ",", "childname", ")", ":", "for", "key", ",", "child", "in", "self", ".", "_childs", ".", "items", "(", ")", ":", "if", "child", ".", "getName", "(", ")", "==", "childname", ":", "return", "self", ".", "_childs", "[", "key", "]", "return", "None" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/manager.py#L16-L21
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/manager.py
python
ChildsManager.addChild
(self,child)
添加一个child节点\n @param child: Child object
添加一个child节点\n
[ "添加一个child节点", "\\", "n" ]
def addChild(self,child): '''添加一个child节点\n @param child: Child object ''' key = child.getName() if self._childs.has_key(key): raise "child node %s exists"% key self._childs[key] = child
[ "def", "addChild", "(", "self", ",", "child", ")", ":", "key", "=", "child", ".", "getName", "(", ")", "if", "self", ".", "_childs", ".", "has_key", "(", "key", ")", ":", "raise", "\"child node %s exists\"", "%", "key", "self", ".", "_childs", "[", "key", "]", "=", "child" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/manager.py#L23-L30
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/manager.py
python
ChildsManager.dropChild
(self,child)
删除一个child 节点\n @param child: Child Object
删除一个child 节点\n
[ "删除一个child", "节点", "\\", "n" ]
def dropChild(self,child): '''删除一个child 节点\n @param child: Child Object ''' key = child.getName() try: del self._childs[key] except Exception,e: log.msg(str(e))
[ "def", "dropChild", "(", "self", ",", "child", ")", ":", "key", "=", "child", ".", "getName", "(", ")", "try", ":", "del", "self", ".", "_childs", "[", "key", "]", "except", "Exception", ",", "e", ":", "log", ".", "msg", "(", "str", "(", "e", ")", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/manager.py#L32-L40
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/manager.py
python
ChildsManager.dropChildByID
(self,childId)
删除一个child 节点\n @param childId: Child ID
删除一个child 节点\n
[ "删除一个child", "节点", "\\", "n" ]
def dropChildByID(self,childId): '''删除一个child 节点\n @param childId: Child ID ''' try: del self._childs[childId] except Exception,e: log.msg(str(e))
[ "def", "dropChildByID", "(", "self", ",", "childId", ")", ":", "try", ":", "del", "self", ".", "_childs", "[", "childId", "]", "except", "Exception", ",", "e", ":", "log", ".", "msg", "(", "str", "(", "e", ")", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/manager.py#L42-L49
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/manager.py
python
ChildsManager.callChild
(self,childname,*args,**kw)
return child.callbackChild(*args,**kw)
调用子节点的接口\n @param childname: str 子节点的名称
调用子节点的接口\n
[ "调用子节点的接口", "\\", "n" ]
def callChild(self,childname,*args,**kw): '''调用子节点的接口\n @param childname: str 子节点的名称 ''' child = self.getChild(childname) if not child: log.err("child %s doesn't exists"%childname) return return child.callbackChild(*args,**kw)
[ "def", "callChild", "(", "self", ",", "childname", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "child", "=", "self", ".", "getChild", "(", "childname", ")", "if", "not", "child", ":", "log", ".", "err", "(", "\"child %s doesn't exists\"", "%", "childname", ")", "return", "return", "child", ".", "callbackChild", "(", "*", "args", ",", "*", "*", "kw", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/manager.py#L51-L59
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/manager.py
python
ChildsManager.callChildNotForResult
(self,childname,*args,**kw)
调用子节点的接口\n @param childname: str 子节点的名称
调用子节点的接口\n
[ "调用子节点的接口", "\\", "n" ]
def callChildNotForResult(self,childname,*args,**kw): '''调用子节点的接口\n @param childname: str 子节点的名称 ''' child = self._childs.get(childname,None) if not child: log.err("child %s doesn't exists"%childname) return child.callbackChildNotForResult(*args,**kw)
[ "def", "callChildNotForResult", "(", "self", ",", "childname", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "child", "=", "self", ".", "_childs", ".", "get", "(", "childname", ",", "None", ")", "if", "not", "child", ":", "log", ".", "err", "(", "\"child %s doesn't exists\"", "%", "childname", ")", "return", "child", ".", "callbackChildNotForResult", "(", "*", "args", ",", "*", "*", "kw", ")" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/manager.py#L61-L69
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/manager.py
python
ChildsManager.getChildBYSessionId
(self, session_id)
return None
根据sessionID获取child节点信息
根据sessionID获取child节点信息
[ "根据sessionID获取child节点信息" ]
def getChildBYSessionId(self, session_id): """根据sessionID获取child节点信息 """ for child in self._childs.values(): if child._transport.transport.sessionno == session_id: return child return None
[ "def", "getChildBYSessionId", "(", "self", ",", "session_id", ")", ":", "for", "child", "in", "self", ".", "_childs", ".", "values", "(", ")", ":", "if", "child", ".", "_transport", ".", "transport", ".", "sessionno", "==", "session_id", ":", "return", "child", "return", "None" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/manager.py#L71-L77
9miao/G-Firefly
8fbeeb3ef9782600560be48228c91cfb8f5ff87d
gfirefly/gfirefly/distributed/node.py
python
BilateralClientProtocol.setProxyReference
(self,pr)
设置代理接口提供对象
设置代理接口提供对象
[ "设置代理接口提供对象" ]
def setProxyReference(self,pr): """设置代理接口提供对象 """ self.reference = pr
[ "def", "setProxyReference", "(", "self", ",", "pr", ")", ":", "self", ".", "reference", "=", "pr" ]
https://github.com/9miao/G-Firefly/blob/8fbeeb3ef9782600560be48228c91cfb8f5ff87d/gfirefly/gfirefly/distributed/node.py#L18-L21