Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/2713tags/v1.22.8.1
@@ -22,6 +22,7 @@ require ( | |||
github.com/PuerkitoBio/goquery v1.5.0 | |||
github.com/RichardKnop/machinery v1.6.9 | |||
github.com/RoaringBitmap/roaring v0.4.23 // indirect | |||
github.com/alecthomas/chroma v0.10.0 | |||
github.com/alibabacloud-go/darabonba-openapi v0.1.18 | |||
github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.9 | |||
github.com/alibabacloud-go/tea v1.1.17 | |||
@@ -120,8 +121,9 @@ require ( | |||
github.com/urfave/cli v1.22.1 | |||
github.com/xanzy/go-gitlab v0.31.0 | |||
github.com/yohcop/openid-go v1.0.0 | |||
github.com/yuin/goldmark v1.1.30 | |||
github.com/yuin/goldmark-meta v0.0.0-20191126180153-f0638e958b60 | |||
github.com/yuin/goldmark v1.4.13 | |||
github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594 | |||
github.com/yuin/goldmark-meta v1.1.0 | |||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 | |||
golang.org/x/mod v0.3.0 // indirect | |||
golang.org/x/net v0.0.0-20200513185701-a91f0712d120 | |||
@@ -138,7 +140,7 @@ require ( | |||
gopkg.in/ldap.v3 v3.0.2 | |||
gopkg.in/macaron.v1 v1.3.9 // indirect | |||
gopkg.in/testfixtures.v2 v2.5.0 | |||
gopkg.in/yaml.v2 v2.2.8 | |||
gopkg.in/yaml.v2 v2.3.0 | |||
mvdan.cc/xurls/v2 v2.1.0 | |||
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251 | |||
xorm.io/builder v0.3.7 | |||
@@ -76,6 +76,8 @@ github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMx | |||
github.com/Unknwon/com v0.0.0-20190321035513-0fed4efef755/go.mod h1:voKvFVpXBJxdIPeqjoJuLK+UVcRlo/JLjeToGxPYu68= | |||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs= | |||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= | |||
github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek= | |||
github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s= | |||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= | |||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= | |||
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.2/go.mod h1:sCavSAvdzOjul4cEqeVtvlSaSScfNsTQ+46HwlTL1hc= | |||
@@ -203,6 +205,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm | |||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= | |||
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= | |||
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= | |||
github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E= | |||
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= | |||
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= | |||
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= | |||
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= | |||
@@ -804,8 +808,16 @@ github.com/yuin/goldmark v1.1.27 h1:nqDD4MMMQA0lmWq03Z2/myGPYLQoXtmi0rGVs95ntbo= | |||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= | |||
github.com/yuin/goldmark v1.1.30 h1:j4d4Lw3zqZelDhBksEo3BnWg9xhXRQGJPPSL6OApZjI= | |||
github.com/yuin/goldmark v1.1.30/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= | |||
github.com/yuin/goldmark v1.4.5/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg= | |||
github.com/yuin/goldmark v1.4.6/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg= | |||
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE= | |||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= | |||
github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594 h1:yHfZyN55+5dp1wG7wDKv8HQ044moxkyGq12KFFMFDxg= | |||
github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594/go.mod h1:U9ihbh+1ZN7fR5Se3daSPoz1CGF9IYtSvWwVQtnzGHU= | |||
github.com/yuin/goldmark-meta v0.0.0-20191126180153-f0638e958b60 h1:gZucqLjL1eDzVWrXj4uiWeMbAopJlBR2mKQAsTGdPwo= | |||
github.com/yuin/goldmark-meta v0.0.0-20191126180153-f0638e958b60/go.mod h1:i9VhcIHN2PxXMbQrKqXNueok6QNONoPjNMoj9MygVL0= | |||
github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc= | |||
github.com/yuin/goldmark-meta v1.1.0/go.mod h1:U4spWENafuA7Zyg+Lj5RqK/MF+ovMYtBvXi1lBb2VP0= | |||
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs= | |||
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0= | |||
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= | |||
@@ -1086,6 +1098,8 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | |||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | |||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= | |||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | |||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= | |||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | |||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | |||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | |||
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= | |||
@@ -8,14 +8,13 @@ import ( | |||
"strings" | |||
"time" | |||
"code.gitea.io/gitea/modules/util" | |||
"xorm.io/builder" | |||
"xorm.io/xorm" | |||
"code.gitea.io/gitea/modules/log" | |||
"code.gitea.io/gitea/modules/setting" | |||
"code.gitea.io/gitea/modules/timeutil" | |||
"code.gitea.io/gitea/modules/util" | |||
) | |||
type CloudbrainStatus string | |||
@@ -31,9 +30,9 @@ const ( | |||
) | |||
const ( | |||
NPUResource = "NPU" | |||
GPUResource = "CPU/GPU" | |||
AllResource = "all" | |||
NPUResource = "NPU" | |||
GPUResource = "CPU/GPU" | |||
AllResource = "all" | |||
//notebook storage category | |||
EVSCategory = "EVS" | |||
@@ -372,6 +371,9 @@ type CloudbrainsOptions struct { | |||
ComputeResource string | |||
BeginTimeUnix int64 | |||
EndTimeUnix int64 | |||
AiCenter string | |||
NeedDeleteInfo string | |||
Cluster string | |||
} | |||
type TaskPod struct { | |||
@@ -1259,6 +1261,52 @@ type LogFile struct { | |||
Name string | |||
} | |||
type JobList struct { | |||
JobName string `json:"job_name"` | |||
JobID int64 `json:"job_id"` | |||
VersionID int64 `json:"version_id"` | |||
VersionCount int64 `json:"version_count"` | |||
Description string `json:"job_desc"` | |||
IntStatus int `json:"status"` | |||
} | |||
type GetTrainJobListResult struct { | |||
ErrorResult | |||
JobTotalCount int `json:"job_total_count"` //查询到的用户创建作业总数 | |||
JobCountLimit int `json:"job_count_limit"` //用户还可以创建训练作业的数量 | |||
Quotas int `json:"quotas"` //训练作业的运行数量上限 | |||
JobList []JobList `json:"jobs"` | |||
} | |||
type JobVersionList struct { | |||
VersionName string `json:"version_name"` | |||
VersionID int64 `json:"version_id"` | |||
IntStatus int `json:"status"` | |||
} | |||
type GetTrainJobVersionListResult struct { | |||
ErrorResult | |||
JobID int64 `json:"job_id"` | |||
JobName string `json:"job_name"` | |||
JobDesc string `json:"job_desc"` | |||
VersionCount int64 `json:"version_count"` | |||
JobVersionList []JobVersionList `json:"versions"` | |||
} | |||
type NotebookList struct { | |||
JobName string `json:"name"` | |||
JobID string `json:"id"` | |||
Status string `json:"status"` | |||
} | |||
type GetNotebookListResult struct { | |||
TotalCount int64 `json:"total"` //总的记录数量 | |||
CurrentPage int `json:"current"` //当前页数 | |||
TotalPages int `json:"pages"` //总的页数 | |||
Size int `json:"size"` //每一页的数量 | |||
NotebookList []NotebookList `json:"data"` | |||
} | |||
//Grampus | |||
type GrampusResult struct { | |||
ErrorCode int `json:"errorCode"` | |||
@@ -1403,6 +1451,23 @@ func Cloudbrains(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, error) { | |||
) | |||
} | |||
} | |||
if (opts.AiCenter) != "" { | |||
cond = cond.And( | |||
builder.Like{"cloudbrain.ai_center", opts.AiCenter}, | |||
) | |||
} | |||
if (opts.Cluster) != "" { | |||
if opts.Cluster == "resource_cluster_openi" { | |||
cond = cond.And( | |||
builder.Or(builder.Eq{"cloudbrain.type": TypeCloudBrainOne}, builder.Eq{"cloudbrain.type": TypeCloudBrainTwo}), | |||
) | |||
} | |||
if opts.Cluster == "resource_cluster_c2net" { | |||
cond = cond.And( | |||
builder.Eq{"cloudbrain.type": TypeC2Net}, | |||
) | |||
} | |||
} | |||
if (opts.IsLatestVersion) != "" { | |||
cond = cond.And(builder.Or(builder.And(builder.Eq{"cloudbrain.is_latest_version": opts.IsLatestVersion}, builder.Eq{"cloudbrain.job_type": "TRAIN"}), builder.Neq{"cloudbrain.job_type": "TRAIN"})) | |||
@@ -1680,21 +1745,6 @@ func GetCloudbrainsNeededStopByUserID(userID int64) ([]*Cloudbrain, error) { | |||
return cloudBrains, err | |||
} | |||
func GetWaittingTop() ([]*CloudbrainInfo, error) { | |||
sess := x.NewSession() | |||
defer sess.Close() | |||
var cond = builder.NewCond() | |||
cond = cond.And( | |||
builder.Eq{"cloudbrain.status": string(JobWaiting)}, | |||
) | |||
sess.OrderBy("cloudbrain.created_unix ASC limit 1") | |||
cloudbrains := make([]*CloudbrainInfo, 0, 1) | |||
if err := sess.Table(&Cloudbrain{}).Where(cond). | |||
Find(&cloudbrains); err != nil { | |||
log.Info("find error.") | |||
} | |||
return cloudbrains, nil | |||
} | |||
func GetModelartsReDebugTaskByJobId(jobID string) ([]*Cloudbrain, error) { | |||
sess := x.NewSession() | |||
defer sess.Close() | |||
@@ -1959,6 +2009,24 @@ func CloudbrainAll(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, error) { | |||
} | |||
} | |||
if (opts.AiCenter) != "" { | |||
cond = cond.And( | |||
builder.Like{"cloudbrain.ai_center", opts.AiCenter}, | |||
) | |||
} | |||
if (opts.NeedDeleteInfo) != "" { | |||
if opts.NeedDeleteInfo == "yes" { | |||
cond = cond.And( | |||
builder.And(builder.NotNull{"cloudbrain.deleted_at"}), | |||
) | |||
} | |||
if opts.NeedDeleteInfo == "no" { | |||
cond = cond.And( | |||
builder.And(builder.IsNull{"cloudbrain.deleted_at"}), | |||
) | |||
} | |||
} | |||
if (opts.IsLatestVersion) != "" { | |||
cond = cond.And(builder.Or(builder.And(builder.Eq{"cloudbrain.is_latest_version": opts.IsLatestVersion}, | |||
builder.Eq{"cloudbrain.job_type": "TRAIN"}), builder.Neq{"cloudbrain.job_type": "TRAIN"})) | |||
@@ -2266,3 +2334,8 @@ func GetCloudbrainByIDs(ids []int64) ([]*Cloudbrain, error) { | |||
In("id", ids). | |||
Find(&cloudbrains) | |||
} | |||
func GetCloudbrainCountByJobName(jobName, jobType string, typeCloudbrain int) (int, error) { | |||
count, err := x.Where("job_name = ? and job_type= ? and type = ?", jobName, jobType, typeCloudbrain).Count(new(Cloudbrain)) | |||
return int(count), err | |||
} |
@@ -36,133 +36,6 @@ type TaskDetail struct { | |||
FlavorName string `json:"FlavorName"` | |||
} | |||
func GetDebugOnePeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { | |||
countSql := "SELECT count(*) FROM " + | |||
"public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + | |||
" and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + | |||
" and job_type ='" + string(JobTypeDebug) + "'" + | |||
" and type='" + strconv.Itoa(TypeCloudBrainOne) + "'" | |||
return x.SQL(countSql).Count() | |||
} | |||
func GetDebugOnePeriodDuration(beginTime time.Time, endTime time.Time) (int64, error) { | |||
total, err := x.Where("created_unix >= ? And created_unix < ? And job_type = ? And type = ? ", strconv.FormatInt(beginTime.Unix(), 10), strconv.FormatInt(endTime.Unix(), 10), JobTypeDebug, TypeCloudBrainOne).SumInt(&Cloudbrain{}, "duration") | |||
if err != nil { | |||
return 0, err | |||
} | |||
return total, nil | |||
} | |||
func GetTrainOnePeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { | |||
countSql := "SELECT count(*) FROM " + | |||
"public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + | |||
" and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + | |||
" and job_type ='" + string(JobTypeTrain) + "'" + | |||
" and type='" + strconv.Itoa(TypeCloudBrainOne) + "'" | |||
return x.SQL(countSql).Count() | |||
} | |||
func GetTrainOnePeriodDuration(beginTime time.Time, endTime time.Time) (int64, error) { | |||
total, err := x.Where("created_unix >= ? And created_unix < ? And job_type = ? And type = ? ", strconv.FormatInt(beginTime.Unix(), 10), strconv.FormatInt(endTime.Unix(), 10), JobTypeTrain, TypeCloudBrainOne).SumInt(&Cloudbrain{}, "duration") | |||
if err != nil { | |||
return 0, err | |||
} | |||
return total, nil | |||
} | |||
func GetBenchmarkOnePeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { | |||
countSql := "SELECT count(*) FROM " + | |||
"public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + | |||
" and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + | |||
" and job_type ='" + string(JobTypeBenchmark) + "'" + | |||
" and type='" + strconv.Itoa(TypeCloudBrainOne) + "'" | |||
return x.SQL(countSql).Count() | |||
} | |||
func GetBenchmarkOnePeriodDuration(beginTime time.Time, endTime time.Time) (int64, error) { | |||
total, err := x.Where("created_unix >= ? And created_unix < ? And job_type = ? And type = ? ", strconv.FormatInt(beginTime.Unix(), 10), strconv.FormatInt(endTime.Unix(), 10), JobTypeBenchmark, TypeCloudBrainOne).SumInt(&Cloudbrain{}, "duration") | |||
if err != nil { | |||
return 0, err | |||
} | |||
return total, nil | |||
} | |||
func GetDebugTwoPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { | |||
countSql := "SELECT count(*) FROM " + | |||
"public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + | |||
" and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + | |||
" and job_type ='" + string(JobTypeDebug) + "'" + | |||
" and type='" + strconv.Itoa(TypeCloudBrainTwo) + "'" | |||
return x.SQL(countSql).Count() | |||
} | |||
func GetDebugTwoPeriodDuration(beginTime time.Time, endTime time.Time) (int64, error) { | |||
total, err := x.Where("created_unix >= ? And created_unix < ? And job_type = ? And type = ? ", strconv.FormatInt(beginTime.Unix(), 10), strconv.FormatInt(endTime.Unix(), 10), JobTypeDebug, TypeCloudBrainTwo).SumInt(&Cloudbrain{}, "duration") | |||
if err != nil { | |||
return 0, err | |||
} | |||
return total, nil | |||
} | |||
func GetTrainTwoPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { | |||
countSql := "SELECT count(*) FROM " + | |||
"public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + | |||
" and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + | |||
" and job_type ='" + string(JobTypeTrain) + "'" + | |||
" and type='" + strconv.Itoa(TypeCloudBrainTwo) + "'" | |||
return x.SQL(countSql).Count() | |||
} | |||
func GetTrainTwoPeriodDuration(beginTime time.Time, endTime time.Time) (int64, error) { | |||
total, err := x.Where("created_unix >= ? And created_unix < ? And job_type = ? And type = ? ", strconv.FormatInt(beginTime.Unix(), 10), strconv.FormatInt(endTime.Unix(), 10), JobTypeTrain, TypeCloudBrainTwo).SumInt(&Cloudbrain{}, "duration") | |||
if err != nil { | |||
return 0, err | |||
} | |||
return total, nil | |||
} | |||
func GetInferenceTwoPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { | |||
countSql := "SELECT count(*) FROM " + | |||
"public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + | |||
" and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + | |||
" and job_type ='" + string(JobTypeInference) + "'" + | |||
" and type='" + strconv.Itoa(TypeCloudBrainTwo) + "'" | |||
return x.SQL(countSql).Count() | |||
} | |||
func GetInferenceTwoPeriodDuration(beginTime time.Time, endTime time.Time) (int64, error) { | |||
total, err := x.Where("created_unix >= ? And created_unix < ? And job_type = ? And type = ? ", strconv.FormatInt(beginTime.Unix(), 10), strconv.FormatInt(endTime.Unix(), 10), JobTypeInference, TypeCloudBrainTwo).SumInt(&Cloudbrain{}, "duration") | |||
if err != nil { | |||
return 0, err | |||
} | |||
return total, nil | |||
} | |||
func GetCloudBrainOnePeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { | |||
countSql := "SELECT count(*) FROM " + | |||
"public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + | |||
" and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + | |||
" and type='" + strconv.Itoa(TypeCloudBrainOne) + "'" | |||
return x.SQL(countSql).Count() | |||
} | |||
func GetCloudBrainOnePeriodDuration(beginTime time.Time, endTime time.Time) (int64, error) { | |||
total, err := x.Where("created_unix >= ? And created_unix < ? And type = ? ", strconv.FormatInt(beginTime.Unix(), 10), strconv.FormatInt(endTime.Unix(), 10), TypeCloudBrainOne).SumInt(&Cloudbrain{}, "duration") | |||
if err != nil { | |||
return 0, err | |||
} | |||
return total, nil | |||
} | |||
func GetCloudBrainTwoPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { | |||
countSql := "SELECT count(*) FROM " + | |||
"public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + | |||
" and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + | |||
" and type='" + strconv.Itoa(TypeCloudBrainTwo) + "'" | |||
return x.SQL(countSql).Count() | |||
} | |||
func GetCloudBrainTwoPeriodDuration(beginTime time.Time, endTime time.Time) (int64, error) { | |||
total, err := x.Where("created_unix >= ? And created_unix < ? And type = ? ", strconv.FormatInt(beginTime.Unix(), 10), strconv.FormatInt(endTime.Unix(), 10), TypeCloudBrainTwo).SumInt(&Cloudbrain{}, "duration") | |||
if err != nil { | |||
return 0, err | |||
} | |||
return total, nil | |||
} | |||
func GetTodayCreatorCount(beginTime time.Time, endTime time.Time) (int64, error) { | |||
countSql := "SELECT count(distinct user_id) FROM " + | |||
"public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + | |||
@@ -211,6 +84,22 @@ func GetAllStatusCloudBrain() map[string]int { | |||
return cloudBrainStatusResult | |||
} | |||
func GetWaittingTop() ([]*CloudbrainInfo, error) { | |||
sess := x.NewSession() | |||
defer sess.Close() | |||
var cond = builder.NewCond() | |||
cond = cond.And( | |||
builder.Eq{"cloudbrain.status": string(JobWaiting)}, | |||
) | |||
sess.OrderBy("cloudbrain.created_unix ASC limit 10") | |||
cloudbrains := make([]*CloudbrainInfo, 0, 10) | |||
if err := sess.Table(&Cloudbrain{}).Where(cond). | |||
Find(&cloudbrains); err != nil { | |||
log.Info("find error.") | |||
} | |||
return cloudbrains, nil | |||
} | |||
func GetRunningTop() ([]*CloudbrainInfo, error) { | |||
sess := x.NewSession() | |||
defer sess.Close() | |||
@@ -0,0 +1,68 @@ | |||
package models | |||
import ( | |||
"time" | |||
"code.gitea.io/gitea/modules/setting" | |||
"code.gitea.io/gitea/modules/timeutil" | |||
) | |||
const ( | |||
TempJobId = "TEMP" | |||
TempVersionId = TempJobId | |||
TempJobStatus = TempJobId | |||
) | |||
type CloudbrainTemp struct { | |||
ID int64 `xorm:"pk autoincr"` | |||
JobID string `xorm:"NOT NULL DEFAULT 'TEMP'"` | |||
VersionID string `xorm:"NOT NULL DEFAULT 'TEMP'"` | |||
JobName string `xorm:"NOT NULL "` | |||
Type int `xorm:"NOT NULL "` | |||
JobType string `xorm:"INDEX NOT NULL DEFAULT 'DEBUG'"` | |||
Status string `xorm:"INDEX NOT NULL DEFAULT 'TEMP'"` | |||
QueryTimes int `xorm:"INDEX NOT NULL DEFAULT 0"` | |||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` | |||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` | |||
DeletedAt time.Time `xorm:"deleted"` | |||
} | |||
func InsertCloudbrainTemp(temp *CloudbrainTemp) (err error) { | |||
if _, err = x.Insert(temp); err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
func getCloudBrainTemp(temp *CloudbrainTemp) (*CloudbrainTemp, error) { | |||
has, err := x.Get(temp) | |||
if err != nil { | |||
return nil, err | |||
} else if !has { | |||
return nil, ErrJobNotExist{} | |||
} | |||
return temp, nil | |||
} | |||
func GetCloudBrainTempJobs() ([]*CloudbrainTemp, error) { | |||
jobs := make([]*CloudbrainTemp, 0, 10) | |||
return jobs, x.In("status", TempJobStatus, string(ModelArtsStopping), string(ModelArtsTrainJobKilling)). | |||
And("query_times < ?", setting.MaxTempQueryTimes). | |||
Limit(100). | |||
Find(&jobs) | |||
} | |||
func DeleteCloudbrainTemp(temp *CloudbrainTemp) error { | |||
return deleteCloudbrainTemp(x, temp) | |||
} | |||
func deleteCloudbrainTemp(e Engine, temp *CloudbrainTemp) error { | |||
_, err := e.ID(temp.ID).Delete(temp) | |||
return err | |||
} | |||
func UpdateCloudbrainTemp(temp *CloudbrainTemp) error { | |||
_, err := x.ID(temp.ID).AllCols().Update(temp) | |||
return err | |||
} |
@@ -145,6 +145,7 @@ func init() { | |||
new(OrgStatistic), | |||
new(SearchRecord), | |||
new(AiModelConvert), | |||
new(CloudbrainTemp), | |||
) | |||
tablesStatistic = append(tablesStatistic, | |||
@@ -2250,6 +2250,18 @@ func CheckRepoStats(ctx context.Context) error { | |||
"UPDATE `repository` SET num_stars=(SELECT COUNT(*) FROM `star` WHERE repo_id=?) WHERE id=?", | |||
"repository count 'num_stars'", | |||
}, | |||
//Repository.NumIssues | |||
{ | |||
"SELECT repo.id FROM `repository` repo WHERE repo.num_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_pull=false)", | |||
"UPDATE `repository` SET num_issues=(SELECT COUNT(*) FROM `issue` WHERE repo_id=? AND is_pull=false) WHERE id=?", | |||
"repository count 'num_issues'", | |||
}, | |||
//Repository.NumPulls | |||
{ | |||
"SELECT repo.id FROM `repository` repo WHERE repo.num_pulls!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_pull=true)", | |||
"UPDATE `repository` SET num_pulls=(SELECT COUNT(*) FROM `issue` WHERE repo_id=? AND is_pull=true) WHERE id=?", | |||
"repository count 'num_pulls'", | |||
}, | |||
// Label.NumIssues | |||
{ | |||
"SELECT label.id FROM `label` WHERE label.num_issues!=(SELECT COUNT(*) FROM `issue_label` WHERE label_id=label.id)", | |||
@@ -1768,7 +1768,6 @@ func (opts *SearchUserOptions) toConds() builder.Cond { | |||
if !opts.IsActive.IsNone() { | |||
cond = cond.And(builder.Eq{"is_active": opts.IsActive.IsTrue()}) | |||
} | |||
return cond | |||
} | |||
@@ -1780,12 +1779,15 @@ func SearchUsers(opts *SearchUserOptions) (users []*User, _ int64, _ error) { | |||
if err != nil { | |||
return nil, 0, fmt.Errorf("Count: %v", err) | |||
} | |||
orderby := opts.OrderBy.String() | |||
if len(opts.OrderBy) == 0 { | |||
opts.OrderBy = SearchOrderByAlphabetically | |||
orderby = SearchOrderByAlphabetically.String() | |||
lowerKeyword := strings.ToLower(opts.Keyword) | |||
if len(opts.Keyword) > 0 { | |||
orderby = "CASE when lower_name='" + lowerKeyword + "' then 0 when strpos(lower_name,'" + lowerKeyword + "')>0 then 1 else 2 END ASC,lower_name ASC" | |||
} | |||
} | |||
sess := x.Where(cond).OrderBy(opts.OrderBy.String()) | |||
sess := x.Where(cond).OrderBy(orderby) | |||
if opts.Page != 0 { | |||
sess = opts.setSessionPagination(sess) | |||
} | |||
@@ -412,7 +412,16 @@ func QueryUserStaticDataAll(opts *UserBusinessAnalysisQueryOptions) ([]*UserBusi | |||
func QueryDataForUserDefineFromDb(opts *UserBusinessAnalysisQueryOptions, key string) ([]*UserBusinessAnalysis, int64) { | |||
statictisSess := xStatistic.NewSession() | |||
defer statictisSess.Close() | |||
cond := "data_date='" + key + "'" | |||
var cond = builder.NewCond() | |||
cond = cond.And( | |||
builder.Eq{"data_date": key}, | |||
) | |||
if len(opts.UserName) > 0 { | |||
cond = cond.And( | |||
builder.Like{"name", opts.UserName}, | |||
) | |||
} | |||
allCount, err := statictisSess.Where(cond).Count(new(UserBusinessAnalysis)) | |||
if err == nil { | |||
if allCount > 0 { | |||
@@ -61,11 +61,12 @@ type TemplateValue struct { | |||
Color string `json:"color"` | |||
} | |||
type CloudbrainTaskData struct { | |||
type DefaultWechatTemplate struct { | |||
First TemplateValue `json:"first"` | |||
Keyword1 TemplateValue `json:"keyword1"` | |||
Keyword2 TemplateValue `json:"keyword2"` | |||
Keyword3 TemplateValue `json:"keyword3"` | |||
Keyword4 TemplateValue `json:"keyword4"` | |||
Remark TemplateValue `json:"remark"` | |||
} | |||
@@ -0,0 +1,164 @@ | |||
package wechat | |||
import ( | |||
"code.gitea.io/gitea/models" | |||
"code.gitea.io/gitea/modules/log" | |||
"code.gitea.io/gitea/modules/setting" | |||
"fmt" | |||
"time" | |||
) | |||
type JobOperateType string | |||
const ( | |||
JobOperateTypeStart JobOperateType = "start" | |||
JobOperateTypeStop JobOperateType = "stop" | |||
) | |||
type CloudbrainStartMsg struct { | |||
} | |||
func (CloudbrainStartMsg) Data(ctx *TemplateContext) *DefaultWechatTemplate { | |||
return &DefaultWechatTemplate{ | |||
First: TemplateValue{Value: setting.CloudbrainStartedTitle}, | |||
Keyword1: TemplateValue{Value: ctx.Cloudbrain.DisplayJobName}, | |||
Keyword2: TemplateValue{Value: getJobTypeDisplayName(ctx.Cloudbrain.JobType)}, | |||
Keyword3: TemplateValue{Value: time.Unix(int64(ctx.Cloudbrain.CreatedUnix), 0).Format("2006-01-02 15:04:05")}, | |||
Remark: TemplateValue{Value: setting.CloudbrainStartedRemark}, | |||
} | |||
} | |||
func (CloudbrainStartMsg) ShouldSend(ctx *TemplateContext) bool { | |||
if len(setting.CloudbrainStartedNotifyList) == 0 { | |||
return false | |||
} | |||
for _, v := range setting.CloudbrainStartedNotifyList { | |||
if v == ctx.Cloudbrain.JobType { | |||
return true | |||
} | |||
} | |||
return false | |||
} | |||
func (CloudbrainStartMsg) MsgId(ctx *TemplateContext) string { | |||
return string(JobOperateTypeStart) + "_" + fmt.Sprint(ctx.Cloudbrain.ID) | |||
} | |||
func (CloudbrainStartMsg) Url(ctx *TemplateContext) string { | |||
repo, err := models.GetRepositoryByID(ctx.Cloudbrain.RepoID) | |||
if err != nil { | |||
log.Error("CloudbrainStartMsg GetRepositoryByID error,%v", err) | |||
return "" | |||
} | |||
return getCloudbrainTemplateUrl(*ctx.Cloudbrain, repo) | |||
} | |||
func (CloudbrainStartMsg) TemplateId(ctx *TemplateContext) string { | |||
return setting.CloudbrainStartedTemplateId | |||
} | |||
type CloudbrainStopMsg struct { | |||
} | |||
func (CloudbrainStopMsg) Data(ctx *TemplateContext) *DefaultWechatTemplate { | |||
return &DefaultWechatTemplate{ | |||
First: TemplateValue{Value: setting.CloudbrainStoppedTitle}, | |||
Keyword1: TemplateValue{Value: ctx.Cloudbrain.DisplayJobName}, | |||
Keyword2: TemplateValue{Value: getJobTypeDisplayName(ctx.Cloudbrain.JobType)}, | |||
Keyword3: TemplateValue{Value: time.Unix(int64(ctx.Cloudbrain.CreatedUnix), 0).Format("2006-01-02 15:04:05")}, | |||
Keyword4: TemplateValue{Value: time.Unix(int64(ctx.Cloudbrain.EndTime), 0).Format("2006-01-02 15:04:05")}, | |||
Remark: TemplateValue{Value: setting.CloudbrainStoppedRemark}, | |||
} | |||
} | |||
func (CloudbrainStopMsg) ShouldSend(ctx *TemplateContext) bool { | |||
if len(setting.CloudbrainStoppedNotifyList) == 0 { | |||
return false | |||
} | |||
for _, v := range setting.CloudbrainStoppedNotifyList { | |||
if v == ctx.Cloudbrain.JobType { | |||
return true | |||
} | |||
} | |||
return false | |||
} | |||
func (CloudbrainStopMsg) MsgId(ctx *TemplateContext) string { | |||
return string(JobOperateTypeStop) + "_" + fmt.Sprint(ctx.Cloudbrain.ID) | |||
} | |||
func (CloudbrainStopMsg) Url(ctx *TemplateContext) string { | |||
repo, err := models.GetRepositoryByID(ctx.Cloudbrain.RepoID) | |||
if err != nil { | |||
log.Error("CloudbrainStopMsg GetRepositoryByID error,%v", err) | |||
return "" | |||
} | |||
return getCloudbrainTemplateUrl(*ctx.Cloudbrain, repo) | |||
} | |||
func (CloudbrainStopMsg) TemplateId(ctx *TemplateContext) string { | |||
return setting.CloudbrainStoppedTemplateId | |||
} | |||
var startMsg = &CloudbrainStartMsg{} | |||
var stopMsg = &CloudbrainStopMsg{} | |||
func GetTemplateFromOperateType(operate JobOperateType) Template { | |||
switch operate { | |||
case JobOperateTypeStart: | |||
return startMsg | |||
case JobOperateTypeStop: | |||
return stopMsg | |||
} | |||
return nil | |||
} | |||
func GetJobOperateTypeFromCloudbrainStatus(cloudbrain *models.Cloudbrain) JobOperateType { | |||
if cloudbrain.IsTerminal() { | |||
return JobOperateTypeStop | |||
} | |||
if cloudbrain.IsRunning() { | |||
return JobOperateTypeStart | |||
} | |||
return "" | |||
} | |||
func getCloudbrainTemplateUrl(cloudbrain models.Cloudbrain, repo *models.Repository) string { | |||
url := setting.AppURL + repo.FullName() | |||
switch cloudbrain.JobType { | |||
case string(models.JobTypeDebug): | |||
if cloudbrain.ComputeResource == "CPU/GPU" { | |||
url += "/cloudbrain/" + fmt.Sprint(cloudbrain.ID) | |||
} else { | |||
url += "/modelarts/notebook/" + fmt.Sprint(cloudbrain.ID) | |||
} | |||
case string(models.JobTypeBenchmark): | |||
url += "/cloudbrain/benchmark/" + fmt.Sprint(cloudbrain.ID) | |||
case string(models.JobTypeTrain): | |||
if cloudbrain.Type == models.TypeCloudBrainOne { | |||
url += "/cloudbrain/train-job/" + fmt.Sprint(cloudbrain.JobID) | |||
} else if cloudbrain.Type == models.TypeCloudBrainTwo { | |||
url += "/modelarts/train-job/" + fmt.Sprint(cloudbrain.JobID) | |||
} else if cloudbrain.Type == models.TypeC2Net { | |||
url += "/grampus/train-job/" + fmt.Sprint(cloudbrain.JobID) | |||
} | |||
case string(models.JobTypeInference): | |||
url += "/modelarts/inference-job/" + fmt.Sprint(cloudbrain.JobID) | |||
} | |||
return url | |||
} | |||
func getJobTypeDisplayName(jobType string) string { | |||
switch jobType { | |||
case string(models.JobTypeDebug): | |||
return "调试任务" | |||
case string(models.JobTypeBenchmark): | |||
return "评测任务" | |||
case string(models.JobTypeTrain): | |||
return "训练任务" | |||
case string(models.JobTypeInference): | |||
return "推理任务" | |||
} | |||
return "" | |||
} |
@@ -3,143 +3,61 @@ package wechat | |||
import ( | |||
"code.gitea.io/gitea/models" | |||
"code.gitea.io/gitea/modules/log" | |||
"code.gitea.io/gitea/modules/setting" | |||
"errors" | |||
"fmt" | |||
"time" | |||
) | |||
type JobOperateType string | |||
const ( | |||
JobOperateTypeStart JobOperateType = "start" | |||
JobOperateTypeStop JobOperateType = "stop" | |||
) | |||
type Template interface { | |||
ShouldSend(ctx *TemplateContext) bool | |||
Data(ctx *TemplateContext) *DefaultWechatTemplate | |||
MsgId(ctx *TemplateContext) string | |||
Url(ctx *TemplateContext) string | |||
TemplateId(ctx *TemplateContext) string | |||
} | |||
func GetJobOperateTypeFromCloudbrainStatus(cloudbrain *models.Cloudbrain) JobOperateType { | |||
if cloudbrain.IsTerminal() { | |||
return JobOperateTypeStop | |||
} | |||
if cloudbrain.IsRunning() { | |||
return JobOperateTypeStart | |||
} | |||
return "" | |||
type TemplateContext struct { | |||
Cloudbrain *models.Cloudbrain | |||
} | |||
func SendCloudbrainStartedMsg(operateType JobOperateType, cloudbrain models.Cloudbrain) error { | |||
func SendTemplateMsg(template Template, ctx *TemplateContext, userId int64) error { | |||
defer func() { | |||
if err := recover(); err != nil { | |||
combinedErr := fmt.Errorf("%s\n%s", err, log.Stack(2)) | |||
log.Error("PANIC:", combinedErr) | |||
} | |||
}() | |||
repo, err := models.GetRepositoryByID(cloudbrain.RepoID) | |||
if err != nil { | |||
log.Error("SendCloudbrainStartedMsg GetRepositoryByID error,%v", err) | |||
} | |||
if setting.CloudbrainStartedTemplateId == "" { | |||
if !template.ShouldSend(ctx) { | |||
log.Info("SendTemplateMsg should not Send.jobId=%d jobType=%s", ctx.Cloudbrain.ID, ctx.Cloudbrain.JobType) | |||
return nil | |||
} | |||
openId := models.GetUserWechatOpenId(cloudbrain.UserID) | |||
openId := models.GetUserWechatOpenId(userId) | |||
if openId == "" { | |||
log.Error("Wechat openId not exist,userId=%d", userId) | |||
return errors.New("Wechat openId not exist") | |||
} | |||
data := CloudbrainTaskData{ | |||
First: TemplateValue{Value: getCloudbrainTemplateTitle(operateType)}, | |||
Keyword1: TemplateValue{Value: cloudbrain.DisplayJobName}, | |||
Keyword2: TemplateValue{Value: getJobTypeDisplayName(cloudbrain.JobType)}, | |||
Keyword3: TemplateValue{Value: time.Unix(int64(cloudbrain.CreatedUnix), 0).Format("2006-01-02 15:04:05")}, | |||
Remark: TemplateValue{Value: getCloudbrainTemplateRemark(operateType)}, | |||
} | |||
req := TemplateMsgRequest{ | |||
ToUser: openId, | |||
TemplateId: setting.CloudbrainStartedTemplateId, | |||
Url: getCloudbrainTemplateUrl(cloudbrain, repo), | |||
ClientMsgId: string(operateType) + "_" + fmt.Sprint(cloudbrain.ID), | |||
Data: data, | |||
TemplateId: template.TemplateId(ctx), | |||
Url: template.Url(ctx), | |||
ClientMsgId: template.MsgId(ctx), | |||
Data: template.Data(ctx), | |||
} | |||
err, retryFlag := sendTemplateMsg(req) | |||
if retryFlag { | |||
log.Info("retrySendCloudbrainTemplateMsg calling") | |||
log.Info("SendTemplateMsg calling") | |||
refreshAccessToken() | |||
err, _ = sendTemplateMsg(req) | |||
if err != nil { | |||
log.Error("SendCloudbrainStartedMsg err. %v", err) | |||
log.Error("SendTemplateMsg err. %v", err) | |||
return err | |||
} | |||
return nil | |||
} | |||
if err != nil { | |||
log.Error("SendCloudbrainStartedMsg err. %v", err) | |||
log.Error("SendTemplateMsg err. %v", err) | |||
return err | |||
} | |||
log.Info("SendTemplateMsg success") | |||
return nil | |||
} | |||
func getCloudbrainTemplateUrl(cloudbrain models.Cloudbrain, repo *models.Repository) string { | |||
url := setting.AppURL + repo.FullName() | |||
switch cloudbrain.JobType { | |||
case string(models.JobTypeDebug): | |||
if cloudbrain.ComputeResource == "CPU/GPU" { | |||
url += "/cloudbrain/" + fmt.Sprint(cloudbrain.ID) | |||
} else { | |||
url += "/modelarts/notebook/" + fmt.Sprint(cloudbrain.ID) | |||
} | |||
case string(models.JobTypeBenchmark): | |||
url += "/cloudbrain/benchmark/" + fmt.Sprint(cloudbrain.ID) | |||
case string(models.JobTypeTrain): | |||
if cloudbrain.Type == models.TypeCloudBrainOne { | |||
url += "/cloudbrain/train-job/" + fmt.Sprint(cloudbrain.JobID) | |||
} else if cloudbrain.Type == models.TypeCloudBrainTwo { | |||
url += "/modelarts/train-job/" + fmt.Sprint(cloudbrain.JobID) | |||
} else if cloudbrain.Type == models.TypeC2Net { | |||
url += "/grampus/train-job/" + fmt.Sprint(cloudbrain.JobID) | |||
} | |||
case string(models.JobTypeInference): | |||
url += "/modelarts/inference-job/" + fmt.Sprint(cloudbrain.JobID) | |||
} | |||
return url | |||
} | |||
func getCloudbrainTemplateTitle(operateType JobOperateType) string { | |||
var title string | |||
switch operateType { | |||
case JobOperateTypeStart: | |||
title = "您好,您提交的算力资源申请已通过,任务已启动,请您关注运行情况。" | |||
case JobOperateTypeStop: | |||
title = "您好,您提交的任务已运行结束。" | |||
} | |||
return title | |||
} | |||
func getCloudbrainTemplateRemark(operateType JobOperateType) string { | |||
var remark string | |||
switch operateType { | |||
case JobOperateTypeStart: | |||
remark = "感谢您的耐心等待。" | |||
case JobOperateTypeStop: | |||
remark = "点击可查看运行结果" | |||
} | |||
return remark | |||
} | |||
func getJobTypeDisplayName(jobType string) string { | |||
switch jobType { | |||
case string(models.JobTypeDebug): | |||
return "调试任务" | |||
case string(models.JobTypeBenchmark): | |||
return "评测任务" | |||
case string(models.JobTypeTrain): | |||
return "训练任务" | |||
case string(models.JobTypeInference): | |||
return "推理任务" | |||
} | |||
return "" | |||
} |
@@ -142,8 +142,8 @@ func isAdminOrImageCreater(ctx *context.Context, image *models.Image, err error) | |||
func AdminOrOwnerOrJobCreaterRight(ctx *context.Context) { | |||
var ID = ctx.Params(":id") | |||
job, err := models.GetCloudbrainByID(ID) | |||
var id = ctx.Params(":id") | |||
job, err := models.GetCloudbrainByID(id) | |||
if err != nil { | |||
log.Error("GetCloudbrainByID failed:%v", err.Error()) | |||
ctx.NotFound(ctx.Req.URL.RequestURI(), nil) | |||
@@ -158,8 +158,8 @@ func AdminOrOwnerOrJobCreaterRight(ctx *context.Context) { | |||
func AdminOrJobCreaterRight(ctx *context.Context) { | |||
var ID = ctx.Params(":id") | |||
job, err := models.GetCloudbrainByID(ID) | |||
var id = ctx.Params(":id") | |||
job, err := models.GetCloudbrainByID(id) | |||
if err != nil { | |||
log.Error("GetCloudbrainByID failed:%v", err.Error()) | |||
ctx.NotFound(ctx.Req.URL.RequestURI(), nil) | |||
@@ -5,6 +5,7 @@ | |||
package cron | |||
import ( | |||
"code.gitea.io/gitea/modules/modelarts" | |||
"context" | |||
"time" | |||
@@ -207,6 +208,17 @@ func registerSyncCloudbrainStatus() { | |||
}) | |||
} | |||
func registerSyncModelArtsTempJobs() { | |||
RegisterTaskFatal("sync_model_arts_temp_jobs", &BaseConfig{ | |||
Enabled: true, | |||
RunAtStart: false, | |||
Schedule: "@every 1m", | |||
}, func(ctx context.Context, _ *models.User, _ Config) error { | |||
modelarts.SyncTempStatusJob() | |||
return nil | |||
}) | |||
} | |||
func initBasicTasks() { | |||
registerUpdateMirrorTask() | |||
registerRepoHealthCheck() | |||
@@ -227,4 +239,5 @@ func initBasicTasks() { | |||
registerSyncCloudbrainStatus() | |||
registerHandleOrgStatistic() | |||
registerSyncModelArtsTempJobs() | |||
} |
@@ -7,6 +7,7 @@ package markdown | |||
import ( | |||
"bytes" | |||
"strings" | |||
"sync" | |||
"code.gitea.io/gitea/modules/log" | |||
@@ -14,6 +15,8 @@ import ( | |||
"code.gitea.io/gitea/modules/markup/common" | |||
"code.gitea.io/gitea/modules/setting" | |||
giteautil "code.gitea.io/gitea/modules/util" | |||
chromahtml "github.com/alecthomas/chroma/formatters/html" | |||
highlighting "github.com/yuin/goldmark-highlighting" | |||
"github.com/yuin/goldmark" | |||
meta "github.com/yuin/goldmark-meta" | |||
@@ -42,16 +45,48 @@ func NewGiteaParseContext(urlPrefix string, isWiki bool) parser.Context { | |||
func RenderRaw(body []byte, urlPrefix string, wikiMarkdown bool) []byte { | |||
once.Do(func() { | |||
converter = goldmark.New( | |||
goldmark.WithExtensions(extension.Table, | |||
goldmark.WithExtensions( | |||
extension.NewTable( | |||
extension.WithTableCellAlignMethod(extension.TableCellAlignAttribute)), | |||
extension.Strikethrough, | |||
extension.TaskList, | |||
extension.DefinitionList, | |||
common.FootnoteExtension, | |||
extension.NewTypographer( | |||
extension.WithTypographicSubstitutions(extension.TypographicSubstitutions{ | |||
extension.EnDash: nil, | |||
extension.EmDash: nil, | |||
extension.Ellipsis: nil, | |||
highlighting.NewHighlighting( | |||
highlighting.WithFormatOptions( | |||
chromahtml.WithClasses(true), | |||
chromahtml.PreventSurroundingPre(true), | |||
), | |||
highlighting.WithWrapperRenderer(func(w util.BufWriter, c highlighting.CodeBlockContext, entering bool) { | |||
if entering { | |||
language, _ := c.Language() | |||
if language == nil { | |||
language = []byte("text") | |||
} | |||
languageStr := string(language) | |||
preClasses := []string{"code-block"} | |||
if languageStr == "mermaid" { | |||
preClasses = append(preClasses, "is-loading") | |||
} | |||
_, err := w.WriteString(`<pre class="` + strings.Join(preClasses, " ") + `">`) | |||
if err != nil { | |||
return | |||
} | |||
// include language-x class as part of commonmark spec | |||
_, err = w.WriteString(`<code class="chroma language-` + string(language) + `">`) | |||
if err != nil { | |||
return | |||
} | |||
} else { | |||
_, err := w.WriteString("</code></pre>") | |||
if err != nil { | |||
return | |||
} | |||
} | |||
}), | |||
), | |||
meta.Meta, | |||
@@ -6,8 +6,7 @@ import ( | |||
"fmt" | |||
"path" | |||
"strconv" | |||
"code.gitea.io/gitea/modules/timeutil" | |||
"strings" | |||
"code.gitea.io/gitea/models" | |||
"code.gitea.io/gitea/modules/context" | |||
@@ -15,6 +14,7 @@ import ( | |||
"code.gitea.io/gitea/modules/notification" | |||
"code.gitea.io/gitea/modules/setting" | |||
"code.gitea.io/gitea/modules/storage" | |||
"code.gitea.io/gitea/modules/timeutil" | |||
) | |||
const ( | |||
@@ -59,7 +59,7 @@ const ( | |||
PerPage = 10 | |||
IsLatestVersion = "1" | |||
NotLatestVersion = "0" | |||
VersionCount = 1 | |||
VersionCountOne = 1 | |||
SortByCreateTime = "create_time" | |||
ConfigTypeCustom = "custom" | |||
@@ -284,9 +284,24 @@ func GenerateNotebook2(ctx *context.Context, displayJobName, jobName, uuid, desc | |||
}) | |||
if err != nil { | |||
log.Error("createNotebook2 failed: %v", err.Error()) | |||
if strings.HasPrefix(err.Error(), UnknownErrorPrefix) { | |||
log.Info("(%s)unknown error, set temp status", displayJobName) | |||
errTemp := models.InsertCloudbrainTemp(&models.CloudbrainTemp{ | |||
JobID: models.TempJobId, | |||
VersionID: models.TempVersionId, | |||
Status: models.TempJobStatus, | |||
Type: models.TypeCloudBrainTwo, | |||
JobName: jobName, | |||
JobType: string(models.JobTypeDebug), | |||
}) | |||
if errTemp != nil { | |||
log.Error("InsertCloudbrainTemp failed: %v", errTemp.Error()) | |||
return errTemp | |||
} | |||
} | |||
return err | |||
} | |||
err = models.CreateCloudbrain(&models.Cloudbrain{ | |||
task := &models.Cloudbrain{ | |||
Status: jobResult.Status, | |||
UserID: ctx.User.ID, | |||
RepoID: ctx.Repo.Repository.ID, | |||
@@ -302,16 +317,13 @@ func GenerateNotebook2(ctx *context.Context, displayJobName, jobName, uuid, desc | |||
Description: description, | |||
CreatedUnix: createTime, | |||
UpdatedUnix: createTime, | |||
}) | |||
if err != nil { | |||
return err | |||
} | |||
task, err := models.GetCloudbrainByName(jobName) | |||
err = models.CreateCloudbrain(task) | |||
if err != nil { | |||
log.Error("GetCloudbrainByName failed: %v", err.Error()) | |||
return err | |||
} | |||
stringId := strconv.FormatInt(task.ID, 10) | |||
notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, stringId, displayJobName, models.ActionCreateDebugNPUTask) | |||
return nil | |||
@@ -364,7 +376,22 @@ func GenerateTrainJob(ctx *context.Context, req *GenerateTrainJobReq) (err error | |||
}) | |||
} | |||
if createErr != nil { | |||
log.Error("CreateJob failed: %v", createErr.Error()) | |||
log.Error("createTrainJob failed: %v", createErr.Error()) | |||
if strings.HasPrefix(createErr.Error(), UnknownErrorPrefix) { | |||
log.Info("(%s)unknown error, set temp status", req.DisplayJobName) | |||
errTemp := models.InsertCloudbrainTemp(&models.CloudbrainTemp{ | |||
JobID: models.TempJobId, | |||
VersionID: models.TempVersionId, | |||
Status: models.TempJobStatus, | |||
Type: models.TypeCloudBrainTwo, | |||
JobName: req.JobName, | |||
JobType: string(models.JobTypeTrain), | |||
}) | |||
if errTemp != nil { | |||
log.Error("InsertCloudbrainTemp failed: %v", errTemp.Error()) | |||
return errTemp | |||
} | |||
} | |||
return createErr | |||
} | |||
jobId := strconv.FormatInt(jobResult.JobID, 10) | |||
@@ -438,7 +465,7 @@ func GenerateTrainJobVersion(ctx *context.Context, req *GenerateTrainJobReq, job | |||
createTime := timeutil.TimeStampNow() | |||
var jobResult *models.CreateTrainJobResult | |||
var createErr error | |||
log.Info(" req.EngineID =" + fmt.Sprint(req.EngineID)) | |||
if req.EngineID < 0 { | |||
jobResult, createErr = createTrainJobVersionUserImage(models.CreateTrainJobVersionUserImageParams{ | |||
Description: req.Description, | |||
@@ -480,7 +507,22 @@ func GenerateTrainJobVersion(ctx *context.Context, req *GenerateTrainJobReq, job | |||
}, jobId) | |||
} | |||
if createErr != nil { | |||
log.Error("CreateJob failed: %v", createErr.Error()) | |||
log.Error("createTrainJobVersion failed: %v", createErr.Error()) | |||
if strings.HasPrefix(createErr.Error(), UnknownErrorPrefix) { | |||
log.Info("(%s)unknown error, set temp status", req.DisplayJobName) | |||
errTemp := models.InsertCloudbrainTemp(&models.CloudbrainTemp{ | |||
JobID: jobId, | |||
VersionID: models.TempVersionId, | |||
Status: models.TempJobStatus, | |||
Type: models.TypeCloudBrainTwo, | |||
JobName: req.JobName, | |||
JobType: string(models.JobTypeTrain), | |||
}) | |||
if errTemp != nil { | |||
log.Error("InsertCloudbrainTemp failed: %v", errTemp.Error()) | |||
return errTemp | |||
} | |||
} | |||
return createErr | |||
} | |||
@@ -540,7 +582,7 @@ func GenerateTrainJobVersion(ctx *context.Context, req *GenerateTrainJobReq, job | |||
} | |||
//将训练任务的上一版本的isLatestVersion设置为"0" | |||
createErr = models.SetVersionCountAndLatestVersion(strconv.FormatInt(jobResult.JobID, 10), VersionTaskList[0].VersionName, VersionCount, NotLatestVersion, TotalVersionCount) | |||
createErr = models.SetVersionCountAndLatestVersion(strconv.FormatInt(jobResult.JobID, 10), VersionTaskList[0].VersionName, VersionCountOne, NotLatestVersion, TotalVersionCount) | |||
if createErr != nil { | |||
ctx.ServerError("Update IsLatestVersion failed", createErr) | |||
return createErr | |||
@@ -549,99 +591,6 @@ func GenerateTrainJobVersion(ctx *context.Context, req *GenerateTrainJobReq, job | |||
return createErr | |||
} | |||
func GenerateTrainJobVersionByUserImage(ctx *context.Context, req *GenerateTrainJobReq, jobId string) (err error) { | |||
createTime := timeutil.TimeStampNow() | |||
jobResult, err := createTrainJobUserImage(models.CreateUserImageTrainJobParams{ | |||
JobName: req.JobName, | |||
Description: req.Description, | |||
Config: models.UserImageConfig{ | |||
WorkServerNum: req.WorkServerNumber, | |||
AppUrl: req.CodeObsPath, | |||
BootFileUrl: req.BootFileUrl, | |||
DataUrl: req.DataUrl, | |||
TrainUrl: req.TrainUrl, | |||
LogUrl: req.LogUrl, | |||
PoolID: req.PoolID, | |||
CreateVersion: true, | |||
Flavor: models.Flavor{ | |||
Code: req.FlavorCode, | |||
}, | |||
Parameter: req.Parameters, | |||
UserImageUrl: req.UserImageUrl, | |||
UserCommand: req.UserCommand, | |||
}, | |||
}) | |||
if err != nil { | |||
log.Error("CreateJob failed: %v", err.Error()) | |||
return err | |||
} | |||
var jobTypes []string | |||
jobTypes = append(jobTypes, string(models.JobTypeTrain)) | |||
repo := ctx.Repo.Repository | |||
VersionTaskList, VersionListCount, err := models.CloudbrainsVersionList(&models.CloudbrainsOptions{ | |||
RepoID: repo.ID, | |||
Type: models.TypeCloudBrainTwo, | |||
JobTypes: jobTypes, | |||
JobID: strconv.FormatInt(jobResult.JobID, 10), | |||
}) | |||
if err != nil { | |||
ctx.ServerError("Cloudbrain", err) | |||
return err | |||
} | |||
//将当前版本的isLatestVersion设置为"1"和任务数量更新,任务数量包括当前版本数VersionCount和历史创建的总版本数TotalVersionCount | |||
err = models.CreateCloudbrain(&models.Cloudbrain{ | |||
Status: TransTrainJobStatus(jobResult.Status), | |||
UserID: ctx.User.ID, | |||
RepoID: ctx.Repo.Repository.ID, | |||
JobID: strconv.FormatInt(jobResult.JobID, 10), | |||
JobName: req.JobName, | |||
DisplayJobName: req.DisplayJobName, | |||
JobType: string(models.JobTypeTrain), | |||
Type: models.TypeCloudBrainTwo, | |||
VersionID: jobResult.VersionID, | |||
VersionName: jobResult.VersionName, | |||
Uuid: req.Uuid, | |||
DatasetName: req.DatasetName, | |||
CommitID: req.CommitID, | |||
IsLatestVersion: req.IsLatestVersion, | |||
PreVersionName: req.PreVersionName, | |||
ComputeResource: models.NPUResource, | |||
EngineID: MORDELART_USER_IMAGE_ENGINE_ID, | |||
Image: req.UserImageUrl, | |||
TrainUrl: req.TrainUrl, | |||
BranchName: req.BranchName, | |||
Parameters: req.Params, | |||
BootFile: req.BootFile, | |||
DataUrl: req.DataUrl, | |||
LogUrl: req.LogUrl, | |||
PreVersionId: req.PreVersionId, | |||
FlavorCode: req.FlavorCode, | |||
Description: req.Description, | |||
WorkServerNumber: req.WorkServerNumber, | |||
FlavorName: req.FlavorName, | |||
EngineName: req.EngineName, | |||
TotalVersionCount: VersionTaskList[0].TotalVersionCount + 1, | |||
VersionCount: VersionListCount + 1, | |||
CreatedUnix: createTime, | |||
UpdatedUnix: createTime, | |||
}) | |||
if err != nil { | |||
log.Error("CreateCloudbrain(%s) failed:%v", req.JobName, err.Error()) | |||
return err | |||
} | |||
//将训练任务的上一版本的isLatestVersion设置为"0" | |||
err = models.SetVersionCountAndLatestVersion(strconv.FormatInt(jobResult.JobID, 10), VersionTaskList[0].VersionName, VersionCount, NotLatestVersion, TotalVersionCount) | |||
if err != nil { | |||
ctx.ServerError("Update IsLatestVersion failed", err) | |||
return err | |||
} | |||
return err | |||
} | |||
func TransTrainJobStatus(status int) string { | |||
switch status { | |||
case 0: | |||
@@ -722,7 +671,22 @@ func GenerateInferenceJob(ctx *context.Context, req *GenerateInferenceJobReq) (e | |||
}, | |||
}) | |||
if err != nil { | |||
log.Error("CreateJob failed: %v", err.Error()) | |||
log.Error("createInferenceJob failed: %v", err.Error()) | |||
if strings.HasPrefix(err.Error(), UnknownErrorPrefix) { | |||
log.Info("(%s)unknown error, set temp status", req.DisplayJobName) | |||
err = models.InsertCloudbrainTemp(&models.CloudbrainTemp{ | |||
JobID: models.TempJobId, | |||
VersionID: models.TempVersionId, | |||
Status: models.TempJobStatus, | |||
Type: models.TypeCloudBrainTwo, | |||
JobName: req.JobName, | |||
JobType: string(models.JobTypeInference), | |||
}) | |||
if err != nil { | |||
log.Error("InsertCloudbrainTemp failed: %v", err.Error()) | |||
return err | |||
} | |||
} | |||
return err | |||
} | |||
@@ -807,3 +771,455 @@ func InitSpecialPool() { | |||
json.Unmarshal([]byte(setting.ModelArtsSpecialPools), &SpecialPools) | |||
} | |||
} | |||
func HandleTrainJobInfo(task *models.Cloudbrain) error { | |||
result, err := GetTrainJob(task.JobID, strconv.FormatInt(task.VersionID, 10)) | |||
if err != nil { | |||
log.Error("GetTrainJob(%s) failed:%v", task.DisplayJobName, err) | |||
return err | |||
} | |||
if result != nil { | |||
oldStatus := task.Status | |||
task.Status = TransTrainJobStatus(result.IntStatus) | |||
task.Duration = result.Duration / 1000 | |||
task.TrainJobDuration = result.TrainJobDuration | |||
if task.StartTime == 0 && result.StartTime > 0 { | |||
task.StartTime = timeutil.TimeStamp(result.StartTime / 1000) | |||
} | |||
task.TrainJobDuration = models.ConvertDurationToStr(task.Duration) | |||
if task.EndTime == 0 && models.IsTrainJobTerminal(task.Status) && task.StartTime > 0 { | |||
task.EndTime = task.StartTime.Add(task.Duration) | |||
} | |||
task.CorrectCreateUnix() | |||
if oldStatus != task.Status { | |||
notification.NotifyChangeCloudbrainStatus(task, oldStatus) | |||
} | |||
err = models.UpdateJob(task) | |||
if err != nil { | |||
log.Error("UpdateJob(%s) failed:%v", task.JobName, err) | |||
return err | |||
} | |||
} | |||
return nil | |||
} | |||
func HandleNotebookInfo(task *models.Cloudbrain) error { | |||
result, err := GetNotebook2(task.JobID) | |||
if err != nil { | |||
log.Error("GetNotebook2(%s) failed:%v", task.DisplayJobName, err) | |||
return err | |||
} | |||
if result != nil { | |||
oldStatus := task.Status | |||
task.Status = result.Status | |||
if task.StartTime == 0 && result.Lease.UpdateTime > 0 { | |||
task.StartTime = timeutil.TimeStamp(result.Lease.UpdateTime / 1000) | |||
} | |||
if task.EndTime == 0 && models.IsModelArtsDebugJobTerminal(task.Status) { | |||
task.EndTime = timeutil.TimeStampNow() | |||
} | |||
task.CorrectCreateUnix() | |||
task.ComputeAndSetDuration() | |||
if oldStatus != task.Status { | |||
notification.NotifyChangeCloudbrainStatus(task, oldStatus) | |||
} | |||
if task.FlavorCode == "" { | |||
task.FlavorCode = result.Flavor | |||
} | |||
err = models.UpdateJob(task) | |||
if err != nil { | |||
log.Error("UpdateJob(%s) failed:%v", task.DisplayJobName, err) | |||
return err | |||
} | |||
} | |||
return nil | |||
} | |||
func SyncTempStatusJob() { | |||
jobs, err := models.GetCloudBrainTempJobs() | |||
if err != nil { | |||
log.Error("GetCloudBrainTempJobs failed:%v", err.Error()) | |||
return | |||
} | |||
for _, temp := range jobs { | |||
log.Info("start to handle record: %s", temp.JobName) | |||
if temp.Type == models.TypeCloudBrainTwo { | |||
if temp.JobType == string(models.JobTypeDebug) { | |||
err = handleNotebook(temp) | |||
if err != nil { | |||
log.Error("handleNotebook falied:%v", err) | |||
break | |||
} | |||
} else if temp.JobType == string(models.JobTypeTrain) || temp.JobType == string(models.JobTypeInference) { | |||
_, err = models.GetCloudbrainByJobID(temp.JobID) | |||
if err != nil { | |||
//one version | |||
err = handleTrainJob(temp) | |||
if err != nil { | |||
log.Error("handleTrainJob falied:%v", err) | |||
break | |||
} | |||
} else { | |||
//multi version | |||
err = handleTrainJobMultiVersion(temp) | |||
if err != nil { | |||
log.Error("handleTrainJobMultiVersion falied:%v", err) | |||
break | |||
} | |||
} | |||
} | |||
} | |||
} | |||
return | |||
} | |||
func handleNotebook(temp *models.CloudbrainTemp) error { | |||
if temp.Status == models.TempJobStatus { | |||
err := handleTempNotebook(temp) | |||
if err != nil { | |||
log.Error("handleTempNotebook failed:%v", err) | |||
return err | |||
} | |||
} else if temp.Status == string(models.ModelArtsStopping) { | |||
res, err := GetNotebook2(temp.JobID) | |||
if err != nil { | |||
log.Error("GetNotebook2 failed:%v", err) | |||
return err | |||
} | |||
temp.Status = res.Status | |||
if temp.Status == string(models.ModelArtsStopped) { | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp failed:%v", err) | |||
return err | |||
} | |||
_, err := DelNotebook2(temp.JobID) | |||
if err != nil { | |||
log.Error("DelNotebook2 failed:%v", err) | |||
return err | |||
} | |||
temp.Status = string(models.ModelArtsDeleted) | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp failed:%v", err) | |||
return err | |||
} | |||
} | |||
} | |||
return nil | |||
} | |||
func handleTempNotebook(temp *models.CloudbrainTemp) error { | |||
var err error | |||
var isExist bool | |||
for { | |||
result, err := GetNotebookList(1000, 0, "createTime", "DESC", temp.JobName) | |||
if err != nil { | |||
log.Error("GetNotebookList failed:%v", err) | |||
break | |||
} | |||
temp.QueryTimes++ | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp failed:%v", err) | |||
} | |||
if result != nil { | |||
for _, notebook := range result.NotebookList { | |||
if temp.JobID == models.TempJobId { | |||
//new notebook | |||
if notebook.JobName == temp.JobName { | |||
isExist = true | |||
temp.Status = notebook.Status | |||
temp.JobID = notebook.JobID | |||
break | |||
} | |||
} else { | |||
//restart: always can find one record | |||
if notebook.JobName == temp.JobName { | |||
if notebook.Status != string(models.ModelArtsStopped) { | |||
isExist = true | |||
temp.Status = notebook.Status | |||
temp.JobID = notebook.JobID | |||
break | |||
} | |||
} | |||
} | |||
} | |||
if isExist { | |||
log.Info("find the record(%s), status(%s)", temp.JobName, temp.Status) | |||
if temp.Status == string(models.ModelArtsCreateFailed) { | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp failed:%v", err) | |||
break | |||
} | |||
_, err := DelNotebook2(temp.JobID) | |||
if err != nil { | |||
log.Error("DelNotebook2(%s) failed:%v", temp.JobName, err) | |||
break | |||
} | |||
temp.Status = string(models.ModelArtsDeleted) | |||
} else { | |||
_, err := ManageNotebook2(temp.JobID, models.NotebookAction{Action: models.ActionStop}) | |||
if err != nil { | |||
log.Error("ManageNotebook2(%s) failed:%v", temp.JobName, err) | |||
break | |||
} | |||
temp.Status = string(models.ModelArtsStopping) | |||
} | |||
models.UpdateCloudbrainTemp(temp) | |||
} else { | |||
log.Error("can not find the record(%s) till now", temp.JobName) | |||
err = errors.New("not found") | |||
break | |||
} | |||
} else { | |||
log.Error("can not find the record(%s) till now", temp.JobName) | |||
err = errors.New("not found") | |||
break | |||
} | |||
break | |||
} | |||
if temp.QueryTimes >= setting.MaxTempQueryTimes && !isExist { | |||
log.Info("reach MaxTempQueryTimes, set the job failed") | |||
temp.Status = string(models.ModelArtsTrainJobFailed) | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp(%s) failed:%v", temp.JobName, err) | |||
return err | |||
} | |||
} | |||
return err | |||
} | |||
func handleTrainJob(temp *models.CloudbrainTemp) error { | |||
if temp.Status == models.TempJobStatus { | |||
err := handleTempTrainJob(temp) | |||
if err != nil { | |||
log.Error("handleTempTrainJob failed:%v", err) | |||
return err | |||
} | |||
} else if temp.Status == string(models.ModelArtsTrainJobKilling) { | |||
res, err := GetTrainJob(temp.JobID, temp.VersionID) | |||
if err != nil { | |||
log.Error("GetTrainJob failed:%v", err) | |||
return err | |||
} | |||
temp.Status = TransTrainJobStatus(res.IntStatus) | |||
if temp.Status == string(models.ModelArtsTrainJobKilled) { | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp failed:%v", err) | |||
return err | |||
} | |||
_, err := DelTrainJob(temp.JobID) | |||
if err != nil { | |||
log.Error("DelTrainJob failed:%v", err) | |||
return err | |||
} | |||
temp.Status = string(models.ModelArtsDeleted) | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp failed:%v", err) | |||
return err | |||
} | |||
} | |||
} | |||
return nil | |||
} | |||
func handleTrainJobMultiVersion(temp *models.CloudbrainTemp) error { | |||
if temp.Status == models.TempJobStatus { | |||
err := handleTempTrainJobMultiVersion(temp) | |||
if err != nil { | |||
log.Error("handleTempTrainJobMultiVersion failed:%v", err) | |||
return err | |||
} | |||
} else if temp.Status == string(models.ModelArtsTrainJobKilling) { | |||
res, err := GetTrainJob(temp.JobID, temp.VersionID) | |||
if err != nil { | |||
log.Error("GetTrainJob failed:%v", err) | |||
return err | |||
} | |||
temp.Status = TransTrainJobStatus(res.IntStatus) | |||
if temp.Status == string(models.ModelArtsTrainJobKilled) { | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp failed:%v", err) | |||
return err | |||
} | |||
_, err := DelTrainJobVersion(temp.JobID, temp.VersionID) | |||
if err != nil { | |||
log.Error("DelTrainJob failed:%v", err) | |||
return err | |||
} | |||
temp.Status = string(models.ModelArtsDeleted) | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp failed:%v", err) | |||
return err | |||
} | |||
} | |||
} | |||
return nil | |||
} | |||
func handleTempTrainJobMultiVersion(temp *models.CloudbrainTemp) error { | |||
var err error | |||
var isExist bool | |||
for { | |||
result, err := GetTrainJobVersionList(1000, 1, temp.JobID) | |||
if err != nil { | |||
log.Error("GetTrainJobVersionList failed:%v", err) | |||
break | |||
} | |||
temp.QueryTimes++ | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp failed:%v", err) | |||
} | |||
if result != nil { | |||
count, _ := models.GetCloudbrainCountByJobName(temp.JobName, temp.JobType, temp.Type) | |||
if result.VersionCount == int64(count+1) { | |||
isExist = true | |||
temp.Status = TransTrainJobStatus(result.JobVersionList[0].IntStatus) | |||
temp.VersionID = strconv.FormatInt(result.JobVersionList[0].VersionID, 10) | |||
log.Info("find the record(%s), status(%s)", temp.JobName, temp.Status) | |||
_, err := StopTrainJob(temp.JobID, temp.VersionID) | |||
if err != nil { | |||
log.Error("StopTrainJob failed:%v", err) | |||
break | |||
} | |||
temp.Status = string(models.ModelArtsTrainJobKilling) | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp(%s) failed:%v", temp.JobName, err) | |||
break | |||
} | |||
} else { | |||
log.Error("can not find the record(%s) till now", temp.JobName) | |||
err = errors.New("not found") | |||
break | |||
} | |||
} | |||
break | |||
} | |||
if temp.QueryTimes >= setting.MaxTempQueryTimes && !isExist { | |||
log.Info("reach MaxTempQueryTimes, set the job failed") | |||
temp.Status = string(models.ModelArtsTrainJobFailed) | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp(%s) failed:%v", temp.JobName, err) | |||
return err | |||
} | |||
} | |||
return err | |||
} | |||
func handleTempTrainJob(temp *models.CloudbrainTemp) error { | |||
var err error | |||
var isExist bool | |||
for { | |||
result, err := GetTrainJobList(1000, 1, "create_time", "desc", temp.JobName) | |||
if err != nil { | |||
log.Error("GetTrainJobList failed:%v", err) | |||
break | |||
} | |||
temp.QueryTimes++ | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp failed:%v", err) | |||
} | |||
if result != nil { | |||
for _, job := range result.JobList { | |||
if temp.JobName == job.JobName && TransTrainJobStatus(job.IntStatus) != string(models.ModelArtsTrainJobFailed) { | |||
isExist = true | |||
temp.Status = TransTrainJobStatus(job.IntStatus) | |||
temp.JobID = strconv.FormatInt(job.JobID, 10) | |||
temp.VersionID = strconv.FormatInt(job.VersionID, 10) | |||
log.Info("find the record(%s), status(%s)", temp.JobName, temp.Status) | |||
_, err = StopTrainJob(temp.JobID, temp.VersionID) | |||
if err != nil { | |||
log.Error("StopTrainJob(%s) failed:%v", temp.JobName, err) | |||
break | |||
} | |||
temp.Status = string(models.ModelArtsTrainJobKilling) | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp(%s) failed:%v", temp.JobName, err) | |||
break | |||
} | |||
} | |||
} | |||
if !isExist { | |||
log.Error("can not find the record(%s) till now", temp.JobName) | |||
err = errors.New("not found") | |||
break | |||
} | |||
} | |||
break | |||
} | |||
if temp.QueryTimes >= setting.MaxTempQueryTimes && !isExist { | |||
log.Info("reach MaxTempQueryTimes, set the job failed") | |||
temp.Status = string(models.ModelArtsTrainJobFailed) | |||
err = models.UpdateCloudbrainTemp(temp) | |||
if err != nil { | |||
log.Error("UpdateCloudbrainTemp(%s) failed:%v", temp.JobName, err) | |||
return err | |||
} | |||
} | |||
return err | |||
} |
@@ -37,6 +37,7 @@ const ( | |||
NotebookNotFound = "ModelArts.6404" | |||
NotebookNoPermission = "ModelArts.6407" | |||
NotebookInvalid = "ModelArts.6400" | |||
UnknownErrorPrefix = "UNKNOWN:" | |||
) | |||
func getRestyClient() *resty.Client { | |||
@@ -298,6 +299,10 @@ sendjob: | |||
return &result, fmt.Errorf("son.Unmarshal failed: %s", err.Error()) | |||
} | |||
if res.StatusCode() == http.StatusBadGateway { | |||
return &result, fmt.Errorf(UnknownErrorPrefix+"createNotebook2 failed(%s): %s", response.ErrorCode, response.ErrorMsg) | |||
} | |||
if len(response.ErrorCode) != 0 { | |||
log.Error("ManageNotebook2 failed(%s): %s", response.ErrorCode, response.ErrorMsg) | |||
if response.ErrorCode == modelartsIllegalToken && retry < 1 { | |||
@@ -506,23 +511,27 @@ sendjob: | |||
log.Error("json.Unmarshal failed(%s): %v", res.String(), err.Error()) | |||
return &result, fmt.Errorf("json.Unmarshal failed(%s): %v", res.String(), err.Error()) | |||
} | |||
log.Error("createTrainJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
BootFileErrorMsg := "Invalid OBS path '" + createJobParams.Config.BootFileUrl + "'." | |||
DataSetErrorMsg := "Invalid OBS path '" + createJobParams.Config.DataUrl + "'." | |||
if temp.ErrorMsg == BootFileErrorMsg { | |||
log.Error("启动文件错误!createTrainJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
log.Error("createTrainJobUserImage failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
bootFileErrorMsg := "Invalid OBS path '" + createJobParams.Config.BootFileUrl + "'." | |||
dataSetErrorMsg := "Invalid OBS path '" + createJobParams.Config.DataUrl + "'." | |||
if temp.ErrorMsg == bootFileErrorMsg { | |||
log.Error("启动文件错误!createTrainJobUserImage failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
return &result, fmt.Errorf("启动文件错误!") | |||
} | |||
if temp.ErrorMsg == DataSetErrorMsg { | |||
log.Error("数据集错误!createTrainJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
if temp.ErrorMsg == dataSetErrorMsg { | |||
log.Error("数据集错误!createTrainJobUserImage failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
return &result, fmt.Errorf("数据集错误!") | |||
} | |||
return &result, fmt.Errorf("createTrainJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
if res.StatusCode() == http.StatusBadGateway { | |||
return &result, fmt.Errorf(UnknownErrorPrefix+"createTrainJobUserImage failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
} else { | |||
return &result, fmt.Errorf("createTrainJobUserImage failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
} | |||
} | |||
if !result.IsSuccess { | |||
log.Error("createTrainJob failed(%s): %s", result.ErrorCode, result.ErrorMsg) | |||
return &result, fmt.Errorf("createTrainJob failed(%s): %s", result.ErrorCode, result.ErrorMsg) | |||
log.Error("createTrainJobUserImage failed(%s): %s", result.ErrorCode, result.ErrorMsg) | |||
return &result, fmt.Errorf("createTrainJobUserImage failed(%s): %s", result.ErrorCode, result.ErrorMsg) | |||
} | |||
return &result, nil | |||
@@ -547,9 +556,6 @@ sendjob: | |||
return nil, fmt.Errorf("resty create train-job: %s", err) | |||
} | |||
req, _ := json.Marshal(createJobParams) | |||
log.Info("%s", req) | |||
if res.StatusCode() == http.StatusUnauthorized && retry < 1 { | |||
retry++ | |||
_ = getToken() | |||
@@ -563,17 +569,21 @@ sendjob: | |||
return &result, fmt.Errorf("json.Unmarshal failed(%s): %v", res.String(), err.Error()) | |||
} | |||
log.Error("createTrainJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
BootFileErrorMsg := "Invalid OBS path '" + createJobParams.Config.BootFileUrl + "'." | |||
DataSetErrorMsg := "Invalid OBS path '" + createJobParams.Config.DataUrl + "'." | |||
if temp.ErrorMsg == BootFileErrorMsg { | |||
bootFileErrorMsg := "Invalid OBS path '" + createJobParams.Config.BootFileUrl + "'." | |||
dataSetErrorMsg := "Invalid OBS path '" + createJobParams.Config.DataUrl + "'." | |||
if temp.ErrorMsg == bootFileErrorMsg { | |||
log.Error("启动文件错误!createTrainJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
return &result, fmt.Errorf("启动文件错误!") | |||
} | |||
if temp.ErrorMsg == DataSetErrorMsg { | |||
if temp.ErrorMsg == dataSetErrorMsg { | |||
log.Error("数据集错误!createTrainJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
return &result, fmt.Errorf("数据集错误!") | |||
} | |||
return &result, fmt.Errorf("createTrainJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
if res.StatusCode() == http.StatusBadGateway { | |||
return &result, fmt.Errorf(UnknownErrorPrefix+"createTrainJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
} else { | |||
return &result, fmt.Errorf("createTrainJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
} | |||
} | |||
if !result.IsSuccess { | |||
@@ -603,9 +613,6 @@ sendjob: | |||
return nil, fmt.Errorf("resty create train-job version: %s", err) | |||
} | |||
req, _ := json.Marshal(createJobVersionParams) | |||
log.Info("%s", req) | |||
if res.StatusCode() == http.StatusUnauthorized && retry < 1 { | |||
retry++ | |||
_ = getToken() | |||
@@ -618,17 +625,23 @@ sendjob: | |||
log.Error("json.Unmarshal failed(%s): %v", res.String(), err.Error()) | |||
return &result, fmt.Errorf("json.Unmarshal failed(%s): %v", res.String(), err.Error()) | |||
} | |||
BootFileErrorMsg := "Invalid OBS path '" + createJobVersionParams.Config.BootFileUrl + "'." | |||
DataSetErrorMsg := "Invalid OBS path '" + createJobVersionParams.Config.DataUrl + "'." | |||
if temp.ErrorMsg == BootFileErrorMsg { | |||
log.Error("createTrainJobVersion failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
bootFileErrorMsg := "Invalid OBS path '" + createJobVersionParams.Config.BootFileUrl + "'." | |||
dataSetErrorMsg := "Invalid OBS path '" + createJobVersionParams.Config.DataUrl + "'." | |||
if temp.ErrorMsg == bootFileErrorMsg { | |||
log.Error("启动文件错误!createTrainJobVersion failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
return &result, fmt.Errorf("启动文件错误!") | |||
} | |||
if temp.ErrorMsg == DataSetErrorMsg { | |||
if temp.ErrorMsg == dataSetErrorMsg { | |||
log.Error("数据集错误!createTrainJobVersion failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
return &result, fmt.Errorf("数据集错误!") | |||
} | |||
return &result, fmt.Errorf("createTrainJobVersion failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
if res.StatusCode() == http.StatusBadGateway { | |||
return &result, fmt.Errorf(UnknownErrorPrefix+"createTrainJobVersion failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
} else { | |||
return &result, fmt.Errorf("createTrainJobVersion failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
} | |||
} | |||
if !result.IsSuccess { | |||
@@ -761,9 +774,6 @@ sendjob: | |||
goto sendjob | |||
} | |||
//temp, _ := json.Marshal(req) | |||
//log.Info("%s", temp) | |||
if res.StatusCode() != http.StatusOK { | |||
var temp models.ErrorResult | |||
if err = json.Unmarshal([]byte(res.String()), &temp); err != nil { | |||
@@ -1172,7 +1182,11 @@ sendjob: | |||
log.Error("数据集错误!createInferenceJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
return &result, fmt.Errorf("数据集错误!") | |||
} | |||
return &result, fmt.Errorf("createInferenceJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
if res.StatusCode() == http.StatusBadGateway { | |||
return &result, fmt.Errorf(UnknownErrorPrefix+"createInferenceJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
} else { | |||
return &result, fmt.Errorf("createInferenceJob failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
} | |||
} | |||
if !result.IsSuccess { | |||
@@ -1212,7 +1226,11 @@ sendjob: | |||
err = json.Unmarshal(res.Body(), &response) | |||
if err != nil { | |||
log.Error("json.Unmarshal failed: %s", err.Error()) | |||
return &result, fmt.Errorf("son.Unmarshal failed: %s", err.Error()) | |||
return &result, fmt.Errorf("json.Unmarshal failed: %s", err.Error()) | |||
} | |||
if res.StatusCode() == http.StatusBadGateway { | |||
return &result, fmt.Errorf(UnknownErrorPrefix+"createNotebook2 failed(%s): %s", response.ErrorCode, response.ErrorMsg) | |||
} | |||
if len(response.ErrorCode) != 0 { | |||
@@ -1271,3 +1289,139 @@ sendjob: | |||
return &result, nil | |||
} | |||
func GetTrainJobList(perPage, page int, sortBy, order, searchContent string) (*models.GetTrainJobListResult, error) { | |||
checkSetting() | |||
client := getRestyClient() | |||
var result models.GetTrainJobListResult | |||
retry := 0 | |||
sendjob: | |||
res, err := client.R(). | |||
SetQueryParams(map[string]string{ | |||
"per_page": strconv.Itoa(perPage), | |||
"page": strconv.Itoa(page), | |||
"sortBy": sortBy, | |||
"order": order, | |||
"search_content": searchContent, | |||
}). | |||
SetAuthToken(TOKEN). | |||
SetResult(&result). | |||
Get(HOST + "/v1/" + setting.ProjectID + urlTrainJob) | |||
if err != nil { | |||
return nil, fmt.Errorf("resty GetTrainJobList: %v", err) | |||
} | |||
if res.StatusCode() == http.StatusUnauthorized && retry < 1 { | |||
retry++ | |||
_ = getToken() | |||
goto sendjob | |||
} | |||
if res.StatusCode() != http.StatusOK { | |||
var temp models.ErrorResult | |||
if err = json.Unmarshal([]byte(res.String()), &temp); err != nil { | |||
log.Error("json.Unmarshal failed(%s): %v", res.String(), err.Error()) | |||
return &result, fmt.Errorf("json.Unmarshal failed(%s): %v", res.String(), err.Error()) | |||
} | |||
log.Error("GetTrainJobList failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
return &result, fmt.Errorf(temp.ErrorMsg) | |||
} | |||
if !result.IsSuccess { | |||
log.Error("GetTrainJobList failed(%s): %s", result.ErrorCode, result.ErrorMsg) | |||
return &result, fmt.Errorf(result.ErrorMsg) | |||
} | |||
return &result, nil | |||
} | |||
func GetTrainJobVersionList(perPage, page int, jobID string) (*models.GetTrainJobVersionListResult, error) { | |||
checkSetting() | |||
client := getRestyClient() | |||
var result models.GetTrainJobVersionListResult | |||
retry := 0 | |||
sendjob: | |||
res, err := client.R(). | |||
SetQueryParams(map[string]string{ | |||
"per_page": strconv.Itoa(perPage), | |||
"page": strconv.Itoa(page), | |||
}). | |||
SetAuthToken(TOKEN). | |||
SetResult(&result). | |||
Get(HOST + "/v1/" + setting.ProjectID + urlTrainJob + "/" + jobID + "/versions") | |||
if err != nil { | |||
return nil, fmt.Errorf("resty GetTrainJobVersionList: %v", err) | |||
} | |||
if res.StatusCode() == http.StatusUnauthorized && retry < 1 { | |||
retry++ | |||
_ = getToken() | |||
goto sendjob | |||
} | |||
if res.StatusCode() != http.StatusOK { | |||
var temp models.ErrorResult | |||
if err = json.Unmarshal([]byte(res.String()), &temp); err != nil { | |||
log.Error("json.Unmarshal failed(%s): %v", res.String(), err.Error()) | |||
return &result, fmt.Errorf("json.Unmarshal failed(%s): %v", res.String(), err.Error()) | |||
} | |||
log.Error("GetTrainJobVersionList failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
return &result, fmt.Errorf(temp.ErrorMsg) | |||
} | |||
if !result.IsSuccess { | |||
log.Error("GetTrainJobVersionList failed(%s): %s", result.ErrorCode, result.ErrorMsg) | |||
return &result, fmt.Errorf(result.ErrorMsg) | |||
} | |||
return &result, nil | |||
} | |||
func GetNotebookList(limit, offset int, sortBy, order, searchContent string) (*models.GetNotebookListResult, error) { | |||
checkSetting() | |||
client := getRestyClient() | |||
var result models.GetNotebookListResult | |||
retry := 0 | |||
sendjob: | |||
res, err := client.R(). | |||
SetQueryParams(map[string]string{ | |||
"limit": strconv.Itoa(limit), | |||
"offset": strconv.Itoa(offset), | |||
"name": searchContent, | |||
"sort_key": sortBy, | |||
"sort_dir": order, | |||
}). | |||
SetAuthToken(TOKEN). | |||
SetResult(&result). | |||
Get(HOST + "/v1/" + setting.ProjectID + urlNotebook2) | |||
if err != nil { | |||
return nil, fmt.Errorf("resty GetNotebookList: %v", err) | |||
} | |||
if res.StatusCode() == http.StatusUnauthorized && retry < 1 { | |||
retry++ | |||
_ = getToken() | |||
goto sendjob | |||
} | |||
if res.StatusCode() != http.StatusOK { | |||
var temp models.ErrorResult | |||
if err = json.Unmarshal([]byte(res.String()), &temp); err != nil { | |||
log.Error("json.Unmarshal failed(%s): %v", res.String(), err.Error()) | |||
return &result, fmt.Errorf("json.Unmarshal failed(%s): %v", res.String(), err.Error()) | |||
} | |||
log.Error("GetNotebookList failed(%d):%s(%s)", res.StatusCode(), temp.ErrorCode, temp.ErrorMsg) | |||
return &result, fmt.Errorf(temp.ErrorMsg) | |||
} | |||
return &result, nil | |||
} |
@@ -7,8 +7,8 @@ package wechat | |||
import ( | |||
"code.gitea.io/gitea/models" | |||
"code.gitea.io/gitea/modules/auth/wechat" | |||
"code.gitea.io/gitea/modules/log" | |||
"code.gitea.io/gitea/modules/notification/base" | |||
"code.gitea.io/gitea/modules/setting" | |||
) | |||
type wechatNotifier struct { | |||
@@ -25,20 +25,12 @@ func NewNotifier() base.Notifier { | |||
} | |||
func (*wechatNotifier) NotifyChangeCloudbrainStatus(cloudbrain *models.Cloudbrain, oldStatus string) { | |||
log.Info("NotifyChangeCloudbrainStatus cloudbrain.id=%d cloudbrain.status=%s oldStatus=%s", cloudbrain.ID, cloudbrain.Status, oldStatus) | |||
operateType := wechat.GetJobOperateTypeFromCloudbrainStatus(cloudbrain) | |||
if operateType == "" { | |||
log.Info("NotifyChangeCloudbrainStatus operateType is incorrect") | |||
return | |||
} | |||
switch operateType { | |||
case wechat.JobOperateTypeStart: | |||
if len(setting.CloudbrainStartedNotifyList) == 0 { | |||
return | |||
} | |||
for _, v := range setting.CloudbrainStartedNotifyList { | |||
if v == cloudbrain.JobType { | |||
go wechat.SendCloudbrainStartedMsg(operateType, *cloudbrain) | |||
return | |||
} | |||
} | |||
} | |||
template := wechat.GetTemplateFromOperateType(operateType) | |||
go wechat.SendTemplateMsg(template, &wechat.TemplateContext{Cloudbrain: cloudbrain}, cloudbrain.UserID) | |||
} |
@@ -539,6 +539,7 @@ var ( | |||
DebugHost string | |||
ImageInfos string | |||
Capacity int | |||
MaxTempQueryTimes int | |||
//train-job | |||
ResourcePools string | |||
Engines string | |||
@@ -586,6 +587,12 @@ var ( | |||
//wechat template msg config | |||
CloudbrainStartedTemplateId string | |||
CloudbrainStartedNotifyList []string | |||
CloudbrainStartedTitle string | |||
CloudbrainStartedRemark string | |||
CloudbrainStoppedTemplateId string | |||
CloudbrainStoppedNotifyList []string | |||
CloudbrainStoppedTitle string | |||
CloudbrainStoppedRemark string | |||
//nginx proxy | |||
PROXYURL string | |||
@@ -1418,6 +1425,7 @@ func NewContext() { | |||
Flavor = sec.Key("FLAVOR").MustString("") | |||
ImageInfos = sec.Key("IMAGE_INFOS").MustString("") | |||
Capacity = sec.Key("IMAGE_INFOS").MustInt(100) | |||
MaxTempQueryTimes = sec.Key("MAX_TEMP_QUERY_TIMES").MustInt(30) | |||
ResourcePools = sec.Key("Resource_Pools").MustString("") | |||
Engines = sec.Key("Engines").MustString("") | |||
EngineVersions = sec.Key("Engine_Versions").MustString("") | |||
@@ -1448,6 +1456,12 @@ func NewContext() { | |||
TreePathOfSubscribe = sec.Key("SUBSCRIBE_TREE_PATH").MustString("wechat/subscribe_reply.json") | |||
CloudbrainStartedTemplateId = sec.Key("CLOUDBRAIN_STARTED_TEMPLATE_ID").MustString("") | |||
CloudbrainStartedNotifyList = strings.Split(sec.Key("CLOUDBRAIN_STARTED_NOTIFY_LIST").MustString("DEBUG"), ",") | |||
CloudbrainStartedTitle = sec.Key("CLOUDBRAIN_STARTED_TITLE").MustString("您好,您提交的算力资源申请已通过,任务已启动,请您关注运行情况。") | |||
CloudbrainStartedRemark = sec.Key("CLOUDBRAIN_STARTED_REMARK").MustString("感谢您的耐心等待。") | |||
CloudbrainStoppedTemplateId = sec.Key("CLOUDBRAIN_STOPPED_TEMPLATE_ID").MustString("") | |||
CloudbrainStoppedNotifyList = strings.Split(sec.Key("CLOUDBRAIN_STOPPED_NOTIFY_LIST").MustString("TRAIN"), ",") | |||
CloudbrainStoppedTitle = sec.Key("CLOUDBRAIN_STOPPED_TITLE").MustString("您好,您申请的算力资源已结束使用,任务已完成运行,请您关注运行结果。") | |||
CloudbrainStoppedRemark = sec.Key("CLOUDBRAIN_STOPPED_REMARK").MustString("感谢您的耐心等待。") | |||
SetRadarMapConfig() | |||
@@ -179,28 +179,39 @@ func GetOneLevelAllObjectUnderDirMinio(bucket string, prefixRootPath string, rel | |||
output, err := core.ListObjects(bucket, Prefix, "", "", 1000) | |||
fileInfos := make([]FileInfo, 0) | |||
prefixLen := len(Prefix) | |||
fileMap := make(map[string]bool, 0) | |||
if err == nil { | |||
for _, val := range output.Contents { | |||
log.Info("val key=" + val.Key) | |||
var isDir bool | |||
var fileName string | |||
if val.Key == Prefix { | |||
continue | |||
} | |||
if strings.HasSuffix(val.Key, "/") { | |||
fileName = val.Key[prefixLen:] | |||
log.Info("fileName =" + fileName) | |||
files := strings.Split(fileName, "/") | |||
if fileMap[files[0]] { | |||
continue | |||
} else { | |||
fileMap[files[0]] = true | |||
} | |||
ParenDir := relativePath | |||
fileName = files[0] | |||
if len(files) > 1 { | |||
isDir = true | |||
fileName = val.Key[prefixLen : len(val.Key)-1] | |||
relativePath += val.Key[prefixLen:] | |||
ParenDir += fileName + "/" | |||
} else { | |||
isDir = false | |||
fileName = val.Key[prefixLen:] | |||
} | |||
fileInfo := FileInfo{ | |||
ModTime: val.LastModified.Local().Format("2006-01-02 15:04:05"), | |||
FileName: fileName, | |||
Size: val.Size, | |||
IsDir: isDir, | |||
ParenDir: relativePath, | |||
ParenDir: ParenDir, | |||
} | |||
fileInfos = append(fileInfos, fileInfo) | |||
} | |||
@@ -395,29 +395,6 @@ func GetOneLevelAllObjectUnderDir(bucket string, prefixRootPath string, relative | |||
} else { | |||
isDir = false | |||
} | |||
// if strings.Contains(val.Key[prefixLen:len(val.Key)-1], "/") { | |||
// files := strings.Split(fileName, "/") | |||
// fileName = files[0] | |||
// isDir = true | |||
// if fileMap[files[0]] { | |||
// continue | |||
// } else { | |||
// fileMap[files[0]] = true | |||
// } | |||
// } else { | |||
// if strings.HasSuffix(val.Key, "/") { | |||
// isDir = true | |||
// fileName = val.Key[prefixLen : len(val.Key)-1] | |||
// relativePath += val.Key[prefixLen:] | |||
// } else { | |||
// isDir = false | |||
// fileName = val.Key[prefixLen:] | |||
// } | |||
// fileMap[fileName] = true | |||
// } | |||
fileInfo := FileInfo{ | |||
ModTime: val.LastModified.Local().Format("2006-01-02 15:04:05"), | |||
FileName: fileName, | |||
@@ -252,11 +252,12 @@ page_dev_env_desc2_title=Model Management and Sharing | |||
page_dev_env_desc2_desc=Associate the model with the code version, you can adjust the model in different ways based on the historical version of the code and save the results. The trained model can be open and shared, so that more people can use the model to test and give feedback. | |||
page_dev_env_desc3_title=Once Configuration, Multiple Reuse | |||
page_dev_env_desc3_desc=Provide execution environment sharing, Once Configuration, Multiple Reuse. Lower the threshold of model development, and avoid spending repetitive time configuring complex environments. | |||
page_dev_yunlao=PengCheng Cloudbrain Open Source Collaboration | |||
page_dev_yunlao_desc1=The platform has been connected with Pengcheng Cloudbrain and can use the rich computing resources of Pengcheng Cloudbrain to complete AI development tasks. | |||
page_dev_yunlao_desc2=Pengcheng Cloudbrain's existing AI computing power is 100p FLOPS@FP16 (billions of half precision floating-point calculations per second), the main hardware infrastructure is composed of GPU server equipped with NVIDIA Tesla V100 and Atlas 900 AI cluster equipped with Kunpeng and Ascend processors. | |||
page_dev_yunlao_desc3=Developers can freely choose the corresponding computing resources according to their needs, and can test the adaptability, performance, stability of the model in different hardware environments. | |||
page_dev_yunlao_desc4=If your model requires more computing resources, you can also apply for it separately. | |||
page_dev_yunlao=OpenI AI Collaboration Platform | |||
page_dev_yunlao_desc1=OpenI AI collaboration platform has cooperated with Pengcheng cloud brain and China computing power network (c ² Net) can be used to complete AI development tasks by using the rich computing resources of Pengcheng cloud brain and China computing network. | |||
page_dev_yunlao_desc2=Pengcheng CloudBrain's existing AI computing power is 100p FLOPS@FP16 (billions of half precision floating-point calculations per second), the main hardware infrastructure consists of GPU servers equipped with NVIDIA Tesla V100 and A100, and Atlas 900 AI clusters equipped with Kunpeng and shengteng processors. | |||
page_dev_yunlao_desc3=China computing power network (c ² Net) phase I can realize high-speed network interconnection between different artificial intelligence computing centers, and realize reasonable scheduling of computing power and flexible allocation of resources. At present, 11 intelligent computing centers have been connected, and the total scale of computing power is 1924p OPS@FP16 。 Qizhi AI collaboration platform has been connected to Pengcheng Cloud Computing Institute, Chengdu Intelligent Computing Center, Zhongyuan Intelligent Computing Center, Hefei brain and other nodes. | |||
page_dev_yunlao_desc4=Developers can freely select the corresponding computing resources according to the use needs, and can test the adaptability, performance, stability, etc. of the model in different hardware environments. | |||
page_dev_yunlao_desc5=If your model requires more computing resources, you can also apply for it separately. | |||
page_dev_yunlao_apply=Apply Separately | |||
search=Search | |||
@@ -1073,6 +1074,7 @@ cloudbrain_operate = Operate | |||
cloudbrain_status_createtime = Status/Createtime | |||
cloudbrain_status_runtime = Running Time | |||
cloudbrain_jobname_err=Name must start with a lowercase letter or number,can include lowercase letter,number,_ and -,can not end with _, and can be up to 36 characters long. | |||
cloudbrain_bootfile_err=The bootfile does not exist in the repository | |||
cloudbrain_query_fail=Failed to query cloudbrain information. | |||
cloudbrain.mirror_tag = Mirror Tag | |||
cloudbrain.mirror_description = Mirror Description | |||
@@ -3085,6 +3087,8 @@ Platform_Tutorial = Tutorial | |||
foot.advice_feedback = Feedback | |||
[cloudbrain] | |||
all_resource_cluster=All Cluster | |||
all_ai_center=All Computing NET | |||
resource_cluster = Resource Cluster | |||
resource_cluster_openi = OpenI Resource Cluster | |||
resource_cluster_c2net = China Computing NET | |||
@@ -3116,7 +3120,8 @@ dataset_path_rule = The dataset location is stored in the environment variable d | |||
view_sample = View sample | |||
inference_output_path_rule = The inference output path is stored in the environment variable result_url. | |||
model_file_path_rule=The model file location is stored in the environment variable ckpt_url | |||
model_file_postfix_rule = The supported format of the model file is [ckpt, pb, h5, json, pkl, pth, t7, pdparams, onnx, pbtxt, keras, mlmodel, cfg, pt] | |||
model_convert_postfix_rule = The supported format of the model file is [.pth, .pkl, .onnx, .mindir, .ckpt, .pb] | |||
delete_task = Delete task | |||
task_delete_confirm = Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered. | |||
operate_confirm = confirm | |||
@@ -3141,5 +3146,6 @@ Not_Stopped=The job is not stopped, can not be deleted. | |||
Already_stopped=The job is already stopped. | |||
Stopped_failed=Fail to stop the job, please try again later. | |||
Stopped_success_update_status_fail=Succeed in stopping th job, but failed to update the job status and duration time. | |||
load_code_failed=Fail to load code, please check if the right branch is selected. | |||
error.dataset_select = dataset select error:the count exceed the limit or has same name |
@@ -254,11 +254,12 @@ page_dev_env_desc2_title=模型管理与共享 | |||
page_dev_env_desc2_desc=将模型与代码版本建立关联,可以基于代码历史版本,使用不同的方式调整模型,并将结果保存下来;训练好的模型可以开放共享,让更多人的使用模型测试并提出反馈 | |||
page_dev_env_desc3_title=一次配置,多次使用 | |||
page_dev_env_desc3_desc=提供执行环境共享,一次配置,多次使用,降低模型开发门槛,避免花费重复的时间配置复杂的环境 | |||
page_dev_yunlao=鹏城云脑开源协同 | |||
page_dev_yunlao_desc1=平台已经与鹏城云脑打通,可以利用鹏城云脑的丰富算力资源,完成AI开发任务 | |||
page_dev_yunlao_desc2=鹏城云脑现有AI算力100P FLOPS@FP16(每秒十亿亿次半精度浮点计算),主要硬件基础设施由搭载英伟达Tesla V100 的GPU服务器和搭载鲲鹏、昇腾处理器的Atlas 900 AI集群构成 | |||
page_dev_yunlao_desc3=开发者可以根据使用需求,自由选择相应计算资源,可以测试模型在不同硬件环境下的适配能力、性能、稳定性等 | |||
page_dev_yunlao_desc4=如果您的模型需要更多的计算资源,也可以单独申请 | |||
page_dev_yunlao=启智AI协作平台 | |||
page_dev_yunlao_desc1=启智AI协作平台已经与鹏城云脑、中国算力网(C²NET)一期打通,可以利用鹏城云脑和中国算力网的丰富算力资源,完成AI开发任务。 | |||
page_dev_yunlao_desc2=鹏城云脑现有AI算力100P FLOPS@FP16(每秒十亿亿次半精度浮点计算),主要硬件基础设施由搭载英伟达Tesla V100 和A100 的GPU服务器,以及搭载鲲鹏、昇腾处理器的Atlas 900 AI集群构成。 | |||
page_dev_yunlao_desc3=中国算力网(C²NET)一期可实现不同人工智能计算中心之间高速网络互联,实现算力合理调度和资源弹性分配。目前已接入11家智算中心,算力总规模1924P OPS@FP16。启智AI协作平台已接入其中的鹏城云计算所、成都智算中心、中原智算中心、合肥类脑等节点。 | |||
page_dev_yunlao_desc4=开发者可以根据使用需求,自由选择相应计算资源,可以测试模型在不同硬件环境下的适配能力、性能、稳定性等。 | |||
page_dev_yunlao_desc5=如果您的模型需要更多的计算资源,也可以单独申请。 | |||
page_dev_yunlao_apply=单独申请 | |||
search=搜索 | |||
@@ -1076,6 +1077,7 @@ cloudbrain_operate=操作 | |||
cloudbrain_status_createtime=状态/创建时间 | |||
cloudbrain_status_runtime = 运行时长 | |||
cloudbrain_jobname_err=只能以小写字母或数字开头且只包含小写字母、数字、_和-,不能以_结尾,最长36个字符。 | |||
cloudbrain_bootfile_err=仓库中不存在启动文件 | |||
cloudbrain_query_fail=查询云脑任务失败。 | |||
cloudbrain.mirror_tag = 镜像标签 | |||
cloudbrain.mirror_description = 镜像描述 | |||
@@ -3099,6 +3101,8 @@ Platform_Tutorial=新手指引 | |||
foot.advice_feedback = 意见反馈 | |||
[cloudbrain] | |||
all_resource_cluster=全部集群 | |||
all_ai_center=全部智算中心 | |||
resource_cluster = 算力集群 | |||
resource_cluster_openi = 启智集群 | |||
resource_cluster_c2net = 智算网络集群 | |||
@@ -3131,7 +3135,8 @@ dataset_path_rule = 数据集位置存储在环境变量data_url中,训练输 | |||
view_sample = 查看样例 | |||
inference_output_path_rule = 推理输出路径存储在环境变量result_url中。 | |||
model_file_path_rule = 模型文件位置存储在环境变量ckpt_url中。 | |||
model_file_postfix_rule = 模型文件支持的格式为 [ckpt, pb, h5, json, pkl, pth, t7, pdparams, onnx, pbtxt, keras, mlmodel, cfg, pt] | |||
model_convert_postfix_rule = 模型文件支持的格式为 [.pth, .pkl, .onnx, .mindir, .ckpt, .pb] | |||
delete_task = 删除任务 | |||
task_delete_confirm = 你确认删除该任务么?此任务一旦删除不可恢复。 | |||
operate_confirm = 确定操作 | |||
@@ -3156,6 +3161,7 @@ Not_Stopped=任务还未终止,不能删除。 | |||
Already_stopped=任务已停止。 | |||
Stopped_failed=任务停止失败,请稍后再试。 | |||
Stopped_success_update_status_fail=任务停止成功,状态及运行时间更新失败。 | |||
load_code_failed=代码加载失败,请确认选择了正确的分支。 | |||
error.dataset_select = 数据集选择错误:数量超过限制或者有同名数据集 |
@@ -35,10 +35,14 @@ func CloudBrains(ctx *context.Context) { | |||
listType := ctx.Query("listType") | |||
jobType := ctx.Query("jobType") | |||
jobStatus := ctx.Query("jobStatus") | |||
aiCenter := ctx.Query("aiCenter") | |||
cluster := ctx.Query("cluster") | |||
ctx.Data["ListType"] = listType | |||
ctx.Data["JobType"] = jobType | |||
ctx.Data["JobStatus"] = jobStatus | |||
ctx.Data["aiCenter"] = aiCenter | |||
ctx.Data["cluster"] = cluster | |||
page := ctx.QueryInt("page") | |||
if page <= 0 { | |||
@@ -80,6 +84,8 @@ func CloudBrains(ctx *context.Context) { | |||
IsLatestVersion: modelarts.IsLatestVersion, | |||
ComputeResource: listType, | |||
Type: models.TypeCloudBrainAll, | |||
AiCenter: aiCenter, | |||
Cluster: cluster, | |||
}) | |||
if err != nil { | |||
ctx.ServerError("Get job failed:", err) | |||
@@ -679,6 +679,8 @@ func GetCloudbrainsDetailData(ctx *context.Context) { | |||
jobType := ctx.Query("jobType") | |||
jobStatus := ctx.Query("jobStatus") | |||
cloudBrainType := ctx.QueryInt("Type") | |||
aiCenter := ctx.Query("aiCenter") | |||
needDeleteInfo := ctx.Query("needDeleteInfo") | |||
page := ctx.QueryInt("page") | |||
pageSize := ctx.QueryInt("pagesize") | |||
@@ -724,6 +726,8 @@ func GetCloudbrainsDetailData(ctx *context.Context) { | |||
NeedRepoInfo: true, | |||
BeginTimeUnix: int64(recordBeginTime), | |||
EndTimeUnix: endTime.Unix(), | |||
AiCenter: aiCenter, | |||
NeedDeleteInfo: needDeleteInfo, | |||
}) | |||
if err != nil { | |||
ctx.ServerError("Get job failed:", err) | |||
@@ -26,40 +26,6 @@ import ( | |||
routerRepo "code.gitea.io/gitea/routers/repo" | |||
) | |||
func GetModelArtsNotebook(ctx *context.APIContext) { | |||
var ( | |||
err error | |||
) | |||
jobID := ctx.Params(":jobid") | |||
repoID := ctx.Repo.Repository.ID | |||
job, err := models.GetRepoCloudBrainByJobID(repoID, jobID) | |||
if err != nil { | |||
ctx.NotFound(err) | |||
return | |||
} | |||
result, err := modelarts.GetJob(jobID) | |||
if err != nil { | |||
ctx.NotFound(err) | |||
return | |||
} | |||
oldStatus := job.Status | |||
job.Status = result.Status | |||
if oldStatus != result.Status { | |||
notification.NotifyChangeCloudbrainStatus(job, oldStatus) | |||
} | |||
err = models.UpdateJob(job) | |||
if err != nil { | |||
log.Error("UpdateJob failed:", err) | |||
} | |||
ctx.JSON(http.StatusOK, map[string]interface{}{ | |||
"JobID": jobID, | |||
"JobStatus": result.Status, | |||
}) | |||
} | |||
func GetModelArtsNotebook2(ctx *context.APIContext) { | |||
var ( | |||
err error | |||
@@ -71,33 +37,16 @@ func GetModelArtsNotebook2(ctx *context.APIContext) { | |||
ctx.NotFound(err) | |||
return | |||
} | |||
result, err := modelarts.GetNotebook2(job.JobID) | |||
err = modelarts.HandleNotebookInfo(job) | |||
if err != nil { | |||
ctx.NotFound(err) | |||
return | |||
} | |||
if job.StartTime == 0 && result.Lease.UpdateTime > 0 { | |||
job.StartTime = timeutil.TimeStamp(result.Lease.UpdateTime / 1000) | |||
} | |||
oldStatus := job.Status | |||
job.Status = result.Status | |||
if job.EndTime == 0 && models.IsModelArtsDebugJobTerminal(job.Status) { | |||
job.EndTime = timeutil.TimeStampNow() | |||
} | |||
job.CorrectCreateUnix() | |||
job.ComputeAndSetDuration() | |||
if oldStatus != result.Status { | |||
notification.NotifyChangeCloudbrainStatus(job, oldStatus) | |||
} | |||
err = models.UpdateJob(job) | |||
if err != nil { | |||
log.Error("UpdateJob failed:", err) | |||
} | |||
ctx.JSON(http.StatusOK, map[string]interface{}{ | |||
"ID": ID, | |||
"JobName": job.JobName, | |||
"JobStatus": result.Status, | |||
"JobStatus": job.Status, | |||
"JobDuration": job.TrainJobDuration, | |||
}) | |||
@@ -189,27 +138,11 @@ func GetModelArtsTrainJobVersion(ctx *context.APIContext) { | |||
} | |||
} | |||
} else if job.Type == models.TypeCloudBrainTwo { | |||
result, err := modelarts.GetTrainJob(jobID, strconv.FormatInt(job.VersionID, 10)) | |||
err := modelarts.HandleTrainJobInfo(job) | |||
if err != nil { | |||
ctx.NotFound(err) | |||
return | |||
} | |||
if job.StartTime == 0 && result.StartTime > 0 { | |||
job.StartTime = timeutil.TimeStamp(result.StartTime / 1000) | |||
} | |||
job.Status = modelarts.TransTrainJobStatus(result.IntStatus) | |||
job.Duration = result.Duration / 1000 | |||
job.TrainJobDuration = models.ConvertDurationToStr(job.Duration) | |||
if job.EndTime == 0 && models.IsTrainJobTerminal(job.Status) && job.StartTime > 0 { | |||
job.EndTime = job.StartTime.Add(job.Duration) | |||
} | |||
job.CorrectCreateUnix() | |||
err = models.UpdateTrainJobVersion(job) | |||
if err != nil { | |||
log.Error("UpdateJob failed:", err) | |||
} | |||
} else if job.Type == models.TypeC2Net { | |||
result, err := grampus.GetJob(jobID) | |||
if err != nil { | |||
@@ -221,6 +154,7 @@ func GetModelArtsTrainJobVersion(ctx *context.APIContext) { | |||
if job.StartTime == 0 && result.JobInfo.StartedAt > 0 { | |||
job.StartTime = timeutil.TimeStamp(result.JobInfo.StartedAt) | |||
} | |||
oldStatus := job.Status | |||
job.Status = grampus.TransTrainJobStatus(result.JobInfo.Status) | |||
job.Duration = result.JobInfo.RunSec | |||
job.TrainJobDuration = models.ConvertDurationToStr(job.Duration) | |||
@@ -243,6 +177,9 @@ func GetModelArtsTrainJobVersion(ctx *context.APIContext) { | |||
aiCenterName = temp[1] | |||
} | |||
} | |||
if oldStatus != job.Status { | |||
notification.NotifyChangeCloudbrainStatus(job, oldStatus) | |||
} | |||
err = models.UpdateTrainJobVersion(job) | |||
if err != nil { | |||
log.Error("UpdateJob failed:", err) | |||
@@ -558,26 +495,11 @@ func GetModelArtsInferenceJob(ctx *context.APIContext) { | |||
ctx.NotFound(err) | |||
return | |||
} | |||
result, err := modelarts.GetTrainJob(jobID, strconv.FormatInt(job.VersionID, 10)) | |||
err = modelarts.HandleTrainJobInfo(job) | |||
if err != nil { | |||
ctx.NotFound(err) | |||
return | |||
} | |||
if job.StartTime == 0 && result.StartTime > 0 { | |||
job.StartTime = timeutil.TimeStamp(result.StartTime / 1000) | |||
} | |||
job.Status = modelarts.TransTrainJobStatus(result.IntStatus) | |||
job.Duration = result.Duration / 1000 | |||
job.TrainJobDuration = models.ConvertDurationToStr(job.Duration) | |||
if job.EndTime == 0 && models.IsTrainJobTerminal(job.Status) && job.StartTime > 0 { | |||
job.EndTime = job.StartTime.Add(job.Duration) | |||
} | |||
job.CorrectCreateUnix() | |||
err = models.UpdateInferenceJob(job) | |||
if err != nil { | |||
log.Error("UpdateJob failed:", err) | |||
} | |||
ctx.JSON(http.StatusOK, map[string]interface{}{ | |||
"JobID": jobID, | |||
@@ -40,7 +40,7 @@ const ( | |||
tplExploreImages base.TplName = "explore/images" | |||
tplExploreExploreDataAnalysis base.TplName = "explore/data_analysis" | |||
tplHomeTerm base.TplName = "terms" | |||
tplHomePrivacy base.TplName = "privacy" | |||
tplHomePrivacy base.TplName = "privacy" | |||
) | |||
// Home render home page | |||
@@ -93,6 +93,7 @@ func setRecommendURL(ctx *context.Context) { | |||
ctx.Data["page_dev_yunlao_desc2"] = ctx.Tr("home.page_dev_yunlao_desc2") | |||
ctx.Data["page_dev_yunlao_desc3"] = ctx.Tr("home.page_dev_yunlao_desc3") | |||
ctx.Data["page_dev_yunlao_desc4"] = ctx.Tr("home.page_dev_yunlao_desc4") | |||
ctx.Data["page_dev_yunlao_desc5"] = ctx.Tr("home.page_dev_yunlao_desc5") | |||
ctx.Data["page_dev_yunlao_apply"] = ctx.Tr("home.page_dev_yunlao_apply") | |||
ctx.Data["page_recommend_activity"] = ctx.Tr("home.page_recommend_activity") | |||
ctx.Data["page_recommend_activity_desc"] = ctx.Tr("home.page_recommend_activity_desc") | |||
@@ -239,6 +239,7 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||
codePath := setting.JobPath + jobName + cloudbrain.CodeMountPath | |||
resourceSpecId := form.ResourceSpecId | |||
branchName := form.BranchName | |||
bootFile := strings.TrimSpace(form.BootFile) | |||
repo := ctx.Repo.Repository | |||
tpl := tplCloudBrainNew | |||
@@ -305,6 +306,13 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||
command := cloudbrain.GetCloudbrainDebugCommand() | |||
if jobType == string(models.JobTypeTrain) { | |||
bootFileExist, err := ctx.Repo.FileExists(bootFile, branchName) | |||
if err != nil || !bootFileExist { | |||
log.Error("Get bootfile error:", err, ctx.Data["MsgID"]) | |||
cloudBrainNewDataPrepare(ctx) | |||
ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_bootfile_err"), tpl, &form) | |||
return | |||
} | |||
tpl = tplCloudBrainTrainJobNew | |||
commandTrain, err := getTrainJobCommand(form) | |||
if err != nil { | |||
@@ -328,12 +336,12 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||
if branchName == "" { | |||
branchName = cloudbrain.DefaultBranchName | |||
} | |||
downloadCode(repo, codePath, branchName) | |||
uploadCodeToMinio(codePath+"/", jobName, cloudbrain.CodeMountPath+"/") | |||
modelPath := setting.JobPath + jobName + cloudbrain.ModelMountPath + "/" | |||
mkModelPath(modelPath) | |||
uploadCodeToMinio(modelPath, jobName, cloudbrain.ModelMountPath+"/") | |||
errStr = loadCodeAndMakeModelPath(repo, codePath, branchName, jobName, cloudbrain.ModelMountPath) | |||
if errStr != "" { | |||
cloudBrainNewDataPrepare(ctx) | |||
ctx.RenderWithErr(ctx.Tr(errStr), tpl, &form) | |||
return | |||
} | |||
commitID, _ := ctx.Repo.GitRepo.GetBranchCommitID(branchName) | |||
@@ -378,6 +386,30 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||
} | |||
} | |||
func loadCodeAndMakeModelPath(repo *models.Repository, codePath string, branchName string, jobName string, resultPath string) string { | |||
err := downloadCode(repo, codePath, branchName) | |||
if err != nil { | |||
return "cloudbrain.load_code_failed" | |||
} | |||
err = uploadCodeToMinio(codePath+"/", jobName, cloudbrain.CodeMountPath+"/") | |||
if err != nil { | |||
return "cloudbrain.load_code_failed" | |||
} | |||
modelPath := setting.JobPath + jobName + resultPath + "/" | |||
err = mkModelPath(modelPath) | |||
if err != nil { | |||
return "cloudbrain.load_code_failed" | |||
} | |||
err = uploadCodeToMinio(modelPath, jobName, resultPath+"/") | |||
if err != nil { | |||
return "cloudbrain.load_code_failed" | |||
} | |||
return "" | |||
} | |||
func CloudBrainInferenceJobCreate(ctx *context.Context, form auth.CreateCloudBrainInferencForm) { | |||
ctx.Data["PageIsCloudBrain"] = true | |||
displayJobName := form.DisplayJobName | |||
@@ -389,6 +421,7 @@ func CloudBrainInferenceJobCreate(ctx *context.Context, form auth.CreateCloudBra | |||
codePath := setting.JobPath + jobName + cloudbrain.CodeMountPath | |||
resourceSpecId := form.ResourceSpecId | |||
branchName := form.BranchName | |||
bootFile := strings.TrimSpace(form.BootFile) | |||
labelName := form.LabelName | |||
repo := ctx.Repo.Repository | |||
@@ -426,6 +459,14 @@ func CloudBrainInferenceJobCreate(ctx *context.Context, form auth.CreateCloudBra | |||
return | |||
} | |||
bootFileExist, err := ctx.Repo.FileExists(bootFile, branchName) | |||
if err != nil || !bootFileExist { | |||
log.Error("Get bootfile error:", err, ctx.Data["MsgID"]) | |||
cloudBrainNewDataPrepare(ctx) | |||
ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_bootfile_err"), tpl, &form) | |||
return | |||
} | |||
count, err := models.GetCloudbrainCountByUserID(ctx.User.ID, jobType) | |||
if err != nil { | |||
log.Error("GetCloudbrainCountByUserID failed:%v", err, ctx.Data["MsgID"]) | |||
@@ -444,11 +485,12 @@ func CloudBrainInferenceJobCreate(ctx *context.Context, form auth.CreateCloudBra | |||
if branchName == "" { | |||
branchName = cloudbrain.DefaultBranchName | |||
} | |||
downloadCode(repo, codePath, branchName) | |||
uploadCodeToMinio(codePath+"/", jobName, cloudbrain.CodeMountPath+"/") | |||
resultPath := setting.JobPath + jobName + cloudbrain.ResultPath + "/" | |||
mkResultPath(resultPath) | |||
uploadCodeToMinio(resultPath, jobName, cloudbrain.ResultPath+"/") | |||
errStr := loadCodeAndMakeModelPath(repo, codePath, branchName, jobName, cloudbrain.ResultPath) | |||
if errStr != "" { | |||
cloudBrainNewDataPrepare(ctx) | |||
ctx.RenderWithErr(ctx.Tr(errStr), tpl, &form) | |||
return | |||
} | |||
commitID, _ := ctx.Repo.GitRepo.GetBranchCommitID(branchName) | |||
@@ -886,7 +928,7 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo | |||
} | |||
} | |||
ctx.Data["datasetDownload"] = GetCloudBrainDataSetInfo(task.Uuid, false) | |||
ctx.Data["task"] = task | |||
labelName := strings.Fields(task.LabelName) | |||
ctx.Data["LabelName"] = labelName | |||
@@ -1664,11 +1706,7 @@ func uploadCodeToMinio(codePath, jobName, parentDir string) error { | |||
} | |||
func mkModelPath(modelPath string) error { | |||
return mkPathAndReadMeFile(modelPath, "You can put the model file into this directory and download it by the web page.") | |||
} | |||
func mkResultPath(resultPath string) error { | |||
return mkPathAndReadMeFile(resultPath, "You can put the result file into this directory and download it by the web page.") | |||
return mkPathAndReadMeFile(modelPath, "You can put the files into this directory and download the files by the web page.") | |||
} | |||
func mkPathAndReadMeFile(path string, text string) error { | |||
@@ -1790,70 +1828,24 @@ func SyncCloudbrainStatus() { | |||
} | |||
} else if task.Type == models.TypeCloudBrainTwo { | |||
if task.JobType == string(models.JobTypeDebug) { | |||
//result, err := modelarts.GetJob(task.JobID) | |||
result, err := modelarts.GetNotebook2(task.JobID) | |||
err := modelarts.HandleNotebookInfo(task) | |||
if err != nil { | |||
log.Error("GetJob(%s) failed:%v", task.JobName, err) | |||
log.Error("HandleNotebookInfo(%s) failed:%v", task.DisplayJobName, err) | |||
continue | |||
} | |||
if result != nil { | |||
oldStatus := task.Status | |||
task.Status = result.Status | |||
if task.StartTime == 0 && result.Lease.UpdateTime > 0 { | |||
task.StartTime = timeutil.TimeStamp(result.Lease.UpdateTime / 1000) | |||
} | |||
if task.EndTime == 0 && models.IsModelArtsDebugJobTerminal(task.Status) { | |||
task.EndTime = timeutil.TimeStampNow() | |||
} | |||
task.CorrectCreateUnix() | |||
task.ComputeAndSetDuration() | |||
if oldStatus != task.Status { | |||
notification.NotifyChangeCloudbrainStatus(task, oldStatus) | |||
} | |||
err = models.UpdateJob(task) | |||
if err != nil { | |||
log.Error("UpdateJob(%s) failed:%v", task.JobName, err) | |||
continue | |||
} | |||
} | |||
} else if task.JobType == string(models.JobTypeTrain) || task.JobType == string(models.JobTypeInference) { | |||
result, err := modelarts.GetTrainJob(task.JobID, strconv.FormatInt(task.VersionID, 10)) | |||
err := modelarts.HandleTrainJobInfo(task) | |||
if err != nil { | |||
log.Error("GetTrainJob(%s) failed:%v", task.JobName, err) | |||
log.Error("HandleTrainJobInfo(%s) failed:%v", task.DisplayJobName, err) | |||
continue | |||
} | |||
if result != nil { | |||
oldStatus := task.Status | |||
task.Status = modelarts.TransTrainJobStatus(result.IntStatus) | |||
task.Duration = result.Duration / 1000 | |||
task.TrainJobDuration = result.TrainJobDuration | |||
if task.StartTime == 0 && result.StartTime > 0 { | |||
task.StartTime = timeutil.TimeStamp(result.StartTime / 1000) | |||
} | |||
task.TrainJobDuration = models.ConvertDurationToStr(task.Duration) | |||
if task.EndTime == 0 && models.IsTrainJobTerminal(task.Status) && task.StartTime > 0 { | |||
task.EndTime = task.StartTime.Add(task.Duration) | |||
} | |||
task.CorrectCreateUnix() | |||
if oldStatus != task.Status { | |||
notification.NotifyChangeCloudbrainStatus(task, oldStatus) | |||
} | |||
err = models.UpdateJob(task) | |||
if err != nil { | |||
log.Error("UpdateJob(%s) failed:%v", task.JobName, err) | |||
continue | |||
} | |||
} | |||
} else { | |||
log.Error("task.JobType(%s) is error:%s", task.JobName, task.JobType) | |||
log.Error("task.JobType(%s) is error:%s", task.DisplayJobName, task.JobType) | |||
} | |||
} else if task.Type == models.TypeC2Net { | |||
result, err := grampus.GetJob(task.JobID) | |||
if err != nil { | |||
log.Error("GetTrainJob(%s) failed:%v", task.JobName, err) | |||
log.Error("GetTrainJob(%s) failed:%v", task.DisplayJobName, err) | |||
continue | |||
} | |||
@@ -3,6 +3,7 @@ package repo | |||
import ( | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
"io/ioutil" | |||
"net/http" | |||
"os" | |||
@@ -45,8 +46,7 @@ func GrampusTrainJobGPUNew(ctx *context.Context) { | |||
ctx.ServerError("get new train-job info failed", err) | |||
return | |||
} | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeC2Net, models.GPUResource, models.JobTypeTrain) | |||
ctx.Data["WaitCount"] = waitCount | |||
ctx.HTML(http.StatusOK, tplGrampusTrainJobGPUNew) | |||
} | |||
@@ -57,8 +57,6 @@ func GrampusTrainJobNPUNew(ctx *context.Context) { | |||
ctx.ServerError("get new train-job info failed", err) | |||
return | |||
} | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeC2Net, models.NPUResource, models.JobTypeTrain) | |||
ctx.Data["WaitCount"] = waitCount | |||
ctx.HTML(200, tplGrampusTrainJobNPUNew) | |||
} | |||
@@ -131,8 +129,12 @@ func grampusTrainJobNewDataPrepare(ctx *context.Context, processType string) err | |||
if processType == grampus.ProcessorTypeGPU { | |||
ctx.Data["datasetType"] = models.TypeCloudBrainOne | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeC2Net, models.GPUResource, models.JobTypeTrain) | |||
ctx.Data["WaitCount"] = waitCount | |||
} else if processType == grampus.ProcessorTypeNPU { | |||
ctx.Data["datasetType"] = models.TypeCloudBrainTwo | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeC2Net, models.NPUResource, models.JobTypeTrain) | |||
ctx.Data["WaitCount"] = waitCount | |||
} | |||
return nil | |||
@@ -213,6 +215,14 @@ func GrampusTrainJobGpuCreate(ctx *context.Context, form auth.CreateGrampusTrain | |||
return | |||
} | |||
bootFileExist, err := ctx.Repo.FileExists(bootFile, branchName) | |||
if err != nil || !bootFileExist { | |||
log.Error("Get bootfile error:", err, ctx.Data["MsgID"]) | |||
grampusTrainJobNewDataPrepare(ctx, grampus.ProcessorTypeGPU) | |||
ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_bootfile_err"), tplGrampusTrainJobGPUNew, &form) | |||
return | |||
} | |||
errStr := checkSpecialPool(ctx, "GPU") | |||
if errStr != "" { | |||
grampusTrainJobNewDataPrepare(ctx, grampus.ProcessorTypeGPU) | |||
@@ -280,7 +290,7 @@ func GrampusTrainJobGpuCreate(ctx *context.Context, form auth.CreateGrampusTrain | |||
if err := downloadZipCode(ctx, codeLocalPath, branchName); err != nil { | |||
log.Error("downloadZipCode failed, server timed out: %s (%v)", repo.FullName(), err, ctx.Data["MsgID"]) | |||
grampusTrainJobNewDataPrepare(ctx, grampus.ProcessorTypeGPU) | |||
ctx.RenderWithErr("Create task failed, internal error", tplGrampusTrainJobGPUNew, &form) | |||
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplGrampusTrainJobGPUNew, &form) | |||
return | |||
} | |||
@@ -289,7 +299,7 @@ func GrampusTrainJobGpuCreate(ctx *context.Context, form auth.CreateGrampusTrain | |||
if err := uploadCodeToMinio(codeLocalPath+"/", jobName, cloudbrain.CodeMountPath+"/"); err != nil { | |||
log.Error("Failed to uploadCodeToMinio: %s (%v)", repo.FullName(), err, ctx.Data["MsgID"]) | |||
grampusTrainJobNewDataPrepare(ctx, grampus.ProcessorTypeGPU) | |||
ctx.RenderWithErr("Create task failed, internal error", tplGrampusTrainJobGPUNew, &form) | |||
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplGrampusTrainJobGPUNew, &form) | |||
return | |||
} | |||
@@ -297,7 +307,7 @@ func GrampusTrainJobGpuCreate(ctx *context.Context, form auth.CreateGrampusTrain | |||
if err := mkModelPath(modelPath); err != nil { | |||
log.Error("Failed to mkModelPath: %s (%v)", repo.FullName(), err, ctx.Data["MsgID"]) | |||
grampusTrainJobNewDataPrepare(ctx, grampus.ProcessorTypeGPU) | |||
ctx.RenderWithErr("Create task failed, internal error", tplGrampusTrainJobGPUNew, &form) | |||
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplGrampusTrainJobGPUNew, &form) | |||
return | |||
} | |||
@@ -305,7 +315,7 @@ func GrampusTrainJobGpuCreate(ctx *context.Context, form auth.CreateGrampusTrain | |||
if err := uploadCodeToMinio(modelPath, jobName, cloudbrain.ModelMountPath+"/"); err != nil { | |||
log.Error("Failed to uploadCodeToMinio: %s (%v)", repo.FullName(), err, ctx.Data["MsgID"]) | |||
grampusTrainJobNewDataPrepare(ctx, grampus.ProcessorTypeGPU) | |||
ctx.RenderWithErr("Create task failed, internal error", tplGrampusTrainJobGPUNew, &form) | |||
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplGrampusTrainJobGPUNew, &form) | |||
return | |||
} | |||
@@ -338,7 +348,7 @@ func GrampusTrainJobGpuCreate(ctx *context.Context, form auth.CreateGrampusTrain | |||
EngineName: image, | |||
DatasetName: attachment.Name, | |||
IsLatestVersion: modelarts.IsLatestVersion, | |||
VersionCount: modelarts.VersionCount, | |||
VersionCount: modelarts.VersionCountOne, | |||
WorkServerNumber: 1, | |||
} | |||
@@ -388,7 +398,7 @@ func GrampusTrainJobNpuCreate(ctx *context.Context, form auth.CreateGrampusTrain | |||
branchName := form.BranchName | |||
isLatestVersion := modelarts.IsLatestVersion | |||
flavorName := form.FlavorName | |||
versionCount := modelarts.VersionCount | |||
versionCount := modelarts.VersionCountOne | |||
engineName := form.EngineName | |||
if !jobNamePattern.MatchString(displayJobName) { | |||
@@ -397,6 +407,14 @@ func GrampusTrainJobNpuCreate(ctx *context.Context, form auth.CreateGrampusTrain | |||
return | |||
} | |||
bootFileExist, err := ctx.Repo.FileExists(bootFile, branchName) | |||
if err != nil || !bootFileExist { | |||
log.Error("Get bootfile error:", err, ctx.Data["MsgID"]) | |||
grampusTrainJobNewDataPrepare(ctx, grampus.ProcessorTypeNPU) | |||
ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_bootfile_err"), tplGrampusTrainJobNPUNew, &form) | |||
return | |||
} | |||
errStr := checkSpecialPool(ctx, "NPU") | |||
if errStr != "" { | |||
grampusTrainJobNewDataPrepare(ctx, grampus.ProcessorTypeNPU) | |||
@@ -464,22 +482,22 @@ func GrampusTrainJobNpuCreate(ctx *context.Context, form auth.CreateGrampusTrain | |||
if err := downloadZipCode(ctx, codeLocalPath, branchName); err != nil { | |||
log.Error("downloadZipCode failed, server timed out: %s (%v)", repo.FullName(), err) | |||
grampusTrainJobNewDataPrepare(ctx, grampus.ProcessorTypeNPU) | |||
ctx.RenderWithErr("Create task failed, server timed out", tplGrampusTrainJobNPUNew, &form) | |||
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplGrampusTrainJobNPUNew, &form) | |||
return | |||
} | |||
//todo: upload code (send to file_server todo this work?) | |||
if err := obsMkdir(setting.CodePathPrefix + jobName + modelarts.OutputPath); err != nil { | |||
log.Error("Failed to obsMkdir_output: %s (%v)", repo.FullName(), err) | |||
grampusTrainJobNewDataPrepare(ctx, grampus.ProcessorTypeGPU) | |||
ctx.RenderWithErr("Failed to obsMkdir_output", tplGrampusTrainJobNPUNew, &form) | |||
grampusTrainJobNewDataPrepare(ctx, grampus.ProcessorTypeNPU) | |||
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplGrampusTrainJobNPUNew, &form) | |||
return | |||
} | |||
if err := uploadCodeToObs(codeLocalPath, jobName, ""); err != nil { | |||
log.Error("Failed to uploadCodeToObs: %s (%v)", repo.FullName(), err) | |||
grampusTrainJobNewDataPrepare(ctx, grampus.ProcessorTypeNPU) | |||
ctx.RenderWithErr("Failed to uploadCodeToObs", tplGrampusTrainJobNPUNew, &form) | |||
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplGrampusTrainJobNPUNew, &form) | |||
return | |||
} | |||
@@ -695,7 +713,7 @@ func GrampusTrainJobShow(ctx *context.Context) { | |||
taskList := make([]*models.Cloudbrain, 0) | |||
taskList = append(taskList, task) | |||
ctx.Data["version_list_task"] = taskList | |||
ctx.Data["datasetDownload"] = GetCloudBrainDataSetInfo(task.Uuid, false) | |||
ctx.Data["canDownload"] = cloudbrain.CanModifyJob(ctx, task) | |||
ctx.Data["displayJobName"] = task.DisplayJobName | |||
@@ -845,6 +863,9 @@ func downloadZipCode(ctx *context.Context, codePath, branchName string) error { | |||
log.Error("GetBranchCommit failed:" + err.Error()) | |||
return err | |||
} | |||
} else { | |||
log.Error("the branch is not exist: " + branchName) | |||
return fmt.Errorf("The branch does not exist.") | |||
} | |||
archivePath = path.Join(archivePath, grampus.CodeArchiveName) | |||
@@ -15,9 +15,6 @@ import ( | |||
"time" | |||
"unicode/utf8" | |||
"code.gitea.io/gitea/modules/notification" | |||
"code.gitea.io/gitea/modules/timeutil" | |||
"code.gitea.io/gitea/models" | |||
"code.gitea.io/gitea/modules/auth" | |||
"code.gitea.io/gitea/modules/base" | |||
@@ -26,9 +23,11 @@ import ( | |||
"code.gitea.io/gitea/modules/git" | |||
"code.gitea.io/gitea/modules/log" | |||
"code.gitea.io/gitea/modules/modelarts" | |||
"code.gitea.io/gitea/modules/notification" | |||
"code.gitea.io/gitea/modules/obs" | |||
"code.gitea.io/gitea/modules/setting" | |||
"code.gitea.io/gitea/modules/storage" | |||
"code.gitea.io/gitea/modules/timeutil" | |||
"code.gitea.io/gitea/modules/util" | |||
) | |||
@@ -119,8 +118,7 @@ func MustEnableModelArts(ctx *context.Context) { | |||
func NotebookNew(ctx *context.Context) { | |||
notebookNewDataPrepare(ctx) | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeCloudBrainTwo, "") | |||
ctx.Data["WaitCount"] = waitCount | |||
ctx.HTML(200, tplModelArtsNotebookNew) | |||
} | |||
@@ -150,6 +148,9 @@ func notebookNewDataPrepare(ctx *context.Context) error { | |||
ctx.Data["datasetType"] = models.TypeCloudBrainTwo | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeCloudBrainTwo, "") | |||
ctx.Data["WaitCount"] = waitCount | |||
return nil | |||
} | |||
@@ -270,66 +271,21 @@ func NotebookShow(ctx *context.Context) { | |||
return | |||
} | |||
result, err := modelarts.GetNotebook2(task.JobID) | |||
if err != nil { | |||
log.Error("GET job error", err.Error()) | |||
ctx.NotFound(ctx.Req.URL.RequestURI(), nil) | |||
return | |||
} | |||
if result != nil { | |||
if task.DeletedAt.IsZero() { //normal record | |||
if task.Status != result.Status { | |||
oldStatus := task.Status | |||
task.Status = result.Status | |||
models.ParseAndSetDurationFromModelArtsNotebook(result, task) | |||
notification.NotifyChangeCloudbrainStatus(task, oldStatus) | |||
err = models.UpdateJob(task) | |||
if err != nil { | |||
log.Error("GET job error", err.Error()) | |||
ctx.NotFound(ctx.Req.URL.RequestURI(), nil) | |||
return | |||
} | |||
} | |||
} else { //deleted record | |||
} | |||
if task.FlavorCode == "" { | |||
task.FlavorCode = result.Flavor | |||
if task.DeletedAt.IsZero() { //normal record | |||
err := modelarts.HandleNotebookInfo(task) | |||
if err != nil { | |||
ctx.Data["error"] = err.Error() | |||
ctx.RenderWithErr(err.Error(), tplModelArtsNotebookShow, nil) | |||
return | |||
} | |||
} else { //deleted record | |||
} | |||
datasetDownload := make([]models.DatasetDownload, 0) | |||
if ctx.IsSigned { | |||
if task.Uuid != "" && task.UserID == ctx.User.ID { | |||
uuidList := strings.Split(task.Uuid, ";") | |||
for _, uuidStr := range uuidList { | |||
attachment, err := models.GetAttachmentByUUID(uuidStr) | |||
if err != nil { | |||
log.Error("GetAttachmentByUUID failed:%v", err.Error()) | |||
return | |||
} | |||
dataset, err := models.GetDatasetByID(attachment.DatasetID) | |||
if err != nil { | |||
log.Error("GetDatasetByID failed:%v", err.Error()) | |||
return | |||
} | |||
repo, err := models.GetRepositoryByID(dataset.RepoID) | |||
if err != nil { | |||
log.Error("GetRepositoryByID failed:%v", err.Error()) | |||
return | |||
} | |||
datasetDownload = append(datasetDownload, models.DatasetDownload{ | |||
DatasetName: attachment.Name, | |||
DatasetDownloadLink: attachment.S3DownloadURL(), | |||
RepositoryLink: repo.Link() + "/datasets", | |||
}) | |||
} | |||
// datasetName, err := GetDatasetNameByUUID(task.Uuid) | |||
// if err == nil { | |||
// task.DatasetName = datasetName | |||
// } | |||
datasetDownload = GetCloudBrainDataSetInfo(task.Uuid, true) | |||
} | |||
} | |||
user, err := models.GetUserByID(task.UserID) | |||
@@ -375,6 +331,39 @@ func NotebookShow(ctx *context.Context) { | |||
ctx.HTML(200, tplModelArtsNotebookShow) | |||
} | |||
func GetCloudBrainDataSetInfo(uuid string, isNeedDown bool) []models.DatasetDownload { | |||
datasetDownload := make([]models.DatasetDownload, 0) | |||
uuidList := strings.Split(uuid, ";") | |||
for _, uuidStr := range uuidList { | |||
attachment, err := models.GetAttachmentByUUID(uuidStr) | |||
if err != nil { | |||
log.Error("GetAttachmentByUUID failed:%v", err.Error()) | |||
return datasetDownload | |||
} | |||
dataset, err := models.GetDatasetByID(attachment.DatasetID) | |||
if err != nil { | |||
log.Error("GetDatasetByID failed:%v", err.Error()) | |||
return datasetDownload | |||
} | |||
repo, err := models.GetRepositoryByID(dataset.RepoID) | |||
if err != nil { | |||
log.Error("GetRepositoryByID failed:%v", err.Error()) | |||
return datasetDownload | |||
} | |||
url := "" | |||
if isNeedDown { | |||
url = attachment.S3DownloadURL() | |||
} | |||
datasetDownload = append(datasetDownload, models.DatasetDownload{ | |||
DatasetName: attachment.Name, | |||
DatasetDownloadLink: url, | |||
RepositoryLink: repo.Link() + "/datasets", | |||
}) | |||
} | |||
return datasetDownload | |||
} | |||
func setShowSpecBySpecialPoolConfig(ctx *context.Context, findSpec bool, task *models.Cloudbrain) { | |||
modelarts.InitSpecialPool() | |||
if modelarts.SpecialPools != nil && !findSpec { | |||
@@ -427,82 +416,127 @@ func NotebookDebug2(ctx *context.Context) { | |||
ctx.Redirect(result.Url + "?token=" + result.Token) | |||
} | |||
func NotebookManage(ctx *context.Context) { | |||
var ID = ctx.Params(":id") | |||
var action = ctx.Params(":action") | |||
var resultCode = "0" | |||
func NotebookRestart(ctx *context.Context) { | |||
var id = ctx.Params(":id") | |||
var resultCode = "-1" | |||
var errorMsg = "" | |||
var status = "" | |||
task := ctx.Cloudbrain | |||
for { | |||
task, err := models.GetCloudbrainByID(ID) | |||
if err != nil { | |||
log.Error("get task(%s) failed:%v", task.JobName, err.Error(), ctx.Data["MsgID"]) | |||
resultCode = "-1" | |||
errorMsg = "system error" | |||
ctx.CheckWechatBind() | |||
if ctx.Written() { | |||
return | |||
} | |||
if task.Status != string(models.ModelArtsStopped) && task.Status != string(models.ModelArtsStartFailed) && task.Status != string(models.ModelArtsCreateFailed) { | |||
log.Error("the job(%s) is not stopped", task.JobName, ctx.Data["MsgID"]) | |||
errorMsg = "the job is not stopped" | |||
break | |||
} | |||
if action == models.ActionStop { | |||
if task.Status != string(models.ModelArtsRunning) { | |||
log.Error("the job(%s) is not running", task.JobName, ctx.Data["MsgID"]) | |||
resultCode = "-1" | |||
errorMsg = "the job is not running" | |||
break | |||
} | |||
if !ctx.IsSigned || (ctx.User.ID != task.UserID && !ctx.IsUserSiteAdmin() && !ctx.IsUserRepoOwner()) { | |||
log.Error("the user has no right ro stop the job", task.JobName, ctx.Data["MsgID"]) | |||
resultCode = "-1" | |||
errorMsg = "you have no right to stop the job" | |||
break | |||
} | |||
} else if action == models.ActionRestart { | |||
ctx.CheckWechatBind() | |||
if ctx.Written() { | |||
return | |||
} | |||
if task.Status != string(models.ModelArtsStopped) && task.Status != string(models.ModelArtsStartFailed) && task.Status != string(models.ModelArtsCreateFailed) { | |||
log.Error("the job(%s) is not stopped", task.JobName, ctx.Data["MsgID"]) | |||
resultCode = "-1" | |||
errorMsg = "the job is not stopped" | |||
count, err := models.GetCloudbrainNotebookCountByUserID(ctx.User.ID) | |||
if err != nil { | |||
log.Error("GetCloudbrainNotebookCountByUserID failed:%v", err, ctx.Data["MsgID"]) | |||
errorMsg = "system error" | |||
break | |||
} else { | |||
if count >= 1 { | |||
log.Error("the user already has running or waiting task", ctx.Data["MsgID"]) | |||
errorMsg = "you have already a running or waiting task, can not create more" | |||
break | |||
} | |||
} | |||
if !ctx.IsSigned || (ctx.User.ID != task.UserID && !ctx.IsUserSiteAdmin()) { | |||
log.Error("the user has no right ro restart the job", task.JobName, ctx.Data["MsgID"]) | |||
resultCode = "-1" | |||
errorMsg = "you have no right to restart the job" | |||
break | |||
} | |||
createTime := timeutil.TimeStampNow() | |||
param := models.NotebookAction{ | |||
Action: models.ActionStart, | |||
} | |||
count, err := models.GetCloudbrainNotebookCountByUserID(ctx.User.ID) | |||
if err != nil { | |||
log.Error("GetCloudbrainNotebookCountByUserID failed:%v", err, ctx.Data["MsgID"]) | |||
resultCode = "-1" | |||
errorMsg = "system error" | |||
break | |||
} else { | |||
if count >= 1 { | |||
log.Error("the user already has running or waiting task", ctx.Data["MsgID"]) | |||
resultCode = "-1" | |||
errorMsg = "you have already a running or waiting task, can not create more" | |||
break | |||
res, err := modelarts.ManageNotebook2(task.JobID, param) | |||
if err != nil { | |||
log.Error("ManageNotebook2(%s) failed:%v", task.DisplayJobName, err.Error(), ctx.Data["MsgID"]) | |||
/* 暂不处理再次调试502的场景,详情见方案 | |||
if strings.HasPrefix(err.Error(), modelarts.UnknownErrorPrefix) { | |||
log.Info("(%s)unknown error, set temp status", task.DisplayJobName) | |||
errTemp := models.InsertCloudbrainTemp(&models.CloudbrainTemp{ | |||
JobID: task.JobID, | |||
VersionID: models.TempVersionId, | |||
Status: models.TempJobStatus, | |||
Type: task.Type, | |||
JobName: task.JobName, | |||
JobType: task.JobType, | |||
}) | |||
if errTemp != nil { | |||
log.Error("InsertCloudbrainTemp failed: %v", errTemp.Error()) | |||
} | |||
} | |||
*/ | |||
errorMsg = err.Error() | |||
break | |||
} | |||
action = models.ActionStart | |||
} else { | |||
log.Error("the action(%s) is illegal", action, ctx.Data["MsgID"]) | |||
newTask := &models.Cloudbrain{ | |||
Status: res.Status, | |||
UserID: task.UserID, | |||
RepoID: task.RepoID, | |||
JobID: task.JobID, | |||
JobName: task.JobName, | |||
DisplayJobName: task.DisplayJobName, | |||
JobType: task.JobType, | |||
Type: task.Type, | |||
Uuid: task.Uuid, | |||
Image: task.Image, | |||
ComputeResource: task.ComputeResource, | |||
Description: task.Description, | |||
CreatedUnix: createTime, | |||
UpdatedUnix: createTime, | |||
FlavorCode: task.FlavorCode, | |||
FlavorName: task.FlavorName, | |||
} | |||
err = models.RestartCloudbrain(task, newTask) | |||
if err != nil { | |||
log.Error("RestartCloudbrain(%s) failed:%v", task.JobName, err.Error(), ctx.Data["MsgID"]) | |||
errorMsg = "system error" | |||
break | |||
} | |||
status = res.Status | |||
resultCode = "0" | |||
notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, strconv.FormatInt(newTask.ID, 10), newTask.DisplayJobName, models.ActionCreateDebugNPUTask) | |||
break | |||
} | |||
ctx.JSON(200, map[string]string{ | |||
"result_code": resultCode, | |||
"error_msg": errorMsg, | |||
"status": status, | |||
"id": id, | |||
}) | |||
} | |||
func NotebookStop(ctx *context.Context) { | |||
var id = ctx.Params(":id") | |||
var resultCode = "0" | |||
var errorMsg = "" | |||
var status = "" | |||
task := ctx.Cloudbrain | |||
for { | |||
if task.Status != string(models.ModelArtsRunning) { | |||
log.Error("the job(%s) is not running", task.JobName, ctx.Data["MsgID"]) | |||
resultCode = "-1" | |||
errorMsg = "非法操作" | |||
errorMsg = "the job is not running" | |||
break | |||
} | |||
param := models.NotebookAction{ | |||
Action: action, | |||
Action: models.ActionStop, | |||
} | |||
createTime := timeutil.TimeStampNow() | |||
res, err := modelarts.ManageNotebook2(task.JobID, param) | |||
if err != nil { | |||
log.Error("ManageNotebook2(%s) failed:%v", task.JobName, err.Error(), ctx.Data["MsgID"]) | |||
@@ -515,52 +549,21 @@ func NotebookManage(ctx *context.Context) { | |||
} | |||
status = res.Status | |||
if action == models.ActionStart { | |||
newTask := &models.Cloudbrain{ | |||
Status: status, | |||
UserID: task.UserID, | |||
RepoID: task.RepoID, | |||
JobID: task.JobID, | |||
JobName: task.JobName, | |||
DisplayJobName: task.DisplayJobName, | |||
JobType: task.JobType, | |||
Type: task.Type, | |||
Uuid: task.Uuid, | |||
Image: task.Image, | |||
ComputeResource: task.ComputeResource, | |||
Description: task.Description, | |||
CreatedUnix: createTime, | |||
UpdatedUnix: createTime, | |||
FlavorCode: task.FlavorCode, | |||
FlavorName: task.FlavorName, | |||
} | |||
err = models.RestartCloudbrain(task, newTask) | |||
if err != nil { | |||
log.Error("RestartCloudbrain(%s) failed:%v", task.JobName, err.Error(), ctx.Data["MsgID"]) | |||
resultCode = "-1" | |||
errorMsg = "system error" | |||
break | |||
} | |||
ID = strconv.FormatInt(newTask.ID, 10) | |||
notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, ID, task.DisplayJobName, models.ActionCreateDebugNPUTask) | |||
} else { | |||
oldStatus := task.Status | |||
task.Status = res.Status | |||
if task.EndTime == 0 && models.IsModelArtsDebugJobTerminal(task.Status) { | |||
task.EndTime = timeutil.TimeStampNow() | |||
} | |||
task.ComputeAndSetDuration() | |||
if oldStatus != task.Status { | |||
notification.NotifyChangeCloudbrainStatus(task, oldStatus) | |||
} | |||
err = models.UpdateJob(task) | |||
if err != nil { | |||
log.Error("UpdateJob(%s) failed:%v", task.JobName, err.Error(), ctx.Data["MsgID"]) | |||
resultCode = "-1" | |||
errorMsg = "system error" | |||
break | |||
} | |||
oldStatus := task.Status | |||
task.Status = res.Status | |||
if task.EndTime == 0 && models.IsModelArtsDebugJobTerminal(task.Status) { | |||
task.EndTime = timeutil.TimeStampNow() | |||
} | |||
task.ComputeAndSetDuration() | |||
if oldStatus != task.Status { | |||
notification.NotifyChangeCloudbrainStatus(task, oldStatus) | |||
} | |||
err = models.UpdateJob(task) | |||
if err != nil { | |||
log.Error("UpdateJob(%s) failed:%v", task.JobName, err.Error(), ctx.Data["MsgID"]) | |||
resultCode = "-1" | |||
errorMsg = "system error" | |||
break | |||
} | |||
break | |||
@@ -570,7 +573,7 @@ func NotebookManage(ctx *context.Context) { | |||
"result_code": resultCode, | |||
"error_msg": errorMsg, | |||
"status": status, | |||
"id": ID, | |||
"id": id, | |||
}) | |||
} | |||
@@ -670,8 +673,6 @@ func TrainJobNew(ctx *context.Context) { | |||
ctx.ServerError("get new train-job info failed", err) | |||
return | |||
} | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeCloudBrainTwo, "") | |||
ctx.Data["WaitCount"] = waitCount | |||
ctx.HTML(200, tplModelArtsTrainJobNew) | |||
} | |||
@@ -741,6 +742,8 @@ func trainJobNewDataPrepare(ctx *context.Context) error { | |||
} | |||
ctx.Data["config_list"] = configList.ParaConfigs | |||
ctx.Data["datasetType"] = models.TypeCloudBrainTwo | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeCloudBrainTwo, "") | |||
ctx.Data["WaitCount"] = waitCount | |||
return nil | |||
} | |||
@@ -857,6 +860,8 @@ func trainJobErrorNewDataPrepare(ctx *context.Context, form auth.CreateModelArts | |||
ctx.Data["dataset_name"] = datasetNames | |||
ctx.Data["branch_name"] = form.BranchName | |||
ctx.Data["datasetType"] = models.TypeCloudBrainTwo | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeCloudBrainTwo, "") | |||
ctx.Data["WaitCount"] = waitCount | |||
return nil | |||
} | |||
@@ -868,8 +873,6 @@ func TrainJobNewVersion(ctx *context.Context) { | |||
ctx.ServerError("get new train-job info failed", err) | |||
return | |||
} | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeCloudBrainTwo, "") | |||
ctx.Data["WaitCount"] = waitCount | |||
ctx.HTML(200, tplModelArtsTrainJobVersionNew) | |||
} | |||
@@ -962,6 +965,8 @@ func trainJobNewVersionDataPrepare(ctx *context.Context) error { | |||
return err | |||
} | |||
ctx.Data["config_list"] = configList.ParaConfigs | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeCloudBrainTwo, "") | |||
ctx.Data["WaitCount"] = waitCount | |||
return nil | |||
} | |||
@@ -1053,6 +1058,8 @@ func versionErrorDataPrepare(ctx *context.Context, form auth.CreateModelArtsTrai | |||
} | |||
ctx.Data["config_list"] = configList.ParaConfigs | |||
ctx.Data["datasetType"] = models.TypeCloudBrainTwo | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeCloudBrainTwo, "") | |||
ctx.Data["WaitCount"] = waitCount | |||
return nil | |||
} | |||
@@ -1077,10 +1084,10 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) | |||
outputObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.OutputPath + VersionOutputPath + "/" | |||
logObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.LogPath + VersionOutputPath + "/" | |||
// dataPath := "/" + setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + uuid + "/" | |||
branch_name := form.BranchName | |||
branchName := form.BranchName | |||
isLatestVersion := modelarts.IsLatestVersion | |||
FlavorName := form.FlavorName | |||
VersionCount := modelarts.VersionCount | |||
VersionCount := modelarts.VersionCountOne | |||
EngineName := form.EngineName | |||
count, err := models.GetCloudbrainTrainJobCountByUserID(ctx.User.ID) | |||
@@ -1105,6 +1112,14 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) | |||
return | |||
} | |||
bootFileExist, err := ctx.Repo.FileExists(bootFile, branchName) | |||
if err != nil || !bootFileExist { | |||
log.Error("Get bootfile error:", err) | |||
trainJobErrorNewDataPrepare(ctx, form) | |||
ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_bootfile_err"), tplModelArtsTrainJobNew, &form) | |||
return | |||
} | |||
errStr := checkModelArtsSpecialPool(ctx, flavorCode, string(models.JobTypeTrain)) | |||
if errStr != "" { | |||
trainJobErrorNewDataPrepare(ctx, form) | |||
@@ -1136,12 +1151,12 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) | |||
} | |||
gitRepo, _ := git.OpenRepository(repo.RepoPath()) | |||
commitID, _ := gitRepo.GetBranchCommitID(branch_name) | |||
commitID, _ := gitRepo.GetBranchCommitID(branchName) | |||
if err := downloadCode(repo, codeLocalPath, branch_name); err != nil { | |||
if err := downloadCode(repo, codeLocalPath, branchName); err != nil { | |||
log.Error("downloadCode failed, server timed out: %s (%v)", repo.FullName(), err) | |||
trainJobErrorNewDataPrepare(ctx, form) | |||
ctx.RenderWithErr("Create task failed, server timed out", tplModelArtsTrainJobNew, &form) | |||
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplModelArtsTrainJobNew, &form) | |||
return | |||
} | |||
@@ -1165,7 +1180,7 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) | |||
// if err := uploadCodeToObs(codeLocalPath, jobName, parentDir); err != nil { | |||
log.Error("Failed to uploadCodeToObs: %s (%v)", repo.FullName(), err) | |||
trainJobErrorNewDataPrepare(ctx, form) | |||
ctx.RenderWithErr("Failed to uploadCodeToObs", tplModelArtsTrainJobNew, &form) | |||
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplModelArtsTrainJobNew, &form) | |||
return | |||
} | |||
@@ -1280,7 +1295,7 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) | |||
Parameters: param, | |||
CommitID: commitID, | |||
IsLatestVersion: isLatestVersion, | |||
BranchName: branch_name, | |||
BranchName: branchName, | |||
Params: form.Params, | |||
FlavorName: FlavorName, | |||
EngineName: EngineName, | |||
@@ -1382,7 +1397,7 @@ func TrainJobCreateVersion(ctx *context.Context, form auth.CreateModelArtsTrainJ | |||
outputObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.OutputPath + VersionOutputPath + "/" | |||
logObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.LogPath + VersionOutputPath + "/" | |||
// dataPath := "/" + setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + uuid + "/" | |||
branch_name := form.BranchName | |||
branchName := form.BranchName | |||
PreVersionName := form.VersionName | |||
FlavorName := form.FlavorName | |||
EngineName := form.EngineName | |||
@@ -1402,6 +1417,14 @@ func TrainJobCreateVersion(ctx *context.Context, form auth.CreateModelArtsTrainJ | |||
return | |||
} | |||
bootFileExist, err := ctx.Repo.FileExists(bootFile, branchName) | |||
if err != nil || !bootFileExist { | |||
log.Error("Get bootfile error:", err) | |||
versionErrorDataPrepare(ctx, form) | |||
ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_bootfile_err"), tplModelArtsTrainJobVersionNew, &form) | |||
return | |||
} | |||
errStr := checkModelArtsSpecialPool(ctx, flavorCode, string(models.JobTypeTrain)) | |||
if errStr != "" { | |||
versionErrorDataPrepare(ctx, form) | |||
@@ -1416,11 +1439,11 @@ func TrainJobCreateVersion(ctx *context.Context, form auth.CreateModelArtsTrainJ | |||
} | |||
gitRepo, _ := git.OpenRepository(repo.RepoPath()) | |||
commitID, _ := gitRepo.GetBranchCommitID(branch_name) | |||
if err := downloadCode(repo, codeLocalPath, branch_name); err != nil { | |||
commitID, _ := gitRepo.GetBranchCommitID(branchName) | |||
if err := downloadCode(repo, codeLocalPath, branchName); err != nil { | |||
log.Error("Failed git clone repo to local(!: %s (%v)", repo.FullName(), err) | |||
versionErrorDataPrepare(ctx, form) | |||
ctx.RenderWithErr("Failed git clone repo to local!", tplModelArtsTrainJobVersionNew, &form) | |||
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplModelArtsTrainJobVersionNew, &form) | |||
return | |||
} | |||
@@ -1445,7 +1468,7 @@ func TrainJobCreateVersion(ctx *context.Context, form auth.CreateModelArtsTrainJ | |||
if err := uploadCodeToObs(codeLocalPath, jobName, parentDir); err != nil { | |||
log.Error("Failed to uploadCodeToObs: %s (%v)", repo.FullName(), err) | |||
versionErrorDataPrepare(ctx, form) | |||
ctx.RenderWithErr("Failed to uploadCodeToObs", tplModelArtsTrainJobVersionNew, &form) | |||
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplModelArtsTrainJobVersionNew, &form) | |||
return | |||
} | |||
@@ -1570,7 +1593,7 @@ func TrainJobCreateVersion(ctx *context.Context, form auth.CreateModelArtsTrainJ | |||
Parameters: param, | |||
PreVersionId: task.VersionID, | |||
CommitID: commitID, | |||
BranchName: branch_name, | |||
BranchName: branchName, | |||
FlavorName: FlavorName, | |||
EngineName: EngineName, | |||
PreVersionName: PreVersionName, | |||
@@ -1758,7 +1781,7 @@ func TrainJobShow(ctx *context.Context) { | |||
return | |||
} | |||
ctx.Data["canNewJob"] = canNewJob | |||
datasetList := make([][]models.DatasetDownload, 0) | |||
//将运行参数转化为epoch_size = 3, device_target = Ascend的格式 | |||
for i, task := range VersionListTasks { | |||
@@ -1781,7 +1804,7 @@ func TrainJobShow(ctx *context.Context) { | |||
} else { | |||
VersionListTasks[i].Parameters = "" | |||
} | |||
datasetList = append(datasetList, GetCloudBrainDataSetInfo(task.Uuid, false)) | |||
VersionListTasks[i].CanDel = cloudbrain.CanDeleteJob(ctx, &task.Cloudbrain) | |||
VersionListTasks[i].CanModify = cloudbrain.CanModifyJob(ctx, &task.Cloudbrain) | |||
} | |||
@@ -1793,64 +1816,11 @@ func TrainJobShow(ctx *context.Context) { | |||
ctx.Data["displayJobName"] = VersionListTasks[0].DisplayJobName | |||
ctx.Data["version_list_task"] = VersionListTasks | |||
ctx.Data["version_list_count"] = VersionListCount | |||
ctx.Data["datasetList"] = datasetList | |||
ctx.Data["canDownload"] = cloudbrain.CanModifyJob(ctx, &VersionListTasks[0].Cloudbrain) | |||
ctx.HTML(http.StatusOK, tplModelArtsTrainJobShow) | |||
} | |||
func TrainJobGetLog(ctx *context.Context) { | |||
ctx.Data["PageIsTrainJob"] = true | |||
var jobID = ctx.Params(":jobid") | |||
var logFileName = ctx.Query("file_name") | |||
var baseLine = ctx.Query("base_line") | |||
var order = ctx.Query("order") | |||
if order != modelarts.OrderDesc && order != modelarts.OrderAsc { | |||
log.Error("order(%s) check failed", order) | |||
ctx.HTML(http.StatusBadRequest, tplModelArtsTrainJobShow) | |||
return | |||
} | |||
task, err := models.GetCloudbrainByJobID(jobID) | |||
if err != nil { | |||
log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error()) | |||
ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobShow, nil) | |||
return | |||
} | |||
result, err := modelarts.GetTrainJobLog(jobID, strconv.FormatInt(task.VersionID, 10), baseLine, logFileName, order, modelarts.Lines) | |||
if err != nil { | |||
log.Error("GetTrainJobLog(%s) failed:%v", jobID, err.Error()) | |||
ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobShow, nil) | |||
return | |||
} | |||
ctx.Data["log"] = result | |||
//ctx.HTML(http.StatusOK, tplModelArtsTrainJobShow) | |||
} | |||
func trainJobGetLog(jobID string) (*models.GetTrainJobLogFileNamesResult, *models.GetTrainJobLogResult, error) { | |||
task, err := models.GetCloudbrainByJobID(jobID) | |||
if err != nil { | |||
log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error()) | |||
return nil, nil, err | |||
} | |||
resultLogFile, err := modelarts.GetTrainJobLogFileNames(jobID, strconv.FormatInt(task.VersionID, 10)) | |||
if err != nil { | |||
log.Error("GetTrainJobLogFileNames(%s) failed:%v", jobID, err.Error()) | |||
return nil, nil, err | |||
} | |||
result, err := modelarts.GetTrainJobLog(jobID, strconv.FormatInt(task.VersionID, 10), "", resultLogFile.LogFileList[0], modelarts.OrderDesc, modelarts.Lines) | |||
if err != nil { | |||
log.Error("GetTrainJobLog(%s) failed:%v", jobID, err.Error()) | |||
return nil, nil, err | |||
} | |||
return resultLogFile, result, err | |||
} | |||
func TrainJobDel(ctx *context.Context) { | |||
var jobID = ctx.Params(":jobid") | |||
var listType = ctx.Query("listType") | |||
@@ -1917,15 +1887,6 @@ func TrainJobStop(ctx *context.Context) { | |||
ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/modelarts/train-job?listType=" + listType) | |||
} | |||
func canUserCreateTrainJob(uid int64) (bool, error) { | |||
org, err := models.GetOrgByName(setting.AllowedOrg) | |||
if err != nil { | |||
log.Error("get allowed org failed: ", setting.AllowedOrg) | |||
return false, err | |||
} | |||
return org.IsOrgMember(uid) | |||
} | |||
func canUserCreateTrainJobVersion(ctx *context.Context, userID int64) (bool, error) { | |||
if ctx == nil || ctx.User == nil { | |||
log.Error("user unlogin!") | |||
@@ -2012,12 +1973,12 @@ func InferenceJobCreate(ctx *context.Context, form auth.CreateModelArtsInference | |||
resultObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.ResultPath + VersionOutputPath + "/" | |||
logObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.LogPath + VersionOutputPath + "/" | |||
dataPath := "/" + setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + uuid + "/" | |||
branch_name := form.BranchName | |||
branchName := form.BranchName | |||
FlavorName := form.FlavorName | |||
EngineName := form.EngineName | |||
LabelName := form.LabelName | |||
isLatestVersion := modelarts.IsLatestVersion | |||
VersionCount := modelarts.VersionCount | |||
VersionCount := modelarts.VersionCountOne | |||
trainUrl := form.TrainUrl | |||
modelName := form.ModelName | |||
modelVersion := form.ModelVersion | |||
@@ -2047,6 +2008,14 @@ func InferenceJobCreate(ctx *context.Context, form auth.CreateModelArtsInference | |||
return | |||
} | |||
bootFileExist, err := ctx.Repo.FileExists(bootFile, branchName) | |||
if err != nil || !bootFileExist { | |||
log.Error("Get bootfile error:", err) | |||
inferenceJobErrorNewDataPrepare(ctx, form) | |||
ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_bootfile_err"), tplModelArtsInferenceJobNew, &form) | |||
return | |||
} | |||
//Determine whether the task name of the task in the project is duplicated | |||
tasks, err := models.GetCloudbrainsByDisplayJobName(repo.ID, string(models.JobTypeInference), displayJobName) | |||
if err == nil { | |||
@@ -2079,12 +2048,12 @@ func InferenceJobCreate(ctx *context.Context, form auth.CreateModelArtsInference | |||
} | |||
gitRepo, _ := git.OpenRepository(repo.RepoPath()) | |||
commitID, _ := gitRepo.GetBranchCommitID(branch_name) | |||
commitID, _ := gitRepo.GetBranchCommitID(branchName) | |||
if err := downloadCode(repo, codeLocalPath, branch_name); err != nil { | |||
if err := downloadCode(repo, codeLocalPath, branchName); err != nil { | |||
log.Error("Create task failed, server timed out: %s (%v)", repo.FullName(), err) | |||
inferenceJobErrorNewDataPrepare(ctx, form) | |||
ctx.RenderWithErr("Create task failed, server timed out", tplModelArtsInferenceJobNew, &form) | |||
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplModelArtsInferenceJobNew, &form) | |||
return | |||
} | |||
@@ -2106,7 +2075,7 @@ func InferenceJobCreate(ctx *context.Context, form auth.CreateModelArtsInference | |||
if err := uploadCodeToObs(codeLocalPath, jobName, ""); err != nil { | |||
log.Error("Failed to uploadCodeToObs: %s (%v)", repo.FullName(), err) | |||
inferenceJobErrorNewDataPrepare(ctx, form) | |||
ctx.RenderWithErr("Failed to uploadCodeToObs", tplModelArtsInferenceJobNew, &form) | |||
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplModelArtsInferenceJobNew, &form) | |||
return | |||
} | |||
@@ -2165,7 +2134,7 @@ func InferenceJobCreate(ctx *context.Context, form auth.CreateModelArtsInference | |||
Uuid: uuid, | |||
Parameters: param, //modelarts train parameters | |||
CommitID: commitID, | |||
BranchName: branch_name, | |||
BranchName: branchName, | |||
Params: form.Params, | |||
FlavorName: FlavorName, | |||
EngineName: EngineName, | |||
@@ -2317,8 +2286,7 @@ func InferenceJobNew(ctx *context.Context) { | |||
ctx.ServerError("get new inference-job info failed", err) | |||
return | |||
} | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeCloudBrainTwo, "") | |||
ctx.Data["WaitCount"] = waitCount | |||
ctx.HTML(200, tplModelArtsInferenceJobNew) | |||
} | |||
func inferenceJobNewDataPrepare(ctx *context.Context) error { | |||
@@ -2389,6 +2357,8 @@ func inferenceJobNewDataPrepare(ctx *context.Context) error { | |||
}) | |||
ctx.Data["MODEL_COUNT"] = model_count | |||
ctx.Data["datasetType"] = models.TypeCloudBrainTwo | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeCloudBrainTwo, "") | |||
ctx.Data["WaitCount"] = waitCount | |||
return nil | |||
} | |||
@@ -2462,6 +2432,8 @@ func inferenceJobErrorNewDataPrepare(ctx *context.Context, form auth.CreateModel | |||
ctx.Data["ckpt_name"] = form.CkptName | |||
ctx.Data["train_url"] = form.TrainUrl | |||
ctx.Data["datasetType"] = models.TypeCloudBrainTwo | |||
waitCount := cloudbrain.GetWaitingCloudbrainCount(models.TypeCloudBrainTwo, "") | |||
ctx.Data["WaitCount"] = waitCount | |||
return nil | |||
} | |||
@@ -2515,7 +2487,7 @@ func InferenceJobShow(ctx *context.Context) { | |||
ctx.Data["displayJobName"] = task.DisplayJobName | |||
ctx.Data["task"] = task | |||
ctx.Data["canDownload"] = cloudbrain.CanModifyJob(ctx, task) | |||
ctx.Data["datasetDownload"] = GetCloudBrainDataSetInfo(task.Uuid, false) | |||
tempUids := []int64{} | |||
tempUids = append(tempUids, task.UserID) | |||
JobCreater, err := models.GetUserNamesByIDs(tempUids) | |||
@@ -1183,7 +1183,8 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
m.Group("/:id", func() { | |||
m.Get("", reqRepoCloudBrainReader, repo.NotebookShow) | |||
m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.NotebookDebug2) | |||
m.Post("/:action", reqRepoCloudBrainWriter, repo.NotebookManage) | |||
m.Post("/restart", cloudbrain.AdminOrJobCreaterRight, repo.NotebookRestart) | |||
m.Post("/stop", cloudbrain.AdminOrJobCreaterRight, repo.NotebookStop) | |||
m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.NotebookDel) | |||
}) | |||
m.Get("/create", reqWechatBind, reqRepoCloudBrainWriter, repo.NotebookNew) | |||
@@ -314,7 +314,7 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa | |||
res, err := client.Search(TableName).Query(boolQ).SortBy(getSort(SortBy, ascending, "num_stars", false)...).From(from).Size(Size).Highlight(queryHighlight("alias", "description", "topics")).Do(ctx.Req.Context()) | |||
if err == nil { | |||
esresult := makeRepoResult(res, Key, OnlyReturnNum, language) | |||
setForkRepoOrder(esresult) | |||
setForkRepoOrder(esresult, SortBy) | |||
resultObj.Total = resultObj.PrivateTotal + esresult.Total | |||
isNeedSort := false | |||
if len(resultObj.Result) > 0 { | |||
@@ -347,24 +347,26 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa | |||
} | |||
} | |||
func setForkRepoOrder(esresult *SearchRes) { | |||
forkidMap := make(map[string]int, 0) | |||
for index, re := range esresult.Result { | |||
if re["fork_id"] != nil { | |||
fork_id := re["fork_id"].(string) | |||
if _, ok := forkidMap[fork_id]; !ok { | |||
forkidMap[fork_id] = index | |||
func setForkRepoOrder(esresult *SearchRes, SortBy string) { | |||
if SortBy == "default" || SortBy == "" { | |||
forkidMap := make(map[string]int, 0) | |||
for index, re := range esresult.Result { | |||
if re["fork_id"] != nil { | |||
fork_id := re["fork_id"].(string) | |||
if _, ok := forkidMap[fork_id]; !ok { | |||
forkidMap[fork_id] = index | |||
} | |||
} | |||
} | |||
} | |||
for key, value := range forkidMap { | |||
for index, re := range esresult.Result { | |||
if re["id"].(string) == key { | |||
if value < index { //swap | |||
tmp := esresult.Result[index] | |||
esresult.Result[index] = esresult.Result[value] | |||
esresult.Result[value] = tmp | |||
break | |||
for key, value := range forkidMap { | |||
for index, re := range esresult.Result { | |||
if re["id"].(string) == key { | |||
if value < index { //swap | |||
tmp := esresult.Result[index] | |||
esresult.Result[index] = esresult.Result[value] | |||
esresult.Result[value] = tmp | |||
break | |||
} | |||
} | |||
} | |||
} | |||
@@ -761,10 +761,14 @@ func Cloudbrains(ctx *context.Context) { | |||
listType := ctx.Query("listType") | |||
jobType := ctx.Query("jobType") | |||
jobStatus := ctx.Query("jobStatus") | |||
aiCenter := ctx.Query("aiCenter") | |||
cluster := ctx.Query("cluster") | |||
ctx.Data["ListType"] = listType | |||
ctx.Data["JobType"] = jobType | |||
ctx.Data["JobStatus"] = jobStatus | |||
ctx.Data["aiCenter"] = aiCenter | |||
ctx.Data["cluster"] = cluster | |||
page := ctx.QueryInt("page") | |||
if page <= 0 { | |||
@@ -825,6 +829,8 @@ func Cloudbrains(ctx *context.Context) { | |||
RepoIDList: repoIDList, | |||
ComputeResource: listType, | |||
Type: models.TypeCloudBrainAll, | |||
AiCenter: aiCenter, | |||
Cluster: cluster, | |||
}) | |||
if err != nil { | |||
ctx.ServerError("Get job failed:", err) | |||
@@ -14,6 +14,10 @@ | |||
<div class="admin user"> | |||
<div class="cloudbrain_debug" style="display: none;" data-debug="{{$.i18n.Tr "repo.debug"}}" | |||
data-debug-again="{{$.i18n.Tr "repo.debug_again"}}" | |||
data-all-cluster="{{.i18n.Tr "cloudbrain.all_resource_cluster"}}" | |||
data-all-aiCenter="{{.i18n.Tr "cloudbrain.all_ai_center"}}" | |||
data-cluster-c2net="{{.i18n.Tr "cloudbrain.resource_cluster_c2net"}}" | |||
data-cluster-openi="{{.i18n.Tr "cloudbrain.resource_cluster_openi"}}" | |||
data-all-task="{{.i18n.Tr "admin.cloudbrain.all_task_types"}}" | |||
data-all-compute="{{.i18n.Tr "admin.cloudbrain.all_computing_resources"}}" | |||
data-all-status="{{.i18n.Tr "admin.cloudbrain.all_status"}}"></div> | |||
@@ -41,12 +45,12 @@ | |||
<div class="one wide column text center nowrap" style="width:6% !important;"> | |||
<span>{{$.i18n.Tr "repo.modelarts.cluster"}}</span> | |||
</div> | |||
<div class="one wide column text center nowrap" style="width:6% !important;"> | |||
<span>{{$.i18n.Tr "repo.cloudbrain_task_type"}}</span> | |||
</div> | |||
<div class="two wide column text center nowrap" style="width: 6% !important;"> | |||
<span>{{$.i18n.Tr "repo.modelarts.status"}}</span> | |||
</div> | |||
<div class="one wide column text center nowrap" style="width:6% !important;"> | |||
<span>{{$.i18n.Tr "repo.cloudbrain_task_type"}}</span> | |||
</div> | |||
<div class="two wide column text center nowrap" style="width: 8% !important;"> | |||
<span>{{$.i18n.Tr "repo.modelarts.createtime"}}</span> | |||
</div> | |||
@@ -8,43 +8,67 @@ | |||
</div> | |||
<div class="ui ten wide column" style="margin: 1rem 0;" id="adminCloud"> | |||
<div class="ui selection dropdown" style="min-width: 10em;min-height:2.6em;border-radius: .28571429rem;margin-right: 1em;padding: .67em 3.2em .7em 1em;"> | |||
<div class="default text" style="color: rgba(0,0,0,.87);">{{.i18n.Tr "cloudbrain.all_resource_cluster"}}</div> | |||
<i class="dropdown icon"></i> | |||
<div class="menu"> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster=&aiCenter={{$.aiCenter}}" data-value='{{.i18n.Tr "cloudbrain.all_resource_cluster"}}'>{{.i18n.Tr "cloudbrain.all_resource_cluster"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster=resource_cluster_openi&aiCenter={{$.aiCenter}}" data-value="{{.i18n.Tr "cloudbrain.resource_cluster_openi"}}">{{.i18n.Tr "cloudbrain.resource_cluster_openi"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster=resource_cluster_c2net&aiCenter={{$.aiCenter}}" data-value="{{.i18n.Tr "cloudbrain.resource_cluster_c2net"}}">{{.i18n.Tr "cloudbrain.resource_cluster_c2net"}}</a> | |||
</div> | |||
</div> | |||
<div class="ui selection dropdown" style="min-width: 10em;min-height:2.6em;border-radius: .28571429rem;margin-right: 1em;padding: .67em 3.2em .7em 1em;"> | |||
<div class="default text" style="color: rgba(0,0,0,.87);">{{.i18n.Tr "cloudbrain.all_ai_center"}}</div> | |||
<i class="dropdown icon"></i> | |||
<div class="menu"> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=" data-value='{{.i18n.Tr "cloudbrain.all_ai_center"}}'>{{.i18n.Tr "cloudbrain.all_ai_center"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=鹏城云计算所" data-value="鹏城云计算所">鹏城云计算所</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=成都智算" data-value="成都智算">成都智算</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=合肥类脑" data-value="合肥类脑">合肥类脑</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=octopus" data-value="octopus">octopus</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=武汉智算" data-value="武汉智算">武汉智算</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=西安智算" data-value="西安智算">西安智算</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=中原智算" data-value="中原智算">中原智算</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=许昌AI中心" data-value="许昌AI中心">许昌AI中心</a> | |||
</div> | |||
</div> | |||
<div class="ui selection dropdown" style="min-width: 10em;min-height:2.6em;border-radius: .28571429rem;margin-right: 1em;padding: .67em 3.2em .7em 1em;"> | |||
<div class="default text" style="color: rgba(0,0,0,.87);">{{.i18n.Tr "admin.cloudbrain.all_task_types"}}</div> | |||
<i class="dropdown icon"></i> | |||
<div class="menu"> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=&listType={{$.ListType}}&jobStatus={{$.JobStatus}}" data-value='{{.i18n.Tr "admin.cloudbrain.all_task_types"}}'>{{.i18n.Tr "admin.cloudbrain.all_task_types"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=DEBUG&listType={{$.ListType}}&jobStatus={{$.JobStatus}}" data-value="DEBUG">DEBUG</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=TRAIN&listType={{$.ListType}}&jobStatus={{$.JobStatus}}" data-value="TRAIN">TRAIN</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=INFERENCE&listType={{$.ListType}}&jobStatus={{$.JobStatus}}" data-value="INFERENCE">INFERENCE</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=BENCHMARK&listType={{$.ListType}}&jobStatus={{$.JobStatus}}" data-value="BENCHMARK">BENCHMARK</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=SNN4IMAGENET&listType={{$.ListType}}&jobStatus={{$.JobStatus}}" data-value="SNN4IMAGENET">SNN4IMAGENET</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=BRAINSCORE&listType={{$.ListType}}&jobStatus={{$.JobStatus}}" data-value="BRAINSCORE">BRAINSCORE</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value='{{.i18n.Tr "admin.cloudbrain.all_task_types"}}'>{{.i18n.Tr "admin.cloudbrain.all_task_types"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=DEBUG&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="DEBUG">DEBUG</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=TRAIN&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="TRAIN">TRAIN</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=INFERENCE&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="INFERENCE">INFERENCE</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=BENCHMARK&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="BENCHMARK">BENCHMARK</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=SNN4IMAGENET&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="SNN4IMAGENET">SNN4IMAGENET</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=BRAINSCORE&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="BRAINSCORE">BRAINSCORE</a> | |||
</div> | |||
</div> | |||
<div class="ui selection dropdown" style="min-width: 10em;min-height:2.6em;border-radius: .28571429rem;margin-right: 1em;padding: .67em 3.2em .7em 1em;"> | |||
<div class="default text" style="color: rgba(0,0,0,.87);">{{.i18n.Tr "admin.cloudbrain.all_computing_resources"}}</div> | |||
<i class="dropdown icon"></i> | |||
<div class="menu"> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType=&jobStatus={{$.JobStatus}}" data-value='{{.i18n.Tr "admin.cloudbrain.all_computing_resources"}}'>{{.i18n.Tr "admin.cloudbrain.all_computing_resources"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType=CPU/GPU&jobStatus={{$.JobStatus}}" data-value="CPU/GPU">CPU/GPU</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType=NPU&jobStatus={{$.JobStatus}}" data-value="NPU">NPU</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType=&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value='{{.i18n.Tr "admin.cloudbrain.all_computing_resources"}}'>{{.i18n.Tr "admin.cloudbrain.all_computing_resources"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType=CPU/GPU&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="CPU/GPU">CPU/GPU</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType=NPU&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="NPU">NPU</a> | |||
</div> | |||
</div> | |||
<div class="ui selection dropdown" style="min-width: 10em;min-height:2.6em;border-radius: .28571429rem;margin-right: 1em;padding: .67em 3.2em .7em 1em;"> | |||
<div class="default text" style="color: rgba(0,0,0,.87);">{{.i18n.Tr "admin.cloudbrain.all_status"}}</div> | |||
<i class="dropdown icon"></i> | |||
<div class="menu"> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=" data-value='{{.i18n.Tr "admin.cloudbrain.all_status"}}'>{{.i18n.Tr "admin.cloudbrain.all_status"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=STARTING" data-value="STARTING">STARTING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=RUNNING" data-value="RUNNING">RUNNING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=RESTARTING" data-value="RESTARTING">RESTARTING </a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=START_FAILED" data-value="START_FAILED">START_FAILED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=STOPPING" data-value="STOPPING">STOPPING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=STOPPED" data-value="STOPPED">STOPPED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=WAITING" data-value="WAITING">WAITING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=COMPLETED" data-value="COMPLETED">COMPLETED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=SUCCEEDED" data-value="SUCCEEDED">SUCCEEDED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=FAILED" data-value="FAILED">FAILED </a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=other" data-value="OTHER">OTHER</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value='{{.i18n.Tr "admin.cloudbrain.all_status"}}'>{{.i18n.Tr "admin.cloudbrain.all_status"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=STARTING&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="STARTING">STARTING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=RUNNING&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="RUNNING">RUNNING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=RESTARTING&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="RESTARTING">RESTARTING </a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=START_FAILED&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="START_FAILED">START_FAILED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=STOPPING&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="STOPPING">STOPPING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=STOPPED&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="STOPPED">STOPPED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=WAITING&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="WAITING">WAITING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=COMPLETED&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="COMPLETED">COMPLETED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=SUCCEEDED&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="SUCCEEDED">SUCCEEDED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=FAILED&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="FAILED">FAILED </a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=other&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="OTHER">OTHER</a> | |||
</div> | |||
</div> |
@@ -20,43 +20,67 @@ | |||
<div class="row"> | |||
<div class="ui {{if $.PageIsUserCloudBrain}}sixteen{{else}}six{{end}} wide column" style="margin: 1rem 0;" id="userCloud"> | |||
<div class="ui selection dropdown" style="min-width: 10em;min-height:2.6em;border-radius: .28571429rem;margin-right: 1em;padding: .67em 3.2em .7em 1em;"> | |||
<div class="default text" style="color: rgba(0,0,0,.87);">{{.i18n.Tr "cloudbrain.all_resource_cluster"}}</div> | |||
<i class="dropdown icon"></i> | |||
<div class="menu"> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster=&aiCenter={{$.aiCenter}}" data-value='{{.i18n.Tr "cloudbrain.all_resource_cluster"}}'>{{.i18n.Tr "cloudbrain.all_resource_cluster"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster=resource_cluster_openi&aiCenter={{$.aiCenter}}" data-value="{{.i18n.Tr "cloudbrain.resource_cluster_openi"}}">{{.i18n.Tr "cloudbrain.resource_cluster_openi"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster=resource_cluster_c2net&aiCenter={{$.aiCenter}}" data-value="{{.i18n.Tr "cloudbrain.resource_cluster_c2net"}}">{{.i18n.Tr "cloudbrain.resource_cluster_c2net"}}</a> | |||
</div> | |||
</div> | |||
<div class="ui selection dropdown" style="min-width: 10em;min-height:2.6em;border-radius: .28571429rem;margin-right: 1em;padding: .67em 3.2em .7em 1em;"> | |||
<div class="default text" style="color: rgba(0,0,0,.87);">{{.i18n.Tr "cloudbrain.all_ai_center"}}</div> | |||
<i class="dropdown icon"></i> | |||
<div class="menu"> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=" data-value='{{.i18n.Tr "cloudbrain.all_ai_center"}}'>{{.i18n.Tr "cloudbrain.all_ai_center"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=鹏城云计算所" data-value="鹏城云计算所">鹏城云计算所</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=成都智算" data-value="成都智算">成都智算</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=合肥类脑" data-value="合肥类脑">合肥类脑</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=octopus" data-value="octopus">octopus</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=武汉智算" data-value="武汉智算">武汉智算</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=西安智算" data-value="西安智算">西安智算</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=中原智算" data-value="中原智算">中原智算</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter=许昌AI中心" data-value="许昌AI中心">许昌AI中心</a> | |||
</div> | |||
</div> | |||
<div class="ui selection dropdown" style="min-width: 10em;min-height:2.6em;border-radius: .28571429rem;margin-right: 1em;padding: .67em 3.2em .7em 1em;"> | |||
<div class="default text" style="color: rgba(0,0,0,.87);">{{.i18n.Tr "admin.cloudbrain.all_task_types"}}</div> | |||
<i class="dropdown icon"></i> | |||
<div class="menu"> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=&listType={{$.ListType}}&jobStatus={{$.JobStatus}}" data-value='{{.i18n.Tr "admin.cloudbrain.all_task_types"}}'>{{.i18n.Tr "admin.cloudbrain.all_task_types"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=DEBUG&listType={{$.ListType}}&jobStatus={{$.JobStatus}}" data-value="DEBUG">{{.i18n.Tr "cloudbrain.DEBUG"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=TRAIN&listType={{$.ListType}}&jobStatus={{$.JobStatus}}" data-value="TRAIN">{{.i18n.Tr "cloudbrain.TRAIN"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=INFERENCE&listType={{$.ListType}}&jobStatus={{$.JobStatus}}" data-value="INFERENCE">{{.i18n.Tr "cloudbrain.INFERENCE"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=BENCHMARK&listType={{$.ListType}}&jobStatus={{$.JobStatus}}" data-value="BENCHMARK">{{.i18n.Tr "cloudbrain.BENCHMARK"}}</a> | |||
<!-- <a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=SNN4IMAGENET&listType={{$.ListType}}&jobStatus={{$.JobStatus}}" data-value="BENCHMARK">{{.i18n.Tr "cloudbrain.SNN4IMAGENET"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=BRAINSCORE&listType={{$.ListType}}&jobStatus={{$.JobStatus}}" data-value="BENCHMARK">{{.i18n.Tr "cloudbrain.BRAINSCORE"}}</a> --> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value='{{.i18n.Tr "admin.cloudbrain.all_task_types"}}'>{{.i18n.Tr "admin.cloudbrain.all_task_types"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=DEBUG&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="DEBUG">{{.i18n.Tr "cloudbrain.DEBUG"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=TRAIN&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="TRAIN">{{.i18n.Tr "cloudbrain.TRAIN"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=INFERENCE&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="INFERENCE">{{.i18n.Tr "cloudbrain.INFERENCE"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=BENCHMARK&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="BENCHMARK">{{.i18n.Tr "cloudbrain.BENCHMARK"}}</a> | |||
<!-- <a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=SNN4IMAGENET&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="BENCHMARK">{{.i18n.Tr "cloudbrain.SNN4IMAGENET"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType=BRAINSCORE&listType={{$.ListType}}&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="BENCHMARK">{{.i18n.Tr "cloudbrain.BRAINSCORE"}}</a> --> | |||
</div> | |||
</div> | |||
<div class="ui selection dropdown" style="min-width: 10em;min-height:2.6em;border-radius: .28571429rem;margin-right: 1em;padding: .67em 3.2em .7em 1em;"> | |||
<div class="default text" style="color: rgba(0,0,0,.87);">{{.i18n.Tr "admin.cloudbrain.all_computing_resources"}}</div> | |||
<i class="dropdown icon"></i> | |||
<div class="menu"> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType=&jobStatus={{$.JobStatus}}" data-value='{{.i18n.Tr "admin.cloudbrain.all_computing_resources"}}'>{{.i18n.Tr "admin.cloudbrain.all_computing_resources"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType=CPU/GPU&jobStatus={{$.JobStatus}}" data-value="CPU/GPU">CPU/GPU</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType=NPU&jobStatus={{$.JobStatus}}" data-value="NPU">NPU</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType=&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value='{{.i18n.Tr "admin.cloudbrain.all_computing_resources"}}'>{{.i18n.Tr "admin.cloudbrain.all_computing_resources"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType=CPU/GPU&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="CPU/GPU">CPU/GPU</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType=NPU&jobStatus={{$.JobStatus}}&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="NPU">NPU</a> | |||
</div> | |||
</div> | |||
<div class="ui selection dropdown" style="min-width: 10em;min-height:2.6em;border-radius: .28571429rem;margin-right: 1em;padding: .67em 3.2em .7em 1em;"> | |||
<div class="default text" style="color: rgba(0,0,0,.87);">{{.i18n.Tr "admin.cloudbrain.all_status"}}</div> | |||
<i class="dropdown icon"></i> | |||
<div class="menu"> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=" data-value='{{.i18n.Tr "admin.cloudbrain.all_status"}}'>{{.i18n.Tr "admin.cloudbrain.all_status"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=STARTING" data-value="STARTING">STARTING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=RUNNING" data-value="RUNNING">RUNNING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=RESTARTING" data-value="RESTARTING">RESTARTING </a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=START_FAILED" data-value="START_FAILED">START_FAILED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=STOPPING" data-value="STOPPING">STOPPING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=STOPPED" data-value="STOPPED">STOPPED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=WAITING" data-value="WAITING">WAITING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=COMPLETED" data-value="COMPLETED">COMPLETED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=SUCCEEDED" data-value="SUCCEEDED">SUCCEEDED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=FAILED" data-value="FAILED">FAILED </a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=other" data-value="OTHER">OTHER</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value='{{.i18n.Tr "admin.cloudbrain.all_status"}}'>{{.i18n.Tr "admin.cloudbrain.all_status"}}</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=STARTING&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="STARTING">STARTING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=RUNNING&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="RUNNING">RUNNING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=RESTARTING&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="RESTARTING">RESTARTING </a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=START_FAILED&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="START_FAILED">START_FAILED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=STOPPING&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="STOPPING">STOPPING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=STOPPED&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="STOPPED">STOPPED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=WAITING&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="WAITING">WAITING</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=COMPLETED&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="COMPLETED">COMPLETED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=SUCCEEDED&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="SUCCEEDED">SUCCEEDED</a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=FAILED&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="FAILED">FAILED </a> | |||
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&jobType={{$.JobType}}&listType={{$.ListType}}&jobStatus=other&cluster={{$.cluster}}&aiCenter={{$.aiCenter}}" data-value="OTHER">OTHER</a> | |||
</div> | |||
</div> | |||
@@ -0,0 +1,21 @@ | |||
<div id="mask"> | |||
<div class="loadingWrap"> | |||
<div id="loading-page"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
<div | |||
style=" | |||
margin-top: 10%; | |||
font-size: 14px; | |||
color: #101010; | |||
font-family: SourceHanSansSC-regular; | |||
" | |||
> | |||
任务正在准备中,喝杯水回来再看看~ | |||
</div> | |||
</div> | |||
</div> |
@@ -90,7 +90,7 @@ | |||
<div class="ui container"> | |||
<div class="ui center am-pt-30 am-pb-30"> | |||
<h2>智算网络</h2> | |||
<p><span class="ui text grey">人工智能算力网络推进联盟已接入10家智算中心,算力总规模1542P</p> | |||
<p><span class="ui text grey">人工智能算力网络推进联盟已接入11家智算中心,算力总规模1924P</p> | |||
</div> | |||
<div id="app" v-cloak> | |||
@@ -200,22 +200,23 @@ | |||
<div class="six wide column"> | |||
<img class="ui centered large image" src="/img/i-yunnao.svg"> | |||
</div> | |||
<div class="ten wide column am-pt-30"> | |||
<div class="ten wide column"> | |||
<h2 class="ui grey inverted header">{{.page_dev_yunlao}}</h2> | |||
<p class="am-lh-18 ui text grey"> | |||
{{.page_dev_yunlao_desc1}}<br> | |||
{{.page_dev_yunlao_desc2}}<br> | |||
{{.page_dev_yunlao_desc3}}<br> | |||
{{.page_dev_yunlao_desc4}}<br> | |||
{{.page_dev_yunlao_desc4}}<br> | |||
{{.page_dev_yunlao_desc5}}<br> | |||
</p> | |||
{{if .IsSigned}} | |||
<a class="ui blue basic button am-mt-20" href="{{AppSubUrl}}/dashboard">{{.page_use}}</a> | |||
<a class="ui blue basic button am-mt-10" href="{{AppSubUrl}}/dashboard">{{.page_use}}</a> | |||
{{else}} | |||
<a class="ui blue basic button am-mt-20" href="{{AppSubUrl}}/user/login">{{.page_use}}</a> | |||
<a class="ui blue basic button am-mt-10" href="{{AppSubUrl}}/user/login">{{.page_use}}</a> | |||
{{end}} | |||
<a class="ui grey basic button am-mt-20" href="mailto:aiforge@openi.org.cn">{{.page_dev_yunlao_apply}}</a> | |||
<a class="ui grey basic button am-mt-10" href="mailto:aiforge@openi.org.cn">{{.page_dev_yunlao_apply}}</a> | |||
</div> | |||
</div> | |||
</div> | |||
@@ -3,7 +3,7 @@ | |||
{{template "repo/header" .}} | |||
<div class="ui container"> | |||
<input type="hidden" id="postPath" value="{{.Link}}"> | |||
<div style="width: 80%;margin: auto;"> | |||
<div> | |||
<h4 class="ui top attached header"> | |||
{{$.i18n.Tr "dataset.upload_dataset_file"}} | |||
</h4> | |||
@@ -54,7 +54,7 @@ | |||
</div> | |||
</div> | |||
</div> | |||
<div style="width: 80%;margin: auto;padding-top: 2em;"> | |||
<div style="padding-top: 2em;"> | |||
<!-- <p>说明:<br> | |||
- 只有<span class="text blue">zip格式</span>zip格式的数据集才能发起云脑任务;<br> | |||
- 云脑1提供 <span class="text blue">CPU / GPU</span> 资源,云脑2提供 <span class="text blue">Ascend NPU</span> 资源;调试使用的数据集也需要上传到对应的环境。 | |||
@@ -30,7 +30,7 @@ | |||
<div class="column"> | |||
<div class="ui blue small menu compact selectcloudbrain"> | |||
<a class="item" href="{{.RepoLink}}/debugjob?debugListType=all">{{$.i18n.Tr "repo.modelarts.notebook"}}</a> | |||
<a class="item" href="{{.RepoLink}}/modelarts/train-job">{{$.i18n.Tr "repo.modelarts.train_job"}}</a> | |||
<a class="item" href="{{.RepoLink}}/modelarts/train-job?listType=all">{{$.i18n.Tr "repo.modelarts.train_job"}}</a> | |||
<a class="item" href="{{.RepoLink}}/modelarts/inference-job">{{$.i18n.Tr "repo.modelarts.infer_job"}}</a> | |||
<a class="active item" href="{{.RepoLink}}/cloudbrain/benchmark">{{$.i18n.Tr "repo.modelarts.evaluate_job"}}</a> | |||
</div> | |||
@@ -28,18 +28,7 @@ | |||
white-space: nowrap !important; | |||
} | |||
</style> | |||
<!-- <div class="ui page dimmer"> | |||
<div class="ui text loader">{{.i18n.Tr "loading"}}</div> | |||
</div> --> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
{{template "custom/global_mask" .}} | |||
<div class="repository"> | |||
{{template "repo/header" .}} | |||
<div class="ui container"> | |||
@@ -36,15 +36,7 @@ | |||
white-space: nowrap !important; | |||
} | |||
</style> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
{{template "custom/global_mask" .}} | |||
<div class="repository"> | |||
{{template "repo/header" .}} | |||
<div class="ui container"> | |||
@@ -141,6 +133,9 @@ | |||
</div> | |||
</div> | |||
<span > | |||
<i class="question circle icon" data-content="{{.i18n.Tr "cloudbrain.model_file_postfix_rule"}}" data-position="top center" data-variation="inverted mini"></i> | |||
</span> | |||
</div> | |||
<!-- AI引擎 --> | |||
@@ -248,7 +248,7 @@ | |||
class="cti-mgRight-sm">{{$.i18n.Tr "repo.modelarts.train_job.dura_time"}}:</span> | |||
<span class="cti-mgRight-sm uc-accordionTitle-black" | |||
id="{{.VersionName}}-duration-span">{{$.duration}}</span> | |||
<span id="refresh-status" data-tooltip="刷新" style="cursor: pointer;" data-inverted="" data-version="{{.VersionName}}"><i | |||
<span class="refresh-status" data-tooltip="刷新" style="cursor: pointer;" data-inverted="" data-version="{{.VersionName}}"><i | |||
class="redo icon redo-color"></i></span> | |||
</div> | |||
@@ -468,7 +468,9 @@ | |||
<td class="ti-text-form-content"> | |||
<div class="text-span text-span-w"> | |||
{{.DatasetName}} | |||
{{range $m ,$n := $.datasetDownload}} | |||
<a href="{{.RepositoryLink}}" target="_blank">{{.DatasetName}}</a> | |||
{{end}} | |||
</div> | |||
</td> | |||
</tr> | |||
@@ -1,91 +1,7 @@ | |||
{{template "base/head" .}} | |||
<style> | |||
/* 遮罩层css效果图 */ | |||
#mask { | |||
position: fixed; | |||
top: 0px; | |||
left: 0px; | |||
right: 0px; | |||
bottom: 0px; | |||
filter: alpha(opacity=60); | |||
background-color: #777; | |||
z-index: 1000; | |||
display: none; | |||
opacity: 0.8; | |||
-moz-opacity: 0.5; | |||
padding-top: 100px; | |||
color: #000000 | |||
} | |||
/* 加载圈css效果图 */ | |||
#loadingPage { | |||
margin: 200px auto; | |||
width: 50px; | |||
height: 40px; | |||
text-align: center; | |||
font-size: 10px; | |||
display: block; | |||
} | |||
#loadingPage>div { | |||
background-color: green; | |||
height: 100%; | |||
width: 6px; | |||
display: inline-block; | |||
-webkit-animation: sk-stretchdelay 1.2s infinite ease-in-out; | |||
animation: sk-stretchdelay 1.2s infinite ease-in-out; | |||
} | |||
#loadingPage .rect2 { | |||
-webkit-animation-delay: -1.1s; | |||
animation-delay: -1.1s; | |||
} | |||
#loadingPage .rect3 { | |||
-webkit-animation-delay: -1.0s; | |||
animation-delay: -1.0s; | |||
} | |||
#loadingPage .rect4 { | |||
-webkit-animation-delay: -0.9s; | |||
animation-delay: -0.9s; | |||
} | |||
#loadingPage .rect5 { | |||
-webkit-animation-delay: -0.8s; | |||
animation-delay: -0.8s; | |||
} | |||
@-webkit-keyframes sk-stretchdelay { | |||
0%, | |||
40%, | |||
100% { | |||
-webkit-transform: scaleY(0.4) | |||
} | |||
20% { | |||
-webkit-transform: scaleY(1.0) | |||
} | |||
} | |||
@keyframes sk-stretchdelay { | |||
0%, | |||
40%, | |||
100% { | |||
transform: scaleY(0.4); | |||
-webkit-transform: scaleY(0.4); | |||
} | |||
20% { | |||
transform: scaleY(1.0); | |||
-webkit-transform: scaleY(1.0); | |||
} | |||
} | |||
.inline.required.field.cloudbrain_benchmark { | |||
display: none; | |||
} | |||
@@ -97,25 +13,11 @@ | |||
.inline.required.field.cloudbrain_brainscore { | |||
display: none; | |||
} | |||
.icons { | |||
/* position: absolute !important; | |||
right: 150px; | |||
top: 14px; | |||
z-index: 2; */ | |||
} | |||
</style> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
{{template "custom/global_mask" .}} | |||
<div class="repository"> | |||
{{template "repo/header" .}} | |||
@@ -330,7 +232,6 @@ | |||
let min_value_task = value_task.toLowerCase() | |||
$("input[name='display_job_name']").attr("value", min_value_task) | |||
document.getElementById("mask").style.display = "block" | |||
} | |||
// 页面加载完毕后遮罩层隐藏 | |||
@@ -345,44 +246,11 @@ | |||
.dropdown({ | |||
placeholder: "选择数据集类别", | |||
}) | |||
console.log("=======================") | |||
// $(document).ready(function(){ | |||
// let waitNums = $('.cloudbrain-type').data('queue').split('map')[1] | |||
// let test = new Map() | |||
// let waitNumsArray = waitNums.split(' ') | |||
// waitNumsArray.forEach((element,index) => { | |||
// if(index===0){ | |||
// test.set(element.slice(1,-2),parseInt(element.slice(-1))) | |||
// }else if(index===waitNumsArray.length-1){ | |||
// test.set(element.slice(0,-3),parseInt(element.slice(-2,-1))) | |||
// }else{ | |||
// test.set(element.slice(0,-2),parseInt(element.slice(-1))) | |||
// } | |||
// }); | |||
// console.log(test) | |||
// $('.ui.search.dropdown.gpu-type').dropdown({ | |||
// onChange: function(value, text, $selectedItem) { | |||
// console.log("=-------------",value) | |||
// console.log("=-------------",test.get(value)) | |||
// let gpuTypeNums= test.get(value) | |||
// $('#gpu-nums').text("{{.i18n.Tr "repo.wait_count_start"}}"+gpuTypeNums+"{{.i18n.Tr "repo.wait_count_end"}}") | |||
// } | |||
// }); | |||
// }) | |||
// $('#cloudbrain_image').select2({ | |||
// placeholder: "选择镜像" | |||
// }); | |||
$(".ui.button.reset").click(function (e) { | |||
e.preventDefault() | |||
$('#cloudbrain_benchmark_category') | |||
.dropdown("clear", true) | |||
}) | |||
$(".ui.positive.button.active.all_selected").click(function (e) { | |||
e.preventDefault() | |||
var selected_value = new Array() | |||
@@ -252,7 +252,7 @@ | |||
</span> | |||
<span class="cti-mgRight-sm uc-accordionTitle-black" | |||
id="{{.VersionName}}-duration-span">{{$.duration}}</span> | |||
<span id="refresh-status" data-tooltip="刷新" style="cursor: pointer;" data-inverted="" data-version="{{.VersionName}}"> | |||
<span class="refresh-status" data-tooltip="刷新" style="cursor: pointer;" data-inverted="" data-version="{{.VersionName}}"> | |||
<i class="redo icon redo-color"></i> | |||
</span> | |||
</div> | |||
@@ -412,7 +412,9 @@ | |||
<td class="ti-text-form-content"> | |||
<div class="text-span text-span-w" | |||
id="{{.VersionName}}-BenchmarkTypeName"> | |||
{{.DatasetName}} | |||
{{range $m ,$n := $.datasetDownload}} | |||
<a href="{{.RepositoryLink}}" target="_blank">{{.DatasetName}}</a> | |||
{{end}} | |||
</div> | |||
</td> | |||
</tr> | |||
@@ -64,18 +64,7 @@ | |||
} | |||
</style> | |||
<!-- <div class="ui page dimmer"> | |||
<div class="ui text loader">{{.i18n.Tr "loading"}}</div> | |||
</div> --> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
{{template "custom/global_mask" .}} | |||
<div class="repository"> | |||
{{template "repo/header" .}} | |||
<div class="ui container"> | |||
@@ -272,6 +272,8 @@ | |||
class="cti-mgRight-sm">{{$.i18n.Tr "repo.modelarts.train_job.dura_time"}}:</span> | |||
<span class="cti-mgRight-sm uc-accordionTitle-black" | |||
id="{{.VersionName}}-duration-span">{{$.duration}}</span> | |||
<span class="refresh-status" data-tooltip="刷新" style="cursor: pointer;" data-inverted="" data-version="{{.VersionName}}"><i | |||
class="redo icon redo-color"></i></span> | |||
</div> | |||
</span> | |||
@@ -428,7 +430,9 @@ | |||
<td class="ti-text-form-content"> | |||
<div class="text-span text-span-w"> | |||
{{.DatasetName}} | |||
{{range $m ,$n := $.datasetDownload}} | |||
<a href="{{.RepositoryLink}}" target="_blank">{{.DatasetName}}</a> | |||
{{end}} | |||
</div> | |||
</td> | |||
</tr> | |||
@@ -698,7 +702,7 @@ | |||
hideMenu(); | |||
} | |||
} | |||
let dirKey="isOnlyDir--:&"; | |||
function loadSelectedModelFile(trainJob){ | |||
console.log("trainJob=" + trainJob); | |||
$('#choice_file').dropdown('clear') | |||
@@ -713,7 +717,7 @@ | |||
var zNodes=[]; | |||
var nodesMap={}; | |||
for (let i=0;i<n_length;i++){ | |||
parentNodeMap = nodesMap; | |||
var parentNodeMap = nodesMap; | |||
var fileSplits = data[i].FileName.split("/"); | |||
for(let j=0;j < fileSplits.length;j++){ | |||
if(fileSplits[j] == ""){ | |||
@@ -722,7 +726,22 @@ | |||
if(parentNodeMap[fileSplits[j]] == null){ | |||
parentNodeMap[fileSplits[j]] = {}; | |||
} | |||
parentNodeMap = parentNodeMap[fileSplits[j]] | |||
parentNodeMap = parentNodeMap[fileSplits[j]]; | |||
} | |||
} | |||
for (let i=0;i<n_length;i++){ | |||
var parentNodeMap = nodesMap; | |||
var fileSplits = data[i].FileName.split("/"); | |||
for(let j=0;j < fileSplits.length;j++){ | |||
if(fileSplits[j] == ""){ | |||
if(data[i].FileName[data[i].FileName.length -1] =="/"){ | |||
if(Object.keys(parentNodeMap).length ==0){ | |||
parentNodeMap[dirKey]="true"; | |||
} | |||
} | |||
break; | |||
} | |||
parentNodeMap = parentNodeMap[fileSplits[j]]; | |||
} | |||
} | |||
convertToNode(zNodes,nodesMap); | |||
@@ -742,12 +761,17 @@ | |||
node["name"] = keyList[i]; | |||
nodeList.push(node); | |||
if(nodesMap[keyList[i]] != null && Object.keys(nodesMap[keyList[i]]).length >0){ | |||
node["children"]=[]; | |||
if(isFirst){ | |||
node["open"] = true; | |||
isFirst= false; | |||
if(nodesMap[keyList[i]][dirKey] != null){ | |||
node["open"] = false; | |||
node["isParent"] = true; | |||
}else{ | |||
node["children"]=[]; | |||
if(isFirst){ | |||
node["open"] = true; | |||
isFirst= false; | |||
} | |||
convertToNode(node["children"],nodesMap[keyList[i]]); | |||
} | |||
convertToNode(node["children"],nodesMap[keyList[i]]); | |||
} | |||
} | |||
} | |||
@@ -19,90 +19,6 @@ | |||
height: 100%; | |||
} | |||
/* 弹窗 */ | |||
#mask { | |||
position: fixed; | |||
top: 0px; | |||
left: 0px; | |||
right: 0px; | |||
bottom: 0px; | |||
filter: alpha(opacity=60); | |||
background-color: #777; | |||
z-index: 1000; | |||
display: none; | |||
opacity: 0.8; | |||
-moz-opacity: 0.5; | |||
padding-top: 100px; | |||
color: #000000 | |||
} | |||
#loadingPage { | |||
margin: 200px auto; | |||
width: 50px; | |||
height: 40px; | |||
text-align: center; | |||
font-size: 10px; | |||
display: block; | |||
} | |||
#loadingPage>div { | |||
background-color: green; | |||
height: 100%; | |||
width: 6px; | |||
display: inline-block; | |||
-webkit-animation: sk-stretchdelay 1.2s infinite ease-in-out; | |||
animation: sk-stretchdelay 1.2s infinite ease-in-out; | |||
} | |||
#loadingPage .rect2 { | |||
-webkit-animation-delay: -1.1s; | |||
animation-delay: -1.1s; | |||
} | |||
#loadingPage .rect3 { | |||
-webkit-animation-delay: -1.0s; | |||
animation-delay: -1.0s; | |||
} | |||
#loadingPage .rect4 { | |||
-webkit-animation-delay: -0.9s; | |||
animation-delay: -0.9s; | |||
} | |||
#loadingPage .rect5 { | |||
-webkit-animation-delay: -0.8s; | |||
animation-delay: -0.8s; | |||
} | |||
@-webkit-keyframes sk-stretchdelay { | |||
0%, | |||
40%, | |||
100% { | |||
-webkit-transform: scaleY(0.4) | |||
} | |||
20% { | |||
-webkit-transform: scaleY(1.0) | |||
} | |||
} | |||
@keyframes sk-stretchdelay { | |||
0%, | |||
40%, | |||
100% { | |||
transform: scaleY(0.4); | |||
-webkit-transform: scaleY(0.4); | |||
} | |||
20% { | |||
transform: scaleY(1.0); | |||
-webkit-transform: scaleY(1.0); | |||
} | |||
} | |||
/* 消息框 */ | |||
.alert { | |||
@@ -203,17 +119,6 @@ | |||
} | |||
</style> | |||
<!-- 弹窗 --> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
<div class="alert"></div> | |||
<div class="repository release dataset-list view"> | |||
{{template "repo/header" .}} | |||
@@ -230,7 +135,7 @@ | |||
<a class="active item" | |||
href="{{.RepoLink}}/debugjob?debugListType=all">{{$.i18n.Tr "repo.modelarts.notebook"}}</a> | |||
<a class="item" | |||
href="{{.RepoLink}}/modelarts/train-job">{{$.i18n.Tr "repo.modelarts.train_job"}}</a> | |||
href="{{.RepoLink}}/modelarts/train-job?listType=all">{{$.i18n.Tr "repo.modelarts.train_job"}}</a> | |||
<a class="item" | |||
href="{{.RepoLink}}/modelarts/inference-job">{{$.i18n.Tr "repo.modelarts.infer_job"}}</a> | |||
<a class="item" | |||
@@ -502,6 +407,16 @@ | |||
</div> | |||
</div> | |||
<div class="ui mini modal debug-again"> | |||
<div class="header">{{$.QueuesDetail}}</div> | |||
<div class="content"> | |||
<p>1111</p> | |||
</div> | |||
<div class="actions"> | |||
<div class="ui mini negative button">Cancel</div> | |||
<div class="ui mini positive button">OK</div> | |||
</div> | |||
</div> | |||
</div> | |||
{{template "base/footer" .}} | |||
<script> | |||
@@ -56,18 +56,7 @@ | |||
font-size: 14px !important; | |||
} | |||
</style> | |||
<!-- <div class="ui page dimmer"> | |||
<div class="ui text loader">{{.i18n.Tr "loading"}}</div> | |||
</div> --> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
{{template "custom/global_mask" .}} | |||
<div class="repository"> | |||
{{template "repo/header" .}} | |||
<div class="ui container"> | |||
@@ -51,18 +51,7 @@ | |||
font-size: 14px !important; | |||
} | |||
</style> | |||
<!-- <div class="ui page dimmer"> | |||
<div class="ui text loader">{{.i18n.Tr "loading"}}</div> | |||
</div> --> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
{{template "custom/global_mask" .}} | |||
<div class="repository"> | |||
{{template "repo/header" .}} | |||
<div class="ui container"> | |||
@@ -209,15 +209,7 @@ | |||
box-shadow: 0 2px 3px 0 rgb(34 36 38 / 15%); | |||
} | |||
</style> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
{{template "custom/global_mask" .}} | |||
<div class="repository"> | |||
{{template "repo/header" .}} | |||
<div class="ui container"> | |||
@@ -265,7 +257,7 @@ | |||
class="cti-mgRight-sm">{{$.i18n.Tr "repo.modelarts.train_job.dura_time"}}:</span> | |||
<span class="cti-mgRight-sm uc-accordionTitle-black" | |||
id="{{.VersionName}}-duration-span">{{.TrainJobDuration}}</span> | |||
<span id="refresh-status" data-tooltip="刷新" style="cursor: pointer;" data-inverted="" data-version="{{.VersionName}}"> | |||
<span class="refresh-status" data-tooltip="刷新" style="cursor: pointer;" data-inverted="" data-version="{{.VersionName}}"> | |||
<i class="redo icon redo-color"></i> | |||
</span> | |||
@@ -289,10 +281,8 @@ | |||
<div class="content-pad"> | |||
<div class="ui pointing secondary menu" style="border-bottom: 1px solid rgba(34,36,38,.15);"> | |||
<a class="active item" | |||
data-tab="first{{$k}}">{{$.i18n.Tr "repo.modelarts.train_job.config"}}</a> | |||
<a class="item" data-tab="second{{$k}}" | |||
onclick="loadLog({{.VersionName}})">{{$.i18n.Tr "repo.modelarts.log"}}</a> | |||
<a class="active item" data-tab="first{{$k}}">{{$.i18n.Tr "repo.modelarts.train_job.config"}}</a> | |||
<a class="item log_bottom" data-tab="second{{$k}}" data-version="{{.VersionName}}">{{$.i18n.Tr "repo.modelarts.log"}}</a> | |||
<a class="item load-model-file" data-tab="third{{$k}}" data-download-flag="{{$.canDownload}}" data-path="{{$.RepoLink}}/modelarts/train-job/{{.JobID}}/model_list" data-version="{{.VersionName}}" data-parents="" data-filename="" data-init="init" >{{$.i18n.Tr "repo.model_download"}}</a> | |||
</div> | |||
<div class="ui tab active" data-tab="first{{$k}}"> | |||
@@ -428,7 +418,9 @@ | |||
<td class="ti-text-form-content"> | |||
<div class="text-span text-span-w"> | |||
{{.DatasetName}} | |||
{{range $m ,$n := $.datasetDownload}} | |||
<a href="{{.RepositoryLink}}" target="_blank">{{.DatasetName}}</a> | |||
{{end}} | |||
</div> | |||
</td> | |||
</tr> | |||
@@ -477,11 +469,23 @@ | |||
</div> | |||
<div class="ui tab" data-tab="second{{$k}}"> | |||
<div style="position: relative;"> | |||
<span> | |||
<a title="滚动到顶部" style="position: absolute; right: -32px;cursor: pointer;" | |||
class="log_top" data-version="{{.VersionName}}"><i class="icon-to-top"></i></a> | |||
</span> | |||
<span class="log-info-{{.VersionName}}"> | |||
<a title="滚动到底部" style="position: absolute; bottom: 10px;right: -32px;cursor: pointer;" | |||
class="log_bottom" data-version="{{.VersionName}}"><i | |||
class="icon-to-bottom"></i></a> | |||
</span> | |||
<div class="ui message message{{.VersionName}}" style="display: none;"> | |||
<div id="header"></div> | |||
</div> | |||
<div class="ui attached log" id="log{{.VersionName}}" | |||
<div class="ui attached log" id="log{{.VersionName}}" | |||
style="height: 300px !important; overflow: auto;"> | |||
<div class="ui inverted active dimmer"> | |||
<div class="ui loader"></div> | |||
</div> | |||
<input type="hidden" name="end_line" value> | |||
<input type="hidden" name="start_line" value> | |||
<pre id="log_file{{.VersionName}}"></pre> | |||
@@ -687,7 +691,7 @@ | |||
hideMenu(); | |||
} | |||
} | |||
let dirKey="isOnlyDir--:&"; | |||
function loadSelectedModelFile(trainJob){ | |||
console.log("trainJob=" + trainJob); | |||
$('#choice_file').dropdown('clear') | |||
@@ -710,7 +714,7 @@ | |||
var zNodes=[]; | |||
var nodesMap={}; | |||
for (let i=0;i<n_length;i++){ | |||
parentNodeMap = nodesMap; | |||
var parentNodeMap = nodesMap; | |||
var fileSplits = data[i].FileName.split("/"); | |||
for(let j=0;j < fileSplits.length;j++){ | |||
if(fileSplits[j] == ""){ | |||
@@ -719,7 +723,22 @@ | |||
if(parentNodeMap[fileSplits[j]] == null){ | |||
parentNodeMap[fileSplits[j]] = {}; | |||
} | |||
parentNodeMap = parentNodeMap[fileSplits[j]] | |||
parentNodeMap = parentNodeMap[fileSplits[j]]; | |||
} | |||
} | |||
for (let i=0;i<n_length;i++){ | |||
var parentNodeMap = nodesMap; | |||
var fileSplits = data[i].FileName.split("/"); | |||
for(let j=0;j < fileSplits.length;j++){ | |||
if(fileSplits[j] == ""){ | |||
if(data[i].FileName[data[i].FileName.length -1] =="/"){ | |||
if(Object.keys(parentNodeMap).length ==0){ | |||
parentNodeMap[dirKey]="true"; | |||
} | |||
} | |||
break; | |||
} | |||
parentNodeMap = parentNodeMap[fileSplits[j]]; | |||
} | |||
} | |||
convertToNode(zNodes,nodesMap); | |||
@@ -739,12 +758,17 @@ | |||
node["name"] = keyList[i]; | |||
nodeList.push(node); | |||
if(nodesMap[keyList[i]] != null && Object.keys(nodesMap[keyList[i]]).length >0){ | |||
node["children"]=[]; | |||
if(isFirst){ | |||
node["open"] = true; | |||
isFirst= false; | |||
if(nodesMap[keyList[i]][dirKey] != null){ | |||
node["open"] = false; | |||
node["isParent"] = true; | |||
}else{ | |||
node["children"]=[]; | |||
if(isFirst){ | |||
node["open"] = true; | |||
isFirst= false; | |||
} | |||
convertToNode(node["children"],nodesMap[keyList[i]]); | |||
} | |||
convertToNode(node["children"],nodesMap[keyList[i]]); | |||
} | |||
} | |||
} | |||
@@ -769,7 +793,7 @@ | |||
} | |||
if (srcEngine == 'mindspore') { | |||
$('#choice_Engine .default.text').text("MindSpore"); | |||
$('#choice_Engine input[name="Engine"]').val(1) | |||
$('#choice_Engine input[name="Engine"]').val(2) | |||
} | |||
} | |||
}else{ | |||
@@ -866,17 +890,4 @@ | |||
size = size.toFixed(0);//保留的小数位数 | |||
return size + unitArr[index]; | |||
} | |||
function loadLog(version_name) { | |||
document.getElementById("mask").style.display = "block" | |||
$.get(`/api/v1/repos/${userName}/${repoPath}/grampus/train-job/${jobID}/log?version_name=${version_name}&lines=50&order=asc`, (data) => { | |||
$('input[name=end_line]').val(data.EndLine) | |||
$('input[name=start_line]').val(data.StartLine) | |||
$(`#log_file${version_name}`).text(data.Content) | |||
document.getElementById("mask").style.display = "none" | |||
}).fail(function (err) { | |||
document.getElementById("mask").style.display = "none" | |||
console.log(err); | |||
}); | |||
} | |||
</script> |
@@ -10,16 +10,6 @@ | |||
} | |||
</style> | |||
<!-- 弹窗 --> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
<!-- 提示框 --> | |||
<div class="alert"></div> | |||
@@ -33,7 +23,7 @@ | |||
<div class="column"> | |||
<div class="ui blue small menu compact selectcloudbrain"> | |||
<a class="item" href="{{.RepoLink}}/debugjob?debugListType=all">{{$.i18n.Tr "repo.modelarts.notebook"}}</a> | |||
<a class="item" href="{{.RepoLink}}/modelarts/train-job">{{$.i18n.Tr "repo.modelarts.train_job"}}</a> | |||
<a class="item" href="{{.RepoLink}}/modelarts/train-job?listType=all">{{$.i18n.Tr "repo.modelarts.train_job"}}</a> | |||
<a class="active item" href="{{.RepoLink}}/modelarts/inference-job">{{$.i18n.Tr "repo.modelarts.infer_job"}}</a> | |||
<a class="item" href="{{.RepoLink}}/cloudbrain/benchmark">{{$.i18n.Tr "repo.modelarts.evaluate_job"}}</a> | |||
</div> | |||
@@ -35,15 +35,7 @@ | |||
white-space: nowrap !important; | |||
} | |||
</style> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
{{template "custom/global_mask" .}} | |||
<div class="repository"> | |||
{{template "repo/header" .}} | |||
<div class="ui container"> | |||
@@ -141,7 +133,7 @@ | |||
</div> | |||
<span > | |||
<i class="question circle icon" data-content="{{.i18n.Tr "cloudbrain.model_file_path_rule"}}" data-position="top center" data-variation="inverted mini"></i> | |||
<i class="question circle icon" data-content="{{.i18n.Tr "cloudbrain.model_file_path_rule"}} {{.i18n.Tr "cloudbrain.model_file_postfix_rule"}}" data-position="top center" data-variation="inverted mini"></i> | |||
</span> | |||
</div> | |||
<!-- AI引擎 --> | |||
@@ -199,7 +199,7 @@ td, th { | |||
class="cti-mgRight-sm">{{$.i18n.Tr "repo.modelarts.train_job.dura_time"}}:</span> | |||
<span class="cti-mgRight-sm uc-accordionTitle-black" | |||
id="{{.VersionName}}-duration-span">{{.TrainJobDuration}}</span> | |||
<span id="refresh-status" data-tooltip="刷新" style="cursor: pointer;" data-inverted="" data-version="{{.VersionName}}"><i | |||
<span class="refresh-status" data-tooltip="刷新" style="cursor: pointer;" data-inverted="" data-version="{{.VersionName}}"><i | |||
class="redo icon redo-color"></i></span> | |||
</div> | |||
@@ -409,7 +409,9 @@ td, th { | |||
<td class="ti-text-form-content"> | |||
<div class="text-span text-span-w"> | |||
{{.DatasetName}} | |||
{{range $m ,$n := $.datasetDownload}} | |||
<a href="{{.RepositoryLink}}" target="_blank">{{.DatasetName}}</a> | |||
{{end}} | |||
</div> | |||
</td> | |||
</tr> | |||
@@ -463,7 +465,7 @@ td, th { | |||
<a title="滚动到顶部" style="position: absolute; right: -32px;cursor: pointer;" | |||
class="log_top" data-version="{{.VersionName}}"><i class="icon-to-top"></i></a> | |||
</span> | |||
<span> | |||
<span class="log-info-{{.VersionName}}"> | |||
<a title="滚动到底部" style="position: absolute; bottom: 10px;right: -32px;cursor: pointer;" | |||
class="log_bottom" data-version="{{.VersionName}}"><i | |||
class="icon-to-bottom"></i></a> | |||
@@ -472,6 +474,9 @@ td, th { | |||
<div id="header"></div> | |||
</div> | |||
<div class="ui attached log log-scroll" data-version="{{.VersionName}}" id="log{{.VersionName}}" style="height: 300px !important; overflow: auto;"> | |||
<div class="ui inverted active dimmer"> | |||
<div class="ui loader"></div> | |||
</div> | |||
<input type="hidden" name="end_line" value> | |||
<input type="hidden" name="start_line" value> | |||
<pre id="log_file{{.VersionName}}"></pre> | |||
@@ -5,15 +5,7 @@ | |||
} | |||
</style> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
{{template "custom/global_mask" .}} | |||
<div class="repository"> | |||
{{template "repo/header" .}} | |||
<div class="repository new repo ui middle very relaxed page grid"> | |||
@@ -208,15 +208,6 @@ | |||
padding-top: 0.5rem; | |||
} | |||
</style> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
<div class="repository"> | |||
{{template "repo/header" .}} | |||
<div class="ui container"> | |||
@@ -257,7 +248,7 @@ | |||
class="cti-mgRight-sm">{{$.i18n.Tr "repo.modelarts.train_job.dura_time"}}:</span> | |||
<span class="cti-mgRight-sm uc-accordionTitle-black" | |||
id="{{.VersionName}}-duration-span">{{$.duration}}</span> | |||
<span id="refresh-status" data-tooltip="刷新" style="cursor: pointer;" data-inverted="" data-version="{{.VersionName}}"> | |||
<span class="refresh-status" data-tooltip="刷新" style="cursor: pointer;" data-inverted="" data-version="{{.VersionName}}"> | |||
<i class="redo icon redo-color"></i> | |||
</span> | |||
</div> | |||
@@ -448,7 +439,7 @@ | |||
<tbody> | |||
{{range $.datasetDownload}} | |||
<tr> | |||
<td style="word-wrap: break-word;word-break: break-all;"><a href="{{.RepositoryLink}}">{{.DatasetName}}</a></td> | |||
<td style="word-wrap: break-word;word-break: break-all;"><a href="{{.RepositoryLink}}" target="_blank">{{.DatasetName}}</a></td> | |||
<td style="word-wrap: break-word;word-break: break-all;">{{.DatasetDownloadLink}}</td> | |||
<td class="center aligned"><a class="ui poping up clipboard" id="clipboard-btn" data-original="{{$.i18n.Tr "repo.copy_link"}}" data-success="{{$.i18n.Tr "repo.copy_link_success"}}" data-error="{{$.i18n.Tr "repo.copy_link_error"}}" data-content="{{$.i18n.Tr "repo.copy_link"}}" data-variation="inverted tiny" data-clipboard-text="{{.DatasetDownloadLink}}">复制链接</a></td> | |||
</tr> | |||
@@ -33,7 +33,7 @@ | |||
<div class="column"> | |||
<div class="ui blue small menu compact selectcloudbrain"> | |||
<a class="item" href="{{.RepoLink}}/debugjob?debugListType=all">{{$.i18n.Tr "repo.modelarts.notebook"}}</a> | |||
<a class="active item" href="{{.RepoLink}}/modelarts/train-job">{{$.i18n.Tr "repo.modelarts.train_job"}}</a> | |||
<a class="active item" href="{{.RepoLink}}/modelarts/train-job?modelarts/train-job?listType=all">{{$.i18n.Tr "repo.modelarts.train_job"}}</a> | |||
<a class="item" href="{{.RepoLink}}/modelarts/inference-job">{{$.i18n.Tr "repo.modelarts.infer_job"}}</a> | |||
<a class="item" href="{{.RepoLink}}/cloudbrain/benchmark">{{$.i18n.Tr "repo.modelarts.evaluate_job"}}</a> | |||
</div> | |||
@@ -58,15 +58,7 @@ | |||
<!-- <div class="ui page dimmer"> | |||
<div class="ui text loader">{{.i18n.Tr "loading"}}</div> | |||
</div> --> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
{{template "custom/global_mask" .}} | |||
<div class="repository"> | |||
{{template "repo/header" .}} | |||
<div class="ui container"> | |||
@@ -215,15 +215,7 @@ | |||
box-shadow: 0 2px 3px 0 rgb(34 36 38 / 15%); | |||
} | |||
</style> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
{{template "custom/global_mask" .}} | |||
<div class="repository"> | |||
{{template "repo/header" .}} | |||
<div class="ui container"> | |||
@@ -307,7 +299,7 @@ | |||
class="cti-mgRight-sm">{{$.i18n.Tr "repo.modelarts.train_job.dura_time"}}:</span> | |||
<span class="cti-mgRight-sm uc-accordionTitle-black" | |||
id="{{.VersionName}}-duration-span">{{.TrainJobDuration}}</span> | |||
<span id="refresh-status" data-tooltip="刷新" style="cursor: pointer;" data-inverted="" data-version="{{.VersionName}}"> | |||
<span class="refresh-status" data-tooltip="刷新" style="cursor: pointer;" data-inverted="" data-version="{{.VersionName}}"> | |||
<i class="redo icon redo-color"></i> | |||
</span> | |||
</div> | |||
@@ -460,7 +452,13 @@ | |||
<td class="ti-text-form-content"> | |||
<div class="text-span text-span-w"> | |||
{{.DatasetName}} | |||
{{range $m ,$n := $.datasetList}} | |||
{{if eq $k $m}} | |||
{{range $f ,$g := $n}} | |||
<a href="{{.RepositoryLink}}" target="_blank">{{.DatasetName}}</a> | |||
{{end}} | |||
{{end}} | |||
{{end}} | |||
</div> | |||
</td> | |||
</tr> | |||
@@ -512,7 +510,7 @@ | |||
<a title="滚动到顶部" style="position: absolute; right: -32px;cursor: pointer;" | |||
class="log_top" data-version="{{.VersionName}}"><i class="icon-to-top"></i></a> | |||
</span> | |||
<span> | |||
<span class="log-info-{{.VersionName}}"> | |||
<a title="滚动到底部" style="position: absolute; bottom: 10px;right: -32px;cursor: pointer;" | |||
class="log_bottom" data-version="{{.VersionName}}"><i | |||
class="icon-to-bottom"></i></a> | |||
@@ -522,6 +520,9 @@ | |||
</div> | |||
<div class="ui attached log log-scroll" id="log{{.VersionName}}" data-version="{{.VersionName}}" | |||
style="height: 300px !important; overflow: auto;"> | |||
<div class="ui inverted active dimmer"> | |||
<div class="ui loader"></div> | |||
</div> | |||
<input type="hidden" name="end_line" value> | |||
<input type="hidden" name="start_line" value> | |||
<pre id="log_file{{.VersionName}}"></pre> | |||
@@ -728,7 +729,7 @@ | |||
hideMenu(); | |||
} | |||
} | |||
let dirKey="isOnlyDir--:&"; | |||
function loadSelectedModelFile(trainJob){ | |||
console.log("trainJob=" + trainJob); | |||
$('#choice_file').dropdown('clear') | |||
@@ -743,7 +744,7 @@ | |||
var zNodes=[]; | |||
var nodesMap={}; | |||
for (let i=0;i<n_length;i++){ | |||
parentNodeMap = nodesMap; | |||
var parentNodeMap = nodesMap; | |||
var fileSplits = data[i].FileName.split("/"); | |||
for(let j=0;j < fileSplits.length;j++){ | |||
if(fileSplits[j] == ""){ | |||
@@ -752,7 +753,22 @@ | |||
if(parentNodeMap[fileSplits[j]] == null){ | |||
parentNodeMap[fileSplits[j]] = {}; | |||
} | |||
parentNodeMap = parentNodeMap[fileSplits[j]] | |||
parentNodeMap = parentNodeMap[fileSplits[j]]; | |||
} | |||
} | |||
for (let i=0;i<n_length;i++){ | |||
var parentNodeMap = nodesMap; | |||
var fileSplits = data[i].FileName.split("/"); | |||
for(let j=0;j < fileSplits.length;j++){ | |||
if(fileSplits[j] == ""){ | |||
if(data[i].FileName[data[i].FileName.length -1] =="/"){ | |||
if(Object.keys(parentNodeMap).length ==0){ | |||
parentNodeMap[dirKey]="true"; | |||
} | |||
} | |||
break; | |||
} | |||
parentNodeMap = parentNodeMap[fileSplits[j]]; | |||
} | |||
} | |||
convertToNode(zNodes,nodesMap); | |||
@@ -772,12 +788,17 @@ | |||
node["name"] = keyList[i]; | |||
nodeList.push(node); | |||
if(nodesMap[keyList[i]] != null && Object.keys(nodesMap[keyList[i]]).length >0){ | |||
node["children"]=[]; | |||
if(isFirst){ | |||
node["open"] = true; | |||
isFirst= false; | |||
if(nodesMap[keyList[i]][dirKey] != null){ | |||
node["open"] = false; | |||
node["isParent"] = true; | |||
}else{ | |||
node["children"]=[]; | |||
if(isFirst){ | |||
node["open"] = true; | |||
isFirst= false; | |||
} | |||
convertToNode(node["children"],nodesMap[keyList[i]]); | |||
} | |||
convertToNode(node["children"],nodesMap[keyList[i]]); | |||
} | |||
} | |||
} | |||
@@ -905,154 +926,7 @@ | |||
} | |||
function loadLog(version_name) { | |||
$.get(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}/log?version_name=${version_name}&lines=50&order=asc`, (data) => { | |||
$('input[name=end_line]').val(data.EndLine) | |||
$('input[name=start_line]').val(data.StartLine) | |||
$(`#log_file${version_name}`).text(data.Content) | |||
if(!data.CanLogDownload){ | |||
$(`#${version_name}-log-down`).removeClass('ti-download-file').addClass('disabled') | |||
} | |||
}).fail(function (err) { | |||
console.log(err); | |||
}); | |||
} | |||
function debounce(fn, delay) { | |||
let timer; | |||
return (...args) => { | |||
// 判断定时器是否存在,清除定时器 | |||
if (timer) { | |||
clearTimeout(timer); | |||
} | |||
// 重新调用setTimeout | |||
timer = setTimeout(() => { | |||
fn.apply(this, args); | |||
}, delay); | |||
}; | |||
} | |||
const fn = debounce(logScroll, 500) | |||
function logScroll(version_name) { | |||
let container = document.querySelector(`#log${version_name}`) | |||
let scrollTop = container.scrollTop | |||
let scrollHeight = container.scrollHeight | |||
let clientHeight = container.clientHeight | |||
let scrollLeft = container.scrollLeft | |||
if (((parseInt(scrollTop) + clientHeight == scrollHeight || parseInt(scrollTop) + clientHeight + 1 == scrollHeight || parseInt(scrollTop) + clientHeight - 1 == scrollHeight)) && parseInt(scrollTop) !== 0 && scrollLeft == 0) { | |||
let end_line = $(`#log${version_name} input[name=end_line]`).val() | |||
$.get(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}/log?version_name=${version_name}&base_line=${end_line}&lines=50&order=desc`, (data) => { | |||
if (data.Lines == 0) { | |||
$(`.message${version_name} #header`).text('您已翻阅至日志底部') | |||
$(`.message${version_name}`).css('display', 'block') | |||
setTimeout(function () { | |||
$(`.message${version_name}`).css('display', 'none') | |||
}, 1000) | |||
} else { | |||
if (end_line === data.EndLine) { | |||
return | |||
} | |||
else { | |||
$(`#log${version_name} input[name=end_line]`).val(data.EndLine) | |||
$(`#log${version_name}`).append('<pre>' + data.Content) | |||
} | |||
} | |||
}).fail(function (err) { | |||
console.log(err); | |||
}); | |||
} | |||
if ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].includes(scrollTop) && scrollLeft == 0) { | |||
let start_line = $(`#log${version_name} input[name=start_line]`).val() | |||
$.get(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}/log?version_name=${version_name}&base_line=${start_line}&lines=50&order=asc`, (data) => { | |||
if (data.Lines == 0) { | |||
$(`.message${version_name} #header`).text('您已翻阅至日志顶部') | |||
$(`.message${version_name}`).css('display', 'block') | |||
setTimeout(function () { | |||
$(`.message${version_name}`).css('display', 'none') | |||
}, 1000) | |||
} else { | |||
$(`#log${version_name} input[name=start_line]`).val(data.StartLine) //如果变动就改变所对应的值 | |||
$(`#log${version_name}`).prepend('<pre>' + data.Content) | |||
} | |||
}).fail(function (err) { | |||
console.log(err); | |||
}); | |||
} | |||
} | |||
function scrollAnimation(dom, currentY, targetY, currentX) { | |||
let needScrollTop = targetY - currentY; | |||
let _currentY = currentY; | |||
setTimeout(() => { | |||
// 一次调用滑动帧数,每次调用会不一样 | |||
//取总距离的十分之一 | |||
const dist = Math.ceil(needScrollTop / 10); | |||
_currentY += dist; | |||
//移动一个十分之一 | |||
dom.scrollTo(currentX || 0, _currentY, 'smooth'); | |||
// 如果移动幅度小于十个像素,直接移动,否则递归调用,实现动画效果 | |||
if (needScrollTop > 10 || needScrollTop < -10) { | |||
scrollAnimation(dom, _currentY, targetY) | |||
} else { | |||
dom.scrollTo(0, targetY, 'smooth') | |||
} | |||
}, 1) | |||
} | |||
$('.log_top').click(function () { | |||
// let logContentDom = document.querySelector('.log') | |||
// if(!logContentDom) | |||
// return | |||
// let version_name = $('.log_top').data('version') | |||
let version_name = $(this).data('version') | |||
let logContentDom = document.querySelector(`#log${version_name}`) | |||
$(`#log_file${version_name}`).siblings('pre').remove() | |||
$.get(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}/log?version_name=${version_name}&base_line=&lines=50&order=asc`, (data) => { | |||
$(`#log${version_name} input[name=end_line]`).val(data.EndLine) //如果变动就改变所对应的值 | |||
$(`#log${version_name} input[name=start_line]`).val(data.StartLine) | |||
$(`#log${version_name}`).prepend('<pre>' + data.Content) | |||
$(`.message${version_name} #header`).text('您已翻阅至日志顶部') | |||
$(`.message${version_name}`).css('display', 'block') | |||
setTimeout(function () { | |||
$(`.message${version_name}`).css('display', 'none') | |||
}, 1000) | |||
scrollAnimation(logContentDom, logContentDom.scrollTop, 0); | |||
}) | |||
}) | |||
$('.log_bottom').click(function (e) { | |||
let version_name = $(this).data('version') | |||
let logContentDom = document.querySelector(`#log${version_name}`) | |||
$(`#log_file${version_name}`).siblings('pre').remove() | |||
$.get(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}/log?version_name=${version_name}&base_line=&lines=50&order=desc`, (data) => { | |||
$(`#log${version_name} input[name=end_line]`).val(data.EndLine) //如果变动就改变所对应的值 | |||
$(`#log${version_name} input[name=start_line]`).val(data.StartLine) | |||
$(`#log${version_name}`).append('<pre>' + data.Content) | |||
$.get(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}/log?version_name=${version_name}&base_line=${data.EndLine}&lines=50&order=desc`, (data) => { | |||
if (data.Lines == 0) { | |||
$(`.message${version_name} #header`).text('您已翻阅至日志底部') | |||
$(`.message${version_name}`).css('display', 'block') | |||
setTimeout(function () { | |||
$(`.message${version_name}`).css('display', 'none') | |||
}, 1000) | |||
} else { | |||
if (end_line === data.EndLine) { | |||
return | |||
} | |||
else { | |||
$(`#log${version_name} input[name=end_line]`).val(data.EndLine) | |||
$(`#log${version_name}`).append('<pre>' + data.Content) | |||
} | |||
} | |||
}).fail(function (err) { | |||
console.log(err); | |||
}); | |||
scrollAnimation(logContentDom, logContentDom.scrollTop + 1, logContentDom.scrollHeight - logContentDom.clientHeight); | |||
}) | |||
}) | |||
@@ -51,18 +51,7 @@ | |||
} | |||
</style> | |||
<!-- <div class="ui page dimmer"> | |||
<div class="ui text loader">{{.i18n.Tr "loading"}}</div> | |||
</div> --> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
{{template "custom/global_mask" .}} | |||
<div class="repository"> | |||
{{template "repo/header" .}} | |||
<div class="ui container"> | |||
@@ -254,6 +254,10 @@ | |||
</div> | |||
</div> | |||
<div data-tooltip="{{.i18n.Tr "cloudbrain.model_convert_postfix_rule"}}" data-inverted="" data-variation="mini"> | |||
<i class="question circle icon"></i> | |||
</div> | |||
</div> | |||
<div class="unite min_title inline fields required"> | |||
<div class="three wide field right aligned"> | |||
@@ -347,7 +351,6 @@ | |||
return true; | |||
} | |||
} | |||
$('#submitId').click(function(){ | |||
let data={}; | |||
data['_csrf']=csrf | |||
@@ -166,15 +166,7 @@ td, th { | |||
padding-top: 0.5rem ; | |||
} | |||
</style> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
{{template "custom/global_mask" .}} | |||
<div class="repository"> | |||
{{template "repo/header" .}} | |||
<div class="ui container"> | |||
@@ -325,6 +325,7 @@ | |||
$('#name').val(modelName) | |||
$('#version').val("0.0.1") | |||
} | |||
let dirKey="isOnlyDir--:&"; | |||
function showcreate(obj) { | |||
$('.ui.modal.second') | |||
.modal({ | |||
@@ -460,7 +461,7 @@ | |||
var zNodes=[]; | |||
var nodesMap={}; | |||
for (let i=0;i<n_length;i++){ | |||
parentNodeMap = nodesMap; | |||
var parentNodeMap = nodesMap; | |||
var fileSplits = data[i].FileName.split("/"); | |||
for(let j=0;j < fileSplits.length;j++){ | |||
if(fileSplits[j] == ""){ | |||
@@ -469,7 +470,22 @@ | |||
if(parentNodeMap[fileSplits[j]] == null){ | |||
parentNodeMap[fileSplits[j]] = {}; | |||
} | |||
parentNodeMap = parentNodeMap[fileSplits[j]] | |||
parentNodeMap = parentNodeMap[fileSplits[j]]; | |||
} | |||
} | |||
for (let i=0;i<n_length;i++){ | |||
var parentNodeMap = nodesMap; | |||
var fileSplits = data[i].FileName.split("/"); | |||
for(let j=0;j < fileSplits.length;j++){ | |||
if(fileSplits[j] == ""){ | |||
if(data[i].FileName[data[i].FileName.length -1] =="/"){ | |||
if(Object.keys(parentNodeMap).length ==0){ | |||
parentNodeMap[dirKey]="true"; | |||
} | |||
} | |||
break; | |||
} | |||
parentNodeMap = parentNodeMap[fileSplits[j]]; | |||
} | |||
} | |||
convertToNode(zNodes,nodesMap); | |||
@@ -488,12 +504,18 @@ | |||
node["name"] = keyList[i]; | |||
nodeList.push(node); | |||
if(nodesMap[keyList[i]] != null && Object.keys(nodesMap[keyList[i]]).length >0){ | |||
node["children"]=[]; | |||
if(isFirst){ | |||
node["open"] = true; | |||
isFirst= false; | |||
if(nodesMap[keyList[i]][dirKey] != null){ | |||
node["open"] = false; | |||
node["isParent"] = true; | |||
}else{ | |||
node["children"]=[]; | |||
if(isFirst){ | |||
node["open"] = true; | |||
isFirst= false; | |||
} | |||
convertToNode(node["children"],nodesMap[keyList[i]]); | |||
} | |||
convertToNode(node["children"],nodesMap[keyList[i]]); | |||
} | |||
} | |||
} | |||
@@ -125,6 +125,14 @@ | |||
</td> | |||
</tr> | |||
<tr> | |||
<td class="ti-text-form-label text-width80">训练任务</td> | |||
<td class="ti-text-form-content word-elipsis"> | |||
<a id="DisplayJobNameHref" class="title" style="font-size: 14px;" target="_blank"> | |||
<span id="DisplayJobName" class="fitted" style="width: 90%;vertical-align: middle;"></span> | |||
</a> | |||
</td> | |||
</tr> | |||
<tr> | |||
<td class="ti-text-form-label text-width80">{{$.i18n.Tr "repo.modelarts.code_version"}}</td> | |||
<td class="ti-text-form-content word-elipsis"><span id="CodeBranch" title=""></span></td> | |||
</tr> | |||
@@ -197,6 +205,7 @@ | |||
{{template "base/footer" .}} | |||
<script> | |||
let url = location.href.split('show_model')[0] | |||
let trainJobUrl =url.split('modelmanage')[0] | |||
let ID = location.search.split('?name=').pop() | |||
$(document).ready(function(){ | |||
$('.secondary.menu .item').tab(); | |||
@@ -279,6 +288,10 @@ function transObj(data){ | |||
WorkServerNumber:TrainTaskInfo.WorkServerNumber || '--', | |||
Parameters:Parameters, | |||
EngineName:EngineName, | |||
DisplayJobName:TrainTaskInfo.DisplayJobName || '--', | |||
TrainJobVersionName:TrainTaskInfo.VersionName || '', | |||
CloudBrainJobID:TrainTaskInfo.JobID|| '', | |||
CloudBrainType:TrainTaskInfo.Type, | |||
} | |||
let initModelAcc = { | |||
Accuracy: modelAcc.Accuracy || '--', | |||
@@ -365,6 +378,26 @@ function renderInfo(obj,accObj,id){ | |||
$('#CodeBranch').append(html) | |||
} | |||
else if(key==="DisplayJobName"){ | |||
let type=obj["CloudBrainType"] | |||
let href="" | |||
if(type==1){ | |||
href=trainJobUrl + "modelarts/train-job/" + obj["CloudBrainJobID"] | |||
}else if(type==0){ | |||
href=trainJobUrl + "cloudbrain/train-job/" + obj["CloudBrainJobID"] | |||
}else if(type==2){ | |||
href=trainJobUrl + "grampus/train-job/" + obj["CloudBrainJobID"] | |||
} | |||
$(`#DisplayJobNameHref`).attr("href",href) | |||
$(`#DisplayJobNameHref`).attr("title",obj[key]) | |||
$(`#${key}`).text(obj[key]) | |||
let versionName = obj["TrainJobVersionName"] | |||
if(versionName!=""){ | |||
let html = `<span style="margin-left:1rem" class="ui label">${versionName}</span>` | |||
$('#DisplayJobName').append(html) | |||
} | |||
} | |||
else if(key==="Parameters"){ | |||
if(obj[key]==='--'){ | |||
$(`#${key}`).text(obj[key]) | |||
@@ -439,10 +472,15 @@ function renderBrend(ID,version_name,parents,filename,init){ | |||
$('input[name=modelback]').val(filename) | |||
}else{ | |||
$('input[name=model]').val(parents) | |||
$('input[name=modelbac]').val(filename) | |||
$('#file_breadcrumb a.section:contains(${filename})').nextAll().remove() | |||
$('#file_breadcrumb a.section:contains(${filename})').replaceWith(`<div class='active section'>${filename}</div>`) | |||
$('#file_breadcrumb div.section:contains(${filename})').append("<div class='divider'> / </div>") | |||
$('input[name=modelback]').val(filename) | |||
let selectEle = $('#file_breadcrumb a.section').filter( | |||
(index, item) => { | |||
return item.text == filename; | |||
} | |||
); | |||
selectEle.nextAll().remove(); | |||
selectEle.after("<div class='divider'> / </div>"); | |||
selectEle.replaceWith(`<div class='active section'>${filename}</div>`); | |||
} | |||
} | |||
@@ -133,16 +133,79 @@ function submitDeleteForm() { | |||
$("#delete-file-form").submit() | |||
} | |||
} | |||
const baseUrls = {}; | |||
const justDomain = /^[^:]+:\/*[^/]*$/; | |||
const protocol = /^([^:]+:)[\s\S]*$/; | |||
const domain = /^([^:]+:\/*[^/]*)[\s\S]*$/; | |||
const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; | |||
function rtrim(str, c, invert) { | |||
const l = str.length; | |||
if (l === 0) { | |||
return ''; | |||
} | |||
let suffLen = 0; | |||
while (suffLen < l) { | |||
const currChar = str.charAt(l - suffLen - 1); | |||
if (currChar === c && !invert) { | |||
suffLen++; | |||
} else if (currChar !== c && invert) { | |||
suffLen++; | |||
} else { | |||
break; | |||
} | |||
} | |||
return str.slice(0, l - suffLen); | |||
} | |||
function resolveUrl(base, href) { | |||
if (!baseUrls[' ' + base]) { | |||
if (justDomain.test(base)) { | |||
baseUrls[' ' + base] = base + '/'; | |||
} else { | |||
baseUrls[' ' + base] = rtrim(base, '/', true); | |||
} | |||
} | |||
base = baseUrls[' ' + base]; | |||
const relativeBase = base.indexOf(':') === -1; | |||
if (href.substring(0, 2) === '//') { | |||
if (relativeBase) { | |||
return href; | |||
} | |||
return base.replace(protocol, '$1') + href; | |||
} else if (href.charAt(0) === '/') { | |||
if (relativeBase) { | |||
return href; | |||
} | |||
return base.replace(domain, '$1') + href; | |||
} else { | |||
return base + href; | |||
} | |||
} | |||
function showNoteBook(){ | |||
var isNoteBook = {{.IsNoteBook}} | |||
var isNoteBook = {{.IsNoteBook}}; | |||
if (isNoteBook) { | |||
var jsonStr = "{{.FileContent}}" | |||
var jsonStr = "{{.FileContent}}"; | |||
var baseUrl={{.FileParentURL}}; | |||
nb.markdown.setOptions({ | |||
baseUrl: {{.FileParentURL}} | |||
baseUrl: baseUrl | |||
}); | |||
var notebook = nb.parse(JSON.parse(jsonStr)); | |||
var rendered = notebook.render(); | |||
$("#notebook").append(rendered); | |||
$("#notebook img").each(function(){ | |||
var oldSrc = $(this).attr('src'); | |||
if (!originIndependentUrl.test(oldSrc)){ | |||
var newSrc=resolveUrl(baseUrl,oldSrc); | |||
$(this).attr('src', newSrc); | |||
} | |||
}); | |||
Prism.highlightAll(); | |||
} | |||
} | |||
@@ -1,14 +1,4 @@ | |||
{{template "base/head" .}} | |||
<!-- 弹窗 --> | |||
<div id="mask"> | |||
<div id="loadingPage"> | |||
<div class="rect1"></div> | |||
<div class="rect2"></div> | |||
<div class="rect3"></div> | |||
<div class="rect4"></div> | |||
<div class="rect5"></div> | |||
</div> | |||
</div> | |||
<!-- 提示框 --> | |||
<div class="alert"></div> | |||
<div class="explore users"> | |||
@@ -16,6 +6,10 @@ | |||
data-debug-again="{{$.i18n.Tr "repo.debug_again"}}" data-debug-task="{{$.i18n.Tr "cloudbrain.DEBUG"}}" | |||
data-train-task="{{$.i18n.Tr "cloudbrain.TRAIN"}}" data-inference-task="{{$.i18n.Tr "cloudbrain.INFERENCE"}}" | |||
data-benchmark-task="{{$.i18n.Tr "cloudbrain.BENCHMARK"}}" | |||
data-all-cluster="{{.i18n.Tr "cloudbrain.all_resource_cluster"}}" | |||
data-all-aiCenter="{{.i18n.Tr "cloudbrain.all_ai_center"}}" | |||
data-cluster-c2net="{{.i18n.Tr "cloudbrain.resource_cluster_c2net"}}" | |||
data-cluster-openi="{{.i18n.Tr "cloudbrain.resource_cluster_openi"}}" | |||
data-all-task="{{.i18n.Tr "admin.cloudbrain.all_task_types"}}" | |||
data-all-compute="{{.i18n.Tr "admin.cloudbrain.all_computing_resources"}}" | |||
data-all-status="{{.i18n.Tr "admin.cloudbrain.all_status"}}"></div> | |||
@@ -22,24 +22,26 @@ | |||
{{template "user/dashboard/heatmap" .}} | |||
{{end}} | |||
{{template "user/dashboard/feeds" .}} | |||
<diV id = "activity_cont" style="display: none;"> | |||
<div class="ui placeholder segment bgtask-none padding_none line" > | |||
<div class="act_title" style="padding-left: 0px ;"> | |||
{{.i18n.Tr "home.activity"}} : | |||
{{ if eq (len .Feeds) 0 }} | |||
<diV ss="{{(len .Feeds)}}" id = "activity_cont" style="display: block;"> | |||
<div class="ui placeholder segment bgtask-none padding_none line" > | |||
<div class="act_title" style="padding-left: 0px ;"> | |||
{{.i18n.Tr "home.activity"}} : | |||
</div> | |||
<div class="ui icon header bgtask-header-pic"></div> | |||
<p class="p_hint"> | |||
{{.i18n.Tr "home.no_events"}} | |||
</p> | |||
</div> | |||
<div class="ui icon header bgtask-header-pic"></div> | |||
<p class="p_hint"> | |||
{{.i18n.Tr "home.no_events"}} | |||
</p> | |||
</div> | |||
</diV> | |||
</diV> | |||
{{ end }} | |||
</div> | |||
{{template "user/dashboard/repolist" .}} | |||
</div> | |||
</div> | |||
</div> | |||
{{template "base/footer" .}} | |||
<script> | |||
<script> | |||
const {AppSubUrl, StaticUrlPrefix, csrf} = window.config; | |||
uid_ = Number((document.querySelector('meta[name=_context_uid]') || {}).content) | |||
@@ -49,11 +51,10 @@ | |||
$.getJSON(URL, (result, _textStatus, request) => { | |||
const counts_pro = request.getResponseHeader('X-Total-Count'); | |||
console.log("count:",counts_pro) | |||
if (counts_pro == 0){ | |||
if (counts_pro == 0 && {{ (len .Feeds) }} == 0) { | |||
document.getElementById("default_page").style.display = "block"; | |||
document.getElementById("activity_cont").style.display = "block" | |||
} | |||
}) | |||
}) | |||
</script> | |||
<style> | |||
@@ -0,0 +1,19 @@ | |||
# Binaries for programs and plugins | |||
*.exe | |||
*.dll | |||
*.so | |||
*.dylib | |||
/cmd/chroma/chroma | |||
# Test binary, build with `go test -c` | |||
*.test | |||
# Output of the go coverage tool, specifically when used with LiteIDE | |||
*.out | |||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 | |||
.glide/ | |||
_models/ | |||
_examples/ |
@@ -0,0 +1,76 @@ | |||
run: | |||
tests: true | |||
skip-dirs: | |||
- _examples | |||
output: | |||
print-issued-lines: false | |||
linters: | |||
enable-all: true | |||
disable: | |||
- maligned | |||
- megacheck | |||
- lll | |||
- gocyclo | |||
- dupl | |||
- gochecknoglobals | |||
- funlen | |||
- godox | |||
- wsl | |||
- gomnd | |||
- gocognit | |||
- goerr113 | |||
- nolintlint | |||
- testpackage | |||
- godot | |||
- nestif | |||
- paralleltest | |||
- nlreturn | |||
- cyclop | |||
- exhaustivestruct | |||
- gci | |||
- gofumpt | |||
- errorlint | |||
- exhaustive | |||
- ifshort | |||
- wrapcheck | |||
- stylecheck | |||
linters-settings: | |||
govet: | |||
check-shadowing: true | |||
gocyclo: | |||
min-complexity: 10 | |||
dupl: | |||
threshold: 100 | |||
goconst: | |||
min-len: 8 | |||
min-occurrences: 3 | |||
forbidigo: | |||
forbid: | |||
- (Must)?NewLexer | |||
exclude_godoc_examples: false | |||
issues: | |||
max-per-linter: 0 | |||
max-same: 0 | |||
exclude-use-default: false | |||
exclude: | |||
# Captured by errcheck. | |||
- '^(G104|G204):' | |||
# Very commonly not checked. | |||
- 'Error return value of .(.*\.Help|.*\.MarkFlagRequired|(os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked' | |||
- 'exported method (.*\.MarshalJSON|.*\.UnmarshalJSON|.*\.EntityURN|.*\.GoString|.*\.Pos) should have comment or be unexported' | |||
- 'composite literal uses unkeyed fields' | |||
- 'declaration of "err" shadows declaration' | |||
- 'should not use dot imports' | |||
- 'Potential file inclusion via variable' | |||
- 'should have comment or be unexported' | |||
- 'comment on exported var .* should be of the form' | |||
- 'at least one file in a package should have a package comment' | |||
- 'string literal contains the Unicode' | |||
- 'methods on the same type should have the same receiver name' | |||
- '_TokenType_name should be _TokenTypeName' | |||
- '`_TokenType_map` should be `_TokenTypeMap`' |
@@ -0,0 +1,37 @@ | |||
project_name: chroma | |||
release: | |||
github: | |||
owner: alecthomas | |||
name: chroma | |||
brews: | |||
- | |||
install: bin.install "chroma" | |||
env: | |||
- CGO_ENABLED=0 | |||
builds: | |||
- goos: | |||
- linux | |||
- darwin | |||
- windows | |||
goarch: | |||
- arm64 | |||
- amd64 | |||
- "386" | |||
goarm: | |||
- "6" | |||
dir: ./cmd/chroma | |||
main: . | |||
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} | |||
binary: chroma | |||
archives: | |||
- | |||
format: tar.gz | |||
name_template: '{{ .Binary }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ | |||
.Arm }}{{ end }}' | |||
files: | |||
- COPYING | |||
- README* | |||
snapshot: | |||
name_template: SNAPSHOT-{{ .Commit }} | |||
checksum: | |||
name_template: '{{ .ProjectName }}-{{ .Version }}-checksums.txt' |
@@ -0,0 +1,19 @@ | |||
Copyright (C) 2017 Alec Thomas | |||
Permission is hereby granted, free of charge, to any person obtaining a copy of | |||
this software and associated documentation files (the "Software"), to deal in | |||
the Software without restriction, including without limitation the rights to | |||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | |||
of the Software, and to permit persons to whom the Software is furnished to do | |||
so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all | |||
copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||
SOFTWARE. |
@@ -0,0 +1,19 @@ | |||
.PHONY: chromad upload all | |||
VERSION ?= $(shell git describe --tags --dirty --always) | |||
all: README.md tokentype_string.go | |||
README.md: lexers/*/*.go | |||
./table.py | |||
tokentype_string.go: types.go | |||
go generate | |||
chromad: | |||
rm -f chromad | |||
(export CGOENABLED=0 GOOS=linux GOARCH=amd64; cd ./cmd/chromad && go build -ldflags="-X 'main.version=$(VERSION)'" -o ../../chromad .) | |||
upload: chromad | |||
scp chromad root@swapoff.org: && \ | |||
ssh root@swapoff.org 'install -m755 ./chromad /srv/http/swapoff.org/bin && service chromad restart' |
@@ -0,0 +1,285 @@ | |||
# Chroma — A general purpose syntax highlighter in pure Go | |||
[](https://godoc.org/github.com/alecthomas/chroma) [](https://github.com/alecthomas/chroma/actions/workflows/ci.yml) [](https://invite.slack.golangbridge.org/) | |||
> **NOTE:** As Chroma has just been released, its API is still in flux. That said, the high-level interface should not change significantly. | |||
Chroma takes source code and other structured text and converts it into syntax | |||
highlighted HTML, ANSI-coloured text, etc. | |||
Chroma is based heavily on [Pygments](http://pygments.org/), and includes | |||
translators for Pygments lexers and styles. | |||
<a id="markdown-table-of-contents" name="table-of-contents"></a> | |||
## Table of Contents | |||
<!-- TOC --> | |||
1. [Table of Contents](#table-of-contents) | |||
2. [Supported languages](#supported-languages) | |||
3. [Try it](#try-it) | |||
4. [Using the library](#using-the-library) | |||
1. [Quick start](#quick-start) | |||
2. [Identifying the language](#identifying-the-language) | |||
3. [Formatting the output](#formatting-the-output) | |||
4. [The HTML formatter](#the-html-formatter) | |||
5. [More detail](#more-detail) | |||
1. [Lexers](#lexers) | |||
2. [Formatters](#formatters) | |||
3. [Styles](#styles) | |||
6. [Command-line interface](#command-line-interface) | |||
7. [What's missing compared to Pygments?](#whats-missing-compared-to-pygments) | |||
<!-- /TOC --> | |||
<a id="markdown-supported-languages" name="supported-languages"></a> | |||
## Supported languages | |||
Prefix | Language | |||
:----: | -------- | |||
A | ABAP, ABNF, ActionScript, ActionScript 3, Ada, Angular2, ANTLR, ApacheConf, APL, AppleScript, Arduino, Awk | |||
B | Ballerina, Base Makefile, Bash, Batchfile, BibTeX, Bicep, BlitzBasic, BNF, Brainfuck | |||
C | C, C#, C++, Caddyfile, Caddyfile Directives, Cap'n Proto, Cassandra CQL, Ceylon, CFEngine3, cfstatement, ChaiScript, Cheetah, Clojure, CMake, COBOL, CoffeeScript, Common Lisp, Coq, Crystal, CSS, Cython | |||
D | D, Dart, Diff, Django/Jinja, Docker, DTD, Dylan | |||
E | EBNF, Elixir, Elm, EmacsLisp, Erlang | |||
F | Factor, Fish, Forth, Fortran, FSharp | |||
G | GAS, GDScript, Genshi, Genshi HTML, Genshi Text, Gherkin, GLSL, Gnuplot, Go, Go HTML Template, Go Text Template, GraphQL, Groff, Groovy | |||
H | Handlebars, Haskell, Haxe, HCL, Hexdump, HLB, HTML, HTTP, Hy | |||
I | Idris, Igor, INI, Io | |||
J | J, Java, JavaScript, JSON, Julia, Jungle | |||
K | Kotlin | |||
L | Lighttpd configuration file, LLVM, Lua | |||
M | Mako, markdown, Mason, Mathematica, Matlab, MiniZinc, MLIR, Modula-2, MonkeyC, MorrowindScript, Myghty, MySQL | |||
N | NASM, Newspeak, Nginx configuration file, Nim, Nix | |||
O | Objective-C, OCaml, Octave, OnesEnterprise, OpenEdge ABL, OpenSCAD, Org Mode | |||
P | PacmanConf, Perl, PHP, PHTML, Pig, PkgConfig, PL/pgSQL, plaintext, Pony, PostgreSQL SQL dialect, PostScript, POVRay, PowerShell, Prolog, PromQL, Protocol Buffer, Puppet, Python 2, Python | |||
Q | QBasic | |||
R | R, Racket, Ragel, Raku, react, ReasonML, reg, reStructuredText, Rexx, Ruby, Rust | |||
S | SAS, Sass, Scala, Scheme, Scilab, SCSS, Smalltalk, Smarty, Snobol, Solidity, SPARQL, SQL, SquidConf, Standard ML, Stylus, Svelte, Swift, SYSTEMD, systemverilog | |||
T | TableGen, TASM, Tcl, Tcsh, Termcap, Terminfo, Terraform, TeX, Thrift, TOML, TradingView, Transact-SQL, Turing, Turtle, Twig, TypeScript, TypoScript, TypoScriptCssData, TypoScriptHtmlData | |||
V | VB.net, verilog, VHDL, VimL, vue | |||
W | WDTE | |||
X | XML, Xorg | |||
Y | YAML, YANG | |||
Z | Zig | |||
_I will attempt to keep this section up to date, but an authoritative list can be | |||
displayed with `chroma --list`._ | |||
<a id="markdown-try-it" name="try-it"></a> | |||
## Try it | |||
Try out various languages and styles on the [Chroma Playground](https://swapoff.org/chroma/playground/). | |||
<a id="markdown-using-the-library" name="using-the-library"></a> | |||
## Using the library | |||
Chroma, like Pygments, has the concepts of | |||
[lexers](https://github.com/alecthomas/chroma/tree/master/lexers), | |||
[formatters](https://github.com/alecthomas/chroma/tree/master/formatters) and | |||
[styles](https://github.com/alecthomas/chroma/tree/master/styles). | |||
Lexers convert source text into a stream of tokens, styles specify how token | |||
types are mapped to colours, and formatters convert tokens and styles into | |||
formatted output. | |||
A package exists for each of these, containing a global `Registry` variable | |||
with all of the registered implementations. There are also helper functions | |||
for using the registry in each package, such as looking up lexers by name or | |||
matching filenames, etc. | |||
In all cases, if a lexer, formatter or style can not be determined, `nil` will | |||
be returned. In this situation you may want to default to the `Fallback` | |||
value in each respective package, which provides sane defaults. | |||
<a id="markdown-quick-start" name="quick-start"></a> | |||
### Quick start | |||
A convenience function exists that can be used to simply format some source | |||
text, without any effort: | |||
```go | |||
err := quick.Highlight(os.Stdout, someSourceCode, "go", "html", "monokai") | |||
``` | |||
<a id="markdown-identifying-the-language" name="identifying-the-language"></a> | |||
### Identifying the language | |||
To highlight code, you'll first have to identify what language the code is | |||
written in. There are three primary ways to do that: | |||
1. Detect the language from its filename. | |||
```go | |||
lexer := lexers.Match("foo.go") | |||
``` | |||
3. Explicitly specify the language by its Chroma syntax ID (a full list is available from `lexers.Names()`). | |||
```go | |||
lexer := lexers.Get("go") | |||
``` | |||
3. Detect the language from its content. | |||
```go | |||
lexer := lexers.Analyse("package main\n\nfunc main()\n{\n}\n") | |||
``` | |||
In all cases, `nil` will be returned if the language can not be identified. | |||
```go | |||
if lexer == nil { | |||
lexer = lexers.Fallback | |||
} | |||
``` | |||
At this point, it should be noted that some lexers can be extremely chatty. To | |||
mitigate this, you can use the coalescing lexer to coalesce runs of identical | |||
token types into a single token: | |||
```go | |||
lexer = chroma.Coalesce(lexer) | |||
``` | |||
<a id="markdown-formatting-the-output" name="formatting-the-output"></a> | |||
### Formatting the output | |||
Once a language is identified you will need to pick a formatter and a style (theme). | |||
```go | |||
style := styles.Get("swapoff") | |||
if style == nil { | |||
style = styles.Fallback | |||
} | |||
formatter := formatters.Get("html") | |||
if formatter == nil { | |||
formatter = formatters.Fallback | |||
} | |||
``` | |||
Then obtain an iterator over the tokens: | |||
```go | |||
contents, err := ioutil.ReadAll(r) | |||
iterator, err := lexer.Tokenise(nil, string(contents)) | |||
``` | |||
And finally, format the tokens from the iterator: | |||
```go | |||
err := formatter.Format(w, style, iterator) | |||
``` | |||
<a id="markdown-the-html-formatter" name="the-html-formatter"></a> | |||
### The HTML formatter | |||
By default the `html` registered formatter generates standalone HTML with | |||
embedded CSS. More flexibility is available through the `formatters/html` package. | |||
Firstly, the output generated by the formatter can be customised with the | |||
following constructor options: | |||
- `Standalone()` - generate standalone HTML with embedded CSS. | |||
- `WithClasses()` - use classes rather than inlined style attributes. | |||
- `ClassPrefix(prefix)` - prefix each generated CSS class. | |||
- `TabWidth(width)` - Set the rendered tab width, in characters. | |||
- `WithLineNumbers()` - Render line numbers (style with `LineNumbers`). | |||
- `LinkableLineNumbers()` - Make the line numbers linkable and be a link to themselves. | |||
- `HighlightLines(ranges)` - Highlight lines in these ranges (style with `LineHighlight`). | |||
- `LineNumbersInTable()` - Use a table for formatting line numbers and code, rather than spans. | |||
If `WithClasses()` is used, the corresponding CSS can be obtained from the formatter with: | |||
```go | |||
formatter := html.New(html.WithClasses()) | |||
err := formatter.WriteCSS(w, style) | |||
``` | |||
<a id="markdown-more-detail" name="more-detail"></a> | |||
## More detail | |||
<a id="markdown-lexers" name="lexers"></a> | |||
### Lexers | |||
See the [Pygments documentation](http://pygments.org/docs/lexerdevelopment/) | |||
for details on implementing lexers. Most concepts apply directly to Chroma, | |||
but see existing lexer implementations for real examples. | |||
In many cases lexers can be automatically converted directly from Pygments by | |||
using the included Python 3 script `pygments2chroma.py`. I use something like | |||
the following: | |||
```sh | |||
python3 _tools/pygments2chroma.py \ | |||
pygments.lexers.jvm.KotlinLexer \ | |||
> lexers/k/kotlin.go \ | |||
&& gofmt -s -w lexers/k/kotlin.go | |||
``` | |||
See notes in [pygments-lexers.txt](https://github.com/alecthomas/chroma/blob/master/pygments-lexers.txt) | |||
for a list of lexers, and notes on some of the issues importing them. | |||
<a id="markdown-formatters" name="formatters"></a> | |||
### Formatters | |||
Chroma supports HTML output, as well as terminal output in 8 colour, 256 colour, and true-colour. | |||
A `noop` formatter is included that outputs the token text only, and a `tokens` | |||
formatter outputs raw tokens. The latter is useful for debugging lexers. | |||
<a id="markdown-styles" name="styles"></a> | |||
### Styles | |||
Chroma styles use the [same syntax](http://pygments.org/docs/styles/) as Pygments. | |||
All Pygments styles have been converted to Chroma using the `_tools/style.py` script. | |||
When you work with one of [Chroma's styles](https://github.com/alecthomas/chroma/tree/master/styles), know that the `chroma.Background` token type provides the default style for tokens. It does so by defining a foreground color and background color. | |||
For example, this gives each token name not defined in the style a default color of `#f8f8f8` and uses `#000000` for the highlighted code block's background: | |||
~~~go | |||
chroma.Background: "#f8f8f2 bg:#000000", | |||
~~~ | |||
Also, token types in a style file are hierarchical. For instance, when `CommentSpecial` is not defined, Chroma uses the token style from `Comment`. So when several comment tokens use the same color, you'll only need to define `Comment` and override the one that has a different color. | |||
For a quick overview of the available styles and how they look, check out the [Chroma Style Gallery](https://xyproto.github.io/splash/docs/). | |||
<a id="markdown-command-line-interface" name="command-line-interface"></a> | |||
## Command-line interface | |||
A command-line interface to Chroma is included. | |||
Binaries are available to install from [the releases page](https://github.com/alecthomas/chroma/releases). | |||
The CLI can be used as a preprocessor to colorise output of `less(1)`, | |||
see documentation for the `LESSOPEN` environment variable. | |||
The `--fail` flag can be used to suppress output and return with exit status | |||
1 to facilitate falling back to some other preprocessor in case chroma | |||
does not resolve a specific lexer to use for the given file. For example: | |||
```shell | |||
export LESSOPEN='| p() { chroma --fail "$1" || cat "$1"; }; p "%s"' | |||
``` | |||
Replace `cat` with your favourite fallback preprocessor. | |||
When invoked as `.lessfilter`, the `--fail` flag is automatically turned | |||
on under the hood for easy integration with [lesspipe shipping with | |||
Debian and derivatives](https://manpages.debian.org/lesspipe#USER_DEFINED_FILTERS); | |||
for that setup the `chroma` executable can be just symlinked to `~/.lessfilter`. | |||
<a id="markdown-whats-missing-compared-to-pygments" name="whats-missing-compared-to-pygments"></a> | |||
## What's missing compared to Pygments? | |||
- Quite a few lexers, for various reasons (pull-requests welcome): | |||
- Pygments lexers for complex languages often include custom code to | |||
handle certain aspects, such as Raku's ability to nest code inside | |||
regular expressions. These require time and effort to convert. | |||
- I mostly only converted languages I had heard of, to reduce the porting cost. | |||
- Some more esoteric features of Pygments are omitted for simplicity. | |||
- Though the Chroma API supports content detection, very few languages support them. | |||
I have plans to implement a statistical analyser at some point, but not enough time. |
@@ -0,0 +1,35 @@ | |||
package chroma | |||
// Coalesce is a Lexer interceptor that collapses runs of common types into a single token. | |||
func Coalesce(lexer Lexer) Lexer { return &coalescer{lexer} } | |||
type coalescer struct{ Lexer } | |||
func (d *coalescer) Tokenise(options *TokeniseOptions, text string) (Iterator, error) { | |||
var prev Token | |||
it, err := d.Lexer.Tokenise(options, text) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return func() Token { | |||
for token := it(); token != (EOF); token = it() { | |||
if len(token.Value) == 0 { | |||
continue | |||
} | |||
if prev == EOF { | |||
prev = token | |||
} else { | |||
if prev.Type == token.Type && len(prev.Value) < 8192 { | |||
prev.Value += token.Value | |||
} else { | |||
out := prev | |||
prev = token | |||
return out | |||
} | |||
} | |||
} | |||
out := prev | |||
prev = EOF | |||
return out | |||
}, nil | |||
} |
@@ -0,0 +1,164 @@ | |||
package chroma | |||
import ( | |||
"fmt" | |||
"math" | |||
"strconv" | |||
"strings" | |||
) | |||
// ANSI2RGB maps ANSI colour names, as supported by Chroma, to hex RGB values. | |||
var ANSI2RGB = map[string]string{ | |||
"#ansiblack": "000000", | |||
"#ansidarkred": "7f0000", | |||
"#ansidarkgreen": "007f00", | |||
"#ansibrown": "7f7fe0", | |||
"#ansidarkblue": "00007f", | |||
"#ansipurple": "7f007f", | |||
"#ansiteal": "007f7f", | |||
"#ansilightgray": "e5e5e5", | |||
// Normal | |||
"#ansidarkgray": "555555", | |||
"#ansired": "ff0000", | |||
"#ansigreen": "00ff00", | |||
"#ansiyellow": "ffff00", | |||
"#ansiblue": "0000ff", | |||
"#ansifuchsia": "ff00ff", | |||
"#ansiturquoise": "00ffff", | |||
"#ansiwhite": "ffffff", | |||
// Aliases without the "ansi" prefix, because...why? | |||
"#black": "000000", | |||
"#darkred": "7f0000", | |||
"#darkgreen": "007f00", | |||
"#brown": "7f7fe0", | |||
"#darkblue": "00007f", | |||
"#purple": "7f007f", | |||
"#teal": "007f7f", | |||
"#lightgray": "e5e5e5", | |||
// Normal | |||
"#darkgray": "555555", | |||
"#red": "ff0000", | |||
"#green": "00ff00", | |||
"#yellow": "ffff00", | |||
"#blue": "0000ff", | |||
"#fuchsia": "ff00ff", | |||
"#turquoise": "00ffff", | |||
"#white": "ffffff", | |||
} | |||
// Colour represents an RGB colour. | |||
type Colour int32 | |||
// NewColour creates a Colour directly from RGB values. | |||
func NewColour(r, g, b uint8) Colour { | |||
return ParseColour(fmt.Sprintf("%02x%02x%02x", r, g, b)) | |||
} | |||
// Distance between this colour and another. | |||
// | |||
// This uses the approach described here (https://www.compuphase.com/cmetric.htm). | |||
// This is not as accurate as LAB, et. al. but is *vastly* simpler and sufficient for our needs. | |||
func (c Colour) Distance(e2 Colour) float64 { | |||
ar, ag, ab := int64(c.Red()), int64(c.Green()), int64(c.Blue()) | |||
br, bg, bb := int64(e2.Red()), int64(e2.Green()), int64(e2.Blue()) | |||
rmean := (ar + br) / 2 | |||
r := ar - br | |||
g := ag - bg | |||
b := ab - bb | |||
return math.Sqrt(float64((((512 + rmean) * r * r) >> 8) + 4*g*g + (((767 - rmean) * b * b) >> 8))) | |||
} | |||
// Brighten returns a copy of this colour with its brightness adjusted. | |||
// | |||
// If factor is negative, the colour is darkened. | |||
// | |||
// Uses approach described here (http://www.pvladov.com/2012/09/make-color-lighter-or-darker.html). | |||
func (c Colour) Brighten(factor float64) Colour { | |||
r := float64(c.Red()) | |||
g := float64(c.Green()) | |||
b := float64(c.Blue()) | |||
if factor < 0 { | |||
factor++ | |||
r *= factor | |||
g *= factor | |||
b *= factor | |||
} else { | |||
r = (255-r)*factor + r | |||
g = (255-g)*factor + g | |||
b = (255-b)*factor + b | |||
} | |||
return NewColour(uint8(r), uint8(g), uint8(b)) | |||
} | |||
// BrightenOrDarken brightens a colour if it is < 0.5 brighteness or darkens if > 0.5 brightness. | |||
func (c Colour) BrightenOrDarken(factor float64) Colour { | |||
if c.Brightness() < 0.5 { | |||
return c.Brighten(factor) | |||
} | |||
return c.Brighten(-factor) | |||
} | |||
// Brightness of the colour (roughly) in the range 0.0 to 1.0 | |||
func (c Colour) Brightness() float64 { | |||
return (float64(c.Red()) + float64(c.Green()) + float64(c.Blue())) / 255.0 / 3.0 | |||
} | |||
// ParseColour in the forms #rgb, #rrggbb, #ansi<colour>, or #<colour>. | |||
// Will return an "unset" colour if invalid. | |||
func ParseColour(colour string) Colour { | |||
colour = normaliseColour(colour) | |||
n, err := strconv.ParseUint(colour, 16, 32) | |||
if err != nil { | |||
return 0 | |||
} | |||
return Colour(n + 1) | |||
} | |||
// MustParseColour is like ParseColour except it panics if the colour is invalid. | |||
// | |||
// Will panic if colour is in an invalid format. | |||
func MustParseColour(colour string) Colour { | |||
parsed := ParseColour(colour) | |||
if !parsed.IsSet() { | |||
panic(fmt.Errorf("invalid colour %q", colour)) | |||
} | |||
return parsed | |||
} | |||
// IsSet returns true if the colour is set. | |||
func (c Colour) IsSet() bool { return c != 0 } | |||
func (c Colour) String() string { return fmt.Sprintf("#%06x", int(c-1)) } | |||
func (c Colour) GoString() string { return fmt.Sprintf("Colour(0x%06x)", int(c-1)) } | |||
// Red component of colour. | |||
func (c Colour) Red() uint8 { return uint8(((c - 1) >> 16) & 0xff) } | |||
// Green component of colour. | |||
func (c Colour) Green() uint8 { return uint8(((c - 1) >> 8) & 0xff) } | |||
// Blue component of colour. | |||
func (c Colour) Blue() uint8 { return uint8((c - 1) & 0xff) } | |||
// Colours is an orderable set of colours. | |||
type Colours []Colour | |||
func (c Colours) Len() int { return len(c) } | |||
func (c Colours) Swap(i, j int) { c[i], c[j] = c[j], c[i] } | |||
func (c Colours) Less(i, j int) bool { return c[i] < c[j] } | |||
// Convert colours to #rrggbb. | |||
func normaliseColour(colour string) string { | |||
if ansi, ok := ANSI2RGB[colour]; ok { | |||
return ansi | |||
} | |||
if strings.HasPrefix(colour, "#") { | |||
colour = colour[1:] | |||
if len(colour) == 3 { | |||
return colour[0:1] + colour[0:1] + colour[1:2] + colour[1:2] + colour[2:3] + colour[2:3] | |||
} | |||
} | |||
return colour | |||
} |
@@ -0,0 +1,137 @@ | |||
package chroma | |||
import ( | |||
"bytes" | |||
) | |||
type delegatingLexer struct { | |||
root Lexer | |||
language Lexer | |||
} | |||
// DelegatingLexer combines two lexers to handle the common case of a language embedded inside another, such as PHP | |||
// inside HTML or PHP inside plain text. | |||
// | |||
// It takes two lexer as arguments: a root lexer and a language lexer. First everything is scanned using the language | |||
// lexer, which must return "Other" for unrecognised tokens. Then all "Other" tokens are lexed using the root lexer. | |||
// Finally, these two sets of tokens are merged. | |||
// | |||
// The lexers from the template lexer package use this base lexer. | |||
func DelegatingLexer(root Lexer, language Lexer) Lexer { | |||
return &delegatingLexer{ | |||
root: root, | |||
language: language, | |||
} | |||
} | |||
func (d *delegatingLexer) Config() *Config { | |||
return d.language.Config() | |||
} | |||
// An insertion is the character range where language tokens should be inserted. | |||
type insertion struct { | |||
start, end int | |||
tokens []Token | |||
} | |||
func (d *delegatingLexer) Tokenise(options *TokeniseOptions, text string) (Iterator, error) { // nolint: gocognit | |||
tokens, err := Tokenise(Coalesce(d.language), options, text) | |||
if err != nil { | |||
return nil, err | |||
} | |||
// Compute insertions and gather "Other" tokens. | |||
others := &bytes.Buffer{} | |||
insertions := []*insertion{} | |||
var insert *insertion | |||
offset := 0 | |||
var last Token | |||
for _, t := range tokens { | |||
if t.Type == Other { | |||
if last != EOF && insert != nil && last.Type != Other { | |||
insert.end = offset | |||
} | |||
others.WriteString(t.Value) | |||
} else { | |||
if last == EOF || last.Type == Other { | |||
insert = &insertion{start: offset} | |||
insertions = append(insertions, insert) | |||
} | |||
insert.tokens = append(insert.tokens, t) | |||
} | |||
last = t | |||
offset += len(t.Value) | |||
} | |||
if len(insertions) == 0 { | |||
return d.root.Tokenise(options, text) | |||
} | |||
// Lex the other tokens. | |||
rootTokens, err := Tokenise(Coalesce(d.root), options, others.String()) | |||
if err != nil { | |||
return nil, err | |||
} | |||
// Interleave the two sets of tokens. | |||
var out []Token | |||
offset = 0 // Offset into text. | |||
tokenIndex := 0 | |||
nextToken := func() Token { | |||
if tokenIndex >= len(rootTokens) { | |||
return EOF | |||
} | |||
t := rootTokens[tokenIndex] | |||
tokenIndex++ | |||
return t | |||
} | |||
insertionIndex := 0 | |||
nextInsertion := func() *insertion { | |||
if insertionIndex >= len(insertions) { | |||
return nil | |||
} | |||
i := insertions[insertionIndex] | |||
insertionIndex++ | |||
return i | |||
} | |||
t := nextToken() | |||
i := nextInsertion() | |||
for t != EOF || i != nil { | |||
// fmt.Printf("%d->%d:%q %d->%d:%q\n", offset, offset+len(t.Value), t.Value, i.start, i.end, Stringify(i.tokens...)) | |||
if t == EOF || (i != nil && i.start < offset+len(t.Value)) { | |||
var l Token | |||
l, t = splitToken(t, i.start-offset) | |||
if l != EOF { | |||
out = append(out, l) | |||
offset += len(l.Value) | |||
} | |||
out = append(out, i.tokens...) | |||
offset += i.end - i.start | |||
if t == EOF { | |||
t = nextToken() | |||
} | |||
i = nextInsertion() | |||
} else { | |||
out = append(out, t) | |||
offset += len(t.Value) | |||
t = nextToken() | |||
} | |||
} | |||
return Literator(out...), nil | |||
} | |||
func splitToken(t Token, offset int) (l Token, r Token) { | |||
if t == EOF { | |||
return EOF, EOF | |||
} | |||
if offset == 0 { | |||
return EOF, t | |||
} | |||
if offset == len(t.Value) { | |||
return t, EOF | |||
} | |||
l = t.Clone() | |||
r = t.Clone() | |||
l.Value = l.Value[:offset] | |||
r.Value = r.Value[offset:] | |||
return | |||
} |
@@ -0,0 +1,7 @@ | |||
// Package chroma takes source code and other structured text and converts it into syntax highlighted HTML, ANSI- | |||
// coloured text, etc. | |||
// | |||
// Chroma is based heavily on Pygments, and includes translators for Pygments lexers and styles. | |||
// | |||
// For more information, go here: https://github.com/alecthomas/chroma | |||
package chroma |
@@ -0,0 +1,43 @@ | |||
package chroma | |||
import ( | |||
"io" | |||
) | |||
// A Formatter for Chroma lexers. | |||
type Formatter interface { | |||
// Format returns a formatting function for tokens. | |||
// | |||
// If the iterator panics, the Formatter should recover. | |||
Format(w io.Writer, style *Style, iterator Iterator) error | |||
} | |||
// A FormatterFunc is a Formatter implemented as a function. | |||
// | |||
// Guards against iterator panics. | |||
type FormatterFunc func(w io.Writer, style *Style, iterator Iterator) error | |||
func (f FormatterFunc) Format(w io.Writer, s *Style, it Iterator) (err error) { // nolint | |||
defer func() { | |||
if perr := recover(); perr != nil { | |||
err = perr.(error) | |||
} | |||
}() | |||
return f(w, s, it) | |||
} | |||
type recoveringFormatter struct { | |||
Formatter | |||
} | |||
func (r recoveringFormatter) Format(w io.Writer, s *Style, it Iterator) (err error) { | |||
defer func() { | |||
if perr := recover(); perr != nil { | |||
err = perr.(error) | |||
} | |||
}() | |||
return r.Formatter.Format(w, s, it) | |||
} | |||
// RecoveringFormatter wraps a formatter with panic recovery. | |||
func RecoveringFormatter(formatter Formatter) Formatter { return recoveringFormatter{formatter} } |
@@ -0,0 +1,500 @@ | |||
package html | |||
import ( | |||
"fmt" | |||
"html" | |||
"io" | |||
"sort" | |||
"strings" | |||
"github.com/alecthomas/chroma" | |||
) | |||
// Option sets an option of the HTML formatter. | |||
type Option func(f *Formatter) | |||
// Standalone configures the HTML formatter for generating a standalone HTML document. | |||
func Standalone(b bool) Option { return func(f *Formatter) { f.standalone = b } } | |||
// ClassPrefix sets the CSS class prefix. | |||
func ClassPrefix(prefix string) Option { return func(f *Formatter) { f.prefix = prefix } } | |||
// WithClasses emits HTML using CSS classes, rather than inline styles. | |||
func WithClasses(b bool) Option { return func(f *Formatter) { f.Classes = b } } | |||
// WithAllClasses disables an optimisation that omits redundant CSS classes. | |||
func WithAllClasses(b bool) Option { return func(f *Formatter) { f.allClasses = b } } | |||
// TabWidth sets the number of characters for a tab. Defaults to 8. | |||
func TabWidth(width int) Option { return func(f *Formatter) { f.tabWidth = width } } | |||
// PreventSurroundingPre prevents the surrounding pre tags around the generated code. | |||
func PreventSurroundingPre(b bool) Option { | |||
return func(f *Formatter) { | |||
if b { | |||
f.preWrapper = nopPreWrapper | |||
} else { | |||
f.preWrapper = defaultPreWrapper | |||
} | |||
} | |||
} | |||
// WithPreWrapper allows control of the surrounding pre tags. | |||
func WithPreWrapper(wrapper PreWrapper) Option { | |||
return func(f *Formatter) { | |||
f.preWrapper = wrapper | |||
} | |||
} | |||
// WrapLongLines wraps long lines. | |||
func WrapLongLines(b bool) Option { | |||
return func(f *Formatter) { | |||
f.wrapLongLines = b | |||
} | |||
} | |||
// WithLineNumbers formats output with line numbers. | |||
func WithLineNumbers(b bool) Option { | |||
return func(f *Formatter) { | |||
f.lineNumbers = b | |||
} | |||
} | |||
// LineNumbersInTable will, when combined with WithLineNumbers, separate the line numbers | |||
// and code in table td's, which make them copy-and-paste friendly. | |||
func LineNumbersInTable(b bool) Option { | |||
return func(f *Formatter) { | |||
f.lineNumbersInTable = b | |||
} | |||
} | |||
// LinkableLineNumbers decorates the line numbers HTML elements with an "id" | |||
// attribute so they can be linked. | |||
func LinkableLineNumbers(b bool, prefix string) Option { | |||
return func(f *Formatter) { | |||
f.linkableLineNumbers = b | |||
f.lineNumbersIDPrefix = prefix | |||
} | |||
} | |||
// HighlightLines higlights the given line ranges with the Highlight style. | |||
// | |||
// A range is the beginning and ending of a range as 1-based line numbers, inclusive. | |||
func HighlightLines(ranges [][2]int) Option { | |||
return func(f *Formatter) { | |||
f.highlightRanges = ranges | |||
sort.Sort(f.highlightRanges) | |||
} | |||
} | |||
// BaseLineNumber sets the initial number to start line numbering at. Defaults to 1. | |||
func BaseLineNumber(n int) Option { | |||
return func(f *Formatter) { | |||
f.baseLineNumber = n | |||
} | |||
} | |||
// New HTML formatter. | |||
func New(options ...Option) *Formatter { | |||
f := &Formatter{ | |||
baseLineNumber: 1, | |||
preWrapper: defaultPreWrapper, | |||
} | |||
for _, option := range options { | |||
option(f) | |||
} | |||
return f | |||
} | |||
// PreWrapper defines the operations supported in WithPreWrapper. | |||
type PreWrapper interface { | |||
// Start is called to write a start <pre> element. | |||
// The code flag tells whether this block surrounds | |||
// highlighted code. This will be false when surrounding | |||
// line numbers. | |||
Start(code bool, styleAttr string) string | |||
// End is called to write the end </pre> element. | |||
End(code bool) string | |||
} | |||
type preWrapper struct { | |||
start func(code bool, styleAttr string) string | |||
end func(code bool) string | |||
} | |||
func (p preWrapper) Start(code bool, styleAttr string) string { | |||
return p.start(code, styleAttr) | |||
} | |||
func (p preWrapper) End(code bool) string { | |||
return p.end(code) | |||
} | |||
var ( | |||
nopPreWrapper = preWrapper{ | |||
start: func(code bool, styleAttr string) string { return "" }, | |||
end: func(code bool) string { return "" }, | |||
} | |||
defaultPreWrapper = preWrapper{ | |||
start: func(code bool, styleAttr string) string { | |||
if code { | |||
return fmt.Sprintf(`<pre tabindex="0"%s><code>`, styleAttr) | |||
} | |||
return fmt.Sprintf(`<pre tabindex="0"%s>`, styleAttr) | |||
}, | |||
end: func(code bool) string { | |||
if code { | |||
return `</code></pre>` | |||
} | |||
return `</pre>` | |||
}, | |||
} | |||
) | |||
// Formatter that generates HTML. | |||
type Formatter struct { | |||
standalone bool | |||
prefix string | |||
Classes bool // Exported field to detect when classes are being used | |||
allClasses bool | |||
preWrapper PreWrapper | |||
tabWidth int | |||
wrapLongLines bool | |||
lineNumbers bool | |||
lineNumbersInTable bool | |||
linkableLineNumbers bool | |||
lineNumbersIDPrefix string | |||
highlightRanges highlightRanges | |||
baseLineNumber int | |||
} | |||
type highlightRanges [][2]int | |||
func (h highlightRanges) Len() int { return len(h) } | |||
func (h highlightRanges) Swap(i, j int) { h[i], h[j] = h[j], h[i] } | |||
func (h highlightRanges) Less(i, j int) bool { return h[i][0] < h[j][0] } | |||
func (f *Formatter) Format(w io.Writer, style *chroma.Style, iterator chroma.Iterator) (err error) { | |||
return f.writeHTML(w, style, iterator.Tokens()) | |||
} | |||
// We deliberately don't use html/template here because it is two orders of magnitude slower (benchmarked). | |||
// | |||
// OTOH we need to be super careful about correct escaping... | |||
func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []chroma.Token) (err error) { // nolint: gocyclo | |||
css := f.styleToCSS(style) | |||
if !f.Classes { | |||
for t, style := range css { | |||
css[t] = compressStyle(style) | |||
} | |||
} | |||
if f.standalone { | |||
fmt.Fprint(w, "<html>\n") | |||
if f.Classes { | |||
fmt.Fprint(w, "<style type=\"text/css\">\n") | |||
err = f.WriteCSS(w, style) | |||
if err != nil { | |||
return err | |||
} | |||
fmt.Fprintf(w, "body { %s; }\n", css[chroma.Background]) | |||
fmt.Fprint(w, "</style>") | |||
} | |||
fmt.Fprintf(w, "<body%s>\n", f.styleAttr(css, chroma.Background)) | |||
} | |||
wrapInTable := f.lineNumbers && f.lineNumbersInTable | |||
lines := chroma.SplitTokensIntoLines(tokens) | |||
lineDigits := len(fmt.Sprintf("%d", f.baseLineNumber+len(lines)-1)) | |||
highlightIndex := 0 | |||
if wrapInTable { | |||
// List line numbers in its own <td> | |||
fmt.Fprintf(w, "<div%s>\n", f.styleAttr(css, chroma.PreWrapper)) | |||
fmt.Fprintf(w, "<table%s><tr>", f.styleAttr(css, chroma.LineTable)) | |||
fmt.Fprintf(w, "<td%s>\n", f.styleAttr(css, chroma.LineTableTD)) | |||
fmt.Fprintf(w, f.preWrapper.Start(false, f.styleAttr(css, chroma.PreWrapper))) | |||
for index := range lines { | |||
line := f.baseLineNumber + index | |||
highlight, next := f.shouldHighlight(highlightIndex, line) | |||
if next { | |||
highlightIndex++ | |||
} | |||
if highlight { | |||
fmt.Fprintf(w, "<span%s>", f.styleAttr(css, chroma.LineHighlight)) | |||
} | |||
fmt.Fprintf(w, "<span%s%s>%s\n</span>", f.styleAttr(css, chroma.LineNumbersTable), f.lineIDAttribute(line), f.lineTitleWithLinkIfNeeded(lineDigits, line)) | |||
if highlight { | |||
fmt.Fprintf(w, "</span>") | |||
} | |||
} | |||
fmt.Fprint(w, f.preWrapper.End(false)) | |||
fmt.Fprint(w, "</td>\n") | |||
fmt.Fprintf(w, "<td%s>\n", f.styleAttr(css, chroma.LineTableTD, "width:100%")) | |||
} | |||
fmt.Fprintf(w, f.preWrapper.Start(true, f.styleAttr(css, chroma.PreWrapper))) | |||
highlightIndex = 0 | |||
for index, tokens := range lines { | |||
// 1-based line number. | |||
line := f.baseLineNumber + index | |||
highlight, next := f.shouldHighlight(highlightIndex, line) | |||
if next { | |||
highlightIndex++ | |||
} | |||
// Start of Line | |||
fmt.Fprint(w, `<span`) | |||
if highlight { | |||
// Line + LineHighlight | |||
if f.Classes { | |||
fmt.Fprintf(w, ` class="%s %s"`, f.class(chroma.Line), f.class(chroma.LineHighlight)) | |||
} else { | |||
fmt.Fprintf(w, ` style="%s %s"`, css[chroma.Line], css[chroma.LineHighlight]) | |||
} | |||
fmt.Fprint(w, `>`) | |||
} else { | |||
fmt.Fprintf(w, "%s>", f.styleAttr(css, chroma.Line)) | |||
} | |||
// Line number | |||
if f.lineNumbers && !wrapInTable { | |||
fmt.Fprintf(w, "<span%s%s>%s</span>", f.styleAttr(css, chroma.LineNumbers), f.lineIDAttribute(line), f.lineTitleWithLinkIfNeeded(lineDigits, line)) | |||
} | |||
fmt.Fprintf(w, `<span%s>`, f.styleAttr(css, chroma.CodeLine)) | |||
for _, token := range tokens { | |||
html := html.EscapeString(token.String()) | |||
attr := f.styleAttr(css, token.Type) | |||
if attr != "" { | |||
html = fmt.Sprintf("<span%s>%s</span>", attr, html) | |||
} | |||
fmt.Fprint(w, html) | |||
} | |||
fmt.Fprint(w, `</span>`) // End of CodeLine | |||
fmt.Fprint(w, `</span>`) // End of Line | |||
} | |||
fmt.Fprintf(w, f.preWrapper.End(true)) | |||
if wrapInTable { | |||
fmt.Fprint(w, "</td></tr></table>\n") | |||
fmt.Fprint(w, "</div>\n") | |||
} | |||
if f.standalone { | |||
fmt.Fprint(w, "\n</body>\n") | |||
fmt.Fprint(w, "</html>\n") | |||
} | |||
return nil | |||
} | |||
func (f *Formatter) lineIDAttribute(line int) string { | |||
if !f.linkableLineNumbers { | |||
return "" | |||
} | |||
return fmt.Sprintf(" id=\"%s\"", f.lineID(line)) | |||
} | |||
func (f *Formatter) lineTitleWithLinkIfNeeded(lineDigits, line int) string { | |||
title := fmt.Sprintf("%*d", lineDigits, line) | |||
if !f.linkableLineNumbers { | |||
return title | |||
} | |||
return fmt.Sprintf("<a style=\"outline: none; text-decoration:none; color:inherit\" href=\"#%s\">%s</a>", f.lineID(line), title) | |||
} | |||
func (f *Formatter) lineID(line int) string { | |||
return fmt.Sprintf("%s%d", f.lineNumbersIDPrefix, line) | |||
} | |||
func (f *Formatter) shouldHighlight(highlightIndex, line int) (bool, bool) { | |||
next := false | |||
for highlightIndex < len(f.highlightRanges) && line > f.highlightRanges[highlightIndex][1] { | |||
highlightIndex++ | |||
next = true | |||
} | |||
if highlightIndex < len(f.highlightRanges) { | |||
hrange := f.highlightRanges[highlightIndex] | |||
if line >= hrange[0] && line <= hrange[1] { | |||
return true, next | |||
} | |||
} | |||
return false, next | |||
} | |||
func (f *Formatter) class(t chroma.TokenType) string { | |||
for t != 0 { | |||
if cls, ok := chroma.StandardTypes[t]; ok { | |||
if cls != "" { | |||
return f.prefix + cls | |||
} | |||
return "" | |||
} | |||
t = t.Parent() | |||
} | |||
if cls := chroma.StandardTypes[t]; cls != "" { | |||
return f.prefix + cls | |||
} | |||
return "" | |||
} | |||
func (f *Formatter) styleAttr(styles map[chroma.TokenType]string, tt chroma.TokenType, extraCSS ...string) string { | |||
if f.Classes { | |||
cls := f.class(tt) | |||
if cls == "" { | |||
return "" | |||
} | |||
return fmt.Sprintf(` class="%s"`, cls) | |||
} | |||
if _, ok := styles[tt]; !ok { | |||
tt = tt.SubCategory() | |||
if _, ok := styles[tt]; !ok { | |||
tt = tt.Category() | |||
if _, ok := styles[tt]; !ok { | |||
return "" | |||
} | |||
} | |||
} | |||
css := []string{styles[tt]} | |||
css = append(css, extraCSS...) | |||
return fmt.Sprintf(` style="%s"`, strings.Join(css, ";")) | |||
} | |||
func (f *Formatter) tabWidthStyle() string { | |||
if f.tabWidth != 0 && f.tabWidth != 8 { | |||
return fmt.Sprintf("; -moz-tab-size: %[1]d; -o-tab-size: %[1]d; tab-size: %[1]d", f.tabWidth) | |||
} | |||
return "" | |||
} | |||
// WriteCSS writes CSS style definitions (without any surrounding HTML). | |||
func (f *Formatter) WriteCSS(w io.Writer, style *chroma.Style) error { | |||
css := f.styleToCSS(style) | |||
// Special-case background as it is mapped to the outer ".chroma" class. | |||
if _, err := fmt.Fprintf(w, "/* %s */ .%sbg { %s }\n", chroma.Background, f.prefix, css[chroma.Background]); err != nil { | |||
return err | |||
} | |||
// Special-case PreWrapper as it is the ".chroma" class. | |||
if _, err := fmt.Fprintf(w, "/* %s */ .%schroma { %s }\n", chroma.PreWrapper, f.prefix, css[chroma.PreWrapper]); err != nil { | |||
return err | |||
} | |||
// Special-case code column of table to expand width. | |||
if f.lineNumbers && f.lineNumbersInTable { | |||
if _, err := fmt.Fprintf(w, "/* %s */ .%schroma .%s:last-child { width: 100%%; }", | |||
chroma.LineTableTD, f.prefix, f.class(chroma.LineTableTD)); err != nil { | |||
return err | |||
} | |||
} | |||
// Special-case line number highlighting when targeted. | |||
if f.lineNumbers || f.lineNumbersInTable { | |||
targetedLineCSS := StyleEntryToCSS(style.Get(chroma.LineHighlight)) | |||
for _, tt := range []chroma.TokenType{chroma.LineNumbers, chroma.LineNumbersTable} { | |||
fmt.Fprintf(w, "/* %s targeted by URL anchor */ .%schroma .%s:target { %s }\n", tt, f.prefix, f.class(tt), targetedLineCSS) | |||
} | |||
} | |||
tts := []int{} | |||
for tt := range css { | |||
tts = append(tts, int(tt)) | |||
} | |||
sort.Ints(tts) | |||
for _, ti := range tts { | |||
tt := chroma.TokenType(ti) | |||
switch tt { | |||
case chroma.Background, chroma.PreWrapper: | |||
continue | |||
} | |||
class := f.class(tt) | |||
if class == "" { | |||
continue | |||
} | |||
styles := css[tt] | |||
if _, err := fmt.Fprintf(w, "/* %s */ .%schroma .%s { %s }\n", tt, f.prefix, class, styles); err != nil { | |||
return err | |||
} | |||
} | |||
return nil | |||
} | |||
func (f *Formatter) styleToCSS(style *chroma.Style) map[chroma.TokenType]string { | |||
classes := map[chroma.TokenType]string{} | |||
bg := style.Get(chroma.Background) | |||
// Convert the style. | |||
for t := range chroma.StandardTypes { | |||
entry := style.Get(t) | |||
if t != chroma.Background { | |||
entry = entry.Sub(bg) | |||
} | |||
if !f.allClasses && entry.IsZero() { | |||
continue | |||
} | |||
classes[t] = StyleEntryToCSS(entry) | |||
} | |||
classes[chroma.Background] += f.tabWidthStyle() | |||
classes[chroma.PreWrapper] += classes[chroma.Background] + `;` | |||
// Make PreWrapper a grid to show highlight style with full width. | |||
if len(f.highlightRanges) > 0 { | |||
classes[chroma.PreWrapper] += `display: grid;` | |||
} | |||
// Make PreWrapper wrap long lines. | |||
if f.wrapLongLines { | |||
classes[chroma.PreWrapper] += `white-space: pre-wrap; word-break: break-word;` | |||
} | |||
lineNumbersStyle := `white-space: pre; user-select: none; margin-right: 0.4em; padding: 0 0.4em 0 0.4em;` | |||
// All rules begin with default rules followed by user provided rules | |||
classes[chroma.Line] = `display: flex;` + classes[chroma.Line] | |||
classes[chroma.LineNumbers] = lineNumbersStyle + classes[chroma.LineNumbers] | |||
classes[chroma.LineNumbersTable] = lineNumbersStyle + classes[chroma.LineNumbersTable] | |||
classes[chroma.LineTable] = "border-spacing: 0; padding: 0; margin: 0; border: 0;" + classes[chroma.LineTable] | |||
classes[chroma.LineTableTD] = "vertical-align: top; padding: 0; margin: 0; border: 0;" + classes[chroma.LineTableTD] | |||
return classes | |||
} | |||
// StyleEntryToCSS converts a chroma.StyleEntry to CSS attributes. | |||
func StyleEntryToCSS(e chroma.StyleEntry) string { | |||
styles := []string{} | |||
if e.Colour.IsSet() { | |||
styles = append(styles, "color: "+e.Colour.String()) | |||
} | |||
if e.Background.IsSet() { | |||
styles = append(styles, "background-color: "+e.Background.String()) | |||
} | |||
if e.Bold == chroma.Yes { | |||
styles = append(styles, "font-weight: bold") | |||
} | |||
if e.Italic == chroma.Yes { | |||
styles = append(styles, "font-style: italic") | |||
} | |||
if e.Underline == chroma.Yes { | |||
styles = append(styles, "text-decoration: underline") | |||
} | |||
return strings.Join(styles, "; ") | |||
} | |||
// Compress CSS attributes - remove spaces, transform 6-digit colours to 3. | |||
func compressStyle(s string) string { | |||
parts := strings.Split(s, ";") | |||
out := []string{} | |||
for _, p := range parts { | |||
p = strings.Join(strings.Fields(p), " ") | |||
p = strings.Replace(p, ": ", ":", 1) | |||
if strings.Contains(p, "#") { | |||
c := p[len(p)-6:] | |||
if c[0] == c[1] && c[2] == c[3] && c[4] == c[5] { | |||
p = p[:len(p)-6] + c[0:1] + c[2:3] + c[4:5] | |||
} | |||
} | |||
out = append(out, p) | |||
} | |||
return strings.Join(out, ";") | |||
} |
@@ -0,0 +1,9 @@ | |||
module github.com/alecthomas/chroma | |||
go 1.13 | |||
require ( | |||
github.com/davecgh/go-spew v1.1.1 // indirect | |||
github.com/dlclark/regexp2 v1.4.0 | |||
github.com/stretchr/testify v1.7.0 | |||
) |
@@ -0,0 +1,14 @@ | |||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | |||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | |||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | |||
github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E= | |||
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= | |||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | |||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | |||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | |||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= | |||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | |||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | |||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | |||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | |||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
@@ -0,0 +1,76 @@ | |||
package chroma | |||
import "strings" | |||
// An Iterator across tokens. | |||
// | |||
// EOF will be returned at the end of the Token stream. | |||
// | |||
// If an error occurs within an Iterator, it may propagate this in a panic. Formatters should recover. | |||
type Iterator func() Token | |||
// Tokens consumes all tokens from the iterator and returns them as a slice. | |||
func (i Iterator) Tokens() []Token { | |||
var out []Token | |||
for t := i(); t != EOF; t = i() { | |||
out = append(out, t) | |||
} | |||
return out | |||
} | |||
// Concaterator concatenates tokens from a series of iterators. | |||
func Concaterator(iterators ...Iterator) Iterator { | |||
return func() Token { | |||
for len(iterators) > 0 { | |||
t := iterators[0]() | |||
if t != EOF { | |||
return t | |||
} | |||
iterators = iterators[1:] | |||
} | |||
return EOF | |||
} | |||
} | |||
// Literator converts a sequence of literal Tokens into an Iterator. | |||
func Literator(tokens ...Token) Iterator { | |||
return func() Token { | |||
if len(tokens) == 0 { | |||
return EOF | |||
} | |||
token := tokens[0] | |||
tokens = tokens[1:] | |||
return token | |||
} | |||
} | |||
// SplitTokensIntoLines splits tokens containing newlines in two. | |||
func SplitTokensIntoLines(tokens []Token) (out [][]Token) { | |||
var line []Token // nolint: prealloc | |||
for _, token := range tokens { | |||
for strings.Contains(token.Value, "\n") { | |||
parts := strings.SplitAfterN(token.Value, "\n", 2) | |||
// Token becomes the tail. | |||
token.Value = parts[1] | |||
// Append the head to the line and flush the line. | |||
clone := token.Clone() | |||
clone.Value = parts[0] | |||
line = append(line, clone) | |||
out = append(out, line) | |||
line = nil | |||
} | |||
line = append(line, token) | |||
} | |||
if len(line) > 0 { | |||
out = append(out, line) | |||
} | |||
// Strip empty trailing token line. | |||
if len(out) > 0 { | |||
last := out[len(out)-1] | |||
if len(last) == 1 && last[0].Value == "" { | |||
out = out[:len(out)-1] | |||
} | |||
} | |||
return | |||
} |
@@ -0,0 +1,128 @@ | |||
package chroma | |||
import ( | |||
"fmt" | |||
"strings" | |||
) | |||
var ( | |||
defaultOptions = &TokeniseOptions{ | |||
State: "root", | |||
EnsureLF: true, | |||
} | |||
) | |||
// Config for a lexer. | |||
type Config struct { | |||
// Name of the lexer. | |||
Name string | |||
// Shortcuts for the lexer | |||
Aliases []string | |||
// File name globs | |||
Filenames []string | |||
// Secondary file name globs | |||
AliasFilenames []string | |||
// MIME types | |||
MimeTypes []string | |||
// Regex matching is case-insensitive. | |||
CaseInsensitive bool | |||
// Regex matches all characters. | |||
DotAll bool | |||
// Regex does not match across lines ($ matches EOL). | |||
// | |||
// Defaults to multiline. | |||
NotMultiline bool | |||
// Don't strip leading and trailing newlines from the input. | |||
// DontStripNL bool | |||
// Strip all leading and trailing whitespace from the input | |||
// StripAll bool | |||
// Make sure that the input ends with a newline. This | |||
// is required for some lexers that consume input linewise. | |||
EnsureNL bool | |||
// If given and greater than 0, expand tabs in the input. | |||
// TabSize int | |||
// Priority of lexer. | |||
// | |||
// If this is 0 it will be treated as a default of 1. | |||
Priority float32 | |||
} | |||
// Token output to formatter. | |||
type Token struct { | |||
Type TokenType `json:"type"` | |||
Value string `json:"value"` | |||
} | |||
func (t *Token) String() string { return t.Value } | |||
func (t *Token) GoString() string { return fmt.Sprintf("&Token{%s, %q}", t.Type, t.Value) } | |||
// Clone returns a clone of the Token. | |||
func (t *Token) Clone() Token { | |||
return *t | |||
} | |||
// EOF is returned by lexers at the end of input. | |||
var EOF Token | |||
// TokeniseOptions contains options for tokenisers. | |||
type TokeniseOptions struct { | |||
// State to start tokenisation in. Defaults to "root". | |||
State string | |||
// Nested tokenisation. | |||
Nested bool | |||
// If true, all EOLs are converted into LF | |||
// by replacing CRLF and CR | |||
EnsureLF bool | |||
} | |||
// A Lexer for tokenising source code. | |||
type Lexer interface { | |||
// Config describing the features of the Lexer. | |||
Config() *Config | |||
// Tokenise returns an Iterator over tokens in text. | |||
Tokenise(options *TokeniseOptions, text string) (Iterator, error) | |||
} | |||
// Lexers is a slice of lexers sortable by name. | |||
type Lexers []Lexer | |||
func (l Lexers) Len() int { return len(l) } | |||
func (l Lexers) Swap(i, j int) { l[i], l[j] = l[j], l[i] } | |||
func (l Lexers) Less(i, j int) bool { | |||
return strings.ToLower(l[i].Config().Name) < strings.ToLower(l[j].Config().Name) | |||
} | |||
// PrioritisedLexers is a slice of lexers sortable by priority. | |||
type PrioritisedLexers []Lexer | |||
func (l PrioritisedLexers) Len() int { return len(l) } | |||
func (l PrioritisedLexers) Swap(i, j int) { l[i], l[j] = l[j], l[i] } | |||
func (l PrioritisedLexers) Less(i, j int) bool { | |||
ip := l[i].Config().Priority | |||
if ip == 0 { | |||
ip = 1 | |||
} | |||
jp := l[j].Config().Priority | |||
if jp == 0 { | |||
jp = 1 | |||
} | |||
return ip > jp | |||
} | |||
// Analyser determines how appropriate this lexer is for the given text. | |||
type Analyser interface { | |||
AnalyseText(text string) float32 | |||
} |
@@ -0,0 +1,40 @@ | |||
# Lexer tests | |||
The tests in this directory feed a known input `testdata/<name>.actual` into the parser for `<name>` and check | |||
that its output matches `<name>.exported`. | |||
It is also possible to perform several tests on a same parser `<name>`, by placing know inputs `*.actual` into a | |||
directory `testdata/<name>/`. | |||
## Running the tests | |||
Run the tests as normal: | |||
```go | |||
go test ./lexers | |||
``` | |||
## Update existing tests | |||
When you add a new test data file (`*.actual`), you need to regenerate all tests. That's how Chroma creates the `*.expected` test file based on the corresponding lexer. | |||
To regenerate all tests, type in your terminal: | |||
```go | |||
RECORD=true go test ./lexers | |||
``` | |||
This first sets the `RECORD` environment variable to `true`. Then it runs `go test` on the `./lexers` directory of the Chroma project. | |||
(That environment variable tells Chroma it needs to output test data. After running `go test ./lexers` you can remove or reset that variable.) | |||
### Windows users | |||
Windows users will find that the `RECORD=true go test ./lexers` command fails in both the standard command prompt terminal and in PowerShell. | |||
Instead we have to perform both steps separately: | |||
- Set the `RECORD` environment variable to `true`. | |||
+ In the regular command prompt window, the `set` command sets an environment variable for the current session: `set RECORD=true`. See [this page](https://superuser.com/questions/212150/how-to-set-env-variable-in-windows-cmd-line) for more. | |||
+ In PowerShell, you can use the `$env:RECORD = 'true'` command for that. See [this article](https://mcpmag.com/articles/2019/03/28/environment-variables-in-powershell.aspx) for more. | |||
+ You can also make a persistent environment variable by hand in the Windows computer settings. See [this article](https://www.computerhope.com/issues/ch000549.htm) for how. | |||
- When the environment variable is set, run `go tests ./lexers`. | |||
Chroma will now regenerate the test files and print its results to the console window. |
@@ -0,0 +1,60 @@ | |||
package a | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// ABAP lexer. | |||
var Abap = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "ABAP", | |||
Aliases: []string{"abap"}, | |||
Filenames: []string{"*.abap", "*.ABAP"}, | |||
MimeTypes: []string{"text/x-abap"}, | |||
CaseInsensitive: true, | |||
}, | |||
abapRules, | |||
)) | |||
func abapRules() Rules { | |||
return Rules{ | |||
"common": { | |||
{`\s+`, Text, nil}, | |||
{`^\*.*$`, CommentSingle, nil}, | |||
{`\".*?\n`, CommentSingle, nil}, | |||
{`##\w+`, CommentSpecial, nil}, | |||
}, | |||
"variable-names": { | |||
{`<\S+>`, NameVariable, nil}, | |||
{`\w[\w~]*(?:(\[\])|->\*)?`, NameVariable, nil}, | |||
}, | |||
"root": { | |||
Include("common"), | |||
{`CALL\s+(?:BADI|CUSTOMER-FUNCTION|FUNCTION)`, Keyword, nil}, | |||
{`(CALL\s+(?:DIALOG|SCREEN|SUBSCREEN|SELECTION-SCREEN|TRANSACTION|TRANSFORMATION))\b`, Keyword, nil}, | |||
{`(FORM|PERFORM)(\s+)(\w+)`, ByGroups(Keyword, Text, NameFunction), nil}, | |||
{`(PERFORM)(\s+)(\()(\w+)(\))`, ByGroups(Keyword, Text, Punctuation, NameVariable, Punctuation), nil}, | |||
{`(MODULE)(\s+)(\S+)(\s+)(INPUT|OUTPUT)`, ByGroups(Keyword, Text, NameFunction, Text, Keyword), nil}, | |||
{`(METHOD)(\s+)([\w~]+)`, ByGroups(Keyword, Text, NameFunction), nil}, | |||
{`(\s+)([\w\-]+)([=\-]>)([\w\-~]+)`, ByGroups(Text, NameVariable, Operator, NameFunction), nil}, | |||
{`(?<=(=|-)>)([\w\-~]+)(?=\()`, NameFunction, nil}, | |||
{`(TEXT)(-)(\d{3})`, ByGroups(Keyword, Punctuation, LiteralNumberInteger), nil}, | |||
{`(TEXT)(-)(\w{3})`, ByGroups(Keyword, Punctuation, NameVariable), nil}, | |||
{`(ADD-CORRESPONDING|AUTHORITY-CHECK|CLASS-DATA|CLASS-EVENTS|CLASS-METHODS|CLASS-POOL|DELETE-ADJACENT|DIVIDE-CORRESPONDING|EDITOR-CALL|ENHANCEMENT-POINT|ENHANCEMENT-SECTION|EXIT-COMMAND|FIELD-GROUPS|FIELD-SYMBOLS|FUNCTION-POOL|INTERFACE-POOL|INVERTED-DATE|LOAD-OF-PROGRAM|LOG-POINT|MESSAGE-ID|MOVE-CORRESPONDING|MULTIPLY-CORRESPONDING|NEW-LINE|NEW-PAGE|NEW-SECTION|NO-EXTENSION|OUTPUT-LENGTH|PRINT-CONTROL|SELECT-OPTIONS|START-OF-SELECTION|SUBTRACT-CORRESPONDING|SYNTAX-CHECK|SYSTEM-EXCEPTIONS|TYPE-POOL|TYPE-POOLS|NO-DISPLAY)\b`, Keyword, nil}, | |||
{`(?<![-\>])(CREATE\s+(PUBLIC|PRIVATE|DATA|OBJECT)|(PUBLIC|PRIVATE|PROTECTED)\s+SECTION|(TYPE|LIKE)\s+((LINE\s+OF|REF\s+TO|(SORTED|STANDARD|HASHED)\s+TABLE\s+OF))?|FROM\s+(DATABASE|MEMORY)|CALL\s+METHOD|(GROUP|ORDER) BY|HAVING|SEPARATED BY|GET\s+(BADI|BIT|CURSOR|DATASET|LOCALE|PARAMETER|PF-STATUS|(PROPERTY|REFERENCE)\s+OF|RUN\s+TIME|TIME\s+(STAMP)?)?|SET\s+(BIT|BLANK\s+LINES|COUNTRY|CURSOR|DATASET|EXTENDED\s+CHECK|HANDLER|HOLD\s+DATA|LANGUAGE|LEFT\s+SCROLL-BOUNDARY|LOCALE|MARGIN|PARAMETER|PF-STATUS|PROPERTY\s+OF|RUN\s+TIME\s+(ANALYZER|CLOCK\s+RESOLUTION)|SCREEN|TITLEBAR|UPADTE\s+TASK\s+LOCAL|USER-COMMAND)|CONVERT\s+((INVERTED-)?DATE|TIME|TIME\s+STAMP|TEXT)|(CLOSE|OPEN)\s+(DATASET|CURSOR)|(TO|FROM)\s+(DATA BUFFER|INTERNAL TABLE|MEMORY ID|DATABASE|SHARED\s+(MEMORY|BUFFER))|DESCRIBE\s+(DISTANCE\s+BETWEEN|FIELD|LIST|TABLE)|FREE\s(MEMORY|OBJECT)?|PROCESS\s+(BEFORE\s+OUTPUT|AFTER\s+INPUT|ON\s+(VALUE-REQUEST|HELP-REQUEST))|AT\s+(LINE-SELECTION|USER-COMMAND|END\s+OF|NEW)|AT\s+SELECTION-SCREEN(\s+(ON(\s+(BLOCK|(HELP|VALUE)-REQUEST\s+FOR|END\s+OF|RADIOBUTTON\s+GROUP))?|OUTPUT))?|SELECTION-SCREEN:?\s+((BEGIN|END)\s+OF\s+((TABBED\s+)?BLOCK|LINE|SCREEN)|COMMENT|FUNCTION\s+KEY|INCLUDE\s+BLOCKS|POSITION|PUSHBUTTON|SKIP|ULINE)|LEAVE\s+(LIST-PROCESSING|PROGRAM|SCREEN|TO LIST-PROCESSING|TO TRANSACTION)(ENDING|STARTING)\s+AT|FORMAT\s+(COLOR|INTENSIFIED|INVERSE|HOTSPOT|INPUT|FRAMES|RESET)|AS\s+(CHECKBOX|SUBSCREEN|WINDOW)|WITH\s+(((NON-)?UNIQUE)?\s+KEY|FRAME)|(BEGIN|END)\s+OF|DELETE(\s+ADJACENT\s+DUPLICATES\sFROM)?|COMPARING(\s+ALL\s+FIELDS)?|(INSERT|APPEND)(\s+INITIAL\s+LINE\s+(IN)?TO|\s+LINES\s+OF)?|IN\s+((BYTE|CHARACTER)\s+MODE|PROGRAM)|END-OF-(DEFINITION|PAGE|SELECTION)|WITH\s+FRAME(\s+TITLE)|(REPLACE|FIND)\s+((FIRST|ALL)\s+OCCURRENCES?\s+OF\s+)?(SUBSTRING|REGEX)?|MATCH\s+(LENGTH|COUNT|LINE|OFFSET)|(RESPECTING|IGNORING)\s+CASE|IN\s+UPDATE\s+TASK|(SOURCE|RESULT)\s+(XML)?|REFERENCE\s+INTO|AND\s+(MARK|RETURN)|CLIENT\s+SPECIFIED|CORRESPONDING\s+FIELDS\s+OF|IF\s+FOUND|FOR\s+EVENT|INHERITING\s+FROM|LEAVE\s+TO\s+SCREEN|LOOP\s+AT\s+(SCREEN)?|LOWER\s+CASE|MATCHCODE\s+OBJECT|MODIF\s+ID|MODIFY\s+SCREEN|NESTING\s+LEVEL|NO\s+INTERVALS|OF\s+STRUCTURE|RADIOBUTTON\s+GROUP|RANGE\s+OF|REF\s+TO|SUPPRESS DIALOG|TABLE\s+OF|UPPER\s+CASE|TRANSPORTING\s+NO\s+FIELDS|VALUE\s+CHECK|VISIBLE\s+LENGTH|HEADER\s+LINE|COMMON\s+PART)\b`, Keyword, nil}, | |||
{`(^|(?<=(\s|\.)))(ABBREVIATED|ABSTRACT|ADD|ALIASES|ALIGN|ALPHA|ASSERT|AS|ASSIGN(ING)?|AT(\s+FIRST)?|BACK|BLOCK|BREAK-POINT|CASE|CATCH|CHANGING|CHECK|CLASS|CLEAR|COLLECT|COLOR|COMMIT|CREATE|COMMUNICATION|COMPONENTS?|COMPUTE|CONCATENATE|CONDENSE|CONSTANTS|CONTEXTS|CONTINUE|CONTROLS|COUNTRY|CURRENCY|DATA|DATE|DECIMALS|DEFAULT|DEFINE|DEFINITION|DEFERRED|DEMAND|DETAIL|DIRECTORY|DIVIDE|DO|DUMMY|ELSE(IF)?|ENDAT|ENDCASE|ENDCATCH|ENDCLASS|ENDDO|ENDFORM|ENDFUNCTION|ENDIF|ENDINTERFACE|ENDLOOP|ENDMETHOD|ENDMODULE|ENDSELECT|ENDTRY|ENDWHILE|ENHANCEMENT|EVENTS|EXACT|EXCEPTIONS?|EXIT|EXPONENT|EXPORT|EXPORTING|EXTRACT|FETCH|FIELDS?|FOR|FORM|FORMAT|FREE|FROM|FUNCTION|HIDE|ID|IF|IMPORT|IMPLEMENTATION|IMPORTING|IN|INCLUDE|INCLUDING|INDEX|INFOTYPES|INITIALIZATION|INTERFACE|INTERFACES|INTO|LANGUAGE|LEAVE|LENGTH|LINES|LOAD|LOCAL|JOIN|KEY|NEXT|MAXIMUM|MESSAGE|METHOD[S]?|MINIMUM|MODULE|MODIFIER|MODIFY|MOVE|MULTIPLY|NODES|NUMBER|OBLIGATORY|OBJECT|OF|OFF|ON|OTHERS|OVERLAY|PACK|PAD|PARAMETERS|PERCENTAGE|POSITION|PROGRAM|PROVIDE|PUBLIC|PUT|PF\d\d|RAISE|RAISING|RANGES?|READ|RECEIVE|REDEFINITION|REFRESH|REJECT|REPORT|RESERVE|RESUME|RETRY|RETURN|RETURNING|RIGHT|ROLLBACK|REPLACE|SCROLL|SEARCH|SELECT|SHIFT|SIGN|SINGLE|SIZE|SKIP|SORT|SPLIT|STATICS|STOP|STYLE|SUBMATCHES|SUBMIT|SUBTRACT|SUM(?!\()|SUMMARY|SUMMING|SUPPLY|TABLE|TABLES|TIMESTAMP|TIMES?|TIMEZONE|TITLE|\??TO|TOP-OF-PAGE|TRANSFER|TRANSLATE|TRY|TYPES|ULINE|UNDER|UNPACK|UPDATE|USING|VALUE|VALUES|VIA|VARYING|VARY|WAIT|WHEN|WHERE|WIDTH|WHILE|WITH|WINDOW|WRITE|XSD|ZERO)\b`, Keyword, nil}, | |||
{`(abs|acos|asin|atan|boolc|boolx|bit_set|char_off|charlen|ceil|cmax|cmin|condense|contains|contains_any_of|contains_any_not_of|concat_lines_of|cos|cosh|count|count_any_of|count_any_not_of|dbmaxlen|distance|escape|exp|find|find_end|find_any_of|find_any_not_of|floor|frac|from_mixed|insert|lines|log|log10|match|matches|nmax|nmin|numofchar|repeat|replace|rescale|reverse|round|segment|shift_left|shift_right|sign|sin|sinh|sqrt|strlen|substring|substring_after|substring_from|substring_before|substring_to|tan|tanh|to_upper|to_lower|to_mixed|translate|trunc|xstrlen)(\()\b`, ByGroups(NameBuiltin, Punctuation), nil}, | |||
{`&[0-9]`, Name, nil}, | |||
{`[0-9]+`, LiteralNumberInteger, nil}, | |||
{`(?<=(\s|.))(AND|OR|EQ|NE|GT|LT|GE|LE|CO|CN|CA|NA|CS|NOT|NS|CP|NP|BYTE-CO|BYTE-CN|BYTE-CA|BYTE-NA|BYTE-CS|BYTE-NS|IS\s+(NOT\s+)?(INITIAL|ASSIGNED|REQUESTED|BOUND))\b`, OperatorWord, nil}, | |||
Include("variable-names"), | |||
{`[?*<>=\-+&]`, Operator, nil}, | |||
{`'(''|[^'])*'`, LiteralStringSingle, nil}, | |||
{"`([^`])*`", LiteralStringSingle, nil}, | |||
{`([|}])([^{}|]*?)([|{])`, ByGroups(Punctuation, LiteralStringSingle, Punctuation), nil}, | |||
{`[/;:()\[\],.]`, Punctuation, nil}, | |||
{`(!)(\w+)`, ByGroups(Operator, Name), nil}, | |||
}, | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
package a | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// Abnf lexer. | |||
var Abnf = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "ABNF", | |||
Aliases: []string{"abnf"}, | |||
Filenames: []string{"*.abnf"}, | |||
MimeTypes: []string{"text/x-abnf"}, | |||
}, | |||
abnfRules, | |||
)) | |||
func abnfRules() Rules { | |||
return Rules{ | |||
"root": { | |||
{`;.*$`, CommentSingle, nil}, | |||
{`(%[si])?"[^"]*"`, Literal, nil}, | |||
{`%b[01]+\-[01]+\b`, Literal, nil}, | |||
{`%b[01]+(\.[01]+)*\b`, Literal, nil}, | |||
{`%d[0-9]+\-[0-9]+\b`, Literal, nil}, | |||
{`%d[0-9]+(\.[0-9]+)*\b`, Literal, nil}, | |||
{`%x[0-9a-fA-F]+\-[0-9a-fA-F]+\b`, Literal, nil}, | |||
{`%x[0-9a-fA-F]+(\.[0-9a-fA-F]+)*\b`, Literal, nil}, | |||
{`\b[0-9]+\*[0-9]+`, Operator, nil}, | |||
{`\b[0-9]+\*`, Operator, nil}, | |||
{`\b[0-9]+`, Operator, nil}, | |||
{`\*`, Operator, nil}, | |||
{Words(``, `\b`, `ALPHA`, `BIT`, `CHAR`, `CR`, `CRLF`, `CTL`, `DIGIT`, `DQUOTE`, `HEXDIG`, `HTAB`, `LF`, `LWSP`, `OCTET`, `SP`, `VCHAR`, `WSP`), Keyword, nil}, | |||
{`[a-zA-Z][a-zA-Z0-9-]+\b`, NameClass, nil}, | |||
{`(=/|=|/)`, Operator, nil}, | |||
{`[\[\]()]`, Punctuation, nil}, | |||
{`\s+`, Text, nil}, | |||
{`.`, Text, nil}, | |||
}, | |||
} | |||
} |
@@ -0,0 +1,43 @@ | |||
package a | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// Actionscript lexer. | |||
var Actionscript = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "ActionScript", | |||
Aliases: []string{"as", "actionscript"}, | |||
Filenames: []string{"*.as"}, | |||
MimeTypes: []string{"application/x-actionscript", "text/x-actionscript", "text/actionscript"}, | |||
NotMultiline: true, | |||
DotAll: true, | |||
}, | |||
actionscriptRules, | |||
)) | |||
func actionscriptRules() Rules { | |||
return Rules{ | |||
"root": { | |||
{`\s+`, Text, nil}, | |||
{`//.*?\n`, CommentSingle, nil}, | |||
{`/\*.*?\*/`, CommentMultiline, nil}, | |||
{`/(\\\\|\\/|[^/\n])*/[gim]*`, LiteralStringRegex, nil}, | |||
{`[~^*!%&<>|+=:;,/?\\-]+`, Operator, nil}, | |||
{`[{}\[\]();.]+`, Punctuation, nil}, | |||
{Words(``, `\b`, `case`, `default`, `for`, `each`, `in`, `while`, `do`, `break`, `return`, `continue`, `if`, `else`, `throw`, `try`, `catch`, `var`, `with`, `new`, `typeof`, `arguments`, `instanceof`, `this`, `switch`), Keyword, nil}, | |||
{Words(``, `\b`, `class`, `public`, `final`, `internal`, `native`, `override`, `private`, `protected`, `static`, `import`, `extends`, `implements`, `interface`, `intrinsic`, `return`, `super`, `dynamic`, `function`, `const`, `get`, `namespace`, `package`, `set`), KeywordDeclaration, nil}, | |||
{`(true|false|null|NaN|Infinity|-Infinity|undefined|Void)\b`, KeywordConstant, nil}, | |||
{Words(``, `\b`, `Accessibility`, `AccessibilityProperties`, `ActionScriptVersion`, `ActivityEvent`, `AntiAliasType`, `ApplicationDomain`, `AsBroadcaster`, `Array`, `AsyncErrorEvent`, `AVM1Movie`, `BevelFilter`, `Bitmap`, `BitmapData`, `BitmapDataChannel`, `BitmapFilter`, `BitmapFilterQuality`, `BitmapFilterType`, `BlendMode`, `BlurFilter`, `Boolean`, `ByteArray`, `Camera`, `Capabilities`, `CapsStyle`, `Class`, `Color`, `ColorMatrixFilter`, `ColorTransform`, `ContextMenu`, `ContextMenuBuiltInItems`, `ContextMenuEvent`, `ContextMenuItem`, `ConvultionFilter`, `CSMSettings`, `DataEvent`, `Date`, `DefinitionError`, `DeleteObjectSample`, `Dictionary`, `DisplacmentMapFilter`, `DisplayObject`, `DisplacmentMapFilterMode`, `DisplayObjectContainer`, `DropShadowFilter`, `Endian`, `EOFError`, `Error`, `ErrorEvent`, `EvalError`, `Event`, `EventDispatcher`, `EventPhase`, `ExternalInterface`, `FileFilter`, `FileReference`, `FileReferenceList`, `FocusDirection`, `FocusEvent`, `Font`, `FontStyle`, `FontType`, `FrameLabel`, `FullScreenEvent`, `Function`, `GlowFilter`, `GradientBevelFilter`, `GradientGlowFilter`, `GradientType`, `Graphics`, `GridFitType`, `HTTPStatusEvent`, `IBitmapDrawable`, `ID3Info`, `IDataInput`, `IDataOutput`, `IDynamicPropertyOutputIDynamicPropertyWriter`, `IEventDispatcher`, `IExternalizable`, `IllegalOperationError`, `IME`, `IMEConversionMode`, `IMEEvent`, `int`, `InteractiveObject`, `InterpolationMethod`, `InvalidSWFError`, `InvokeEvent`, `IOError`, `IOErrorEvent`, `JointStyle`, `Key`, `Keyboard`, `KeyboardEvent`, `KeyLocation`, `LineScaleMode`, `Loader`, `LoaderContext`, `LoaderInfo`, `LoadVars`, `LocalConnection`, `Locale`, `Math`, `Matrix`, `MemoryError`, `Microphone`, `MorphShape`, `Mouse`, `MouseEvent`, `MovieClip`, `MovieClipLoader`, `Namespace`, `NetConnection`, `NetStatusEvent`, `NetStream`, `NewObjectSample`, `Number`, `Object`, `ObjectEncoding`, `PixelSnapping`, `Point`, `PrintJob`, `PrintJobOptions`, `PrintJobOrientation`, `ProgressEvent`, `Proxy`, `QName`, `RangeError`, `Rectangle`, `ReferenceError`, `RegExp`, `Responder`, `Sample`, `Scene`, `ScriptTimeoutError`, `Security`, `SecurityDomain`, `SecurityError`, `SecurityErrorEvent`, `SecurityPanel`, `Selection`, `Shape`, `SharedObject`, `SharedObjectFlushStatus`, `SimpleButton`, `Socket`, `Sound`, `SoundChannel`, `SoundLoaderContext`, `SoundMixer`, `SoundTransform`, `SpreadMethod`, `Sprite`, `StackFrame`, `StackOverflowError`, `Stage`, `StageAlign`, `StageDisplayState`, `StageQuality`, `StageScaleMode`, `StaticText`, `StatusEvent`, `String`, `StyleSheet`, `SWFVersion`, `SyncEvent`, `SyntaxError`, `System`, `TextColorType`, `TextField`, `TextFieldAutoSize`, `TextFieldType`, `TextFormat`, `TextFormatAlign`, `TextLineMetrics`, `TextRenderer`, `TextSnapshot`, `Timer`, `TimerEvent`, `Transform`, `TypeError`, `uint`, `URIError`, `URLLoader`, `URLLoaderDataFormat`, `URLRequest`, `URLRequestHeader`, `URLRequestMethod`, `URLStream`, `URLVariabeles`, `VerifyError`, `Video`, `XML`, `XMLDocument`, `XMLList`, `XMLNode`, `XMLNodeType`, `XMLSocket`, `XMLUI`), NameBuiltin, nil}, | |||
{Words(``, `\b`, `decodeURI`, `decodeURIComponent`, `encodeURI`, `escape`, `eval`, `isFinite`, `isNaN`, `isXMLName`, `clearInterval`, `fscommand`, `getTimer`, `getURL`, `getVersion`, `parseFloat`, `parseInt`, `setInterval`, `trace`, `updateAfterEvent`, `unescape`), NameFunction, nil}, | |||
{`[$a-zA-Z_]\w*`, NameOther, nil}, | |||
{`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil}, | |||
{`0x[0-9a-f]+`, LiteralNumberHex, nil}, | |||
{`[0-9]+`, LiteralNumberInteger, nil}, | |||
{`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil}, | |||
{`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil}, | |||
}, | |||
} | |||
} |
@@ -0,0 +1,60 @@ | |||
package a | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// Actionscript 3 lexer. | |||
var Actionscript3 = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "ActionScript 3", | |||
Aliases: []string{"as3", "actionscript3"}, | |||
Filenames: []string{"*.as"}, | |||
MimeTypes: []string{"application/x-actionscript3", "text/x-actionscript3", "text/actionscript3"}, | |||
DotAll: true, | |||
}, | |||
actionscript3Rules, | |||
)) | |||
func actionscript3Rules() Rules { | |||
return Rules{ | |||
"root": { | |||
{`\s+`, Text, nil}, | |||
{`(function\s+)([$a-zA-Z_]\w*)(\s*)(\()`, ByGroups(KeywordDeclaration, NameFunction, Text, Operator), Push("funcparams")}, | |||
{`(var|const)(\s+)([$a-zA-Z_]\w*)(\s*)(:)(\s*)([$a-zA-Z_]\w*(?:\.<\w+>)?)`, ByGroups(KeywordDeclaration, Text, Name, Text, Punctuation, Text, KeywordType), nil}, | |||
{`(import|package)(\s+)((?:[$a-zA-Z_]\w*|\.)+)(\s*)`, ByGroups(Keyword, Text, NameNamespace, Text), nil}, | |||
{`(new)(\s+)([$a-zA-Z_]\w*(?:\.<\w+>)?)(\s*)(\()`, ByGroups(Keyword, Text, KeywordType, Text, Operator), nil}, | |||
{`//.*?\n`, CommentSingle, nil}, | |||
{`/\*.*?\*/`, CommentMultiline, nil}, | |||
{`/(\\\\|\\/|[^\n])*/[gisx]*`, LiteralStringRegex, nil}, | |||
{`(\.)([$a-zA-Z_]\w*)`, ByGroups(Operator, NameAttribute), nil}, | |||
{`(case|default|for|each|in|while|do|break|return|continue|if|else|throw|try|catch|with|new|typeof|arguments|instanceof|this|switch|import|include|as|is)\b`, Keyword, nil}, | |||
{`(class|public|final|internal|native|override|private|protected|static|import|extends|implements|interface|intrinsic|return|super|dynamic|function|const|get|namespace|package|set)\b`, KeywordDeclaration, nil}, | |||
{`(true|false|null|NaN|Infinity|-Infinity|undefined|void)\b`, KeywordConstant, nil}, | |||
{`(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|unescape)\b`, NameFunction, nil}, | |||
{`[$a-zA-Z_]\w*`, Name, nil}, | |||
{`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil}, | |||
{`0x[0-9a-f]+`, LiteralNumberHex, nil}, | |||
{`[0-9]+`, LiteralNumberInteger, nil}, | |||
{`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil}, | |||
{`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil}, | |||
{`[~^*!%&<>|+=:;,/?\\{}\[\]().-]+`, Operator, nil}, | |||
}, | |||
"funcparams": { | |||
{`\s+`, Text, nil}, | |||
{`(\s*)(\.\.\.)?([$a-zA-Z_]\w*)(\s*)(:)(\s*)([$a-zA-Z_]\w*(?:\.<\w+>)?|\*)(\s*)`, ByGroups(Text, Punctuation, Name, Text, Operator, Text, KeywordType, Text), Push("defval")}, | |||
{`\)`, Operator, Push("type")}, | |||
}, | |||
"type": { | |||
{`(\s*)(:)(\s*)([$a-zA-Z_]\w*(?:\.<\w+>)?|\*)`, ByGroups(Text, Operator, Text, KeywordType), Pop(2)}, | |||
{`\s+`, Text, Pop(2)}, | |||
Default(Pop(2)), | |||
}, | |||
"defval": { | |||
{`(=)(\s*)([^(),]+)(\s*)(,?)`, ByGroups(Operator, Text, UsingSelf("root"), Text, Operator), Pop(1)}, | |||
{`,`, Operator, Pop(1)}, | |||
Default(Pop(1)), | |||
}, | |||
} | |||
} |
@@ -0,0 +1,118 @@ | |||
package a | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// Ada lexer. | |||
var Ada = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "Ada", | |||
Aliases: []string{"ada", "ada95", "ada2005"}, | |||
Filenames: []string{"*.adb", "*.ads", "*.ada"}, | |||
MimeTypes: []string{"text/x-ada"}, | |||
CaseInsensitive: true, | |||
}, | |||
adaRules, | |||
)) | |||
func adaRules() Rules { | |||
return Rules{ | |||
"root": { | |||
{`[^\S\n]+`, Text, nil}, | |||
{`--.*?\n`, CommentSingle, nil}, | |||
{`[^\S\n]+`, Text, nil}, | |||
{`function|procedure|entry`, KeywordDeclaration, Push("subprogram")}, | |||
{`(subtype|type)(\s+)(\w+)`, ByGroups(KeywordDeclaration, Text, KeywordType), Push("type_def")}, | |||
{`task|protected`, KeywordDeclaration, nil}, | |||
{`(subtype)(\s+)`, ByGroups(KeywordDeclaration, Text), nil}, | |||
{`(end)(\s+)`, ByGroups(KeywordReserved, Text), Push("end")}, | |||
{`(pragma)(\s+)(\w+)`, ByGroups(KeywordReserved, Text, CommentPreproc), nil}, | |||
{`(true|false|null)\b`, KeywordConstant, nil}, | |||
{Words(``, `\b`, `Address`, `Byte`, `Boolean`, `Character`, `Controlled`, `Count`, `Cursor`, `Duration`, `File_Mode`, `File_Type`, `Float`, `Generator`, `Integer`, `Long_Float`, `Long_Integer`, `Long_Long_Float`, `Long_Long_Integer`, `Natural`, `Positive`, `Reference_Type`, `Short_Float`, `Short_Integer`, `Short_Short_Float`, `Short_Short_Integer`, `String`, `Wide_Character`, `Wide_String`), KeywordType, nil}, | |||
{`(and(\s+then)?|in|mod|not|or(\s+else)|rem)\b`, OperatorWord, nil}, | |||
{`generic|private`, KeywordDeclaration, nil}, | |||
{`package`, KeywordDeclaration, Push("package")}, | |||
{`array\b`, KeywordReserved, Push("array_def")}, | |||
{`(with|use)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")}, | |||
{`(\w+)(\s*)(:)(\s*)(constant)`, ByGroups(NameConstant, Text, Punctuation, Text, KeywordReserved), nil}, | |||
{`<<\w+>>`, NameLabel, nil}, | |||
{`(\w+)(\s*)(:)(\s*)(declare|begin|loop|for|while)`, ByGroups(NameLabel, Text, Punctuation, Text, KeywordReserved), nil}, | |||
{Words(`\b`, `\b`, `abort`, `abs`, `abstract`, `accept`, `access`, `aliased`, `all`, `array`, `at`, `begin`, `body`, `case`, `constant`, `declare`, `delay`, `delta`, `digits`, `do`, `else`, `elsif`, `end`, `entry`, `exception`, `exit`, `interface`, `for`, `goto`, `if`, `is`, `limited`, `loop`, `new`, `null`, `of`, `or`, `others`, `out`, `overriding`, `pragma`, `protected`, `raise`, `range`, `record`, `renames`, `requeue`, `return`, `reverse`, `select`, `separate`, `subtype`, `synchronized`, `task`, `tagged`, `terminate`, `then`, `type`, `until`, `when`, `while`, `xor`), KeywordReserved, nil}, | |||
{`"[^"]*"`, LiteralString, nil}, | |||
Include("attribute"), | |||
Include("numbers"), | |||
{`'[^']'`, LiteralStringChar, nil}, | |||
{`(\w+)(\s*|[(,])`, ByGroups(Name, UsingSelf("root")), nil}, | |||
{`(<>|=>|:=|[()|:;,.'])`, Punctuation, nil}, | |||
{`[*<>+=/&-]`, Operator, nil}, | |||
{`\n+`, Text, nil}, | |||
}, | |||
"numbers": { | |||
{`[0-9_]+#[0-9a-f]+#`, LiteralNumberHex, nil}, | |||
{`[0-9_]+\.[0-9_]*`, LiteralNumberFloat, nil}, | |||
{`[0-9_]+`, LiteralNumberInteger, nil}, | |||
}, | |||
"attribute": { | |||
{`(')(\w+)`, ByGroups(Punctuation, NameAttribute), nil}, | |||
}, | |||
"subprogram": { | |||
{`\(`, Punctuation, Push("#pop", "formal_part")}, | |||
{`;`, Punctuation, Pop(1)}, | |||
{`is\b`, KeywordReserved, Pop(1)}, | |||
{`"[^"]+"|\w+`, NameFunction, nil}, | |||
Include("root"), | |||
}, | |||
"end": { | |||
{`(if|case|record|loop|select)`, KeywordReserved, nil}, | |||
{`"[^"]+"|[\w.]+`, NameFunction, nil}, | |||
{`\s+`, Text, nil}, | |||
{`;`, Punctuation, Pop(1)}, | |||
}, | |||
"type_def": { | |||
{`;`, Punctuation, Pop(1)}, | |||
{`\(`, Punctuation, Push("formal_part")}, | |||
{`with|and|use`, KeywordReserved, nil}, | |||
{`array\b`, KeywordReserved, Push("#pop", "array_def")}, | |||
{`record\b`, KeywordReserved, Push("record_def")}, | |||
{`(null record)(;)`, ByGroups(KeywordReserved, Punctuation), Pop(1)}, | |||
Include("root"), | |||
}, | |||
"array_def": { | |||
{`;`, Punctuation, Pop(1)}, | |||
{`(\w+)(\s+)(range)`, ByGroups(KeywordType, Text, KeywordReserved), nil}, | |||
Include("root"), | |||
}, | |||
"record_def": { | |||
{`end record`, KeywordReserved, Pop(1)}, | |||
Include("root"), | |||
}, | |||
"import": { | |||
{`[\w.]+`, NameNamespace, Pop(1)}, | |||
Default(Pop(1)), | |||
}, | |||
"formal_part": { | |||
{`\)`, Punctuation, Pop(1)}, | |||
{`\w+`, NameVariable, nil}, | |||
{`,|:[^=]`, Punctuation, nil}, | |||
{`(in|not|null|out|access)\b`, KeywordReserved, nil}, | |||
Include("root"), | |||
}, | |||
"package": { | |||
{`body`, KeywordDeclaration, nil}, | |||
{`is\s+new|renames`, KeywordReserved, nil}, | |||
{`is`, KeywordReserved, Pop(1)}, | |||
{`;`, Punctuation, Pop(1)}, | |||
{`\(`, Punctuation, Push("package_instantiation")}, | |||
{`([\w.]+)`, NameClass, nil}, | |||
Include("root"), | |||
}, | |||
"package_instantiation": { | |||
{`("[^"]+"|\w+)(\s+)(=>)`, ByGroups(NameVariable, Text, Punctuation), nil}, | |||
{`[\w.\'"]`, Text, nil}, | |||
{`\)`, Punctuation, Pop(1)}, | |||
Include("root"), | |||
}, | |||
} | |||
} |
@@ -0,0 +1,47 @@ | |||
package a | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// Al lexer. | |||
var Al = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "AL", | |||
Aliases: []string{"al"}, | |||
Filenames: []string{"*.al", "*.dal"}, | |||
MimeTypes: []string{"text/x-al"}, | |||
DotAll: true, | |||
CaseInsensitive: true, | |||
}, | |||
alRules, | |||
)) | |||
// https://github.com/microsoft/AL/blob/master/grammar/alsyntax.tmlanguage | |||
func alRules() Rules { | |||
return Rules{ | |||
"root": { | |||
{`\s+`, TextWhitespace, nil}, | |||
{`(?s)\/\*.*?\\*\*\/`, CommentMultiline, nil}, | |||
{`(?s)//.*?\n`, CommentSingle, nil}, | |||
{`\"([^\"])*\"`, Text, nil}, | |||
{`'([^'])*'`, LiteralString, nil}, | |||
{`\b(?i:(ARRAY|ASSERTERROR|BEGIN|BREAK|CASE|DO|DOWNTO|ELSE|END|EVENT|EXIT|FOR|FOREACH|FUNCTION|IF|IMPLEMENTS|IN|INDATASET|INTERFACE|INTERNAL|LOCAL|OF|PROCEDURE|PROGRAM|PROTECTED|REPEAT|RUNONCLIENT|SECURITYFILTERING|SUPPRESSDISPOSE|TEMPORARY|THEN|TO|TRIGGER|UNTIL|VAR|WHILE|WITH|WITHEVENTS))\b`, Keyword, nil}, | |||
{`\b(?i:(AND|DIV|MOD|NOT|OR|XOR))\b`, OperatorWord, nil}, | |||
{`\b(?i:(AVERAGE|CONST|COUNT|EXIST|FIELD|FILTER|LOOKUP|MAX|MIN|ORDER|SORTING|SUM|TABLEDATA|UPPERLIMIT|WHERE|ASCENDING|DESCENDING))\b`, Keyword, nil}, | |||
{`\b(?i:(CODEUNIT|PAGE|PAGEEXTENSION|PAGECUSTOMIZATION|DOTNET|ENUM|ENUMEXTENSION|VALUE|QUERY|REPORT|TABLE|TABLEEXTENSION|XMLPORT|PROFILE|CONTROLADDIN|REPORTEXTENSION|INTERFACE|PERMISSIONSET|PERMISSIONSETEXTENSION|ENTITLEMENT))\b`, Keyword, nil}, | |||
{`\b(?i:(Action|Array|Automation|BigInteger|BigText|Blob|Boolean|Byte|Char|ClientType|Code|Codeunit|CompletionTriggerErrorLevel|ConnectionType|Database|DataClassification|DataScope|Date|DateFormula|DateTime|Decimal|DefaultLayout|Dialog|Dictionary|DotNet|DotNetAssembly|DotNetTypeDeclaration|Duration|Enum|ErrorInfo|ErrorType|ExecutionContext|ExecutionMode|FieldClass|FieldRef|FieldType|File|FilterPageBuilder|Guid|InStream|Integer|Joker|KeyRef|List|ModuleDependencyInfo|ModuleInfo|None|Notification|NotificationScope|ObjectType|Option|OutStream|Page|PageResult|Query|Record|RecordId|RecordRef|Report|ReportFormat|SecurityFilter|SecurityFiltering|Table|TableConnectionType|TableFilter|TestAction|TestField|TestFilterField|TestPage|TestPermissions|TestRequestPage|Text|TextBuilder|TextConst|TextEncoding|Time|TransactionModel|TransactionType|Variant|Verbosity|Version|XmlPort|HttpContent|HttpHeaders|HttpClient|HttpRequestMessage|HttpResponseMessage|JsonToken|JsonValue|JsonArray|JsonObject|View|Views|XmlAttribute|XmlAttributeCollection|XmlComment|XmlCData|XmlDeclaration|XmlDocument|XmlDocumentType|XmlElement|XmlNamespaceManager|XmlNameTable|XmlNode|XmlNodeList|XmlProcessingInstruction|XmlReadOptions|XmlText|XmlWriteOptions|WebServiceActionContext|WebServiceActionResultCode|SessionSettings))\b`, Keyword, nil}, | |||
{`\b([<>]=|<>|<|>)\b?`, Operator, nil}, | |||
{`\b(\-|\+|\/|\*)\b`, Operator, nil}, | |||
{`\s*(\:=|\+=|-=|\/=|\*=)\s*?`, Operator, nil}, | |||
{`\b(?i:(ADD|ADDFIRST|ADDLAST|ADDAFTER|ADDBEFORE|ACTION|ACTIONS|AREA|ASSEMBLY|CHARTPART|CUEGROUP|CUSTOMIZES|COLUMN|DATAITEM|DATASET|ELEMENTS|EXTENDS|FIELD|FIELDGROUP|FIELDATTRIBUTE|FIELDELEMENT|FIELDGROUPS|FIELDS|FILTER|FIXED|GRID|GROUP|MOVEAFTER|MOVEBEFORE|KEY|KEYS|LABEL|LABELS|LAYOUT|MODIFY|MOVEFIRST|MOVELAST|MOVEBEFORE|MOVEAFTER|PART|REPEATER|USERCONTROL|REQUESTPAGE|SCHEMA|SEPARATOR|SYSTEMPART|TABLEELEMENT|TEXTATTRIBUTE|TEXTELEMENT|TYPE))\b`, Keyword, nil}, | |||
{`\s*[(\.\.)&\|]\s*`, Operator, nil}, | |||
{`\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\b`, LiteralNumber, nil}, | |||
{`[;:,]`, Punctuation, nil}, | |||
{`#[ \t]*(if|else|elif|endif|define|undef|region|endregion|pragma)\b.*?\n`, CommentPreproc, nil}, | |||
{`\w+`, Text, nil}, | |||
{`.`, Text, nil}, | |||
}, | |||
} | |||
} |
@@ -0,0 +1,46 @@ | |||
package a | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// Angular2 lexer. | |||
var Angular2 = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "Angular2", | |||
Aliases: []string{"ng2"}, | |||
Filenames: []string{}, | |||
MimeTypes: []string{}, | |||
}, | |||
angular2Rules, | |||
)) | |||
func angular2Rules() Rules { | |||
return Rules{ | |||
"root": { | |||
{`[^{([*#]+`, Other, nil}, | |||
{`(\{\{)(\s*)`, ByGroups(CommentPreproc, Text), Push("ngExpression")}, | |||
{`([([]+)([\w:.-]+)([\])]+)(\s*)(=)(\s*)`, ByGroups(Punctuation, NameAttribute, Punctuation, Text, Operator, Text), Push("attr")}, | |||
{`([([]+)([\w:.-]+)([\])]+)(\s*)`, ByGroups(Punctuation, NameAttribute, Punctuation, Text), nil}, | |||
{`([*#])([\w:.-]+)(\s*)(=)(\s*)`, ByGroups(Punctuation, NameAttribute, Punctuation, Operator), Push("attr")}, | |||
{`([*#])([\w:.-]+)(\s*)`, ByGroups(Punctuation, NameAttribute, Punctuation), nil}, | |||
}, | |||
"ngExpression": { | |||
{`\s+(\|\s+)?`, Text, nil}, | |||
{`\}\}`, CommentPreproc, Pop(1)}, | |||
{`:?(true|false)`, LiteralStringBoolean, nil}, | |||
{`:?"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil}, | |||
{`:?'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil}, | |||
{`[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?`, LiteralNumber, nil}, | |||
{`[a-zA-Z][\w-]*(\(.*\))?`, NameVariable, nil}, | |||
{`\.[\w-]+(\(.*\))?`, NameVariable, nil}, | |||
{`(\?)(\s*)([^}\s]+)(\s*)(:)(\s*)([^}\s]+)(\s*)`, ByGroups(Operator, Text, LiteralString, Text, Operator, Text, LiteralString, Text), nil}, | |||
}, | |||
"attr": { | |||
{`".*?"`, LiteralString, Pop(1)}, | |||
{`'.*?'`, LiteralString, Pop(1)}, | |||
{`[^\s>]+`, LiteralString, Pop(1)}, | |||
}, | |||
} | |||
} |
@@ -0,0 +1,105 @@ | |||
package a | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// ANTLR lexer. | |||
var ANTLR = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "ANTLR", | |||
Aliases: []string{"antlr"}, | |||
Filenames: []string{}, | |||
MimeTypes: []string{}, | |||
}, | |||
antlrRules, | |||
)) | |||
func antlrRules() Rules { | |||
return Rules{ | |||
"whitespace": { | |||
{`\s+`, TextWhitespace, nil}, | |||
}, | |||
"comments": { | |||
{`//.*$`, Comment, nil}, | |||
{`/\*(.|\n)*?\*/`, Comment, nil}, | |||
}, | |||
"root": { | |||
Include("whitespace"), | |||
Include("comments"), | |||
{`(lexer|parser|tree)?(\s*)(grammar\b)(\s*)([A-Za-z]\w*)(;)`, ByGroups(Keyword, TextWhitespace, Keyword, TextWhitespace, NameClass, Punctuation), nil}, | |||
{`options\b`, Keyword, Push("options")}, | |||
{`tokens\b`, Keyword, Push("tokens")}, | |||
{`(scope)(\s*)([A-Za-z]\w*)(\s*)(\{)`, ByGroups(Keyword, TextWhitespace, NameVariable, TextWhitespace, Punctuation), Push("action")}, | |||
{`(catch|finally)\b`, Keyword, Push("exception")}, | |||
{`(@[A-Za-z]\w*)(\s*)(::)?(\s*)([A-Za-z]\w*)(\s*)(\{)`, ByGroups(NameLabel, TextWhitespace, Punctuation, TextWhitespace, NameLabel, TextWhitespace, Punctuation), Push("action")}, | |||
{`((?:protected|private|public|fragment)\b)?(\s*)([A-Za-z]\w*)(!)?`, ByGroups(Keyword, TextWhitespace, NameLabel, Punctuation), Push("rule-alts", "rule-prelims")}, | |||
}, | |||
"exception": { | |||
{`\n`, TextWhitespace, Pop(1)}, | |||
{`\s`, TextWhitespace, nil}, | |||
Include("comments"), | |||
{`\[`, Punctuation, Push("nested-arg-action")}, | |||
{`\{`, Punctuation, Push("action")}, | |||
}, | |||
"rule-prelims": { | |||
Include("whitespace"), | |||
Include("comments"), | |||
{`returns\b`, Keyword, nil}, | |||
{`\[`, Punctuation, Push("nested-arg-action")}, | |||
{`\{`, Punctuation, Push("action")}, | |||
{`(throws)(\s+)([A-Za-z]\w*)`, ByGroups(Keyword, TextWhitespace, NameLabel), nil}, | |||
{`(,)(\s*)([A-Za-z]\w*)`, ByGroups(Punctuation, TextWhitespace, NameLabel), nil}, | |||
{`options\b`, Keyword, Push("options")}, | |||
{`(scope)(\s+)(\{)`, ByGroups(Keyword, TextWhitespace, Punctuation), Push("action")}, | |||
{`(scope)(\s+)([A-Za-z]\w*)(\s*)(;)`, ByGroups(Keyword, TextWhitespace, NameLabel, TextWhitespace, Punctuation), nil}, | |||
{`(@[A-Za-z]\w*)(\s*)(\{)`, ByGroups(NameLabel, TextWhitespace, Punctuation), Push("action")}, | |||
{`:`, Punctuation, Pop(1)}, | |||
}, | |||
"rule-alts": { | |||
Include("whitespace"), | |||
Include("comments"), | |||
{`options\b`, Keyword, Push("options")}, | |||
{`:`, Punctuation, nil}, | |||
{`'(\\\\|\\'|[^'])*'`, LiteralString, nil}, | |||
{`"(\\\\|\\"|[^"])*"`, LiteralString, nil}, | |||
{`<<([^>]|>[^>])>>`, LiteralString, nil}, | |||
{`\$?[A-Z_]\w*`, NameConstant, nil}, | |||
{`\$?[a-z_]\w*`, NameVariable, nil}, | |||
{`(\+|\||->|=>|=|\(|\)|\.\.|\.|\?|\*|\^|!|\#|~)`, Operator, nil}, | |||
{`,`, Punctuation, nil}, | |||
{`\[`, Punctuation, Push("nested-arg-action")}, | |||
{`\{`, Punctuation, Push("action")}, | |||
{`;`, Punctuation, Pop(1)}, | |||
}, | |||
"tokens": { | |||
Include("whitespace"), | |||
Include("comments"), | |||
{`\{`, Punctuation, nil}, | |||
{`([A-Z]\w*)(\s*)(=)?(\s*)(\'(?:\\\\|\\\'|[^\']*)\')?(\s*)(;)`, ByGroups(NameLabel, TextWhitespace, Punctuation, TextWhitespace, LiteralString, TextWhitespace, Punctuation), nil}, | |||
{`\}`, Punctuation, Pop(1)}, | |||
}, | |||
"options": { | |||
Include("whitespace"), | |||
Include("comments"), | |||
{`\{`, Punctuation, nil}, | |||
{`([A-Za-z]\w*)(\s*)(=)(\s*)([A-Za-z]\w*|\'(?:\\\\|\\\'|[^\']*)\'|[0-9]+|\*)(\s*)(;)`, ByGroups(NameVariable, TextWhitespace, Punctuation, TextWhitespace, Text, TextWhitespace, Punctuation), nil}, | |||
{`\}`, Punctuation, Pop(1)}, | |||
}, | |||
"action": { | |||
{`([^${}\'"/\\]+|"(\\\\|\\"|[^"])*"|'(\\\\|\\'|[^'])*'|//.*$\n?|/\*(.|\n)*?\*/|/(?!\*)(\\\\|\\/|[^/])*/|\\(?!%)|/)+`, Other, nil}, | |||
{`(\\)(%)`, ByGroups(Punctuation, Other), nil}, | |||
{`(\$[a-zA-Z]+)(\.?)(text|value)?`, ByGroups(NameVariable, Punctuation, NameProperty), nil}, | |||
{`\{`, Punctuation, Push()}, | |||
{`\}`, Punctuation, Pop(1)}, | |||
}, | |||
"nested-arg-action": { | |||
{`([^$\[\]\'"/]+|"(\\\\|\\"|[^"])*"|'(\\\\|\\'|[^'])*'|//.*$\n?|/\*(.|\n)*?\*/|/(?!\*)(\\\\|\\/|[^/])*/|/)+`, Other, nil}, | |||
{`\[`, Punctuation, Push()}, | |||
{`\]`, Punctuation, Pop(1)}, | |||
{`(\$[a-zA-Z]+)(\.?)(text|value)?`, ByGroups(NameVariable, Punctuation, NameProperty), nil}, | |||
{`(\\\\|\\\]|\\\[|[^\[\]])+`, Other, nil}, | |||
}, | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
package a | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// Apacheconf lexer. | |||
var Apacheconf = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "ApacheConf", | |||
Aliases: []string{"apacheconf", "aconf", "apache"}, | |||
Filenames: []string{".htaccess", "apache.conf", "apache2.conf"}, | |||
MimeTypes: []string{"text/x-apacheconf"}, | |||
CaseInsensitive: true, | |||
}, | |||
apacheconfRules, | |||
)) | |||
func apacheconfRules() Rules { | |||
return Rules{ | |||
"root": { | |||
{`\s+`, Text, nil}, | |||
{`(#.*?)$`, Comment, nil}, | |||
{`(<[^\s>]+)(?:(\s+)(.*?))?(>)`, ByGroups(NameTag, Text, LiteralString, NameTag), nil}, | |||
{`([a-z]\w*)(\s+)`, ByGroups(NameBuiltin, Text), Push("value")}, | |||
{`\.+`, Text, nil}, | |||
}, | |||
"value": { | |||
{`\\\n`, Text, nil}, | |||
{`$`, Text, Pop(1)}, | |||
{`\\`, Text, nil}, | |||
{`[^\S\n]+`, Text, nil}, | |||
{`\d+\.\d+\.\d+\.\d+(?:/\d+)?`, LiteralNumber, nil}, | |||
{`\d+`, LiteralNumber, nil}, | |||
{`/([a-z0-9][\w./-]+)`, LiteralStringOther, nil}, | |||
{`(on|off|none|any|all|double|email|dns|min|minimal|os|productonly|full|emerg|alert|crit|error|warn|notice|info|debug|registry|script|inetd|standalone|user|group)\b`, Keyword, nil}, | |||
{`"([^"\\]*(?:\\.[^"\\]*)*)"`, LiteralStringDouble, nil}, | |||
{`[^\s"\\]+`, Text, nil}, | |||
}, | |||
} | |||
} |
@@ -0,0 +1,40 @@ | |||
package a | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// Apl lexer. | |||
var Apl = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "APL", | |||
Aliases: []string{"apl"}, | |||
Filenames: []string{"*.apl"}, | |||
MimeTypes: []string{}, | |||
}, | |||
aplRules, | |||
)) | |||
func aplRules() Rules { | |||
return Rules{ | |||
"root": { | |||
{`\s+`, Text, nil}, | |||
{`[⍝#].*$`, CommentSingle, nil}, | |||
{`\'((\'\')|[^\'])*\'`, LiteralStringSingle, nil}, | |||
{`"(("")|[^"])*"`, LiteralStringDouble, nil}, | |||
{`[⋄◇()]`, Punctuation, nil}, | |||
{`[\[\];]`, LiteralStringRegex, nil}, | |||
{`⎕[A-Za-zΔ∆⍙][A-Za-zΔ∆⍙_¯0-9]*`, NameFunction, nil}, | |||
{`[A-Za-zΔ∆⍙_][A-Za-zΔ∆⍙_¯0-9]*`, NameVariable, nil}, | |||
{`¯?(0[Xx][0-9A-Fa-f]+|[0-9]*\.?[0-9]+([Ee][+¯]?[0-9]+)?|¯|∞)([Jj]¯?(0[Xx][0-9A-Fa-f]+|[0-9]*\.?[0-9]+([Ee][+¯]?[0-9]+)?|¯|∞))?`, LiteralNumber, nil}, | |||
{`[\.\\/⌿⍀¨⍣⍨⍠⍤∘⍥@⌺⌶⍢]`, NameAttribute, nil}, | |||
{`[+\-×÷⌈⌊∣|⍳?*⍟○!⌹<≤=>≥≠≡≢∊⍷∪∩~∨∧⍱⍲⍴,⍪⌽⊖⍉↑↓⊂⊃⌷⍋⍒⊤⊥⍕⍎⊣⊢⍁⍂≈⌸⍯↗⊆⍸]`, Operator, nil}, | |||
{`⍬`, NameConstant, nil}, | |||
{`[⎕⍞]`, NameVariableGlobal, nil}, | |||
{`[←→]`, KeywordDeclaration, nil}, | |||
{`[⍺⍵⍶⍹∇:]`, NameBuiltinPseudo, nil}, | |||
{`[{}]`, KeywordType, nil}, | |||
}, | |||
} | |||
} |
@@ -0,0 +1,59 @@ | |||
package a | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// Applescript lexer. | |||
var Applescript = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "AppleScript", | |||
Aliases: []string{"applescript"}, | |||
Filenames: []string{"*.applescript"}, | |||
MimeTypes: []string{}, | |||
DotAll: true, | |||
}, | |||
applescriptRules, | |||
)) | |||
func applescriptRules() Rules { | |||
return Rules{ | |||
"root": { | |||
{`\s+`, Text, nil}, | |||
{`¬\n`, LiteralStringEscape, nil}, | |||
{`'s\s+`, Text, nil}, | |||
{`(--|#).*?$`, Comment, nil}, | |||
{`\(\*`, CommentMultiline, Push("comment")}, | |||
{`[(){}!,.:]`, Punctuation, nil}, | |||
{`(«)([^»]+)(»)`, ByGroups(Text, NameBuiltin, Text), nil}, | |||
{`\b((?:considering|ignoring)\s*)(application responses|case|diacriticals|hyphens|numeric strings|punctuation|white space)`, ByGroups(Keyword, NameBuiltin), nil}, | |||
{`(-|\*|\+|&|≠|>=?|<=?|=|≥|≤|/|÷|\^)`, Operator, nil}, | |||
{`\b(and|or|is equal|equals|(is )?equal to|is not|isn't|isn't equal( to)?|is not equal( to)?|doesn't equal|does not equal|(is )?greater than|comes after|is not less than or equal( to)?|isn't less than or equal( to)?|(is )?less than|comes before|is not greater than or equal( to)?|isn't greater than or equal( to)?|(is )?greater than or equal( to)?|is not less than|isn't less than|does not come before|doesn't come before|(is )?less than or equal( to)?|is not greater than|isn't greater than|does not come after|doesn't come after|starts? with|begins? with|ends? with|contains?|does not contain|doesn't contain|is in|is contained by|is not in|is not contained by|isn't contained by|div|mod|not|(a )?(ref( to)?|reference to)|is|does)\b`, OperatorWord, nil}, | |||
{`^(\s*(?:on|end)\s+)(zoomed|write to file|will zoom|will show|will select tab view item|will resize( sub views)?|will resign active|will quit|will pop up|will open|will move|will miniaturize|will hide|will finish launching|will display outline cell|will display item cell|will display cell|will display browser cell|will dismiss|will close|will become active|was miniaturized|was hidden|update toolbar item|update parameters|update menu item|shown|should zoom|should selection change|should select tab view item|should select row|should select item|should select column|should quit( after last window closed)?|should open( untitled)?|should expand item|should end editing|should collapse item|should close|should begin editing|selection changing|selection changed|selected tab view item|scroll wheel|rows changed|right mouse up|right mouse dragged|right mouse down|resized( sub views)?|resigned main|resigned key|resigned active|read from file|prepare table drop|prepare table drag|prepare outline drop|prepare outline drag|prepare drop|plugin loaded|parameters updated|panel ended|opened|open untitled|number of rows|number of items|number of browser rows|moved|mouse up|mouse moved|mouse exited|mouse entered|mouse dragged|mouse down|miniaturized|load data representation|launched|keyboard up|keyboard down|items changed|item value changed|item value|item expandable|idle|exposed|end editing|drop|drag( (entered|exited|updated))?|double clicked|document nib name|dialog ended|deminiaturized|data representation|conclude drop|column resized|column moved|column clicked|closed|clicked toolbar item|clicked|choose menu item|child of item|changed|change item value|change cell value|cell value changed|cell value|bounds changed|begin editing|became main|became key|awake from nib|alert ended|activated|action|accept table drop|accept outline drop)`, ByGroups(Keyword, NameFunction), nil}, | |||
{`^(\s*)(in|on|script|to)(\s+)`, ByGroups(Text, Keyword, Text), nil}, | |||
{`\b(as )(alias |application |boolean |class |constant |date |file |integer |list |number |POSIX file |real |record |reference |RGB color |script |text |unit types|(?:Unicode )?text|string)\b`, ByGroups(Keyword, NameClass), nil}, | |||
{`\b(AppleScript|current application|false|linefeed|missing value|pi|quote|result|return|space|tab|text item delimiters|true|version)\b`, NameConstant, nil}, | |||
{`\b(ASCII (character|number)|activate|beep|choose URL|choose application|choose color|choose file( name)?|choose folder|choose from list|choose remote application|clipboard info|close( access)?|copy|count|current date|delay|delete|display (alert|dialog)|do shell script|duplicate|exists|get eof|get volume settings|info for|launch|list (disks|folder)|load script|log|make|mount volume|new|offset|open( (for access|location))?|path to|print|quit|random number|read|round|run( script)?|say|scripting components|set (eof|the clipboard to|volume)|store script|summarize|system attribute|system info|the clipboard|time to GMT|write|quoted form)\b`, NameBuiltin, nil}, | |||
{`\b(considering|else|error|exit|from|if|ignoring|in|repeat|tell|then|times|to|try|until|using terms from|while|with|with timeout( of)?|with transaction|by|continue|end|its?|me|my|return|of|as)\b`, Keyword, nil}, | |||
{`\b(global|local|prop(erty)?|set|get)\b`, Keyword, nil}, | |||
{`\b(but|put|returning|the)\b`, NameBuiltin, nil}, | |||
{`\b(attachment|attribute run|character|day|month|paragraph|word|year)s?\b`, NameBuiltin, nil}, | |||
{`\b(about|above|against|apart from|around|aside from|at|below|beneath|beside|between|for|given|instead of|on|onto|out of|over|since)\b`, NameBuiltin, nil}, | |||
{`\b(accepts arrow key|action method|active|alignment|allowed identifiers|allows branch selection|allows column reordering|allows column resizing|allows column selection|allows customization|allows editing text attributes|allows empty selection|allows mixed state|allows multiple selection|allows reordering|allows undo|alpha( value)?|alternate image|alternate increment value|alternate title|animation delay|associated file name|associated object|auto completes|auto display|auto enables items|auto repeat|auto resizes( outline column)?|auto save expanded items|auto save name|auto save table columns|auto saves configuration|auto scroll|auto sizes all columns to fit|auto sizes cells|background color|bezel state|bezel style|bezeled|border rect|border type|bordered|bounds( rotation)?|box type|button returned|button type|can choose directories|can choose files|can draw|can hide|cell( (background color|size|type))?|characters|class|click count|clicked( data)? column|clicked data item|clicked( data)? row|closeable|collating|color( (mode|panel))|command key down|configuration|content(s| (size|view( margins)?))?|context|continuous|control key down|control size|control tint|control view|controller visible|coordinate system|copies( on scroll)?|corner view|current cell|current column|current( field)? editor|current( menu)? item|current row|current tab view item|data source|default identifiers|delta (x|y|z)|destination window|directory|display mode|displayed cell|document( (edited|rect|view))?|double value|dragged column|dragged distance|dragged items|draws( cell)? background|draws grid|dynamically scrolls|echos bullets|edge|editable|edited( data)? column|edited data item|edited( data)? row|enabled|enclosing scroll view|ending page|error handling|event number|event type|excluded from windows menu|executable path|expanded|fax number|field editor|file kind|file name|file type|first responder|first visible column|flipped|floating|font( panel)?|formatter|frameworks path|frontmost|gave up|grid color|has data items|has horizontal ruler|has horizontal scroller|has parent data item|has resize indicator|has shadow|has sub menu|has vertical ruler|has vertical scroller|header cell|header view|hidden|hides when deactivated|highlights by|horizontal line scroll|horizontal page scroll|horizontal ruler view|horizontally resizable|icon image|id|identifier|ignores multiple clicks|image( (alignment|dims when disabled|frame style|scaling))?|imports graphics|increment value|indentation per level|indeterminate|index|integer value|intercell spacing|item height|key( (code|equivalent( modifier)?|window))?|knob thickness|label|last( visible)? column|leading offset|leaf|level|line scroll|loaded|localized sort|location|loop mode|main( (bunde|menu|window))?|marker follows cell|matrix mode|maximum( content)? size|maximum visible columns|menu( form representation)?|miniaturizable|miniaturized|minimized image|minimized title|minimum column width|minimum( content)? size|modal|modified|mouse down state|movie( (controller|file|rect))?|muted|name|needs display|next state|next text|number of tick marks|only tick mark values|opaque|open panel|option key down|outline table column|page scroll|pages across|pages down|palette label|pane splitter|parent data item|parent window|pasteboard|path( (names|separator))?|playing|plays every frame|plays selection only|position|preferred edge|preferred type|pressure|previous text|prompt|properties|prototype cell|pulls down|rate|released when closed|repeated|requested print time|required file type|resizable|resized column|resource path|returns records|reuses columns|rich text|roll over|row height|rulers visible|save panel|scripts path|scrollable|selectable( identifiers)?|selected cell|selected( data)? columns?|selected data items?|selected( data)? rows?|selected item identifier|selection by rect|send action on arrow key|sends action when done editing|separates columns|separator item|sequence number|services menu|shared frameworks path|shared support path|sheet|shift key down|shows alpha|shows state by|size( mode)?|smart insert delete enabled|sort case sensitivity|sort column|sort order|sort type|sorted( data rows)?|sound|source( mask)?|spell checking enabled|starting page|state|string value|sub menu|super menu|super view|tab key traverses cells|tab state|tab type|tab view|table view|tag|target( printer)?|text color|text container insert|text container origin|text returned|tick mark position|time stamp|title(d| (cell|font|height|position|rect))?|tool tip|toolbar|trailing offset|transparent|treat packages as directories|truncated labels|types|unmodified characters|update views|use sort indicator|user defaults|uses data source|uses ruler|uses threaded animation|uses title from previous column|value wraps|version|vertical( (line scroll|page scroll|ruler view))?|vertically resizable|view|visible( document rect)?|volume|width|window|windows menu|wraps|zoomable|zoomed)\b`, NameAttribute, nil}, | |||
{`\b(action cell|alert reply|application|box|browser( cell)?|bundle|button( cell)?|cell|clip view|color well|color-panel|combo box( item)?|control|data( (cell|column|item|row|source))?|default entry|dialog reply|document|drag info|drawer|event|font(-panel)?|formatter|image( (cell|view))?|matrix|menu( item)?|item|movie( view)?|open-panel|outline view|panel|pasteboard|plugin|popup button|progress indicator|responder|save-panel|scroll view|secure text field( cell)?|slider|sound|split view|stepper|tab view( item)?|table( (column|header cell|header view|view))|text( (field( cell)?|view))?|toolbar( item)?|user-defaults|view|window)s?\b`, NameBuiltin, nil}, | |||
{`\b(animate|append|call method|center|close drawer|close panel|display|display alert|display dialog|display panel|go|hide|highlight|increment|item for|load image|load movie|load nib|load panel|load sound|localized string|lock focus|log|open drawer|path for|pause|perform action|play|register|resume|scroll|select( all)?|show|size to fit|start|step back|step forward|stop|synchronize|unlock focus|update)\b`, NameBuiltin, nil}, | |||
{`\b((in )?back of|(in )?front of|[0-9]+(st|nd|rd|th)|first|second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth|after|back|before|behind|every|front|index|last|middle|some|that|through|thru|where|whose)\b`, NameBuiltin, nil}, | |||
{`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil}, | |||
{`\b([a-zA-Z]\w*)\b`, NameVariable, nil}, | |||
{`[-+]?(\d+\.\d*|\d*\.\d+)(E[-+][0-9]+)?`, LiteralNumberFloat, nil}, | |||
{`[-+]?\d+`, LiteralNumberInteger, nil}, | |||
}, | |||
"comment": { | |||
{`\(\*`, CommentMultiline, Push()}, | |||
{`\*\)`, CommentMultiline, Pop(1)}, | |||
{`[^*(]+`, CommentMultiline, nil}, | |||
{`[*(]`, CommentMultiline, nil}, | |||
}, | |||
} | |||
} |
@@ -0,0 +1,114 @@ | |||
package a | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// Arduino lexer. | |||
var Arduino = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "Arduino", | |||
Aliases: []string{"arduino"}, | |||
Filenames: []string{"*.ino"}, | |||
MimeTypes: []string{"text/x-arduino"}, | |||
EnsureNL: true, | |||
}, | |||
arduinoRules, | |||
)) | |||
func arduinoRules() Rules { | |||
return Rules{ | |||
"statements": { | |||
{Words(``, `\b`, `catch`, `const_cast`, `delete`, `dynamic_cast`, `explicit`, `export`, `friend`, `mutable`, `namespace`, `new`, `operator`, `private`, `protected`, `public`, `reinterpret_cast`, `restrict`, `static_cast`, `template`, `this`, `throw`, `throws`, `try`, `typeid`, `typename`, `using`, `virtual`, `constexpr`, `nullptr`, `decltype`, `thread_local`, `alignas`, `alignof`, `static_assert`, `noexcept`, `override`, `final`), Keyword, nil}, | |||
{`char(16_t|32_t)\b`, KeywordType, nil}, | |||
{`(class)\b`, ByGroups(Keyword, Text), Push("classname")}, | |||
{`(R)(")([^\\()\s]{,16})(\()((?:.|\n)*?)(\)\3)(")`, ByGroups(LiteralStringAffix, LiteralString, LiteralStringDelimiter, LiteralStringDelimiter, LiteralString, LiteralStringDelimiter, LiteralString), nil}, | |||
{`(u8|u|U)(")`, ByGroups(LiteralStringAffix, LiteralString), Push("string")}, | |||
{`(L?)(")`, ByGroups(LiteralStringAffix, LiteralString), Push("string")}, | |||
{`(L?)(')(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])(')`, ByGroups(LiteralStringAffix, LiteralStringChar, LiteralStringChar, LiteralStringChar), nil}, | |||
{`(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*`, LiteralNumberFloat, nil}, | |||
{`(\d+\.\d*|\.\d+|\d+[fF])[fF]?`, LiteralNumberFloat, nil}, | |||
{`0x[0-9a-fA-F]+[LlUu]*`, LiteralNumberHex, nil}, | |||
{`0[0-7]+[LlUu]*`, LiteralNumberOct, nil}, | |||
{`\d+[LlUu]*`, LiteralNumberInteger, nil}, | |||
{`\*/`, Error, nil}, | |||
{`[~!%^&*+=|?:<>/-]`, Operator, nil}, | |||
{`[()\[\],.]`, Punctuation, nil}, | |||
{Words(``, `\b`, `asm`, `auto`, `break`, `case`, `const`, `continue`, `default`, `do`, `else`, `enum`, `extern`, `for`, `goto`, `if`, `register`, `restricted`, `return`, `sizeof`, `static`, `struct`, `switch`, `typedef`, `union`, `volatile`, `while`), Keyword, nil}, | |||
{`(_Bool|_Complex|_Imaginary|array|atomic_bool|atomic_char|atomic_int|atomic_llong|atomic_long|atomic_schar|atomic_short|atomic_uchar|atomic_uint|atomic_ullong|atomic_ulong|atomic_ushort|auto|bool|boolean|BooleanVariables|Byte|byte|Char|char|char16_t|char32_t|class|complex|Const|const|const_cast|delete|double|dynamic_cast|enum|explicit|extern|Float|float|friend|inline|Int|int|int16_t|int32_t|int64_t|int8_t|Long|long|new|NULL|null|operator|private|PROGMEM|protected|public|register|reinterpret_cast|short|signed|sizeof|Static|static|static_cast|String|struct|typedef|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|virtual|Void|void|Volatile|volatile|word)\b`, KeywordType, nil}, | |||
// Start of: Arduino-specific syntax | |||
{`(and|final|If|Loop|loop|not|or|override|setup|Setup|throw|try|xor)\b`, Keyword, nil}, // Addition to keywords already defined by C++ | |||
{`(ANALOG_MESSAGE|BIN|CHANGE|DEC|DEFAULT|DIGITAL_MESSAGE|EXTERNAL|FALLING|FIRMATA_STRING|HALF_PI|HEX|HIGH|INPUT|INPUT_PULLUP|INTERNAL|INTERNAL1V1|INTERNAL1V1|INTERNAL2V56|INTERNAL2V56|LED_BUILTIN|LED_BUILTIN_RX|LED_BUILTIN_TX|LOW|LSBFIRST|MSBFIRST|OCT|OUTPUT|PI|REPORT_ANALOG|REPORT_DIGITAL|RISING|SET_PIN_MODE|SYSEX_START|SYSTEM_RESET|TWO_PI)\b`, KeywordConstant, nil}, | |||
{`(boolean|const|byte|word|string|String|array)\b`, NameVariable, nil}, | |||
{`(Keyboard|KeyboardController|MouseController|SoftwareSerial|EthernetServer|EthernetClient|LiquidCrystal|RobotControl|GSMVoiceCall|EthernetUDP|EsploraTFT|HttpClient|RobotMotor|WiFiClient|GSMScanner|FileSystem|Scheduler|GSMServer|YunClient|YunServer|IPAddress|GSMClient|GSMModem|Keyboard|Ethernet|Console|GSMBand|Esplora|Stepper|Process|WiFiUDP|GSM_SMS|Mailbox|USBHost|Firmata|PImage|Client|Server|GSMPIN|FileIO|Bridge|Serial|EEPROM|Stream|Mouse|Audio|Servo|File|Task|GPRS|WiFi|Wire|TFT|GSM|SPI|SD)\b`, NameClass, nil}, | |||
{`(abs|Abs|accept|ACos|acos|acosf|addParameter|analogRead|AnalogRead|analogReadResolution|AnalogReadResolution|analogReference|AnalogReference|analogWrite|AnalogWrite|analogWriteResolution|AnalogWriteResolution|answerCall|asin|ASin|asinf|atan|ATan|atan2|ATan2|atan2f|atanf|attach|attached|attachGPRS|attachInterrupt|AttachInterrupt|autoscroll|available|availableForWrite|background|beep|begin|beginPacket|beginSD|beginSMS|beginSpeaker|beginTFT|beginTransmission|beginWrite|bit|Bit|BitClear|bitClear|bitRead|BitRead|bitSet|BitSet|BitWrite|bitWrite|blink|blinkVersion|BSSID|buffer|byte|cbrt|cbrtf|Ceil|ceil|ceilf|changePIN|char|charAt|checkPIN|checkPUK|checkReg|circle|cityNameRead|cityNameWrite|clear|clearScreen|click|close|compareTo|compassRead|concat|config|connect|connected|constrain|Constrain|copysign|copysignf|cos|Cos|cosf|cosh|coshf|countryNameRead|countryNameWrite|createChar|cursor|debugPrint|degrees|Delay|delay|DelayMicroseconds|delayMicroseconds|detach|DetachInterrupt|detachInterrupt|DigitalPinToInterrupt|digitalPinToInterrupt|DigitalRead|digitalRead|DigitalWrite|digitalWrite|disconnect|display|displayLogos|drawBMP|drawCompass|encryptionType|end|endPacket|endSMS|endsWith|endTransmission|endWrite|equals|equalsIgnoreCase|exists|exitValue|Exp|exp|expf|fabs|fabsf|fdim|fdimf|fill|find|findUntil|float|floor|Floor|floorf|flush|fma|fmaf|fmax|fmaxf|fmin|fminf|fmod|fmodf|gatewayIP|get|getAsynchronously|getBand|getButton|getBytes|getCurrentCarrier|getIMEI|getKey|getModifiers|getOemKey|getPINUsed|getResult|getSignalStrength|getSocket|getVoiceCallStatus|getXChange|getYChange|hangCall|height|highByte|HighByte|home|hypot|hypotf|image|indexOf|int|interrupts|IPAddress|IRread|isActionDone|isAlpha|isAlphaNumeric|isAscii|isControl|isDigit|isDirectory|isfinite|isGraph|isHexadecimalDigit|isinf|isListening|isLowerCase|isnan|isPIN|isPressed|isPrintable|isPunct|isSpace|isUpperCase|isValid|isWhitespace|keyboardRead|keyPressed|keyReleased|knobRead|lastIndexOf|ldexp|ldexpf|leftToRight|length|line|lineFollowConfig|listen|listenOnLocalhost|loadImage|localIP|log|Log|log10|log10f|logf|long|lowByte|LowByte|lrint|lrintf|lround|lroundf|macAddress|maintain|map|Map|Max|max|messageAvailable|Micros|micros|millis|Millis|Min|min|mkdir|motorsStop|motorsWrite|mouseDragged|mouseMoved|mousePressed|mouseReleased|move|noAutoscroll|noBlink|noBuffer|noCursor|noDisplay|noFill|noInterrupts|NoInterrupts|noListenOnLocalhost|noStroke|noTone|NoTone|onReceive|onRequest|open|openNextFile|overflow|parseCommand|parseFloat|parseInt|parsePacket|pauseMode|peek|PinMode|pinMode|playFile|playMelody|point|pointTo|position|Pow|pow|powf|prepare|press|print|printFirmwareVersion|println|printVersion|process|processInput|PulseIn|pulseIn|pulseInLong|PulseInLong|put|radians|random|Random|randomSeed|RandomSeed|read|readAccelerometer|readBlue|readButton|readBytes|readBytesUntil|readGreen|readJoystickButton|readJoystickSwitch|readJoystickX|readJoystickY|readLightSensor|readMessage|readMicrophone|readNetworks|readRed|readSlider|readString|readStringUntil|readTemperature|ready|rect|release|releaseAll|remoteIP|remoteNumber|remotePort|remove|replace|requestFrom|retrieveCallingNumber|rewindDirectory|rightToLeft|rmdir|robotNameRead|robotNameWrite|round|roundf|RSSI|run|runAsynchronously|running|runShellCommand|runShellCommandAsynchronously|scanNetworks|scrollDisplayLeft|scrollDisplayRight|seek|sendAnalog|sendDigitalPortPair|sendDigitalPorts|sendString|sendSysex|Serial_Available|Serial_Begin|Serial_End|Serial_Flush|Serial_Peek|Serial_Print|Serial_Println|Serial_Read|serialEvent|setBand|setBitOrder|setCharAt|setClockDivider|setCursor|setDataMode|setDNS|setFirmwareVersion|setMode|setPINUsed|setSpeed|setTextSize|setTimeout|ShiftIn|shiftIn|ShiftOut|shiftOut|shutdown|signbit|sin|Sin|sinf|sinh|sinhf|size|sizeof|Sq|sq|Sqrt|sqrt|sqrtf|SSID|startLoop|startsWith|step|stop|stroke|subnetMask|substring|switchPIN|tan|Tan|tanf|tanh|tanhf|tempoWrite|text|toCharArray|toInt|toLowerCase|tone|Tone|toUpperCase|transfer|trim|trunc|truncf|tuneWrite|turn|updateIR|userNameRead|userNameWrite|voiceCall|waitContinue|width|WiFiServer|word|write|writeBlue|writeGreen|writeJSON|writeMessage|writeMicroseconds|writeRed|writeRGB|yield|Yield)\b`, NameFunction, nil}, | |||
// End of: Arduino-specific syntax | |||
{Words(``, `\b`, `inline`, `_inline`, `__inline`, `naked`, `restrict`, `thread`, `typename`), KeywordReserved, nil}, | |||
{`(__m(128i|128d|128|64))\b`, KeywordReserved, nil}, | |||
{Words(`__`, `\b`, `asm`, `int8`, `based`, `except`, `int16`, `stdcall`, `cdecl`, `fastcall`, `int32`, `declspec`, `finally`, `int64`, `try`, `leave`, `wchar_t`, `w64`, `unaligned`, `raise`, `noop`, `identifier`, `forceinline`, `assume`), KeywordReserved, nil}, | |||
{`(true|false|NULL)\b`, NameBuiltin, nil}, | |||
{`([a-zA-Z_]\w*)(\s*)(:)(?!:)`, ByGroups(NameLabel, Text, Punctuation), nil}, | |||
{`[a-zA-Z_]\w*`, Name, nil}, | |||
}, | |||
"root": { | |||
Include("whitespace"), | |||
{`((?:[\w*\s])+?(?:\s|[*]))([a-zA-Z_]\w*)(\s*\([^;]*?\))([^;{]*)(\{)`, ByGroups(UsingSelf("root"), NameFunction, UsingSelf("root"), UsingSelf("root"), Punctuation), Push("function")}, | |||
{`((?:[\w*\s])+?(?:\s|[*]))([a-zA-Z_]\w*)(\s*\([^;]*?\))([^;]*)(;)`, ByGroups(UsingSelf("root"), NameFunction, UsingSelf("root"), UsingSelf("root"), Punctuation), nil}, | |||
Default(Push("statement")), | |||
{Words(`__`, `\b`, `virtual_inheritance`, `uuidof`, `super`, `single_inheritance`, `multiple_inheritance`, `interface`, `event`), KeywordReserved, nil}, | |||
{`__(offload|blockingoffload|outer)\b`, KeywordPseudo, nil}, | |||
}, | |||
"classname": { | |||
{`[a-zA-Z_]\w*`, NameClass, Pop(1)}, | |||
{`\s*(?=>)`, Text, Pop(1)}, | |||
}, | |||
"whitespace": { | |||
{`^#if\s+0`, CommentPreproc, Push("if0")}, | |||
{`^#`, CommentPreproc, Push("macro")}, | |||
{`^(\s*(?:/[*].*?[*]/\s*)?)(#if\s+0)`, ByGroups(UsingSelf("root"), CommentPreproc), Push("if0")}, | |||
{`^(\s*(?:/[*].*?[*]/\s*)?)(#)`, ByGroups(UsingSelf("root"), CommentPreproc), Push("macro")}, | |||
{`\n`, Text, nil}, | |||
{`\s+`, Text, nil}, | |||
{`\\\n`, Text, nil}, | |||
{`//(\n|[\w\W]*?[^\\]\n)`, CommentSingle, nil}, | |||
{`/(\\\n)?[*][\w\W]*?[*](\\\n)?/`, CommentMultiline, nil}, | |||
{`/(\\\n)?[*][\w\W]*`, CommentMultiline, nil}, | |||
}, | |||
"statement": { | |||
Include("whitespace"), | |||
Include("statements"), | |||
{`[{}]`, Punctuation, nil}, | |||
{`;`, Punctuation, Pop(1)}, | |||
}, | |||
"function": { | |||
Include("whitespace"), | |||
Include("statements"), | |||
{`;`, Punctuation, nil}, | |||
{`\{`, Punctuation, Push()}, | |||
{`\}`, Punctuation, Pop(1)}, | |||
}, | |||
"string": { | |||
{`"`, LiteralString, Pop(1)}, | |||
{`\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|[0-7]{1,3})`, LiteralStringEscape, nil}, | |||
{`[^\\"\n]+`, LiteralString, nil}, | |||
{`\\\n`, LiteralString, nil}, | |||
{`\\`, LiteralString, nil}, | |||
}, | |||
"macro": { | |||
{`(include)(\s*(?:/[*].*?[*]/\s*)?)([^\n]+)`, ByGroups(CommentPreproc, Text, CommentPreprocFile), nil}, | |||
{`[^/\n]+`, CommentPreproc, nil}, | |||
{`/[*](.|\n)*?[*]/`, CommentMultiline, nil}, | |||
{`//.*?\n`, CommentSingle, Pop(1)}, | |||
{`/`, CommentPreproc, nil}, | |||
{`(?<=\\)\n`, CommentPreproc, nil}, | |||
{`\n`, CommentPreproc, Pop(1)}, | |||
}, | |||
"if0": { | |||
{`^\s*#if.*?(?<!\\)\n`, CommentPreproc, Push()}, | |||
{`^\s*#el(?:se|if).*\n`, CommentPreproc, Pop(1)}, | |||
{`^\s*#endif.*?(?<!\\)\n`, CommentPreproc, Pop(1)}, | |||
{`.*?\n`, Comment, nil}, | |||
}, | |||
} | |||
} |
@@ -0,0 +1,72 @@ | |||
package a | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
var ArmAsm = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "ArmAsm", | |||
Aliases: []string{"armasm"}, | |||
EnsureNL: true, | |||
Filenames: []string{"*.s", "*.S"}, | |||
MimeTypes: []string{"text/x-armasm", "text/x-asm"}, | |||
}, | |||
armasmRules, | |||
)) | |||
func armasmRules() Rules { | |||
return Rules{ | |||
"commentsandwhitespace": { | |||
{`\s+`, Text, nil}, | |||
{`[@;].*?\n`, CommentSingle, nil}, | |||
{`/\*.*?\*/`, CommentMultiline, nil}, | |||
}, | |||
"literal": { | |||
// Binary | |||
{`0b[01]+`, NumberBin, Pop(1)}, | |||
// Hex | |||
{`0x\w{1,8}`, NumberHex, Pop(1)}, | |||
// Octal | |||
{`0\d+`, NumberOct, Pop(1)}, | |||
// Float | |||
{`\d+?\.\d+?`, NumberFloat, Pop(1)}, | |||
// Integer | |||
{`\d+`, NumberInteger, Pop(1)}, | |||
// String | |||
{`(")(.+)(")`, ByGroups(Punctuation, StringDouble, Punctuation), Pop(1)}, | |||
// Char | |||
{`(')(.{1}|\\.{1})(')`, ByGroups(Punctuation, StringChar, Punctuation), Pop(1)}, | |||
}, | |||
"opcode": { | |||
// Escape at line end | |||
{`\n`, Text, Pop(1)}, | |||
// Comment | |||
{`(@|;).*\n`, CommentSingle, Pop(1)}, | |||
// Whitespace | |||
{`(\s+|,)`, Text, nil}, | |||
// Register by number | |||
{`[rapcfxwbhsdqv]\d{1,2}`, NameClass, nil}, | |||
// Address by hex | |||
{`=0x\w+`, ByGroups(Text, NameLabel), nil}, | |||
// Pseudo address by label | |||
{`(=)(\w+)`, ByGroups(Text, NameLabel), nil}, | |||
// Immediate | |||
{`#`, Text, Push("literal")}, | |||
}, | |||
"root": { | |||
Include("commentsandwhitespace"), | |||
// Directive with optional param | |||
{`(\.\w+)([ \t]+\w+\s+?)?`, ByGroups(KeywordNamespace, NameLabel), nil}, | |||
// Label with data | |||
{`(\w+)(:)(\s+\.\w+\s+)`, ByGroups(NameLabel, Punctuation, KeywordNamespace), Push("literal")}, | |||
// Label | |||
{`(\w+)(:)`, ByGroups(NameLabel, Punctuation), nil}, | |||
// Syscall Op | |||
{`svc\s+\w+`, NameNamespace, nil}, | |||
// Opcode | |||
{`[a-zA-Z]+`, Text, Push("opcode")}, | |||
}, | |||
} | |||
} |
@@ -0,0 +1,52 @@ | |||
package a | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// Awk lexer. | |||
var Awk = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "Awk", | |||
Aliases: []string{"awk", "gawk", "mawk", "nawk"}, | |||
Filenames: []string{"*.awk"}, | |||
MimeTypes: []string{"application/x-awk"}, | |||
}, | |||
awkRules, | |||
)) | |||
func awkRules() Rules { | |||
return Rules{ | |||
"commentsandwhitespace": { | |||
{`\s+`, Text, nil}, | |||
{`#.*$`, CommentSingle, nil}, | |||
}, | |||
"slashstartsregex": { | |||
Include("commentsandwhitespace"), | |||
{`/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/\B`, LiteralStringRegex, Pop(1)}, | |||
{`(?=/)`, Text, Push("#pop", "badregex")}, | |||
Default(Pop(1)), | |||
}, | |||
"badregex": { | |||
{`\n`, Text, Pop(1)}, | |||
}, | |||
"root": { | |||
{`^(?=\s|/)`, Text, Push("slashstartsregex")}, | |||
Include("commentsandwhitespace"), | |||
{`\+\+|--|\|\||&&|in\b|\$|!?~|\|&|(\*\*|[-<>+*%\^/!=|])=?`, Operator, Push("slashstartsregex")}, | |||
{`[{(\[;,]`, Punctuation, Push("slashstartsregex")}, | |||
{`[})\].]`, Punctuation, nil}, | |||
{`(break|continue|do|while|exit|for|if|else|return|switch|case|default)\b`, Keyword, Push("slashstartsregex")}, | |||
{`function\b`, KeywordDeclaration, Push("slashstartsregex")}, | |||
{`(atan2|cos|exp|int|log|rand|sin|sqrt|srand|gensub|gsub|index|length|match|split|patsplit|sprintf|sub|substr|tolower|toupper|close|fflush|getline|next(file)|print|printf|strftime|systime|mktime|delete|system|strtonum|and|compl|lshift|or|rshift|asorti?|isarray|bindtextdomain|dcn?gettext|@(include|load|namespace))\b`, KeywordReserved, nil}, | |||
{`(ARGC|ARGIND|ARGV|BEGIN(FILE)?|BINMODE|CONVFMT|ENVIRON|END(FILE)?|ERRNO|FIELDWIDTHS|FILENAME|FNR|FPAT|FS|IGNORECASE|LINT|NF|NR|OFMT|OFS|ORS|PROCINFO|RLENGTH|RS|RSTART|RT|SUBSEP|TEXTDOMAIN)\b`, NameBuiltin, nil}, | |||
{`[@$a-zA-Z_]\w*`, NameOther, nil}, | |||
{`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil}, | |||
{`0x[0-9a-fA-F]+`, LiteralNumberHex, nil}, | |||
{`[0-9]+`, LiteralNumberInteger, nil}, | |||
{`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil}, | |||
{`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil}, | |||
}, | |||
} | |||
} |
@@ -0,0 +1,50 @@ | |||
package b | |||
import ( | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// Ballerina lexer. | |||
var Ballerina = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "Ballerina", | |||
Aliases: []string{"ballerina"}, | |||
Filenames: []string{"*.bal"}, | |||
MimeTypes: []string{"text/x-ballerina"}, | |||
DotAll: true, | |||
}, | |||
ballerinaRules, | |||
)) | |||
func ballerinaRules() Rules { | |||
return Rules{ | |||
"root": { | |||
{`[^\S\n]+`, Text, nil}, | |||
{`//.*?\n`, CommentSingle, nil}, | |||
{`/\*.*?\*/`, CommentMultiline, nil}, | |||
{`(break|catch|continue|done|else|finally|foreach|forever|fork|if|lock|match|return|throw|transaction|try|while)\b`, Keyword, nil}, | |||
{`((?:(?:[^\W\d]|\$)[\w.\[\]$<>]*\s+)+?)((?:[^\W\d]|\$)[\w$]*)(\s*)(\()`, ByGroups(UsingSelf("root"), NameFunction, Text, Operator), nil}, | |||
{`@[^\W\d][\w.]*`, NameDecorator, nil}, | |||
{`(annotation|bind|but|endpoint|error|function|object|private|public|returns|service|type|var|with|worker)\b`, KeywordDeclaration, nil}, | |||
{`(boolean|byte|decimal|float|int|json|map|nil|record|string|table|xml)\b`, KeywordType, nil}, | |||
{`(true|false|null)\b`, KeywordConstant, nil}, | |||
{`(import)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")}, | |||
{`"(\\\\|\\"|[^"])*"`, LiteralString, nil}, | |||
{`'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'`, LiteralStringChar, nil}, | |||
{`(\.)((?:[^\W\d]|\$)[\w$]*)`, ByGroups(Operator, NameAttribute), nil}, | |||
{`^\s*([^\W\d]|\$)[\w$]*:`, NameLabel, nil}, | |||
{`([^\W\d]|\$)[\w$]*`, Name, nil}, | |||
{`([0-9][0-9_]*\.([0-9][0-9_]*)?|\.[0-9][0-9_]*)([eE][+\-]?[0-9][0-9_]*)?[fFdD]?|[0-9][eE][+\-]?[0-9][0-9_]*[fFdD]?|[0-9]([eE][+\-]?[0-9][0-9_]*)?[fFdD]|0[xX]([0-9a-fA-F][0-9a-fA-F_]*\.?|([0-9a-fA-F][0-9a-fA-F_]*)?\.[0-9a-fA-F][0-9a-fA-F_]*)[pP][+\-]?[0-9][0-9_]*[fFdD]?`, LiteralNumberFloat, nil}, | |||
{`0[xX][0-9a-fA-F][0-9a-fA-F_]*[lL]?`, LiteralNumberHex, nil}, | |||
{`0[bB][01][01_]*[lL]?`, LiteralNumberBin, nil}, | |||
{`0[0-7_]+[lL]?`, LiteralNumberOct, nil}, | |||
{`0|[1-9][0-9_]*[lL]?`, LiteralNumberInteger, nil}, | |||
{`[~^*!%&\[\](){}<>|+=:;,./?-]`, Operator, nil}, | |||
{`\n`, Text, nil}, | |||
}, | |||
"import": { | |||
{`[\w.]+`, NameNamespace, Pop(1)}, | |||
}, | |||
} | |||
} |
@@ -0,0 +1,100 @@ | |||
package b | |||
import ( | |||
"regexp" | |||
. "github.com/alecthomas/chroma" // nolint | |||
"github.com/alecthomas/chroma/lexers/internal" | |||
) | |||
// TODO(moorereason): can this be factored away? | |||
var bashAnalyserRe = regexp.MustCompile(`(?m)^#!.*/bin/(?:env |)(?:bash|zsh|sh|ksh)`) | |||
// Bash lexer. | |||
var Bash = internal.Register(MustNewLazyLexer( | |||
&Config{ | |||
Name: "Bash", | |||
Aliases: []string{"bash", "sh", "ksh", "zsh", "shell"}, | |||
Filenames: []string{"*.sh", "*.ksh", "*.bash", "*.ebuild", "*.eclass", ".env", "*.env", "*.exheres-0", "*.exlib", "*.zsh", "*.zshrc", ".bashrc", "bashrc", ".bash_*", "bash_*", "zshrc", ".zshrc", "PKGBUILD"}, | |||
MimeTypes: []string{"application/x-sh", "application/x-shellscript"}, | |||
}, | |||
bashRules, | |||
).SetAnalyser(func(text string) float32 { | |||
if bashAnalyserRe.FindString(text) != "" { | |||
return 1.0 | |||
} | |||
return 0.0 | |||
})) | |||
func bashRules() Rules { | |||
return Rules{ | |||
"root": { | |||
Include("basic"), | |||
{"`", LiteralStringBacktick, Push("backticks")}, | |||
Include("data"), | |||
Include("interp"), | |||
}, | |||
"interp": { | |||
{`\$\(\(`, Keyword, Push("math")}, | |||
{`\$\(`, Keyword, Push("paren")}, | |||
{`\$\{#?`, LiteralStringInterpol, Push("curly")}, | |||
{`\$[a-zA-Z_]\w*`, NameVariable, nil}, | |||
{`\$(?:\d+|[#$?!_*@-])`, NameVariable, nil}, | |||
{`\$`, Text, nil}, | |||
}, | |||
"basic": { | |||
{`\b(if|fi|else|while|do|done|for|then|return|function|case|select|continue|until|esac|elif)(\s*)\b`, ByGroups(Keyword, Text), nil}, | |||
{"\\b(alias|bg|bind|break|builtin|caller|cd|command|compgen|complete|declare|dirs|disown|echo|enable|eval|exec|exit|export|false|fc|fg|getopts|hash|help|history|jobs|kill|let|local|logout|popd|printf|pushd|pwd|read|readonly|set|shift|shopt|source|suspend|test|time|times|trap|true|type|typeset|ulimit|umask|unalias|unset|wait)(?=[\\s)`])", NameBuiltin, nil}, | |||
{`\A#!.+\n`, CommentPreproc, nil}, | |||
{`#.*(\S|$)`, CommentSingle, nil}, | |||
{`\\[\w\W]`, LiteralStringEscape, nil}, | |||
{`(\b\w+)(\s*)(\+?=)`, ByGroups(NameVariable, Text, Operator), nil}, | |||
{`[\[\]{}()=]`, Operator, nil}, | |||
{`<<<`, Operator, nil}, | |||
{`<<-?\s*(\'?)\\?(\w+)[\w\W]+?\2`, LiteralString, nil}, | |||
{`&&|\|\|`, Operator, nil}, | |||
}, | |||
"data": { | |||
{`(?s)\$?"(\\\\|\\[0-7]+|\\.|[^"\\$])*"`, LiteralStringDouble, nil}, | |||
{`"`, LiteralStringDouble, Push("string")}, | |||
{`(?s)\$'(\\\\|\\[0-7]+|\\.|[^'\\])*'`, LiteralStringSingle, nil}, | |||
{`(?s)'.*?'`, LiteralStringSingle, nil}, | |||
{`;`, Punctuation, nil}, | |||
{`&`, Punctuation, nil}, | |||
{`\|`, Punctuation, nil}, | |||
{`\s+`, Text, nil}, | |||
{`\d+(?= |$)`, LiteralNumber, nil}, | |||
{"[^=\\s\\[\\]{}()$\"\\'`\\\\<&|;]+", Text, nil}, | |||
{`<`, Text, nil}, | |||
}, | |||
"string": { | |||
{`"`, LiteralStringDouble, Pop(1)}, | |||
{`(?s)(\\\\|\\[0-7]+|\\.|[^"\\$])+`, LiteralStringDouble, nil}, | |||
Include("interp"), | |||
}, | |||
"curly": { | |||
{`\}`, LiteralStringInterpol, Pop(1)}, | |||
{`:-`, Keyword, nil}, | |||
{`\w+`, NameVariable, nil}, | |||
{"[^}:\"\\'`$\\\\]+", Punctuation, nil}, | |||
{`:`, Punctuation, nil}, | |||
Include("root"), | |||
}, | |||
"paren": { | |||
{`\)`, Keyword, Pop(1)}, | |||
Include("root"), | |||
}, | |||
"math": { | |||
{`\)\)`, Keyword, Pop(1)}, | |||
{`[-+*/%^|&]|\*\*|\|\|`, Operator, nil}, | |||
{`\d+#\d+`, LiteralNumber, nil}, | |||
{`\d+#(?! )`, LiteralNumber, nil}, | |||
{`\d+`, LiteralNumber, nil}, | |||
Include("root"), | |||
}, | |||
"backticks": { | |||
{"`", LiteralStringBacktick, Pop(1)}, | |||
Include("root"), | |||
}, | |||
} | |||
} |