Hello,
another philosophical question:
How would you implement a plugin system (for a web-based application)?
Conditions are:
- One plugin can have one or many "parts" (or "subplugins ", or whatever)
- Each subplugin has a type
- The rest of the plugin interface is dependent on the type
I have one possible solution in mind, but I want to wait for your
opinion before revealing it.
Reinhold
--
[Windows ist wie] die Bahn: Man muss sich um nichts kuemmern, zahlt fuer
jede Kleinigkeit einen Aufpreis, der Service ist mies, Fremde koennen
jederzeit einsteigen, es ist unflexibel und zu allen anderen Verkehrs-
mitteln inkompatibel. -- Florian Diesch in dcoulm 7 1816
Reinhold Birkenfeld wrote: How would you implement a plugin system (for a web-based application)?
This is so general a question that I cannot think of anything concrete to answer.
Please ask again, with more detail about what you want/need/have in mind.
--Irmen
Irmen de Jong wrote: Reinhold Birkenfeld wrote:
How would you implement a plugin system (for a web-based application)?
This is so general a question that I cannot think of anything concrete to answer. Please ask again, with more detail about what you want/need/have in mind.
Okay, the question is too open: My focus is on how you would structure
the plugin code (directories, files) and how you would write code to
load these plugins.
Reinhold
--
[Windows ist wie] die Bahn: Man muss sich um nichts kuemmern, zahlt fuer
jede Kleinigkeit einen Aufpreis, der Service ist mies, Fremde koennen
jederzeit einsteigen, es ist unflexibel und zu allen anderen Verkehrs-
mitteln inkompatibel. -- Florian Diesch in dcoulm
Reinhold Birkenfeld wrote: Irmen de Jong wrote:Reinhold Birkenfeld wrote:
How would you implement a plugin system (for a web-based application)?
This is so general a question that I cannot think of anything concrete to answer. Please ask again, with more detail about what you want/need/have in mind.
Okay, the question is too open: My focus is on how you would structure the plugin code (directories, files) and how you would write code to load these plugins.
And _this_ sounds like a combination of something that's more
a design issue (the structure) and a trivial implementation
detail (trivial in Python, anyway).
I'll try anyway, as a first test case: put all plugins in a
standard folder, with nothing else present in that folder.
They can be individual modules or packages as you will.
The code to load the plugin consists of an __import__...
and not much else.
Maybe this feedback will help you refine the question further...
-Peter
Reinhold Birkenfeld <re************ ************@wo lke7.net> wrote: Irmen de Jong wrote: Reinhold Birkenfeld wrote: How would you implement a plugin system (for a web-based application)? This is so general a question that I cannot think of anything concrete to answer. Please ask again, with more detail about what you want/need/have in mind. Okay, the question is too open: My focus is on how you would structure the plugin code (directories, files) and how you would write code to load these plugins.
...Have a place for plugins
app/plugins
...Load the plugins on startup
import traceback
import os
for fn in os.listdir('plu gins'):
if fn[:1] != '_' and fn.split('.')[-1] in ('py', 'pyw'):
try:
globals()[fn] = \
__import__('plu gins.%s'%fn, globals(), locals(), [fn])
except:
traceback.print _exc()
Etcetera. May not be the best, but it will get the job done.
- Josiah
"Peter Hansen" <pe***@engcorp. com> wrote in message
news:Rp******** ************@po wergate.ca... Reinhold Birkenfeld wrote: Irmen de Jong wrote:Reinhold Birkenfeld wrote:
How would you implement a plugin system (for a web-based application)?
This is so general a question that I cannot think of anything concrete to answer. Please ask again, with more detail about what you want/need/have in mind. Okay, the question is too open: My focus is on how you would structure the plugin code (directories, files) and how you would write code to load these plugins.
And _this_ sounds like a combination of something that's more a design issue (the structure) and a trivial implementation detail (trivial in Python, anyway).
I'll try anyway, as a first test case: put all plugins in a standard folder, with nothing else present in that folder. They can be individual modules or packages as you will. The code to load the plugin consists of an __import__... and not much else.
I have done something similar, with a few differences. I am using a
convention that all the plugins are implemented as a class with a specific
name ("Handler" in my case), each plugin in its own module (so each Handler
class is scoped by its module). I import all the modules in the directory
dedicated to plugins and I do the following checks: the module contains a
class Handler, the module is not the one implementing the base class itself
(bit of a hack, I admit), and the Handler class is a subclass of the base
class (use isinstance). The checks allow to have also other modules in the
plugins directory that do not actually implement a plugin (for instance, I
have a mixin class in that same directory).
Because you have both plugins and sub-plugins you may want to use some
checks like mine, so you have both plugins and sub-plugins in the same
directory, but you select only the plugin classes. That's if I understand
your requirements correctly.
Dan
Maybe this feedback will help you refine the question further...
-Peter
On Sat, 30 Oct 2004 07:58:27 -0700, Josiah Carlson wrote: Reinhold Birkenfeld <re************ ************@wo lke7.net> wrote: Irmen de Jong wrote: > Reinhold Birkenfeld wrote: > >> How would you implement a plugin system (for a web-based application)? > > This is so general a question that I cannot think of anything concrete to answer. > Please ask again, with more detail about what you want/need/have in mind.
Okay, the question is too open: My focus is on how you would structure the plugin code (directories, files) and how you would write code to load these plugins.
...Have a place for plugins app/plugins
...Load the plugins on startup import traceback import os for fn in os.listdir('plu gins'): if fn[:1] != '_' and fn.split('.')[-1] in ('py', 'pyw'): try: globals()[fn] = \ __import__('plu gins.%s'%fn, globals(), locals(), [fn]) except: traceback.print _exc()
Etcetera. May not be the best, but it will get the job done.
- Josiah
Just FYI, dynamically loaded plugins will not be caught by tools like
py2exe. Another mechanism, which may be more py2exe friendly, is to make
a tool which dynamically creates a python file, which lists all of the
imports. That way, you import the dynamically created file, but once it's
created, you immediately leverage the file for use with py2exe, which can
now follow all of the imports.
Of course, if you never plan on being a py2exe user, you can happily
ignore my ramblings. ;)
Cheers,
Greg
"Dan Perl" <da*****@rogers .com> wrote in message
news:CJ******** ************@ro gers.com... "Peter Hansen" <pe***@engcorp. com> wrote in message news:Rp******** ************@po wergate.ca... Reinhold Birkenfeld wrote: Irmen de Jong wrote: Reinhold Birkenfeld wrote:
>How would you implement a plugin system (for a web-based application)?
This is so general a question that I cannot think of anything concrete to answer. Please ask again, with more detail about what you want/need/have in mind.
Okay, the question is too open: My focus is on how you would structure the plugin code (directories, files) and how you would write code to load these plugins. And _this_ sounds like a combination of something that's more a design issue (the structure) and a trivial implementation detail (trivial in Python, anyway).
I'll try anyway, as a first test case: put all plugins in a standard folder, with nothing else present in that folder. They can be individual modules or packages as you will. The code to load the plugin consists of an __import__... and not much else.
I have done something similar, with a few differences. I am using a convention that all the plugins are implemented as a class with a specific name ("Handler" in my case), each plugin in its own module (so each Handler class is scoped by its module). I import all the modules in the directory dedicated to plugins and I do the following checks: the module contains a class Handler, the module is not the one implementing the base class itself (bit of a hack, I admit), and the Handler class is a subclass of the base class (use isinstance). The checks allow to have also other modules in the
I forgot what I'm doing in my own code. I looked at it again and found that
I'm not using isinstance(), instead I am doing a check for
"baseClass.Hand ler in hndlrCls.__base s__", which is much better, because it
doesn't need the creation of an instance. Here is the actual code (my
handlers are the equivalent of your plugins):
# Build a list of the modules that contain a valid Handler class.
hndlrList = []
for hndlrFile in glob.glob(
os.path.join(os .environ['zigzag_install _dir'], 'handlers',
'*.py')):
modName = os.path.split(o s.path.splitext (hndlrFile)[0])[1]
if modName == 'baseClass' or \
modName == 'handlerTemplat e':
continue
impMod = __import__('han dlers.'+modName ,
globals(),
locals(),
['Handler'])
if not vars(impMod).ha s_key('Handler' ):
continue
hndlrCls = vars(impMod)['Handler']
if not baseClass.Handl er in hndlrCls.__base s__:
continue
hndlrList.appen d(modName)
baseClass.Handl er is the base class for all my handlers.
plugins directory that do not actually implement a plugin (for instance, I have a mixin class in that same directory).
Because you have both plugins and sub-plugins you may want to use some checks like mine, so you have both plugins and sub-plugins in the same directory, but you select only the plugin classes. That's if I understand your requirements correctly.
Dan
Maybe this feedback will help you refine the question further...
-Peter
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rudolf |
last post by:
Dear NG,
I want to create a Plugin System in C# (WinForms). Has anybody experience
about this, tips, tricks, or any links. Thank you very much
The DotNetJunkie
|
by: Matt |
last post by:
I'm hoping someone can steer me in the right direction to try to do the
following:
I am developing an application where we receive files from customers. Right
now we receive a variety of formats. I was looking at writing some type of
base application that would allow me to add-in either new assemblies or
plugins, don't know how or which way, for different scenarios. We may
just recieve a text file so an assembly would handle...
|
by: David Levine |
last post by:
This is a lengthy post; please bear with me...
This will be a large system with dozens of plugins. In addition to plugins
developed internally there will be 3rd parties that will write their own and
integrate them into our application. I will be managing the identification
and loading of these plugins. In addition, there are a number of assemblies
that plugins will reference, some shared, and others private.
There are a couple of...
|
by: Edvard Majakari |
last post by:
Hi,
My idea is to create a system working as follows: each module knows
path to plugin directory, and that directory contains modules which
may add hooks to some points in the code.
Inspired by http://www.python.org/pycon/2005/papers/7/pyconHooking.html
I would create a class like this:
|
by: auad |
last post by:
hi,
I'm having a problem with plugins....as follows:
I have 3 projects: 2 class libraries and 1 Windows App
(Project 1: ClassLibrary)
I have a plugin interface:
--------------------------------------------------------------------
namespace API
{
| |
by: Zeya |
last post by:
Situation:
Using C#, ASP.Net
Requirement:
1. ASP.net application with virtual hosting service.
2. Requires a service that will run every predefined frequency in
minutes (2, 30, 100, 10000) defined in web.config and do some data
crunching in the database
How am I doing this?
|
by: Flavio |
last post by:
Hi,
Nowadays the addition of functionality to programs by means of
plugins is very frequent.
I want to know the opinions of experienced Python developers about the
best practices when it comes to developing a plugin system for a
Python package.
Should plugins be modules in a separate package?
|
by: Shiplu |
last post by:
Hi,
I think you are familier with plugin system in windows application.
I have created and application which has this facility.
One is PluginHost, container of the plugin.
Other is Plugin itself.
Both PluginHost.GlobalSettings and Plugin.GlobalSettings contains
static methods and members.
I have a GlobalSettings class in the namespace of PluginHost. It does
all the settings savings and retriving task. In the same way I also
have a...
|
by: WTH |
last post by:
I am now aware (I am primarily a C++ developer) that in C# if you reference
the same interface from the same file in two different projects the types
are actually incompatible.
I found this out because I have written a generic plugin system for my
current and future C# needs. I defined a base plugin system interface named
IPlugin (original, I know...) which contains some basic plugin infomration
all plugins of this system must expose...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |