aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2023-08-13 10:25:53 -0400
committerXe Iaso <me@xeiaso.net>2023-08-13 10:25:53 -0400
commit07cd5a82210a34ed71ca40057d4bf68cd2d70459 (patch)
tree6f4de93386040264d7acf4daff28a2d19fc655d2
parentf940520e74d2ac589f231d3386346534035effd3 (diff)
downloadx-07cd5a82210a34ed71ca40057d4bf68cd2d70459.tar.xz
x-07cd5a82210a34ed71ca40057d4bf68cd2d70459.zip
cmd/sanguisuga: fix lock hang
Signed-off-by: Xe Iaso <me@xeiaso.net>
-rw-r--r--cmd/sanguisuga/main.go5
-rw-r--r--cmd/x/main.go22
-rw-r--r--cmd/x/sanguisuga.go60
-rw-r--r--go.mod2
-rw-r--r--go.sum10
-rw-r--r--gomod2nix.toml6
6 files changed, 103 insertions, 2 deletions
diff --git a/cmd/sanguisuga/main.go b/cmd/sanguisuga/main.go
index 1f6a630..88d0906 100644
--- a/cmd/sanguisuga/main.go
+++ b/cmd/sanguisuga/main.go
@@ -290,9 +290,10 @@ func (s *Sanguisuga) HandleIRCMessage(ev *irc.Event) {
stateKey := fmt.Sprintf("%s %s", ti.Title, id)
+ s.dbLock.Lock()
+ defer s.dbLock.Unlock()
+
for _, show := range s.Config.Shows {
- s.dbLock.Lock()
- defer s.dbLock.Unlock()
if s.db.Data == nil {
s.db.Data = &State{
Seen: map[string]TorrentAnnouncement{},
diff --git a/cmd/x/main.go b/cmd/x/main.go
new file mode 100644
index 0000000..706cd9c
--- /dev/null
+++ b/cmd/x/main.go
@@ -0,0 +1,22 @@
+package main
+
+import (
+ "context"
+ "os"
+
+ "github.com/google/subcommands"
+ "within.website/x/internal"
+)
+
+func main() {
+ subcommands.Register(subcommands.HelpCommand(), "")
+ subcommands.Register(subcommands.FlagsCommand(), "")
+ subcommands.Register(subcommands.CommandsCommand(), "")
+
+ subcommands.Register(&sanguisugaAnimeList{}, "sanguisuga")
+
+ internal.HandleStartup()
+ ctx := context.Background()
+
+ os.Exit(int(subcommands.Execute(ctx)))
+}
diff --git a/cmd/x/sanguisuga.go b/cmd/x/sanguisuga.go
new file mode 100644
index 0000000..667412c
--- /dev/null
+++ b/cmd/x/sanguisuga.go
@@ -0,0 +1,60 @@
+package main
+
+import (
+ "context"
+ "encoding/json"
+ "flag"
+ "fmt"
+ "log"
+ "net/http"
+
+ "github.com/google/subcommands"
+ "github.com/rodaine/table"
+)
+
+var (
+ sanguisugaURL = flag.String("url", "http://sanguisuga", "Base sanguisuga URL")
+)
+
+type Show struct {
+ Title string `json:"title"`
+ DiskPath string `json:"diskPath"`
+ Quality string `json:"quality"`
+}
+
+type sanguisugaAnimeList struct {
+ URL string
+}
+
+func (*sanguisugaAnimeList) Name() string { return "anime-list" }
+func (*sanguisugaAnimeList) Synopsis() string { return "Print list of anime tracked by sanguisuga." }
+func (*sanguisugaAnimeList) Usage() string {
+ return `anime-list [--url]:
+ Print list of anime tracked by sanguisuga.`
+}
+
+func (sal *sanguisugaAnimeList) SetFlags(f *flag.FlagSet) {}
+
+func (sal *sanguisugaAnimeList) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
+ resp, err := http.Get(fmt.Sprintf("%s/api/anime/list", *sanguisugaURL))
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ var shows []Show
+
+ defer resp.Body.Close()
+ if err := json.NewDecoder(resp.Body).Decode(&shows); err != nil {
+ log.Fatal(err)
+ }
+
+ tbl := table.New("Name", "Disk Path", "Quality")
+
+ for _, show := range shows {
+ tbl.AddRow(show.Title, show.DiskPath, show.Quality)
+ }
+
+ tbl.Print()
+
+ return subcommands.ExitSuccess
+}
diff --git a/go.mod b/go.mod
index 0f08c35..285865a 100644
--- a/go.mod
+++ b/go.mod
@@ -62,12 +62,14 @@ require (
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f // indirect
github.com/google/nftables v0.1.1-0.20230115205135-9aa6fdf5a28c // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
+ github.com/google/subcommands v1.2.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/miekg/dns v1.1.55 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
+ github.com/rodaine/table v1.1.0 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.48.0 // indirect
diff --git a/go.sum b/go.sum
index 1afcd59..cc5496c 100644
--- a/go.sum
+++ b/go.sum
@@ -210,6 +210,7 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
+github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
@@ -325,6 +326,8 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 h1:4/hN5RUoecvl+RmJRE2YxKWtnnQls6rQjjW5oV7qg2U=
github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
+github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
+github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
@@ -380,15 +383,18 @@ github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwA
github.com/josharian/native v1.0.1-0.20221213033349-c1e37c09b531/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 h1:elKwZS1OcdQ0WwEDBeqxKwb7WB62QX8bvZ/FJnVXIfk=
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86/go.mod h1:aFAMtuldEgx/4q7iSGazk22+IcgvtiC+HIimFO9XlS8=
+github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/jsimonetti/rtnetlink v1.3.2 h1:dcn0uWkfxycEEyNy0IGfx3GrhQ38LH7odjxAghimsVI=
github.com/jsimonetti/rtnetlink v1.3.2/go.mod h1:BBu4jZCpTjP6Gk0/wfrO8qcqymnN3g0hoFqObRmUo6U=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
+github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
+github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
@@ -444,7 +450,9 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
+github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
+github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mymmrac/telego v0.26.0 h1:m4B3SW9dxL4uHpyjBnmhQeiFO7GWCxFjsUKUvFx3mf0=
github.com/mymmrac/telego v0.26.0/go.mod h1:kizipjY3MhxmkcGvyz8jiw/26vEKAhR2V7YTE69iqvw=
github.com/oklog/ulid/v2 v2.1.0 h1:+9lhoxAP56we25tyYETBBY1YLA2SaoLvUFgrP2miPJU=
@@ -498,6 +506,8 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qq
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
+github.com/rodaine/table v1.1.0 h1:/fUlCSdjamMY8VifdQRIu3VWZXYLY7QHFkVorS8NTr4=
+github.com/rodaine/table v1.1.0/go.mod h1:Qu3q5wi1jTQD6B6HsP6szie/S4w1QUQ8pq22pz9iL8g=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
diff --git a/gomod2nix.toml b/gomod2nix.toml
index 43673b3..ba8107d 100644
--- a/gomod2nix.toml
+++ b/gomod2nix.toml
@@ -175,6 +175,9 @@ schema = 3
[mod."github.com/google/pprof"]
version = "v0.0.0-20230207041349-798e818bf904"
hash = "sha256-uBlQacjKVBHhsxJBudNqtpey0XS9kLG0A53KDI3p77w="
+ [mod."github.com/google/subcommands"]
+ version = "v1.2.0"
+ hash = "sha256-HEKRAxZsIzBN8dB2g4xDbwhAVjjvbh3HLd8kI1J3hwM="
[mod."github.com/google/uuid"]
version = "v1.3.0"
hash = "sha256-QoR55eBtA94T2tBszyxfDtO7/pjZZSGb5vm7U0Xhs0Y="
@@ -319,6 +322,9 @@ schema = 3
[mod."github.com/rivo/uniseg"]
version = "v0.4.4"
hash = "sha256-B8tbL9K6ICLdm0lEhs9+h4cpjAfvFtNiFMGvQZmw0bM="
+ [mod."github.com/rodaine/table"]
+ version = "v1.1.0"
+ hash = "sha256-Vy12XP5XF7g/fsWGvOIyShUaQ+p9H+NYbzhtUewRMzU="
[mod."github.com/rogpeppe/go-internal"]
version = "v1.11.0"
hash = "sha256-BucSndJVnqX9e6p5PfA6Z8N2bGfIeRfxAxYLUDXTbIo="