odoo根据模型生成security配置信息
2016-07-26 09:11
501 查看
在odoo开发中,根据model生成security也是重复性且容易犯错的阶段,因此我也写了一个简单的生成程序,可以生成相应的,下面是我的程序。#coding=utf-8
import re
import os
name_re = re.compile(r"\'([^\']*)\'")
name_line_re = re.compile(r" _name")
def get_security_config(file_names,target_file):
fwrite = open(target_file, 'w')
head_str = "id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink"
fwrite.write(head_str)
fwrite.write("\n")
fwrite.close()
name_re = re.compile(r"\'([^\']*)\'")
for file in file_names:
if os.path.exists(file):
if os.path.isfile(file):
write_security_config(file,target_file)
else:
file_list = os.listdir(file)
for file in file_list:
if endwith(file,'.py'):
write_security_config(file,target_file)
def endwith(s,*endstring):
array = map(s.endswith,endstring)
if True in array:
return True
else:
return False
def write_security_config(file_name,target_file):
fwrite = open(target_file, 'a')
with open(file_name, 'r') as f:
for line in f.readlines():
if name_line_re.findall(line):
names = name_re.findall(line.strip())
if names:
print names
names_formate = names[0].replace('.', '_')
print names_formate
first = "access_{}_user,{}.user,model_{},base.group_user,1,0,0,0".format(names_formate,
names[0],
names_formate)
second = "access_{}_user_operate,{}.user,model_{},define.group_system,1,1,1,0".format(
names_formate, names[0], names_formate)
third = "access_{}_user_group_system,{}.user,model_{},base.group_system,1,1,1,1".format(
names_formate, names[0], names_formate)
print first
print second
print third
fwrite.write(first)
fwrite.write("\n")
fwrite.write(second)
fwrite.write("\n")
fwrite.write(third)
fwrite.write("\n")
fwrite.write("\n")
fwrite.close()
if __name__ =='__main__':
file_name = [
'model.py'
]
new_file_name = 'security_tmp.txt'
get_security_config(file_name,new_file_name)
注意在生成过程中,first,second,third根据自己产品的security配置写相应的配置信息。
import re
import os
name_re = re.compile(r"\'([^\']*)\'")
name_line_re = re.compile(r" _name")
def get_security_config(file_names,target_file):
fwrite = open(target_file, 'w')
head_str = "id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink"
fwrite.write(head_str)
fwrite.write("\n")
fwrite.close()
name_re = re.compile(r"\'([^\']*)\'")
for file in file_names:
if os.path.exists(file):
if os.path.isfile(file):
write_security_config(file,target_file)
else:
file_list = os.listdir(file)
for file in file_list:
if endwith(file,'.py'):
write_security_config(file,target_file)
def endwith(s,*endstring):
array = map(s.endswith,endstring)
if True in array:
return True
else:
return False
def write_security_config(file_name,target_file):
fwrite = open(target_file, 'a')
with open(file_name, 'r') as f:
for line in f.readlines():
if name_line_re.findall(line):
names = name_re.findall(line.strip())
if names:
print names
names_formate = names[0].replace('.', '_')
print names_formate
first = "access_{}_user,{}.user,model_{},base.group_user,1,0,0,0".format(names_formate,
names[0],
names_formate)
second = "access_{}_user_operate,{}.user,model_{},define.group_system,1,1,1,0".format(
names_formate, names[0], names_formate)
third = "access_{}_user_group_system,{}.user,model_{},base.group_system,1,1,1,1".format(
names_formate, names[0], names_formate)
print first
print second
print third
fwrite.write(first)
fwrite.write("\n")
fwrite.write(second)
fwrite.write("\n")
fwrite.write(third)
fwrite.write("\n")
fwrite.write("\n")
fwrite.close()
if __name__ =='__main__':
file_name = [
'model.py'
]
new_file_name = 'security_tmp.txt'
get_security_config(file_name,new_file_name)
注意在生成过程中,first,second,third根据自己产品的security配置写相应的配置信息。
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法