mirror of
https://github.com/vbatts/sl-feeds.git
synced 2024-11-28 18:35:40 +00:00
*: it works and is mostly ready
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
871ba61aa1
commit
25fc064194
2 changed files with 78 additions and 5 deletions
|
@ -3,9 +3,13 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
_ "../../fetch"
|
"../../changelog"
|
||||||
|
"../../fetch"
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
@ -58,19 +62,84 @@ func main() {
|
||||||
"slackwarearm-current",
|
"slackwarearm-current",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Mirror{
|
||||||
|
URL: "http://alphageek.noip.me/mirrors/alphageek/",
|
||||||
|
Prefix: "alphageek-",
|
||||||
|
Releases: []string{
|
||||||
|
"slackware64-14.2",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
toml.NewEncoder(os.Stdout).Encode(c)
|
toml.NewEncoder(os.Stdout).Encode(c)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(os.ExpandEnv(config.Dest))
|
dest := os.ExpandEnv(config.Dest)
|
||||||
|
fmt.Printf("Writing to: %q\n", dest)
|
||||||
/*
|
/*
|
||||||
for each mirror in Mirrors
|
for each mirror in Mirrors
|
||||||
if there is not a $release.RSS file, then fetch the whole ChangeLog
|
if there is not a $release.RSS file, then fetch the whole ChangeLog
|
||||||
if there is a $release.RSS file, then stat the file and only fetch remote if it is newer than the local RSS file
|
if there is a $release.RSS file, then stat the file and only fetch remote if it is newer than the local RSS file
|
||||||
if the remote returns any error (404, 503, etc) then print a warning but continue
|
if the remote returns any error (404, 503, etc) then print a warning but continue
|
||||||
*/
|
*/
|
||||||
|
for _, mirror := range config.Mirrors {
|
||||||
|
for _, release := range mirror.Releases {
|
||||||
|
repo := fetch.Repo{
|
||||||
|
URL: mirror.URL,
|
||||||
|
Release: release,
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("processing %q", repo.URL+"/"+repo.Release)
|
||||||
|
|
||||||
|
stat, err := os.Stat(filepath.Join(dest, mirror.Prefix+release+".rss"))
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
log.Println(release, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var (
|
||||||
|
entries []changelog.Entry
|
||||||
|
mtime time.Time
|
||||||
|
)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
entries, mtime, err = repo.ChangeLog()
|
||||||
|
if err != nil {
|
||||||
|
log.Println(release, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// compare times
|
||||||
|
entries, mtime, err = repo.NewerChangeLog(stat.ModTime())
|
||||||
|
if err != nil {
|
||||||
|
log.Println(release, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// write out the rss and chtime it to be mtime
|
||||||
|
feeds, err := changelog.ToFeed(repo.URL+"/"+release, entries)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(release, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fh, err := os.Create(filepath.Join(dest, mirror.Prefix+release+".rss"))
|
||||||
|
if err != nil {
|
||||||
|
log.Println(release, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := feeds.WriteRss(fh); err != nil {
|
||||||
|
log.Println(release, err)
|
||||||
|
fh.Close()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fh.Close()
|
||||||
|
err = os.Chtimes(filepath.Join(dest, mirror.Prefix+release+".rss"), mtime, mtime)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(release, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,4 +172,5 @@ type Config struct {
|
||||||
type Mirror struct {
|
type Mirror struct {
|
||||||
URL string
|
URL string
|
||||||
Releases []string
|
Releases []string
|
||||||
|
Prefix string
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,15 +11,18 @@ import (
|
||||||
// Repo represents a remote slackware software repo
|
// Repo represents a remote slackware software repo
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
URL string
|
URL string
|
||||||
|
Release string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Repo) head(file string) (*http.Response, error) {
|
func (r Repo) head(file string) (*http.Response, error) {
|
||||||
return http.Head(r.URL + "/" + file)
|
return http.Head(r.URL + "/" + r.Release + "/" + file)
|
||||||
}
|
}
|
||||||
func (r Repo) get(file string) (*http.Response, error) {
|
func (r Repo) get(file string) (*http.Response, error) {
|
||||||
return http.Get(r.URL + "/" + file)
|
return http.Get(r.URL + "/" + r.Release + "/" + file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewerChangeLog checks the last-modified time of the remote ChangeLog.txt and
|
||||||
|
// only fetches it if the remote is newer than the provided time.
|
||||||
func (r Repo) NewerChangeLog(than time.Time) (e []changelog.Entry, mtime time.Time, err error) {
|
func (r Repo) NewerChangeLog(than time.Time) (e []changelog.Entry, mtime time.Time, err error) {
|
||||||
resp, err := r.head("ChangeLog.txt")
|
resp, err := r.head("ChangeLog.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue