update some tool paths
This commit is contained in:
parent
057572f030
commit
7bd487a7ee
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1 @@
|
|||||||
build
|
build
|
||||||
tool/build-html
|
|
||||||
tool/number
|
|
||||||
tool/measure
|
|
||||||
|
3
tool/build-html
Executable file
3
tool/build-html
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
exec go run tool/build-html.go
|
@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
go build -o tool/build-html tool/src/build-html.go
|
|
||||||
go build -o tool/number tool/src/number.go
|
|
||||||
go build -o tool/measure tool/src/measure.go
|
|
3
tool/measure
Executable file
3
tool/measure
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
exec go run tool/measure.go
|
@ -1,77 +0,0 @@
|
|||||||
// (Re-)number the book source directories according to the index.
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"regexp"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func minInt(a, b int) int {
|
|
||||||
if a < b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// read names of source files
|
|
||||||
sourceNames := make([]string, 0)
|
|
||||||
sourceMap := make(map[string]string)
|
|
||||||
fileInfos, dirErr := ioutil.ReadDir("./src")
|
|
||||||
if dirErr != nil {
|
|
||||||
panic(dirErr)
|
|
||||||
}
|
|
||||||
baseTrimmer, _ := regexp.Compile("^[0-9x]+-")
|
|
||||||
for _, fi := range fileInfos {
|
|
||||||
if fi.Name() != "index.txt" {
|
|
||||||
baseName := baseTrimmer.ReplaceAllString(fi.Name(), "")
|
|
||||||
sourceNames = append(sourceNames, baseName)
|
|
||||||
sourceMap[baseName] = fi.Name()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// read names from index
|
|
||||||
indexBytes, idxErr := ioutil.ReadFile("src/index.txt")
|
|
||||||
if idxErr != nil {
|
|
||||||
panic(idxErr)
|
|
||||||
}
|
|
||||||
indexNamesAll := strings.Split(string(indexBytes), "\n")
|
|
||||||
indexNames := make([]string, 0)
|
|
||||||
for _, indexName := range indexNamesAll {
|
|
||||||
if indexName != "" && !strings.Contains(indexName, "#") && !strings.Contains(indexName, "~") {
|
|
||||||
indexNames = append(indexNames, indexName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// sanity check two lists
|
|
||||||
if len(sourceNames) != len(indexNames) {
|
|
||||||
sort.Strings(sourceNames)
|
|
||||||
sort.Strings(indexNames)
|
|
||||||
for i := 0; i < minInt(len(sourceNames), len(indexNames)); i++ {
|
|
||||||
fmt.Printf("%s %s\n", sourceNames[i], indexNames[i])
|
|
||||||
}
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
for _, indexName := range indexNames {
|
|
||||||
_, ok := sourceMap[indexName]
|
|
||||||
if !ok {
|
|
||||||
fmt.Printf("%s\n", indexName)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// rename some stuff
|
|
||||||
for _, indexName := range indexNames {
|
|
||||||
oldName := sourceMap[indexName]
|
|
||||||
newName := indexName
|
|
||||||
if oldName != newName {
|
|
||||||
fmt.Println(oldName, "->", newName)
|
|
||||||
os.Rename("src/"+oldName, "src/"+newName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user