浏览代码

Merge branch 'master' of github.com:webnotes/wnframework

version-14
Nabin Hait 14 年前
父节点
当前提交
e19df90b9b
共有 4 个文件被更改,包括 24 次插入9 次删除
  1. +4
    -1
      py/webnotes/model/db_schema.py
  2. +5
    -1
      py/webnotes/utils/__init__.py
  3. +3
    -3
      py/webnotes/utils/backups.py
  4. +12
    -4
      py/webnotes/utils/nestedset.py

+ 4
- 1
py/webnotes/model/db_schema.py 查看文件

@@ -357,8 +357,11 @@ class DbManager:
mysql_path = getattr(webnotes.defs, 'mysql_path', None) mysql_path = getattr(webnotes.defs, 'mysql_path', None)
mysql = mysql_path and os.path.join(mysql_path, 'mysql') or 'mysql' mysql = mysql_path and os.path.join(mysql_path, 'mysql') or 'mysql'
from webnotes.utils import make_esc
esc = make_esc('$ ')
try: try:
ret = os.system("%s -u root -p%s %s < %s"%(mysql, root_password.replace(" ", "\ "), target.replace("$", "\$"), source))
ret = os.system("%s -u root -p%s %s < %s"%(mysql, esc(root_password), esc(target), source))
except Exception,e: except Exception,e:
raise e raise e




+ 5
- 1
py/webnotes/utils/__init__.py 查看文件

@@ -636,6 +636,10 @@ def get_file_timestamp(fn):
else: else:
return None return None



def make_esc(esc_chars):
"""
Function generator for Escaping special characters
"""
return lambda s: ''.join(['\\' + c if c in esc_chars else c for c in s])



+ 3
- 3
py/webnotes/utils/backups.py 查看文件

@@ -24,11 +24,11 @@ class BackupGenerator:
If specifying db_file_name, also append ".sql.gz" If specifying db_file_name, also append ".sql.gz"
""" """
def __init__(self, db_name, user, password, db_file_name=None): def __init__(self, db_name, user, password, db_file_name=None):
self.db_name = db_name
self.db_name = db_name.replace('$', '\$')
self.user = user self.user = user
self.password = password self.password = password
self.db_file_name = db_file_name and db_file_name \ self.db_file_name = db_file_name and db_file_name \
or (os.path.join(backup_path, db_name + ".sql.gz"))
or (os.path.join(backup_path, self.db_name + ".sql.gz"))


def take_dump(self): def take_dump(self):
""" """
@@ -88,7 +88,7 @@ class BackupGenerator:
Also, a new backup will be available for download (if requested)\ Also, a new backup will be available for download (if requested)\
only after 24 hours.""" % {"file_url":file_url} only after 24 hours.""" % {"file_url":file_url}
datetime_str = datetime.fromtimestamp(os.stat(self.db_file_name).st_ctime)
datetime_str = datetime.fromtimestamp(os.stat(self.db_file_name.replace('\$', '$')).st_ctime)
subject = datetime_str.strftime("%d/%m/%Y %H:%M:%S") + """ - Backup ready to be downloaded""" subject = datetime_str.strftime("%d/%m/%Y %H:%M:%S") + """ - Backup ready to be downloaded"""
sendmail(recipients=recipient_list, msg=msg, subject=subject) sendmail(recipients=recipient_list, msg=msg, subject=subject)


+ 12
- 4
py/webnotes/utils/nestedset.py 查看文件

@@ -156,8 +156,10 @@ def rebuild_tree(doctype, parent_field):
result = webnotes.conn.sql("SELECT name FROM `tab%s` WHERE `%s`='' or `%s` IS NULL ORDER BY name ASC" % (doctype, parent_field, parent_field)) result = webnotes.conn.sql("SELECT name FROM `tab%s` WHERE `%s`='' or `%s` IS NULL ORDER BY name ASC" % (doctype, parent_field, parent_field))
for r in result: for r in result:
right = rebuild_node(doctype, r[0], right, parent_field) right = rebuild_node(doctype, r[0], right, parent_field)
webnotes.conn.sql("commit")
webnotes.conn.sql("start transaction")
def rebuild_node(doctype, parent, left, parent_field):
def rebuild_node(doctype, parent, left, parent_field, cnt = 0):
""" """
reset lft, rgt and recursive call for all children reset lft, rgt and recursive call for all children
""" """
@@ -165,17 +167,24 @@ def rebuild_node(doctype, parent, left, parent_field):
n = now() n = now()
# the right value of this node is the left value + 1 # the right value of this node is the left value + 1
right = left+1
right = left+1


# get all children of this node # get all children of this node
result = webnotes.conn.sql("SELECT name FROM `tab%s` WHERE `%s`='%s'" % (doctype, parent_field, parent)) result = webnotes.conn.sql("SELECT name FROM `tab%s` WHERE `%s`='%s'" % (doctype, parent_field, parent))
for r in result: for r in result:
right = rebuild_node(doctype, r[0], right, parent_field)
right = rebuild_node(doctype, r[0], right, parent_field, cnt)


# we've got the left value, and now that we've processed # we've got the left value, and now that we've processed
# the children of this node we also know the right value # the children of this node we also know the right value
webnotes.conn.sql("UPDATE `tab%s` SET lft=%s, rgt=%s, modified='%s' WHERE name='%s'" % (doctype,left,right,n,parent)) webnotes.conn.sql("UPDATE `tab%s` SET lft=%s, rgt=%s, modified='%s' WHERE name='%s'" % (doctype,left,right,n,parent))


# commit after every 100
cnt += 1
if cnt % 100 == 0:
cnt = 0
webnotes.conn.sql("commit")
webnotes.conn.sql("start transaction")

#return the right value of this node + 1 #return the right value of this node + 1
return right+1 return right+1
@@ -220,4 +229,3 @@ def update_remove_node(doctype, name):
# update all on the right # update all on the right
webnotes.conn.sql("update `tab%s` set rgt = rgt-2, modified='%s' where rgt > %s" %(doctype,n,left[0][0])) webnotes.conn.sql("update `tab%s` set rgt = rgt-2, modified='%s' where rgt > %s" %(doctype,n,left[0][0]))
webnotes.conn.sql("update `tab%s` set lft = lft-2, modified='%s' where lft > %s" %(doctype,n,left[0][0])) webnotes.conn.sql("update `tab%s` set lft = lft-2, modified='%s' where lft > %s" %(doctype,n,left[0][0]))


正在加载...
取消
保存