Skip to main content

A Generic plug-in system for python

Project description

== Plug n' Play ==

Plug n' PLay (PnP) is a Generic plug-in system inspired by Trac's (http://trac.edgewall.org)
internal component management. With PnP you can turn any program into a pluggable software very easily.

You just have to define the Interfaces and let others implement them. When your code is running
you can dynamically retrieve who are the classes that implement a certain Interface, and call
the specific methods.

== A simple example ==

Think this way: You have e very simple program that just copy files around.

Say you want to check if the copy was OK by calculating the MD5 hash of the
two files (the original and the copy). You can do this implementing the MD5 check
inside your main code, that's OK too, but when you need to add another check
(e.g. calculate the SHA-1 of the files) you will have to modify your code so
it can call two methods, the MD5 checker and the SHA-1 checker.

With PnP you write only the main piece of the program, the part that does only the copying,
and the hash checkers you can implement whenever you want, *without* any modification
to the main code.

PnP is roughly a implementation of the Observer pattern (http://en.wikipedia.org/wiki/Observer_pattern).

== A Pseudo-code example ==

Ok, too much talk, now some code. A pseudo-code to the example above would be:

class CopyListener(Interface):

def copy_finished(self, original_file, new_file):
pass


The main code would be:

PnP.load_plugins("/some/path/with/python/files") # egg files in the future?.
copy_file(file1, file2)

# Would return all python classes that
# implement CopyListerner interface
copy_listeners = CopyListener.implementors()

# Call each of the listeners telling the copy finished
for listener in copy_listeners:
listener.copy_finished(file1, file2)


And an example of one such listener would be:

from myproject.interfaces import CopyListener

class MD5Check(Plugin):
implements = (CopyListener,)

def copy_finished(self, file1, file2):
md5_1 = hash.md5(file1.read()).hexdigest()
md5_2 = hash.md5(file2.read()).hexdigest()
if md5_1 is not md5_2:
# Do something very useful! =)

== Conclusion ==

Did you like this project? Very nice, so help me write it! Fork the repo and
send me some pull requests! Or talk to me directly if you have some great ideas to implement!


Thanks,

Dalton Barreto

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plugnplay-0.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plugnplay-0.1-py2.6.egg (10.2 kB view details)

Uploaded Egg

File details

Details for the file plugnplay-0.1.tar.gz.

File metadata

  • Download URL: plugnplay-0.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for plugnplay-0.1.tar.gz
Algorithm Hash digest
SHA256 40d0ab055cafb7fec959b348e34bb4322efd6110d3d3953a07b7b376cc13d97f
MD5 d8f69bd4c5b2ebff6a322bc63c9bf9d0
BLAKE2b-256 2fdec8c2cb9b5a540898f10f2934dbc1f6e1902d392e761f8f06377fa22ccd03

See more details on using hashes here.

File details

Details for the file plugnplay-0.1-py2.6.egg.

File metadata

  • Download URL: plugnplay-0.1-py2.6.egg
  • Upload date:
  • Size: 10.2 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for plugnplay-0.1-py2.6.egg
Algorithm Hash digest
SHA256 1261f48a24a721ca6ad50689b70668b9ef38db47311ff65035cccbb16848771b
MD5 80341a6ade1f7ccaa2206c4a9ed8ba85
BLAKE2b-256 51b1d2cca31b419fd23028513aa9abd65636792638d127dfa4e04483e4e6d422

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page