当前位置: 首页 > 工具软件 > Trac > 使用案例 >

python项目管理工具_项目管理工具之Trac

苏伟志
2023-12-01

trac部署

@依赖:

python2.5+,setuptools0.6+ ,genshi0.6+ pip自动安装依赖

db:mysql5.0+,mysqldb1.2.2+(MySQL-python)

git:1.5.6+

webserver:nginx,apache

other:babel0.9.5+,docutils0.3.9+,pygments(for syntax highlighiting),pytz(timezone)

@安装trac

#pip环境准备

yum install  wget unzip -y

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

yum install python-pip python-devel httpd-tools -y

pip install --upgrade pip

pip install --upgrade setuptools

#pip安装

pip install trac (此方式安装没有中文支持。如需中文,请直接进行源码编译)

#源码安装

语言插件 bael介绍:https://babel.edgewall.org/wiki/Documentation/setup.html

1.安装pip install babel

2.安装trac

wget http://download.edgewall.org/trac/Trac-0.12.7.tar.gz

或wget http://download.edgewall.org/trac/Trac-1.0.10.tar.gz

tar xvf Trac-1.0.10.tar.gz

cd Trac-1.0.10

3. 生成pot

python setup.py extract_messages

4. 编译po(这里可以指定编译为哪种语言,不指定就是全部)

python setup.py update_catalog

5. 检查你要的语言装了没

python setup.py update_catalog -l zh_CN

6. 编译为mo

python setup.py compile_catalog -f

7. 安装trac

python setup.py install

@支持mysql

yum install  mysql mysql-server mysql-devel  -y

pip install MySQL-python

配置数据库

mysql> set global storage_engine=innodb;

1)  mysql> CREATE DATABASE trac DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

2)mysql> GRANT ALL ON trac.* TO tracuser@localhost IDENTIFIED BY 'password';

@初始化项目环境

#前台模式

trac-admin /usr/local/data/test1 initenv test mysql://tracuser:password@localhost:3306/trac

#cgi静态资源模式

trac-admin /usr/local/data/test1/ deploy /tmp/deploy

/usr/local/data/test1/

├── conf

│   ├── trac.ini

│   └── trac.ini.sample

├── htdocs

├── log

├── plugins

├── README

├── templates

│   └── site.html.sample

└── VERSION

修改配置文件

vim /usr/local/data/test1/conf/trac.ini

[trac]

default_charset= utf-8

default_language= zh_CN

default_timezone=

@trac-admin帮助

trac-admin yourenv help(trac-admin test1 help)

@帐号权限管理(tracstandalone或tracmodwsgi或tracfastcgi)

https://trac-hacks.org/wiki/AccountManagerPlugin

https://trac-hacks.org/wiki/CookBook/AccountManagerPluginConfiguration

#命令行模式:

添加管理htpasswd -c /usr/local/data/test1/.htpasswd admin

或: htpasswd -b -c ./test1/.htpasswd admin admin

添加管理界面trac-admin /usr/local/data/test1/ permission add admin  TRAC_ADMIN

#插件模式:TracAccountManager

pip install TracAccountManager

@启动测试 https://trac.edgewall.org/wiki/TracStandalone

#启动方式1:

tracd -p 8080 -b 192.168.50.108 --basic-auth=test1,/usr/local/data/test1/.htpasswd,mytest -d /usr/local/data/test1

测试:192.168.50.108:8080  使用自动的logmodule登录测试

#启动方式2:web-server(fastcgi)

多实例:tracd -d -p 3050 --pidfile=/var/live/run/tracd.3050 --protocol=http -e /var/live/trac

单实例:tracd -d -p 3050 --pidfile=/var/live/run/tracd.3051 --protocol=http -s /var/live/trac/telecardia

@git插件  http://${yourip}/test1/wiki/TracRepositoryAdmin#Synchronization

yum install git -y

#方法1.trac-admin initenv 环境的时候指定版本控制类型为git

#方法2.手动配置trac.ini,不需要重启服务

[trac] (1.1.3 之前的版本)

repository_type = git

repository_dir = /path/to/my/git/repository/.git[components]

tracopt.versioncontrol.git.* = enabled

[repositories] (1.1.3之后的版本)

.type = git

.dir = /path/to/my/git/repository/.git

[git]  (git的执行程序不在默认路径)

git_bin = C:/Dev/msysgit/bin/git.exe

[components]

tracopt.versioncontrol.git.* = enabled

`

添加仓库方式:本地,如果是远程的必须git clone

命令行添加:trac-admin /usr/local/trac_proj/test1/ repository add /root/gitolite/ git

web界面添加:

手动同步仓库更新:

trac-admin /usr/local/trac_proj/test1 repository resync "NGINX"

trac-admin /usr/local/trac_proj/test1 changeset added "NGINX" $REV

自动同步仓库更新:

配置git仓库下.git/hooks post-receive

配置trac.ini中compenents模块

tracopt.ticket.commit_updater.* = enabled

#tracopt.versioncontrol.git.* = enabled

@nginx支持 https://trac.edgewall.org/wiki/TracNginxRecipe

方法1#nginx认证(使用trac默认的LoginModule)

tracd -p 8080 --basic-auth=yunwei,/usr/local/data/test1/.htpasswd,yuni /usr/local/data/test1/

cat default.conf

server {

location / {

proxy_pass http://localhost:8080;  # Replace localhost:8000 with your server:port

auth_basic "Restricted";

auth_basic_user_file /usr/local/data/test1/.htpasswd;     # Will effectively be /etc/nginx/htpasswd in Ubuntu, check your distribution

proxy_pass_header Authorization;   # Here you tell Nginx to forward the Authorization header to tracd

}

}#trac的多实例启动:tracd --port=8000 --hostname=127.0.0.1 --env-parent-dir=/home/trac --basic-auth="*,/etc/nginx/htpasswd,Restricted"

方法2#nginx支持fastcgi(使用TracAccountManager插件认证):

##生成静态资源

trac-admin ./test1/ deploy ./deploy

##复制静态资源到项目路径

cat test1.conf

server {

server_name 'trac.test1.com';

location ~ /chrome/(.*) {

alias /usr/local/data/test1/htdocs/$1;

}

# You can copy this whole location to ``location [/some/prefix](/login)``

# and remove the auth entries below if you want Trac to enforce

# authorization where appropriate instead of needing to authenticate

# for accessing the whole site.

# (Or ``~ location /some/prefix(/.*)``.)

location ~ (/.*) {

#auth_basic            "trac realm";

#auth_basic_user_file /usr/local/data/htpasswd;

# socket address

fastcgi_pass   unix:/tmp/test1.sock;

# python - wsgi specific

#fastcgi_param HTTPS on;

## WSGI REQUIRED VARIABLES

# WSGI application name - trac instance prefix.

# (Or ``fastcgi_param  SCRIPT_NAME  /some/prefix``.)

fastcgi_param  SCRIPT_NAME        "";

fastcgi_param  PATH_INFO          $1;

## WSGI NEEDED VARIABLES - trac warns about them

fastcgi_param  REQUEST_METHOD     $request_method;

fastcgi_param  SERVER_NAME        $server_name;

fastcgi_param  SERVER_PORT        $server_port;

fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  QUERY_STRING       $query_string;

# For Nginx authentication to work - do not forget to comment these

# lines if not using Nginx for authentication

fastcgi_param  AUTH_USER          $remote_user;

fastcgi_param  REMOTE_USER        $remote_user;

# for ip to work

fastcgi_param REMOTE_ADDR         $remote_addr;

# For attchments to work

fastcgi_param    CONTENT_TYPE     $content_type;

fastcgi_param    CONTENT_LENGTH   $content_length;

}

}

##fcgi启动脚本:

cat trac.fcgi

#!/usr/bin/env python

import os

sockaddr = '/tmp/test1.sock'

os.environ['TRAC_ENV'] = '/usr/local/data/test1'

try:

from trac.web.main import dispatch_request

import trac.web._fcgi

fcgiserv = trac.web._fcgi.WSGIServer(dispatch_request,

bindAddress = sockaddr, umask = 7)

fcgiserv.run()

except SystemExit:

raise

except Exception, e:

print 'Content-Type: text/plain\r\n\r\n',

print 'Oops...'

print

print 'Trac detected an internal error:'

print

print e

print

import traceback

import StringIO

tb = StringIO.StringIO()

traceback.print_exc(file=tb)

print tb.getvalue()

##chmod a+x trac.fcgi

##chmod 777 /tmp/test1.sock

##启动服务

nginx -s reload

./trac.fcgi

@禁止匿名用户访问指定信息(web 管理)

#web表单登录配置

[components]

acct_mgr.web_ui.LoginModule = enabled

acct_mgr.* = enabled

trac.web.auth.LoginModule = disabled

[account-manager]

account_changes_notify_addresses =

password_store = HtPasswdStore

htpasswd_hash_type = md5

htpasswd_file = /usr/local/data/test1/.htpasswd   ; new style (acct_mgr >= 0.4)

reset_password = false

#重新启动trac:python /usr/local/data/test/trac.fcgi && chmod 777 /tmp/test1.sock

@trac备份

#保证数据库的数据正常且一致,前端文件支持热备份,即复制到任意一台trac环境下即可使用

##tar备份

##trac-admin

trac-admin /usr/local/data/test1/ hotcopy /tmp/test1

@其他插件

#trac-plugin list:

#注册并连接数据库,邮箱等功能

#权限的细分

https://trac.edgewall.org/wiki/TracFineGrainedPermissions#AuthzSourcePolicy

#安装wiki扩展插件

##cp -r tracwysiwyg/htdocs/* tracwysiwyg/    #此方法正常。这里用到css和js文件,路径在htdocs下无法识别插件。或者采用前端模式查看trac的请求模块再修改nginx配置。

##cp -r plugins/tracwysiwyg/ /usr/local/data/test1/htdocs/   #此方法正常。nginx的配置中指定所有文件都在htdocs下.或者采用前端模式查看trac的请求模块再修改nginx配置。

##配置trac对插件的支持

[components]

tracwysiwyg.* = enabled

#其他

https://trac-hacks.org/wiki/SimpleMultiProjectPlugin

https://trac-hacks.org/wiki/ProjectMenuPlugin

https://trac-hacks.org/wiki/AcronymsPlugin

https://trac-hacks.org/wiki/MyPagePlugin

https://trac-hacks.org/wiki/ReadmePlugin

https://trac-hacks.org/wiki/RobotsTxtPlugin

https://trac-hacks.org/wiki/TracLinksPlugin

https://trac-hacks.org/wiki/TracIniAdminPanelPlugin

https://trac-hacks.org/wiki/TracWysiwygPlugin

https://trac-hacks.org/wiki/WikiExtrasPlugin

 类似资料: