changeset 17:9b4d166e6a7e

add util
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Thu, 02 Apr 2020 03:19:24 +0900
parents cc568d791a28
children e0e36291a6f4
files util.go
diffstat 1 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/util.go	Thu Apr 02 03:19:24 2020 +0900
@@ -0,0 +1,39 @@
+package lectable
+
+import (
+	"os"
+	"path/filepath"
+	"strconv"
+	"time"
+
+	"github.com/pkg/errors"
+)
+
+//CreateGetSyllabus is constructor  and initialize from now time
+func guessOutputDir() string {
+	tm := time.Now()
+	year := tm.Year()
+
+	var term string
+
+	if tm.Month() < 7 {
+		term = "previous"
+	} else {
+		term = "latter"
+	}
+
+	outputdir := filepath.Join(strconv.Itoa(year), term)
+	return outputdir
+}
+
+//CheckAndMkdirBuilddir is builld 2019/early dir
+func checkAndMkdirBuilddir(outputdir string) error {
+	if f, err := os.Stat(outputdir); os.IsNotExist(err) || !f.IsDir() {
+		err := os.MkdirAll(outputdir, 0755)
+		if err != nil {
+			return errors.Wrap(err, "failed mkdir")
+		}
+		return nil
+	}
+	return nil
+}