PiwigoDirectoryUploader/internal/app/app.go

80 lines
2.5 KiB
Go
Raw Normal View History

/*
* Copyright (C) 2019 Philipp Haefelfinger (http://www.haefelfinger.ch/). All Rights Reserved.
* This application is licensed under GPLv2. See the LICENSE file in the root directory of the project.
*/
2019-02-23 21:57:54 +01:00
package app
import (
2019-02-24 23:11:52 +01:00
"flag"
2019-03-02 00:21:01 +01:00
"github.com/sirupsen/logrus"
"os"
2019-02-23 21:57:54 +01:00
)
2019-02-24 23:11:52 +01:00
var (
2019-03-21 22:31:16 +01:00
imagesRootPath = flag.String("imagesRootPath", "", "This is the images root path that should be mirrored to piwigo.")
sqliteDb = flag.String("sqliteDb", "./localstate.db", "The connection string to the sql lite database file.")
noUpload = flag.Bool("noUpload", false, "If set to true, the metadata gets prepared but the upload is not called and the application is exited with code 90")
piwigoUrl = flag.String("piwigoUrl", "", "The root url without tailing slash to your piwigo installation.")
piwigoUser = flag.String("piwigoUser", "", "The username to use during sync.")
piwigoPassword = flag.String("piwigoPassword", "", "This is password to the given username.")
2019-03-24 23:58:35 +01:00
removeImages = flag.Bool("removeImages", false, "If set to true, images scheduled to delete will be removed from the piwigo server. Be sure you want to delete images before enabling this flag.")
2019-02-24 23:11:52 +01:00
)
func Run() {
context, err := newAppContext()
if err != nil {
2019-02-25 23:51:18 +01:00
logErrorAndExit(err, 1)
}
err = context.piwigo.Login()
2019-02-24 23:32:05 +01:00
if err != nil {
2019-02-25 23:51:18 +01:00
logErrorAndExit(err, 2)
2019-02-24 23:32:05 +01:00
}
//filesystemNodes, err := localFileStructure.ScanLocalFileStructure(context.localRootPath)
//if err != nil {
// logErrorAndExit(err, 3)
//}
//err = category.SynchronizeCategories(filesystemNodes, context.piwigo, context.dataStore)
//if err != nil {
// logErrorAndExit(err, 4)
//}
//
//err = images.SynchronizeLocalImageMetadata(context.dataStore, filesystemNodes, categories, localFileStructure.CalculateFileCheckSums)
//if err != nil {
// logErrorAndExit(err, 5)
//}
//
//err = images.SynchronizePiwigoMetadata(context.piwigo, context.dataStore)
//if err != nil {
// logErrorAndExit(err, 6)
//}
//
//if *removeImages {
// err = images.DeleteImages(context.piwigo, context.dataStore)
// if err != nil {
// logErrorAndExit(err, 7)
// }
//} else {
// logrus.Info("The flag removeImages is disabled. Skipping...")
//}
//
//if !(*noUpload) {
// err = images.UploadImages(context.piwigo, context.dataStore)
// if err != nil {
// logErrorAndExit(err, 8)
// }
//} else {
// logrus.Warnln("Skipping upload of images as flag noUpload is set to true!")
//}
_ = context.piwigo.Logout()
}
2019-02-25 23:51:18 +01:00
func logErrorAndExit(err error, exitCode int) {
logrus.Errorln(err)
os.Exit(exitCode)
}