Skip to content

Commit

Permalink
rebrand: metha
Browse files Browse the repository at this point in the history
  • Loading branch information
miku committed Apr 21, 2016
1 parent e144013 commit e700cfb
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1 +1 @@
/perimorph-*
/metha-*
4 changes: 2 additions & 2 deletions Makefile
@@ -1,7 +1,7 @@
SHELL = /bin/bash
TARGETS = perimorph-cat perimorph-info perimorph-records perimorph-sync
TARGETS = metha-sync

PKGNAME = perimorph
PKGNAME = metha

all: $(TARGETS)

Expand Down
22 changes: 10 additions & 12 deletions README.md
@@ -1,24 +1,22 @@
Perimorph
=========
metha
=====

> A mineral enclosed within another.
Command line OAI-PMH client and incremental harvester.
Command line OAI-PMH incremental harvester.

Usage
-----

```sh
$ perimorph-info http://export.arxiv.org/oai2
$ metha-info http://export.arxiv.org/oai2
{
"identify": ...,
"formats": ...,
"sets": ...
"identify": ...,
"formats": ...,
"sets": ...
}
$ perimorph-sync http://export.arxiv.org/oai2
$ metha-sync http://export.arxiv.org/oai2
...
$ perimorph-cat http://export.arxiv.org/oai2
$ metha-cat http://export.arxiv.org/oai2
...
$ perimorph-records http://export.arxiv.org/oai2
$ metha-records http://export.arxiv.org/oai2
...
```
32 changes: 21 additions & 11 deletions client.go
@@ -1,4 +1,4 @@
package perimorph
package metha

import (
"bytes"
Expand All @@ -20,17 +20,9 @@ const (
DefaultMaxRetries = 8
)

// defaultDoer is a resilient http client with retries and longer timeout.
var defaultDoer = func() Doer {
c := pester.New()
c.Timeout = DefaultTimeout
c.MaxRetries = DefaultMaxRetries
c.Backoff = pester.ExponentialBackoff
return c
}()

var (
DefaultClient = Client{Doer: defaultDoer}
StdClient = Client{Doer: http.DefaultClient}
DefaultClient = Client{Doer: CreateDoer(DefaultTimeout, DefaultMaxRetries)}
// Example for broken XML: http://eprints.vu.edu.au/perl/oai2. Add more
// weird things to be cleaned before XML parsing here. Another faulty:
// http://digitalcommons.gardner-webb.edu/do/oai/?from=2016-02-29&metadataPr
Expand All @@ -49,6 +41,24 @@ var (
"\u001E", "", "\u001F", "")
)

// CreateDoer will return http request clients with specific timeout and retry
// properties.
func CreateDoer(timeout time.Duration, retries int) Doer {
if timeout == 0 && retries == 0 {
return http.DefaultClient
}
c := pester.New()
c.Timeout = timeout
c.MaxRetries = retries
c.Backoff = pester.ExponentialBackoff
return c
}

// Create a client with timeout and retry properties.
func CreateClient(timeout time.Duration, retries int) Client {
return Client{Doer: CreateDoer(timeout, retries)}
}

// Doer is a minimal HTTP interface.
type Doer interface {
Do(*http.Request) (*http.Response, error)
Expand Down
25 changes: 17 additions & 8 deletions cmd/perimorph-sync/main.go → cmd/metha-sync/main.go
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"os"

"github.com/miku/perimorph"
"github.com/miku/metha"
)

func main() {
Expand All @@ -21,15 +21,29 @@ func main() {
flag.Parse()

if *version {
fmt.Println(perimorph.Version)
fmt.Println(metha.Version)
os.Exit(0)
}

if flag.NArg() == 0 {
log.Fatal("endpoint required")
}

harvest, err := perimorph.NewHarvest(perimorph.PrependSchema(flag.Arg(0)))
baseURL := metha.PrependSchema(flag.Arg(0))

if *showDir {
// showDir only needs these parameters
harvest := metha.Harvest{
BaseURL: baseURL,
Format: *format,
Set: *set,
}
fmt.Println(harvest.Dir())
os.Exit(0)
}

// NewHarvest ensures the endpoint is sane, before we start
harvest, err := metha.NewHarvest(baseURL)
if err != nil {
log.Fatal(err)
}
Expand All @@ -41,11 +55,6 @@ func main() {
harvest.DisableSelectiveHarvesting = *disableSelectiveHarvesting
harvest.MaxEmptyResponses = 10

if *showDir {
fmt.Println(harvest.Dir())
os.Exit(0)
}

log.Printf("harvest: %+v", harvest)

if err := harvest.Run(); err != nil {
Expand Down
15 changes: 0 additions & 15 deletions cmd/perimorph-cat/main.go

This file was deleted.

7 changes: 0 additions & 7 deletions cmd/perimorph-info/main.go

This file was deleted.

7 changes: 0 additions & 7 deletions cmd/perimorph-records/main.go

This file was deleted.

2 changes: 1 addition & 1 deletion fileutil.go
@@ -1,4 +1,4 @@
package perimorph
package metha

import "path/filepath"

Expand Down
12 changes: 8 additions & 4 deletions harvest.go
@@ -1,4 +1,4 @@
package perimorph
package metha

import (
"encoding/base64"
Expand All @@ -22,7 +22,7 @@ const Day = 24 * time.Hour

var (
// BaseDir is where all downloaded data is stored
BaseDir = filepath.Join(UserHomeDir(), ".perimorph")
BaseDir = filepath.Join(UserHomeDir(), ".metha")
fnPattern = regexp.MustCompile("(?P<Date>[0-9]{4,4}-[0-9]{2,2}-[0-9]{2,2})-[0-9]{8,}.xml(.gz)?$")
datePattern = regexp.MustCompile("[0-9]{4,4}-[0-9]{2,2}-[0-9]{2,2}")

Expand Down Expand Up @@ -354,7 +354,11 @@ func (h *Harvest) earliestDate() (time.Time, error) {

func (h *Harvest) identify() error {
req := Request{Verb: "Identify", BaseURL: h.BaseURL}
resp, err := Do(&req)

// use a less resilient client for indentify requests
c := CreateClient(1*time.Second, 2)

resp, err := c.Do(&req)
if err != nil {
return err
}
Expand All @@ -363,7 +367,7 @@ func (h *Harvest) identify() error {
}

func init() {
if dir := os.Getenv("PERIMORPH_DIR"); dir != "" {
if dir := os.Getenv("METHA_DIR"); dir != "" {
BaseDir = dir
}
}
2 changes: 1 addition & 1 deletion home.go
@@ -1,4 +1,4 @@
package perimorph
package metha

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion intervals.go
@@ -1,4 +1,4 @@
package perimorph
package metha

import (
"time"
Expand Down
2 changes: 1 addition & 1 deletion laster.go
@@ -1,4 +1,4 @@
package perimorph
package metha

import (
"io/ioutil"
Expand Down
2 changes: 1 addition & 1 deletion logging.go
@@ -1,4 +1,4 @@
package perimorph
package metha

import (
"flag"
Expand Down
2 changes: 1 addition & 1 deletion multierror.go
@@ -1,4 +1,4 @@
package perimorph
package metha

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion request.go
@@ -1,4 +1,4 @@
package perimorph
package metha

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion request_test.go
@@ -1,4 +1,4 @@
package perimorph
package metha

import (
"net/url"
Expand Down
2 changes: 1 addition & 1 deletion response.go
@@ -1,4 +1,4 @@
package perimorph
package metha

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion version.go
@@ -1,3 +1,3 @@
package perimorph
package metha

const Version = "0.1.0"

0 comments on commit e700cfb

Please sign in to comment.