2006年03月31日 星期五 13:33
因为在trac中只能使用trac-admin命令一个个提交权限,很麻烦,所以就想写一个脚本来搞定它,如果是在以前,我就会用shell来做,现在我想用python来锻练一下: trac-access-file content as follow: permission_all = BROWSER_VIEW,CHANGESET_VIEW,CONFIG_VIEW,FILE_VIEW,LOG_VIEW,MILESTONE_ADMIN,MILESTONE_CREATE,MILESTONE_DELETE,MILESTONE_MODIFY,MILESTONE_VIEW,REPORT_ADMIN,REPORT_CREATE,REPORT_DELETE,REPORT_MODIFY,REPORT_SQL_VIEW,REPORT_VIEW,ROADMAP_ADMIN,ROADMAP_VIEW,SEARCH_VIEW,TICKET_ADMIN,TICKET_APPEND,TICKET_CHGPROP,TICKET_CREATE,TICKET_MODIFY,TICKET_VIEW,TIMELINE_VIEW,TRAC_ADMIN,WIKI_ADMIN,WIKI_CREATE,WIKI_DELETE,WIKI_MODIFY,WIKI_VIEW team_all = alexxu,arielgu,ericgao,geminisshao,thunderzhang,junzhao,rogersong,johnshen,jackytian,sanzhong,yitangcheng permission_allow = BROWSER_VIEW,LOG_VIEW,FILE_VIEW,CHANGESET_VIEW,TICKET_VIEW,MILESTONE_VIEW,ROADMAP_VIEW,REPORT_VIEW,WIKI_VIEW,TIMELINE_VIEW,SEARCH_VIEW 我已经编写了一个脚本permission.py: #!/usr/bin/python import os f = open("/etc/apache2/trac-access-file","r"); str = f.read() for line in str.split('\n'): if line == '': continue elif line[0:8] == 'team_all': for unit in line[11:].split(','): command= "trac-admin /var/trac permission add %s team_all anonymous " %(unit) if os.system(command) == 0: print command,' Success' else: print command,'Failed' continue elif line[0:16] == 'permission_allow': for unit in line[19:].split(','): command= "trac-admin /var/trac permission add team_all %s" %(unit) command2= "trac-admin /var/trac permission add anonymous %s" %(unit) if os.system(command) == 0 or os.system(command2)==0: print command,' Success' else: print command,'Failed' continue elif line[0:14] == 'permission_all': for unit in line[17:].split(','): command= "trac-admin /var/trac permission remove anonymous %s" %(unit) if os.system(command) == 0: print command,' Success' else: print command,'Failed' continue 我这个脚本只能算个简单的工作脚本而已,肯定会有高人能提出改进的意见,请不吝赐教,给思路也行。谢谢 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060331/295a59b0/attachment.htm
2006年03月31日 星期五 13:46
On 3/31/06, GeminisShao at viatech.com.cn <GeminisShao at viatech.com.cn> wrote: > > 因为在trac中只能使用trac-admin命令一个个提交权限,很麻烦,所以就想写一个脚本来搞定它,如果是在以前,我就会用shell来做,现在我想用python来锻练一下: > > trac-access-file content as follow: > permission_all = > BROWSER_VIEW,CHANGESET_VIEW,CONFIG_VIEW,FILE_VIEW,LOG_VIEW,MILESTONE_ADMIN,MILESTONE_CREATE,MILESTONE_DELETE,MILESTONE_MODIFY,MILESTONE_VIEW,REPORT_ADMIN,REPORT_CREATE,REPORT_DELETE,REPORT_MODIFY,REPORT_SQL_VIEW,REPORT_VIEW,ROADMAP_ADMIN,ROADMAP_VIEW,SEARCH_VIEW,TICKET_ADMIN,TICKET_APPEND,TICKET_CHGPROP,TICKET_CREATE,TICKET_MODIFY,TICKET_VIEW,TIMELINE_VIEW,TRAC_ADMIN,WIKI_ADMIN,WIKI_CREATE,WIKI_DELETE,WIKI_MODIFY,WIKI_VIEW > > team_all = > alexxu,arielgu,ericgao,geminisshao,thunderzhang,junzhao,rogersong,johnshen,jackytian,sanzhong,yitangcheng > > permission_allow = > BROWSER_VIEW,LOG_VIEW,FILE_VIEW,CHANGESET_VIEW,TICKET_VIEW,MILESTONE_VIEW,ROADMAP_VIEW,REPORT_VIEW,WIKI_VIEW,TIMELINE_VIEW,SEARCH_VIEW > > > 我已经编写了一个脚本permission.py: > > #!/usr/bin/python > import os > f = open("/etc/apache2/trac-access-file","r"); > str = f.read() > for line in str.split('\n'): > if line == '': > continue > > elif line[0:8] == 'team_all': > for unit in line[11:].split(','): > command= "trac-admin /var/trac permission add %s > team_all anonymous " %(unit) > if os.system(command) == 0: > print command,' Success' > else: > print command,'Failed' > continue > > elif line[0:16] == 'permission_allow': > for unit in line[19:].split(','): > command= "trac-admin /var/trac permission add > team_all %s" %(unit) > command2= "trac-admin /var/trac permission add > anonymous %s" %(unit) > if os.system(command) == 0 or > os.system(command2)==0: > print command,' Success' > else: > print command,'Failed' > continue > > elif line[0:14] == 'permission_all': > for unit in line[17:].split(','): > command= "trac-admin /var/trac permission remove > anonymous %s" %(unit) > if os.system(command) == 0: > print command,' Success' > else: > print command,'Failed' > continue > > 我这个脚本只能算个简单的工作脚本而已,肯定会有高人能提出改进的意见,请不吝赐教,给思路也行。谢谢 > 不错。就是取名字的时候你使用定长。比较好的方式是使用splite('=', 1)来处理,这样按=进行拆分。然后再去掉首尾空格就好了。使用定长的话一旦前面的串名发生变化,改动就比较多,而且不通用。 另外权限可以与用户分开,这样互不影响。另外还可以有两种工作模式,一种是预设好的,即有哪些组,有哪些权限。一种是运行后再修改,这样可以提供一个交互环境。 -- I like python! My Blog: http://www.donews.net/limodou My Django Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit
Zeuux © 2025
京ICP备05028076号