Skip to content

Commit

Permalink
Use embedded tzdata package
Browse files Browse the repository at this point in the history
Remove --timezone flag
  • Loading branch information
crazy-max committed Nov 2, 2020
1 parent 094b758 commit cf443a1
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
-
name: GitHub Release
uses: softprops/action-gh-release@v1
if: success() && startsWith(github.ref, 'refs/tags/')
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
files: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
pages_threshold: major_outage
-
name: Deploy
if: success() && github.event_name != 'pull_request' && (endsWith(github.ref, github.event.repository.default_branch) || steps.prepare.outputs.release == 'true')
if: github.event_name != 'pull_request' && (endsWith(github.ref, github.event.repository.default_branch) || steps.prepare.outputs.release == 'true')
uses: crazy-max/ghaction-github-pages@v2.1.3
with:
target_branch: gh-pages
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: test
on:
push:
branches:
- 'master'
- 'v*'
- '**'
paths-ignore:
- '**.md'
pull_request:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 7.1.1 (2020/11/02)

* Use embedded tzdata package
* Remove `--timezone` flag
* Docker image also available on [GitHub Container Registry](https://github.com/users/crazy-max/packages/container/package/ftpgrab)
* Use Docker meta action to handle tags and labels

## 7.1.0 (2020/10/04)

* Allow to disable `OPTS UTF8 ON` command
Expand Down
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ LABEL maintainer="CrazyMax"
RUN apk --update --no-cache add \
ca-certificates \
libressl \
tzdata \
&& rm -rf /tmp/* /var/cache/apk/*

COPY --from=builder /app/ftpgrab /usr/local/bin/ftpgrab
COPY --from=builder /usr/local/go/lib/time/zoneinfo.zip /usr/local/go/lib/time/zoneinfo.zip
RUN ftpgrab --version

ENV FTPGRAB_DB_PATH="/db/ftpgrab.db" \
Expand Down
12 changes: 3 additions & 9 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"runtime"
"strings"
"syscall"
"time"
_ "time/tzdata"

"github.com/alecthomas/kong"
"github.com/crazy-max/ftpgrab/v7/internal/app"
Expand Down Expand Up @@ -53,14 +53,8 @@ func main() {
Summary: true,
}))

// Load timezone location
location, err := time.LoadLocation(cli.Timezone)
if err != nil {
log.Panic().Err(err).Msgf("Cannot load timezone %s", cli.Timezone)
}

// Init
logging.Configure(cli, location)
logging.Configure(cli)
log.Info().Str("version", version).Msgf("Starting %s", meta.Name)

// Handle os signals
Expand All @@ -81,7 +75,7 @@ func main() {
log.Debug().Msg(cfg.String())

// Init
if ftpgrab, err = app.New(cfg, location); err != nil {
if ftpgrab, err = app.New(cfg); err != nil {
log.Fatal().Err(err).Msgf("Cannot initialize %s", meta.Name)
}

Expand Down
73 changes: 19 additions & 54 deletions docs/faq.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# FAQ

## How to grab from multiple sources?
## Timezone

You can add multiple sources in the `sources` field of the configuration file:
By default, all interpretation and scheduling is done with your local timezone (`TZ` environment variable).

```yaml
ftp|sftp:
...
sources:
- /path1
- /path2/folder
Cron schedule may also override the timezone to be interpreted in by providing an additional space-separated field
at the beginning of the cron spec, of the form `CRON_TZ=<timezone>`:

```shell
$ ftpgrab --schedule "CRON_TZ=Asia/Tokyo */30 * * * *"
```

## What kind of CRON expression can I use for scheduling?
Expand All @@ -21,59 +20,25 @@ A CRON expression represents a set of times, using 6 space-separated fields.

More examples can be found on the [official library documentation](https://godoc.org/github.com/robfig/cron#hdr-CRON_Expression_Format).

## How to grab from multiple sources?

You can add multiple sources in the `sources` field of the configuration file:

```yaml
ftp|sftp:
...
sources:
- /path1
- /path2/folder
```

## What Regexp semantic is used to filter inclusions/exclusions?

FTPGrab uses [Compile](https://golang.org/pkg/regexp/#Compile) to parse regular expressions. This means the regexp
returns a match that begins as early as possible in the input (leftmost) like Perl, Python, and other implementations
use. You can test your regular expression on [regex101.com](https://regex101.com/) and select Golang
flavor. Check this [quick example](https://regex101.com/r/jITi0D/1).

## What logs look like?

Here is a sample output:

```text
Tue, 29 Jan 2019 22:23:58 CET INF Starting FTPGrab 5.0.0
Tue, 29 Jan 2019 22:23:58 CET INF ########
Tue, 29 Jan 2019 22:23:58 CET INF Connecting to 198.51.100.0:21...
Tue, 29 Jan 2019 22:23:58 CET INF Grabbing from /complete/
Tue, 29 Jan 2019 22:23:59 CET INF --------
Tue, 29 Jan 2019 22:23:59 CET INF Checking /complete/Burn.Notice.S06E16.VOSTFR.HDTV.XviD.avi
Tue, 29 Jan 2019 22:23:59 CET INF Never downloaded
Tue, 29 Jan 2019 22:23:59 CET INF Downloading file (184.18MB) to /tmp/seedbox/Burn.Notice.S06E16.VOSTFR.HDTV.XviD.avi...
Tue, 29 Jan 2019 22:24:47 CET INF File successfully downloaded!
Tue, 29 Jan 2019 22:24:47 CET INF Time spent: 48 seconds
Tue, 29 Jan 2019 22:24:47 CET INF --------
Tue, 29 Jan 2019 22:24:47 CET INF Checking /complete/Burn.Notice.S06E17.VOSTFR.HDTV.XviD.avi
Tue, 29 Jan 2019 22:24:47 CET INF Never downloaded
Tue, 29 Jan 2019 22:24:47 CET INF Downloading file (186.27MB) to /tmp/seedbox/Burn.Notice.S06E17.VOSTFR.HDTV.XviD.avi...
Tue, 29 Jan 2019 22:25:40 CET INF File successfully downloaded!
Tue, 29 Jan 2019 22:25:40 CET INF Time spent: 50 seconds
Tue, 29 Jan 2019 22:25:40 CET INF --------
Tue, 29 Jan 2019 22:25:40 CET INF Checking /complete/test_special_chars/123.bin
Tue, 29 Jan 2019 22:25:40 CET INF Never downloaded
Tue, 29 Jan 2019 22:25:40 CET INF Downloading file (33.27kB) to /tmp/seedbox/test/test_special_chars/123.bin...
Tue, 29 Jan 2019 22:25:42 CET ERR Error downloading, retry 1/3 error="dial tcp 198.51.100.0:21: connect: connection refused"
Tue, 29 Jan 2019 22:25:42 CET INF --------
Tue, 29 Jan 2019 22:25:42 CET INF Checking /complete/test_special_chars/123.bin
Tue, 29 Jan 2019 22:25:42 CET INF Exists but size is different
Tue, 29 Jan 2019 22:25:42 CET INF Downloading file (33.27kB) to /tmp/seedbox/test/test_special_chars/123.bin...
Tue, 29 Jan 2019 22:25:44 CET ERR Error downloading, retry 2/3 error="dial tcp 198.51.100.0:21: connect: connection refused"
Tue, 29 Jan 2019 22:25:44 CET INF --------
Tue, 29 Jan 2019 22:25:44 CET INF Checking /complete/test_special_chars/123.bin
Tue, 29 Jan 2019 22:25:44 CET INF Exists but size is different
Tue, 29 Jan 2019 22:25:44 CET INF Downloading file (33.27kB) to /tmp/seedbox/test/test_special_chars/123.bin...
Tue, 29 Jan 2019 22:25:46 CET ERR Error downloading, retry 3/3 error="dial tcp 198.51.100.0:21: connect: connection refused"
Tue, 29 Jan 2019 22:25:46 CET ERR Cannot download file error="dial tcp 198.51.100.0:21: connect: connection refused"
Tue, 29 Jan 2019 22:25:46 CET INF Time spent: 6 seconds
Tue, 29 Jan 2019 22:25:46 CET INF --------
Tue, 29 Jan 2019 22:25:46 CET INF Checking /complete/exlcuded_file.txt
Tue, 29 Jan 2019 22:25:46 CET INF Not included
Tue, 29 Jan 2019 22:25:46 CET WRN Skipped: Not included
Tue, 29 Jan 2019 22:25:46 CET INF ########
Tue, 29 Jan 2019 22:25:51 CET INF Finished, total time spent: 1 minute 56 seconds
```

## How can I edit/remove some entries in the database?

FTPGrab currently uses the embedded key/value database [bbolt](https://github.com/etcd-io/bbolt).
Expand Down
1 change: 0 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ periodically to your Synology, Qnap, D-Link and others NAS.
* Webhook notification
* Slack incoming webhook notification
* Enhanced logging
* Timezone can be changed

## License

Expand Down
1 change: 1 addition & 0 deletions docs/install/linux-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ User=ftpgrab
Group=ftpgrab
ExecStart=/usr/local/bin/ftpgrab --config /etc/ftpgrab/ftpgrab.yml --schedule "*/30 * * * *" --log-level info
Restart=always
#Environment=TZ=Europe/Paris
Environment=FTPGRAB_DB=/var/lib/ftpgrab/ftpgrab.db
[Install]
Expand Down
2 changes: 0 additions & 2 deletions docs/usage/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Flags:
--version
--config=STRING FTPGrab configuration file ($CONFIG).
--schedule=STRING CRON expression format ($SCHEDULE).
--timezone="UTC" Timezone assigned to FTPGrab ($TZ).
--log-level="info" Set log level ($LOG_LEVEL).
--log-json Enable JSON logging output ($LOG_JSON).
--log-file=STRING Add logging to a specific file ($LOG_FILE).
Expand All @@ -34,7 +33,6 @@ Following environment variables can be used in place:
|--------------------|---------------|---------------|
| `CONFIG` | | FTPGrab configuration file |
| `SCHEDULE` | | [CRON expression](https://godoc.org/github.com/robfig/cron#hdr-CRON_Expression_Format) to schedule FTPGrab |
| `TZ` | `UTC` | Timezone assigned |
| `LOG_LEVEL` | `info` | Log level output |
| `LOG_JSON` | `false` | Enable JSON logging output |
| `LOG_FILE` | | Add logging to a specific file |
6 changes: 3 additions & 3 deletions internal/app/ftpgrab.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ type FtpGrab struct {
}

// New creates new ftpgrab instance
func New(cfg *config.Config, location *time.Location) (*FtpGrab, error) {
func New(cfg *config.Config) (*FtpGrab, error) {
return &FtpGrab{
cfg: cfg,
cron: cron.New(cron.WithLocation(location), cron.WithParser(cron.NewParser(
cron.SecondOptional|cron.Minute|cron.Hour|cron.Dom|cron.Month|cron.Dow|cron.Descriptor),
cron: cron.New(cron.WithParser(cron.NewParser(
cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor),
)),
}, nil
}
Expand Down
1 change: 0 additions & 1 deletion internal/config/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ type Cli struct {
Version kong.VersionFlag
Cfgfile string `kong:"name='config',env='CONFIG',help='FTPGrab configuration file.'"`
Schedule string `kong:"name='schedule',env='SCHEDULE',help='CRON expression format.'"`
Timezone string `kong:"name='timezone',env='TZ',default='UTC',help='Timezone assigned to FTPGrab.'"`
LogLevel string `kong:"name='log-level',env='LOG_LEVEL',default='info',help='Set log level.'"`
LogJSON bool `kong:"name='log-json',env='LOG_JSON',default='false',help='Enable JSON logging output.'"`
LogFile string `kong:"name='log-file',env='LOG_FILE',help='Add logging to a specific file.'"`
Expand Down
6 changes: 1 addition & 5 deletions internal/logging/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ import (
)

// Configure configures logger
func Configure(cli config.Cli, location *time.Location) {
func Configure(cli config.Cli) {
var err error
var w io.Writer

zerolog.TimestampFunc = func() time.Time {
return time.Now().In(location)
}

if !cli.LogJSON {
w = zerolog.ConsoleWriter{
Out: os.Stdout,
Expand Down

0 comments on commit cf443a1

Please sign in to comment.