[trac]配置trac实例权限的脚本

   如果要为多个trac实例分配权限, 而且每一个trac实例又有多个用户, 做起来挺枯燥的,. 于是我用python写了个 脚本, 用来为多个trac实例分配权限. 代码如下, SetPermission.py是实现代码, PermissionConf.py是配置文件.

SetPermission.py

# --*-- coding:cp936 --*--

"""
@file: SetPermission.py
    配置trac实例的权限
@author: riag 
@contract: [email protected], http://blog.csdn.net/riag
@version: 0.10
@summary: 
@change: 
"""


import  os
import  PermissionConf
import  traceback
import  sys

if   __name__   ==   " __main__ " :
    PythonPath 
=  raw_input( " 输入python安装路径(默认值:C:/Python24, 选默认值按回车即可):  " ) ;
    
if  PythonPath:
        TracAdminPath 
= PythonPath  +   " /Scripts/trac-admin "  ;
    
else
        PythonPath 
=   " C:/Python24 "
        TracAdminPath 
=   " C:/Python24/Scripts/trac-admin "  ;
    
    RunTracAdmin 
=   " python  " +  TracAdminPath ;
    
print  RunTracAdmin
    
    
if  PermissionConf.Commd:
        Commd 
=  PermissionConf.Commd
    
else : Commd  =   " add "  ;
    
    PermissionsList 
=   "" ;
    
for  elem  in  PermissionConf.Permissions:
        PermissionsList 
+=  elem ;
        PermissionsList 
+=   "   "  ;
    
    
try :
        
if  PermissionsList:
            
for  elem  in  PermissionConf.ProjectList:
                RunPermissions 
=  RunTracAdmin  +   "   "   +  elem  +   "  permission  "   +  Commd  +   "   " ;
                
for  user_elem  in  PermissionConf.UserList:
                    RunCommd 
= RunPermissions  +  user_elem  +   "   "   +  PermissionsList
                    
print  RunCommd
                    os.system(RunCommd)
    
except :
        traceback.print_exc(file 
=  sys.stdout)
    
    
    os.system(
" pause " ) ;
    

 

PermissionConf.py

# --*-- coding:cp936 --*--

# 每个项目的路径
ProjectList  =  ( " c:/trac1 " " d:/trac2 " )
# 用户
UserList  =  ( " a " " b " )

# Permissions = ("TRAC_ADMIN") #最高权限
Permissions  =  ( " TICKET_CREATE " " WIKI_CREATE " " WIKI_MODIFY " " TICKET_APPEND " " TICKET_MODIFY " " BLOG_POSTER " " BROWSER_VIEW " # 开发人员权限
#
Permissions = ("BLOG_POSTER", "TICKET_CREATE", "TICKET_APPEND", "TICKET_MODIFY", "WIKI_CREATE", "WIKI_MODIFY") #测试人员权限

Commd 
=   " add "   # 添加权限
#
Commd = "remove" #删除权限

 

 

你可能感兴趣的:(python,脚本,Blog,import,browser,permissions)