Skip to content

Commit

Permalink
Added the Python plugin environment [comixed#26]
Browse files Browse the repository at this point in the history
 * Python sources are packaged in the JAR file.
  • Loading branch information
mcpierce committed Jun 27, 2020
1 parent e49371e commit d6add28
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
26 changes: 26 additions & 0 deletions comixed-plugins/pom.xml
Expand Up @@ -30,4 +30,30 @@
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-sources</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main/python</directory>
<targetPath>python</targetPath>
<includes>**/*.py</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,71 @@
/*
* ComiXed - A digital comic book library management application.
* Copyright (C) 2020, The ComiXed Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

package org.comixed.plugins.interpreters;

import lombok.extern.log4j.Log4j2;
import org.comixed.plugins.PluginException;
import org.comixed.plugins.model.Plugin;
import org.comixed.service.comic.ComicService;
import org.comixed.service.comic.PageService;
import org.python.util.PythonInterpreter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
* <code>PythonPluginInterpreter</code> defines a type of {@link PluginInterpreter} that executes
* Python code.
*
* @author Darryl L. Pierce
*/
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Log4j2
public class PythonPluginInterpreter extends AbstractPluginInterpreter {
@Autowired private ComicService comicService;
@Autowired private PageService pageService;

private PythonInterpreter interpreter;

@Override
public void initialize() throws PluginException {
super.initialize();

log.debug("Initializing Python runtime environment");
this.interpreter = new PythonInterpreter();

this.loadRuntimeObjects();
}

private void loadRuntimeObjects() {
log.debug("Loading ComiXed Python runtime objects");
this.interpreter.set("comicService", this.comicService);
this.interpreter.set("pageService", this.pageService);
this.interpreter.set("logger", this.log);
}

@Override
public void start(Plugin plugin) throws PluginException {}

@Override
public void finish() throws PluginException {
super.finish();
}
}
18 changes: 18 additions & 0 deletions comixed-plugins/src/main/python/comixed/__init__.py
@@ -0,0 +1,18 @@
# ComiXed - A digital comic book library management application.
# Copyright (C) 2020, The ComiXed Project
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses>

import org.comixed.service.comic.ComicService as ComicService

Expand Up @@ -2,3 +2,5 @@
# * language: the name of the language
# * interpreter: the name of the Java bean

plugin.language.runtime[0].language=python
plugin.language.runtime[0].bean=pythonPluginInterpreter

0 comments on commit d6add28

Please sign in to comment.