Skip to content

Commit

Permalink
Merge pull request #3 from anitschke/anitschk/initialVersion
Browse files Browse the repository at this point in the history
Initial commit of photo-db-fs
  • Loading branch information
anitschke authored Nov 30, 2022
2 parents 7d70242 + e1fa5db commit 8638fc5
Show file tree
Hide file tree
Showing 67 changed files with 3,247 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
19 changes: 19 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on:
release:
types: [created]

jobs:
release-linux-amd64:
name: release linux/amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: wangyoucao577/go-release-action@v1.33
with:
go-version: 1.19
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: linux
goarch: amd64
extra_files: LICENSE README.md
md5sum: true
sha256sum: true
13 changes: 13 additions & 0 deletions .github/workflows/spellcheck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: spellcheck
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
spellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: streetsidesoftware/cspell-action@v2
14 changes: 12 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,15 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
# Debug binary
__debug_bin

# digikam has a few different databases that get generated when you open
# digikam. At the moment the only one we use is the digikam4.db so we can ignore
# all the other ones.
recognition.db
similarity.db
thumbnails-digikam.db

# sqlite journal file for rolling back db changes
digikam4.db-journal
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# photo-db-fs
[![Release](https://github.com/anitschke/photo-db-fs/actions/workflows/release.yml/badge.svg)](https://github.com/anitschke/photo-db-fs/actions/workflows/release.yml) [![CI](https://github.com/anitschke/photo-db-fs/actions/workflows/ci.yml/badge.svg)](https://github.com/anitschke/photo-db-fs/actions/workflows/ci.yml) ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/anitschke/photo-db-fs) [![Go Report Card](https://goreportcard.com/badge/github.com/anitschke/photo-db-fs)](https://goreportcard.com/report/github.com/anitschke/photo-db-fs)

`photo-db-fs` is a FUSE virtual file system for Linux that exposes a photo database as a file system. At the moment it only supports digiKam but is built to be extensible so as to support other photo management programs in the future.

## Installation
### GitHub Release
Visit the [releases page](https://github.com/anitschke/photo-db-fs/releases) to download one of the prebuilt binaries.

### go install
Build and install from source:
```
go install github.com/anitschke/photo-db-fs@latest
```

## Usage
```
[anitschk@localhost ~]$ photo-db-fs -h
Usage of photo-db-fs:
-db-source string
source of the database photo-db-fs will use for querying, ie for local databases this is the path to the database
-db-type string
type of photo database photo-db-fs will use for querying
-log-level string
debugging logging level
-mount-point string
location where photo-db-fs file system will be mounted
```

example:
```
[anitschk@localhost ~]$ mkdir /tmp/myPhotos
[anitschk@localhost ~]$ photo-db-fs --mount-point /tmp/myPhotos --db-type digikam-sqlite --db-source ~/Pictures/digikam4.db &
[1] 12910
[anitschk@localhost ~]$ ls /tmp/myPhotos/tags/DesktopBackground/photos
009318790e574d9764679ec1b8f0a987.jpg 5c23b47abdb881acee6b1f5313ecbc71.JPG ae1628e3571980c2f8909fff5a8d860c.JPG
01586b0bc31424ab3b156ffdac8ef58f.JPG 5c4918818f3f14575f76c78ad1cf62d6.JPG ae4beaabd272f22fbc04dd57c42d9826.jpg
0338a700e5e602c496abdcad2deaa133.jpg 5da619a984339d0e1bd4b80de91a79cd.jpg ae5cd09cafe0f53a737d6f53d3567314.JPG
[anitschk@localhost ~]$ kill %1
```
24 changes: 24 additions & 0 deletions cspell-words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
anitschk
anitschke
digikam
digiKam
digikamtestresources
Dups
dylib
Embedder
goarch
hanwen
inode
inodes
integrationtests
Lookuper
mattn
photofs
Readdirer
stretchr
Subquery
subselector
testtools
wangyoucao
watersports
zapcore
20 changes: 20 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"version": "0.2",
"dictionaryDefinitions": [
{
"name": "cspell-words",
"path": "./cspell-words.txt",
"addWords": true
}
],
"dictionaries": ["cspell-words"],
"ignorePaths": [
"/go.sum",
"/go.mod",
"**/digikam4.db",
"recognition.db",
"similarity.db",
"thumbnails-digikam.db"
]
}
53 changes: 53 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package db

import (
"context"
"fmt"
"sync"

"github.com/anitschke/photo-db-fs/types"
)

var (
dbFactoryMu sync.RWMutex
dbFactory = make(map[string]DBConstructor)
)

type DBConstructor func(dbSource string) (DB, error)

// DB is an interface for interacting with a photo database to query information
// about photos within the database.
type DB interface {
Photos(ctx context.Context, q types.Query) ([]types.Photo, error)
RootTags(ctx context.Context) ([]types.Tag, error)
ChildrenTags(ctx context.Context, parent types.Tag) ([]types.Tag, error)
Close() error
}

// Register handles registration of a new DB type.
//
// We handle registration of new DB types similar to how SQL database drivers
// are registered. We expect that all DB types Register by calling Register with
// the init() function of their package. Then They should import their package
// into db/register. This way importing the db/register package into main will
// import all DB types
func Register(name string, dbCtor DBConstructor) {
dbFactoryMu.Lock()
defer dbFactoryMu.Unlock()
if dbCtor == nil {
panic("nil dbCtor")
}
if _, dup := dbFactory[name]; dup {
panic("duplicate database type: " + name)
}
dbFactory[name] = dbCtor
}

func New(name string, dbSource string) (DB, error) {
ctor, ok := dbFactory[name]
if !ok {
return nil, fmt.Errorf("dbCtor with name %q does not exist", name)
}

return ctor(dbSource)
}
Loading

0 comments on commit 8638fc5

Please # to comment.