Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
rename whitespace in files too
Browse files Browse the repository at this point in the history
  • Loading branch information
marguerite committed Jun 3, 2018
1 parent 505d62f commit afa1b56
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
WPS Office Installer for openSUSE

------

Installation:

go build wps-installer.go
go build ghost_generator.go
go build depends_generator.go

wps-installer will be installed to /var/adm/update-scripts.

`ghost_generator -wpsdir` will generate directories and ghost files files used by specfile.

`depends_generator -wpsdir` will generate wps-office's runtime dependencies used in specfile.
23 changes: 18 additions & 5 deletions ghost_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"log"
"os"
"path"
"path/filepath"
"regexp"
"sort"
Expand Down Expand Up @@ -49,11 +50,22 @@ func renameWhitespaceInDir(dir string) {

for _, p := range dirs {
if re.MatchString(p) {
os.Rename(p, strings.Replace(p, " ", "_", -1))
os.Rename(p, path.Dir(p)+"/"+strings.Replace(filepath.Base(p), " ", "_", -1))
}
}
}

func renameWhitespaceInFiles(dir string) {
re := regexp.MustCompile(`[[:space:]]`)
err := filepath.Walk(dir, func(p string, i os.FileInfo, e error) error {
if !i.IsDir() && re.MatchString(p) {
os.Rename(p, strings.Replace(p, " ", "_", -1))
}
return nil
})
checkError(err)
}

func getDirsAndFiles(dir string) ([]string, []string) {
var dirs []string
var files []string
Expand Down Expand Up @@ -99,15 +111,16 @@ func main() {
var wpsDir string
flag.StringVar(&wpsDir, "wpsdir", "", "wps office directory")
flag.Parse()
if wpsDir == "" {
panic("You must specify the unpacked wps office dir with -wpsdir")
}
if wpsDir == "" {
panic("You must specify the unpacked wps office dir with -wpsdir")
}

log.Println("wpsDir: " + wpsDir)
log.Println("wpsDir: " + wpsDir)

office6Dir := wpsDir + "/office6"
fontsDir := wpsDir + "/fonts"
renameWhitespaceInDir(office6Dir)
renameWhitespaceInFiles(office6Dir)
officeDirs, officeFiles := getDirsAndFiles(office6Dir)
_, fontFiles := getDirsAndFiles(fontsDir)

Expand Down
14 changes: 13 additions & 1 deletion wps-installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,22 @@ func renameWhitespaceInDir(dir string) {

for _, p := range dirs {
if re.MatchString(p) {
os.Rename(p, strings.Replace(p, " ", "_", -1))
os.Rename(p, path.Dir(p)+"/"+strings.Replace(filepath.Base(p), " ", "_", -1))
}
}
}

func renameWhitespaceInFiles(dir string) {
re := regexp.MustCompile(`[[:space:]]`)
err := filepath.Walk(dir, func(p string, i os.FileInfo, e error) error {
if !i.IsDir() && re.MatchString(p) {
os.Rename(p, strings.Replace(p, " ", "_", -1))
}
return nil
})
checkError(err)
}

func absolutePath(relativePath, parentDir string) string {
if strings.HasPrefix(relativePath, "/") {
return filepath.Clean(relativePath)
Expand Down Expand Up @@ -339,6 +350,7 @@ func main() {
unpack(wpsTmp+wpsTar, wpsPrefix)
createDir(wpsDestDir)
renameWhitespaceInDir(wpsPrefix)
renameWhitespaceInFiles(wpsPrefix)

log.Println("Copying files...Ultra slow...")
copyDir(wpsPrefix+"/office6", wpsDestDir+"/office6")
Expand Down

0 comments on commit afa1b56

Please sign in to comment.