2021-02-01 20:25:20 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("embed", metavar="<true/false>|<internal/external>|<yes/no>", type=str)
|
|
|
|
trues = ["true", "internal", "yes", "y"]
|
|
|
|
falses = ["false", "external", "no", "n"]
|
|
|
|
|
|
|
|
EMBED = parser.parse_args().embed
|
|
|
|
|
|
|
|
with open("embed.go", "w") as f:
|
|
|
|
if EMBED in trues:
|
|
|
|
f.write("""package main
|
|
|
|
import (
|
2021-02-02 15:19:43 +00:00
|
|
|
"embed"
|
|
|
|
"io/fs"
|
|
|
|
"log"
|
2021-02-01 20:25:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed data data/html data/web data/web/css data/web/js
|
2021-02-02 15:44:30 +00:00
|
|
|
var loFS embed.FS
|
2021-02-01 20:25:20 +00:00
|
|
|
|
|
|
|
//go:embed lang/common lang/admin lang/email lang/form lang/setup
|
2021-02-02 15:44:30 +00:00
|
|
|
var laFS embed.FS
|
2021-02-02 15:19:43 +00:00
|
|
|
|
2021-02-02 15:44:30 +00:00
|
|
|
var langFS rewriteFS
|
|
|
|
var localFS rewriteFS
|
2021-02-02 15:19:43 +00:00
|
|
|
|
2021-02-02 15:44:30 +00:00
|
|
|
type rewriteFS struct {
|
|
|
|
fs embed.FS
|
|
|
|
prefix string
|
2021-02-02 15:19:43 +00:00
|
|
|
}
|
|
|
|
|
2021-02-02 15:44:30 +00:00
|
|
|
func (l rewriteFS) Open(name string) (fs.File, error) { return l.fs.Open(l.prefix + name) }
|
|
|
|
func (l rewriteFS) ReadDir(name string) ([]fs.DirEntry, error) { return l.fs.ReadDir(l.prefix + name) }
|
|
|
|
func (l rewriteFS) ReadFile(name string) ([]byte, error) { return l.fs.ReadFile(l.prefix + name) }
|
2021-02-01 20:25:20 +00:00
|
|
|
|
2021-02-02 18:09:02 +00:00
|
|
|
func loadFilesystems() {
|
2021-02-02 15:44:30 +00:00
|
|
|
langFS = rewriteFS{laFS, "lang/"}
|
|
|
|
localFS = rewriteFS{loFS, "data/"}
|
2021-02-02 15:19:43 +00:00
|
|
|
log.Println("Using internal storage")
|
2021-02-01 20:25:20 +00:00
|
|
|
}""")
|
|
|
|
elif EMBED in falses:
|
|
|
|
f.write("""package main
|
|
|
|
import (
|
|
|
|
"io/fs"
|
|
|
|
"os"
|
|
|
|
"log"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
var localFS fs.FS
|
|
|
|
var langFS fs.FS
|
|
|
|
|
2021-02-02 18:09:02 +00:00
|
|
|
func loadFilesystems() {
|
2021-02-01 20:25:20 +00:00
|
|
|
log.Println("Using external storage")
|
|
|
|
executable, _ := os.Executable()
|
2021-02-02 15:44:30 +00:00
|
|
|
localFS = os.DirFS(filepath.Join(filepath.Dir(executable), "data"))
|
2021-02-02 15:19:43 +00:00
|
|
|
langFS = os.DirFS(filepath.Join(filepath.Dir(executable), "data", "lang"))
|
2021-02-01 20:25:20 +00:00
|
|
|
}""")
|