moved state.go to diff/state package

master
Oliver Tonnhofer 2013-07-19 09:35:21 +02:00
parent 4a0abacbc5
commit c6bad82131
4 changed files with 20 additions and 16 deletions

View File

@ -6,10 +6,13 @@ import (
"goposm/diff/parser"
"goposm/element"
"goposm/expire"
"goposm/logging"
"goposm/mapping"
"goposm/proj"
)
var log = logging.NewLogger("diff")
type Deleter struct {
delDb database.Deleter
osmCache *cache.OSMCache

View File

@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"goposm/diff/state"
"io"
"io/ioutil"
"net/http"
@ -63,7 +64,7 @@ func (d *diffDownload) downloadDiff(sequence int32) error {
return nil
}
func (d *diffDownload) currentState() (*DiffState, error) {
func (d *diffDownload) currentState() (*state.DiffState, error) {
resp, err := http.Get(d.url + "state.txt")
if err != nil {
return nil, err
@ -72,10 +73,10 @@ func (d *diffDownload) currentState() (*DiffState, error) {
return nil, errors.New(fmt.Sprintf("invalid repsonse: %v", resp))
}
defer resp.Body.Close()
return parseState(resp.Body)
return state.Parse(resp.Body)
}
func (d *diffDownload) downloadState(sequence int32) (*DiffState, error) {
func (d *diffDownload) downloadState(sequence int32) (*state.DiffState, error) {
dest := path.Join(d.dest, diffPath(sequence))
err := os.MkdirAll(path.Dir(dest), 0755)
if err != nil {
@ -104,7 +105,7 @@ func (d *diffDownload) downloadState(sequence int32) (*DiffState, error) {
}
reader := bytes.NewReader(buf.Bytes())
return parseState(reader)
return state.Parse(reader)
}
// func missingDiffs(since time.Time, source *diffDownload) ([]int, error) {

View File

@ -1,4 +1,4 @@
package diff
package state
import (
"bufio"
@ -54,7 +54,7 @@ func WriteLastState(cacheDir string, state *DiffState) error {
return state.WriteToFile(stateFile)
}
func ParseStateFromOsc(oscFile string) (*DiffState, error) {
func ParseFromOsc(oscFile string) (*DiffState, error) {
var stateFile string
if !strings.HasSuffix(oscFile, ".osc.gz") {
log.Warn("cannot read state file for non .osc.gz files")
@ -72,10 +72,10 @@ func ParseStateFromOsc(oscFile string) (*DiffState, error) {
return nil, err
}
defer f.Close()
return parseStateFile(stateFile)
return ParseFile(stateFile)
}
func StateFromPbf(pbfFile *pbf.Pbf) *DiffState {
func FromPbf(pbfFile *pbf.Pbf) *DiffState {
var timestamp time.Time
if pbfFile.Header.Time.Unix() != 0 {
timestamp = pbfFile.Header.Time
@ -90,16 +90,16 @@ func StateFromPbf(pbfFile *pbf.Pbf) *DiffState {
return &DiffState{Time: timestamp}
}
func parseStateFile(stateFile string) (*DiffState, error) {
func ParseFile(stateFile string) (*DiffState, error) {
f, err := os.Open(stateFile)
if err != nil {
return nil, err
}
defer f.Close()
return parseState(f)
return Parse(f)
}
func parseState(f io.Reader) (*DiffState, error) {
func Parse(f io.Reader) (*DiffState, error) {
values, err := parseSimpleIni(f)
if err != nil {
return nil, err
@ -123,7 +123,7 @@ func ParseLastState(cacheDir string) (*DiffState, error) {
log.Warn("cannot find state file ", stateFile)
return nil, nil
}
return parseStateFile(stateFile)
return ParseFile(stateFile)
}
func parseSimpleIni(f io.Reader) (map[string]string, error) {

View File

@ -6,7 +6,7 @@ import (
"goposm/config"
"goposm/database"
_ "goposm/database/postgis"
diffstate "goposm/diff"
state "goposm/diff/state"
"goposm/geom/clipper"
"goposm/logging"
"goposm/mapping"
@ -180,9 +180,9 @@ func main() {
osmCache.Close()
log.StopStep(step)
if *diff {
state := diffstate.StateFromPbf(pbfFile)
if state != nil {
state.WriteToFile(path.Join(conf.CacheDir, "last.state.txt"))
diffstate := state.FromPbf(pbfFile)
if diffstate != nil {
diffstate.WriteToFile(path.Join(conf.CacheDir, "last.state.txt"))
}
}
}