wip
This commit is contained in:
@@ -3,15 +3,59 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/starkers/safer-eve/pkg/eve"
|
"github.com/starkers/safer-eve/pkg/eve"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("searching")
|
fmt.Println("searching")
|
||||||
|
|
||||||
|
//logDirs := eve.PathSearch()
|
||||||
|
//fmt.Println(a)
|
||||||
fileList := eve.FileSearchUnix()
|
fileList := eve.FileSearchUnix()
|
||||||
|
|
||||||
List := eve.GetActiveChannels(fileList)
|
//List := eve.GetActiveChannels(fileList)
|
||||||
for _, name := range List{
|
//for _, name := range List{
|
||||||
fmt.Println(name)
|
// fmt.Println(name)
|
||||||
|
//}
|
||||||
|
|
||||||
|
//for _, d := range logDirs {
|
||||||
|
// fmt.Println(d)
|
||||||
|
// go eve.WatchPath(d)
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
for _, f := range fileList{
|
||||||
|
if eve.IsCurrentLog(f) {
|
||||||
|
//if strings.Contains(f, "delve.imperium") {
|
||||||
|
fmt.Printf("tailing file: %v\n", f)
|
||||||
|
go eve.Tail(f)
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
//else {
|
||||||
|
// fmt.Println(f)
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
time.Sleep(9999 * time.Hour)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//func parseLine(text string){
|
||||||
|
// fmt.Printf("parsing: '%v'\n", text)
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//func tailFile(filePath string) {
|
||||||
|
//
|
||||||
|
// // https://godoc.org/github.com/hpcloud/tail#Config
|
||||||
|
// t, err := tail.TailFile(
|
||||||
|
// filePath,
|
||||||
|
// tail.Config{
|
||||||
|
// Follow: true,
|
||||||
|
// })
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// }
|
||||||
|
// for line := range t.Lines{
|
||||||
|
// parseLine(line.Text)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|||||||
@@ -59,3 +59,42 @@ func FileSearchUnix() []string {
|
|||||||
return filesPotential
|
return filesPotential
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns paths with eve chat log files
|
||||||
|
func PathSearch() []string {
|
||||||
|
var pathsWithLogs []string
|
||||||
|
fmt.Println("PathSearch looking for chat log files..")
|
||||||
|
|
||||||
|
searchPath = append(searchPath, "~/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs")
|
||||||
|
|
||||||
|
userName, _ := user.Current()
|
||||||
|
homeDir := userName.HomeDir
|
||||||
|
|
||||||
|
for _, d := range searchPath {
|
||||||
|
|
||||||
|
// if has trailing slash, remove it
|
||||||
|
d = suffixTrim(d, "/")
|
||||||
|
|
||||||
|
// do a unix like expansion if the path starts like `~/`
|
||||||
|
if strings.HasPrefix(d, "~/") {
|
||||||
|
d = filepath.Join(homeDir, d[2:])
|
||||||
|
}
|
||||||
|
f, err := os.Open(d)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
files, err := f.Readdir(-1)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
err = f.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(files) > 0 {
|
||||||
|
pathsWithLogs = append(pathsWithLogs, d)
|
||||||
|
}
|
||||||
|
fmt.Println(len(files))
|
||||||
|
|
||||||
|
}
|
||||||
|
return pathsWithLogs
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ package eve
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// GetActiveChannels will parse a list of files for ones with today's timestamps
|
// GetActiveChannels will parse a list of files for ones with today's timestamps
|
||||||
// This really just returns a list of human-readable channel names so
|
// This really just returns a list of human-readable channel names so
|
||||||
// there will be some eve specific logic to guess the channel name
|
// there will be some eve specific logic to guess the channel name
|
||||||
@@ -35,7 +33,6 @@ func GetActiveChannels(fileList []string) []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for _, file := range candidateFiles {
|
for _, file := range candidateFiles {
|
||||||
fmt.Println(file)
|
fmt.Println(file)
|
||||||
chanList = append(chanList, chatNameFromFile(file))
|
chanList = append(chanList, chatNameFromFile(file))
|
||||||
@@ -46,10 +43,30 @@ func GetActiveChannels(fileList []string) []string {
|
|||||||
return chanList
|
return chanList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsCurrentLog will return True if the logfile has a timestamp that looks like
|
||||||
|
// Today or Yesterdays (there is an assumption that the eve client won't be run for more than 24hrs strait)
|
||||||
|
func IsCurrentLog(file string) bool {
|
||||||
|
timeToday := time.Now()
|
||||||
|
timeYesterday := time.Now().Add(-24 * time.Hour)
|
||||||
|
layout := "20060102"
|
||||||
|
todayString := fmt.Sprintf(timeToday.Format(layout))
|
||||||
|
yesterdayString := fmt.Sprintf(timeYesterday.Format(layout))
|
||||||
|
fileNameSplit := strings.Split(file, "/")
|
||||||
|
fileName := fileNameSplit[len(fileNameSplit)-1] // returns file name without any "/" prefixes
|
||||||
|
|
||||||
|
if strings.Contains(fileName, todayString) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if strings.Contains(fileName, yesterdayString) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func chatNameFromFile(fname string) string {
|
func chatNameFromFile(fname string) string {
|
||||||
a := strings.Split(fname, "/")
|
a := strings.Split(fname, "/")
|
||||||
b := a[len(a)-1] // returns file name without any "/" prefixes
|
b := a[len(a)-1] // returns file name without any "/" prefixes
|
||||||
|
|
||||||
// create a rune of the file name only
|
// create a rune of the file name only
|
||||||
c := []rune(b)
|
c := []rune(b)
|
||||||
@@ -64,7 +81,6 @@ func chatNameFromFile(fname string) string {
|
|||||||
return myShortString
|
return myShortString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: run a uniq pass on the list of channels maybe
|
// TODO: run a uniq pass on the list of channels maybe
|
||||||
//func unique(intSlice []int) []int {
|
//func unique(intSlice []int) []int {
|
||||||
// keys := make(map[int]bool)
|
// keys := make(map[int]bool)
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package eve
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/hpcloud/tail"
|
||||||
|
"github.com/radovskyb/watcher"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Tail(file string) {
|
||||||
|
// https://godoc.org/github.com/hpcloud/tail#Config
|
||||||
|
t, err := tail.TailFile(
|
||||||
|
file,
|
||||||
|
tail.Config{
|
||||||
|
Follow: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
//totalLines := 0
|
||||||
|
//for _ = range t.Lines {
|
||||||
|
// totalLines ++
|
||||||
|
//}
|
||||||
|
|
||||||
|
//currentLine := 0
|
||||||
|
for line := range t.Lines {
|
||||||
|
//fmt.Printf("%v/%v", currentLine, totalLines)
|
||||||
|
//currentLine ++
|
||||||
|
//if currentLine > totalLines {
|
||||||
|
fmt.Printf("##%v##%v##\n", line.Time, line.Text)
|
||||||
|
//}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// sends newly created files for tail'ing
|
||||||
|
// WIP
|
||||||
|
func WatchPath(dir string) {
|
||||||
|
w := watcher.New()
|
||||||
|
|
||||||
|
w.FilterOps()
|
||||||
|
w.FilterOps(watcher.Create, watcher.Remove, watcher.Write)
|
||||||
|
|
||||||
|
//r := regexp.MustCompile("^abc$")
|
||||||
|
//w.AddFilterHook(watcher.RegexFilterHook(r, false))
|
||||||
|
|
||||||
|
// dispatch creation/removal events here
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case event := <-w.Event:
|
||||||
|
// fmt.Println(event)
|
||||||
|
fmt.Printf("%s (%s)\n", event.Path, event.Op)
|
||||||
|
case err := <-w.Error:
|
||||||
|
log.Fatalln(err)
|
||||||
|
case <-w.Closed:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err := w.Add(dir); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for path, f := range w.WatchedFiles() {
|
||||||
|
fmt.Printf("%s: %s\n", path, f.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("=== startup complete ===")
|
||||||
|
|
||||||
|
// go func() {
|
||||||
|
// w.Wait()
|
||||||
|
// w.TriggerEvent(watcher.Create, nil)
|
||||||
|
// }()
|
||||||
|
|
||||||
|
if err := w.Start(time.Millisecond * 100); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user