Skip to content

Commit

Permalink
new version 0.0.5:
Browse files Browse the repository at this point in the history
* fix api for piwigo 2.7 (image uploaded without creation date)
* implement legacy piwigo_import_tree mecanism (but md5hex is different)
* user configuration management: load/save/valid in ui and file
* some minor refactoring
  • Loading branch information
mhelleboid committed May 7, 2015
1 parent ffd9a31 commit 5884c60
Show file tree
Hide file tree
Showing 38 changed files with 1,016 additions and 311 deletions.
2 changes: 1 addition & 1 deletion remotesync-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
<parent>
<groupId>piwigo</groupId>
<artifactId>remotesync</artifactId>
<version>0.0.4-SNAPSHOT</version>
<version>0.0.5</version>
<relativePath>../remotesync</relativePath>
</parent>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.kohsuke.args4j.Option;
import org.kohsuke.args4j.OptionHandlerFilter;
import org.piwigo.remotesync.api.conf.Config;
import org.piwigo.remotesync.api.conf.ConfigUtil;
import org.piwigo.remotesync.api.conf.GalleryConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -25,20 +27,23 @@ public abstract class AbstractMain {
private static final Logger logger = LoggerFactory.getLogger(AbstractMain.class);

protected void run(String[] args) {
Config config = new Config();
CmdLineParser cmdLineParser = createParser(config);
GalleryConfig parsedGalleryConfig = new GalleryConfig();
CmdLineParser cmdLineParser = createParser(parsedGalleryConfig);

try {
cmdLineParser.parseArgument(args);

configureLog(debug);

createConfig(parsedGalleryConfig);

if (help) {
System.out.println("Piwigo Remote Sync : java -jar remotesync.jar");
cmdLineParser.printUsage(System.out);
return;
}

start(config);
start();
} catch (CmdLineException e) {
System.err.println(e.getMessage());
System.err.println("Piwigo Remote Sync : java -jar remotesync.jar");
Expand All @@ -48,22 +53,29 @@ protected void run(String[] args) {
}
}

protected abstract void start(Config config);
protected abstract void start();

@Option(name = "-debug", usage = "enable debug messages")
protected boolean debug = false;

@Option(name = "-help", usage = "help")
protected boolean help = false;

protected CmdLineParser createParser(Config config) {
protected CmdLineParser createParser(GalleryConfig galleryConfig) {
CmdLineParser cmdLineParser = new CmdLineParser(null);
new ClassParser().parse(this, cmdLineParser);
new ClassParser().parse(config, cmdLineParser);
new ClassParser().parse(config.getCurrentGalleryConfig(), cmdLineParser);
new ClassParser().parse(galleryConfig, cmdLineParser);
return cmdLineParser;
}

protected void createConfig(GalleryConfig parsedGalleryConfig) {
Config config = ConfigUtil.INSTANCE.getUserConfig();

//if some gallery configuration was provided through parameters
if (!parsedGalleryConfig.isEmpty())
config.setCurrentGalleryConfig(parsedGalleryConfig);
}

protected void configureLog(boolean debug) {
if (debug) {
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("ROOT")).setLevel(Level.DEBUG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,35 @@
******************************************************************************/
package org.piwigo.remotesync.api;

public interface Constants {
import java.io.File;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.filefilter.AbstractFileFilter;
import org.apache.commons.io.filefilter.IOFileFilter;

public class Constants {

//TODO should be moved to API?

// TODO ask pierrick :
// * isAdmin should be isWebmaster || isAdmin
public enum UserType {
webmaster, admin, guest, generic, normal
}

private static List<String> IMAGE_EXTENSIONS = Arrays.asList(new String[] {"jpg", "jpeg", "png", "gif", "tif", "tiff"});

public static IOFileFilter IMAGE_EXTENSIONS_FILTER = new ExtensionFileFilter();

private static final class ExtensionFileFilter extends AbstractFileFilter {

@Override
public boolean accept(File file) {
return IMAGE_EXTENSIONS.contains(FilenameUtils.getExtension(file.getName()).toLowerCase());
}

public enum ImageExtension {
jpg, jpeg, png, gif, tif, tiff;
}

}
53 changes: 53 additions & 0 deletions remotesync-api/src/main/java/org/piwigo/remotesync/api/Job.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2014 Matthieu Helleboid.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v2.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* Contributors:
* Matthieu Helleboid - initial API and implementation
******************************************************************************/
package org.piwigo.remotesync.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class Job {

private static final Logger logger = LoggerFactory.getLogger(Job.class);
private static boolean running;

public synchronized void execute() {
logger.debug("running " + running);
if (running) {
logger.info("Already running");
return;
}
running = true;

try {
doExecute();
} catch (Exception e) {
// FIXME
} finally {
running = false;
}
}

public void executeInThread() {
new Thread(new Runnable() {

public void run() {
execute();
}
}).start();
}

protected abstract void doExecute();

public boolean isRunning() {
return running;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
******************************************************************************/
package org.piwigo.remotesync.api;

import org.piwigo.remotesync.api.conf.Config;
import org.piwigo.remotesync.api.sync.SyncJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -21,9 +21,9 @@ public static void main(String[] args) {
new Main().run(args);
}

protected void start(Config config) {
protected void start() {
logger.debug("will start batch Remotesync");
new Sync(config.getCurrentGalleryConfig()).sync();
new SyncJob().execute();
}

// // TODO implement dry run
Expand Down
136 changes: 0 additions & 136 deletions remotesync-api/src/main/java/org/piwigo/remotesync/api/Sync.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class Config {

@ElementList
public List<GalleryConfig> galleryConfigs = new ArrayList<GalleryConfig>();
private List<GalleryConfig> galleryConfigs = new ArrayList<GalleryConfig>();

@Attribute(required = false)
private Integer currentGalleryConfigId;
Expand All @@ -33,7 +33,13 @@ public GalleryConfig getCurrentGalleryConfig() {
}

public void setCurrentGalleryConfig(GalleryConfig currentGalleryConfig) {
if (!galleryConfigs.contains(currentGalleryConfig))
galleryConfigs.add(currentGalleryConfig);
currentGalleryConfigId = galleryConfigs.indexOf(currentGalleryConfig);
}

public List<GalleryConfig> getGalleryConfigs() {
return galleryConfigs;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,32 @@ public File getUserConfigFile() {

public Config getUserConfig() {
if (userConfig == null)
userConfig = loadUserConfig();
loadUserConfig();
return userConfig;
}

public Config loadUserConfig() {
userConfig = loadConfig(getUserConfigFile());
return userConfig;
public void loadUserConfig() {
loadConfig(getUserConfigFile());
}

public void saveUserConfig() {
saveConfig(getUserConfigFile(), userConfig);
}

public Config loadConfig(File configFile) {
public void loadConfig(File configFile) {
if (configFile.exists()) {
logger.debug("found userConfig file " + configFile.getAbsolutePath());
try {
userConfig = PersisterFactory.createPersister().read(Config.class, configFile);
logger.debug("configuration loaded");
return userConfig;
return;
} catch (Exception e) {
logger.error("unable to read userConfig file", e);
}
} else
}
logger.debug("no userConfig file found");

return new Config();
userConfig = new Config();
}

public void saveConfig(File configFile, Config config) {
Expand Down
Loading

0 comments on commit 5884c60

Please sign in to comment.