This commit is contained in:
Liang Ding 2014-09-05 11:07:29 +08:00
parent fcfe3eb221
commit 932d472c0d
7 changed files with 16 additions and 21 deletions

View File

@ -28,8 +28,8 @@ type conf struct {
StaticPath string StaticPath string
MaxProcs int MaxProcs int
RuntimeMode string RuntimeMode string
Repos string Workspace string
UserRepos string UserWorkspaces string
Users []User Users []User
} }
@ -91,8 +91,8 @@ func Load() {
pwd = pwd[:strings.LastIndex(pwd, string(os.PathSeparator))] pwd = pwd[:strings.LastIndex(pwd, string(os.PathSeparator))]
glog.Infof("pwd [%s]", pwd) glog.Infof("pwd [%s]", pwd)
Wide.Repos = strings.Replace(Wide.Repos, "{pwd}", pwd, 1) Wide.Workspace = strings.Replace(Wide.Workspace, "{pwd}", pwd, 1)
Wide.UserRepos = strings.Replace(Wide.UserRepos, "{pwd}", pwd, 1) Wide.UserWorkspaces = strings.Replace(Wide.UserWorkspaces, "{pwd}", pwd, 1)
glog.Info("Conf: \n" + string(bytes)) glog.Info("Conf: \n" + string(bytes))
} }

View File

@ -9,8 +9,8 @@
"StaticPath": "", "StaticPath": "",
"MaxProcs": 4, "MaxProcs": 4,
"RuntimeMode": "dev", "RuntimeMode": "dev",
"Repos": "{pwd}/data/workspace/src", "Workspace": "{pwd}/data/workspace",
"UserRepos": "{pwd}/data/user_workspaces/{user}/src", "UserWorkspaces": "{pwd}/data/user_workspaces",
"Users": [ "Users": [
{ {
"Name": "admin", "Name": "admin",

View File

@ -11,7 +11,6 @@ import (
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
@ -151,15 +150,13 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
// glog.Infof("offset: %d", offset) // glog.Infof("offset: %d", offset)
userRepos := strings.Replace(conf.Wide.UserRepos, "{user}", username, -1) userWorkspace := conf.Wide.UserWorkspaces + string(os.PathSeparator) + username
userWorkspace := userRepos[:strings.LastIndex(userRepos, "/src")]
userWorkspace = filepath.FromSlash(userWorkspace)
//glog.Infof("User [%s] workspace [%s]", username, userWorkspace) //glog.Infof("User [%s] workspace [%s]", username, userWorkspace)
userLib := userWorkspace + string(os.PathSeparator) + "pkg" + string(os.PathSeparator) + userLib := userWorkspace + string(os.PathSeparator) + "pkg" + string(os.PathSeparator) +
runtime.GOOS + "_" + runtime.GOARCH runtime.GOOS + "_" + runtime.GOARCH
masterWorkspace := conf.Wide.Repos[:strings.LastIndex(conf.Wide.Repos, "/src")] masterWorkspace := conf.Wide.Workspace
masterWorkspace = filepath.FromSlash(masterWorkspace)
//glog.Infof("Master workspace [%s]", masterWorkspace) //glog.Infof("Master workspace [%s]", masterWorkspace)
masterLib := masterWorkspace + string(os.PathSeparator) + "pkg" + string(os.PathSeparator) + masterLib := masterWorkspace + string(os.PathSeparator) + "pkg" + string(os.PathSeparator) +
runtime.GOOS + "_" + runtime.GOARCH runtime.GOOS + "_" + runtime.GOARCH

View File

@ -21,8 +21,7 @@ func GetFiles(w http.ResponseWriter, r *http.Request) {
session, _ := user.Session.Get(r, "wide-session") session, _ := user.Session.Get(r, "wide-session")
username := session.Values["username"].(string) username := session.Values["username"].(string)
userRepos := conf.Wide.UserWorkspaces + string(os.PathSeparator) + username + string(os.PathSeparator) + "src"
userRepos := strings.Replace(conf.Wide.UserRepos, "{user}", username, -1)
root := FileNode{"projects", userRepos, "d", []*FileNode{}} root := FileNode{"projects", userRepos, "d", []*FileNode{}}
fileInfo, _ := os.Lstat(userRepos) fileInfo, _ := os.Lstat(userRepos)

View File

@ -231,8 +231,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
} }
func setCmdEnv(cmd *exec.Cmd, username string) { func setCmdEnv(cmd *exec.Cmd, username string) {
userRepos := strings.Replace(conf.Wide.UserRepos, "{user}", username, -1) userWorkspace := conf.Wide.UserWorkspaces + string(os.PathSeparator) + username
userWorkspace := userRepos[:strings.LastIndex(userRepos, "/src")]
cmd.Env = append(cmd.Env, cmd.Env = append(cmd.Env,
"GOPATH="+userWorkspace, "GOPATH="+userWorkspace,

View File

@ -97,8 +97,8 @@ func pipeCommands(commands ...*exec.Cmd) string {
func setCmdEnv(cmd *exec.Cmd) { func setCmdEnv(cmd *exec.Cmd) {
// TODO: 使用用户自己的仓库路径设置 GOPATH // TODO: 使用用户自己的仓库路径设置 GOPATH
cmd.Env = append(cmd.Env, "TERM=xterm", "GOPATH="+conf.Wide.Repos, cmd.Env = append(cmd.Env, "TERM=xterm", "GOPATH="+conf.Wide.Workspace,
"GOROOT="+os.Getenv("GOROOT")) "GOROOT="+os.Getenv("GOROOT"))
cmd.Dir = conf.Wide.Repos cmd.Dir = conf.Wide.Workspace
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/b3log/wide/util" "github.com/b3log/wide/util"
"github.com/golang/glog" "github.com/golang/glog"
"net/http" "net/http"
"strings" "os"
) )
const ( const (
@ -47,11 +47,11 @@ func InitGitRepos(w http.ResponseWriter, r *http.Request) {
session, _ := Session.Get(r, "wide-session") session, _ := Session.Get(r, "wide-session")
username := session.Values["username"].(string) username := session.Values["username"].(string)
userRepos := strings.Replace(conf.Wide.UserRepos, "{user}", username, -1) userRepos := conf.Wide.UserWorkspaces + string(os.PathSeparator) + username + string(os.PathSeparator) + "src"
// TODO: git clone // TODO: git clone
glog.Infof("Git Cloned from [%s] to [%s]", conf.Wide.Repos, userRepos) glog.Infof("Git Cloned from [%s] to [%s]", conf.Wide.Workspace+string(os.PathSeparator)+"src", userRepos)
} }
func addUser(username, password string) string { func addUser(username, password string) string {