mirror of https://github.com/gogits/gogs.git
Unknown
11 years ago
11 changed files with 439 additions and 378 deletions
@ -1,105 +1,40 @@
|
||||
// Copyright 2013 gopm authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||
// not use this file except in compliance with the License. You may obtain
|
||||
// a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
// License for the specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package doc |
||||
|
||||
import ( |
||||
"bufio" |
||||
"os" |
||||
"strings" |
||||
) |
||||
|
||||
const ( |
||||
Greater = ">" |
||||
GreaterOrEq = ">=" |
||||
Equeal = "=" |
||||
Lesser = "<" |
||||
LesserOrEq = "<=" |
||||
) |
||||
"github.com/Unknwon/goconfig" |
||||
|
||||
var ( |
||||
Ops = []string{GreaterOrEq, LesserOrEq, Greater, Equeal, Lesser} |
||||
"github.com/gpmgo/gopm/log" |
||||
) |
||||
|
||||
const ( |
||||
GopmFileName = ".gopmfile" |
||||
) |
||||
|
||||
type Depend struct { |
||||
Pkg *Pkg |
||||
Op string |
||||
Ver string |
||||
} |
||||
|
||||
type Section struct { |
||||
Name string |
||||
Deps map[string]*Depend |
||||
Props map[string]string |
||||
} |
||||
|
||||
func NewSection() *Section { |
||||
return &Section{Deps: make(map[string]*Depend), |
||||
Props: make(map[string]string), |
||||
} |
||||
} |
||||
|
||||
type Gopmfile struct { |
||||
Sections map[string]*Section |
||||
} |
||||
|
||||
func NewGopmfile() *Gopmfile { |
||||
return &Gopmfile{Sections: make(map[string]*Section)} |
||||
} |
||||
|
||||
func (this *Gopmfile) Load(path string) error { |
||||
f, err := os.Open(path) |
||||
func NewGopmfile(dirPath string) *goconfig.ConfigFile { |
||||
gf, err := goconfig.LoadConfigFile(dirPath + "/" + GopmFileName) |
||||
if err != nil { |
||||
return err |
||||
log.Error("", "Fail to load gopmfile") |
||||
log.Fatal("", err.Error()) |
||||
} |
||||
|
||||
scanner := bufio.NewScanner(f) |
||||
var sec *Section |
||||
for scanner.Scan() { |
||||
text := strings.TrimSpace(scanner.Text()) |
||||
if strings.HasPrefix(text, "[") && strings.HasSuffix(text, "]") { |
||||
sec = NewSection() |
||||
sec.Name = text[1 : len(text)-1] |
||||
this.Sections[sec.Name] = sec |
||||
} else { |
||||
if sec == nil { |
||||
continue |
||||
} |
||||
if sec.Name == "target" { |
||||
ss := strings.Split(text, "=") |
||||
if len(ss) == 1 { |
||||
sec.Props[strings.TrimSpace(ss[0])] = strings.TrimSpace(ss[0]) |
||||
} else if len(ss) == 2 { |
||||
sec.Props[strings.TrimSpace(ss[0])] = strings.TrimSpace(ss[1]) |
||||
} |
||||
} else { |
||||
var dep *Depend |
||||
for _, op := range Ops { |
||||
if strings.Contains(text, op) { |
||||
ss := strings.Split(text, op) |
||||
pkver := strings.Split(ss[1], ":") |
||||
var tp, value string |
||||
tp = pkver[0] |
||||
if len(pkver) == 2 { |
||||
value = pkver[1] |
||||
} |
||||
dep = &Depend{NewPkg(ss[0], tp, value), ss[1], value} |
||||
break |
||||
} |
||||
} |
||||
|
||||
if dep == nil { |
||||
dep = &Depend{NewDefaultPkg(text), Equeal, ""} |
||||
} |
||||
sec.Deps[dep.Pkg.ImportPath] = dep |
||||
} |
||||
} |
||||
} |
||||
|
||||
return nil |
||||
return gf |
||||
} |
||||
|
||||
func (this *Gopmfile) Save(path string) error { |
||||
return nil |
||||
var PackageNameList map[string]string |
||||
|
||||
func init() { |
||||
PackageNameList = make(map[string]string) |
||||
} |
||||
|
@ -0,0 +1,56 @@
|
||||
// Copyright 2013 gopm authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||
// not use this file except in compliance with the License. You may obtain
|
||||
// a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
// License for the specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package log |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
) |
||||
|
||||
func Error(hl, msg string) { |
||||
if len(hl) > 0 { |
||||
hl = " " + hl |
||||
} |
||||
fmt.Printf("gopm ERR!%s %s\n", hl, msg) |
||||
} |
||||
|
||||
func Fatal(hl, msg string) { |
||||
Error(hl, msg) |
||||
os.Exit(2) |
||||
} |
||||
|
||||
func Log(format string, args ...interface{}) { |
||||
fmt.Printf("gopm INFO %s\n", |
||||
fmt.Sprintf(format, args...)) |
||||
} |
||||
|
||||
func Trace(format string, args ...interface{}) { |
||||
fmt.Printf("gopm TRAC %s\n", |
||||
fmt.Sprintf(format, args...)) |
||||
} |
||||
|
||||
func Success(title, hl, msg string) { |
||||
if len(hl) > 0 { |
||||
hl = " " + hl |
||||
} |
||||
fmt.Printf("gopm %s%s %s\n", title, hl, msg) |
||||
} |
||||
|
||||
func Message(hl, msg string) { |
||||
if len(hl) > 0 { |
||||
hl = " " + hl |
||||
} |
||||
fmt.Printf("gopm MSG!%s %s\n", hl, msg) |
||||
} |
Loading…
Reference in new issue