durusmail: qp: subclassing site
subclassing site
2005-12-14
2005-12-14
2005-12-14
subclassing site
mario ruggier
2005-12-14
Hi,

been swimming in the code to try and figure out where and how the
publisher gets initialised, and with all the cross references it is
easy to start feeling a little dizzy. But, for a rather complex whole,
the simplicity of the interplay between the clear components is really
quite pleasing.

The publisher gets initialised in Site.get_publisher(), which is nicely
enough isolated. However, I cannot just subclass Site and override this
method, as the actual site instances themselves are instantiated in the
class method Site.get_sites(). The only real snag with this (other than
the little one below) is that this method is called (and thus site
instances are created) when you run the qp script, and that script
hardwires the use of qp.lib.site.Site. The question is would it be
possible to somehow specify which Site class is to be used by this
script ?

The other small snag with qp.lib.site.Site.get_sites() is that the site
instances are created using Site explicitly... when it would be more
generic to use the klass parameter that the method is passed. Using
this the only limitation (as far as I can see) for freely subclassing
Site would be the import statement in the qp script. I.e. the return
statement of get_sites() will become:

         return dict([(name, klass(name))
                      for name in listdir(sites_directory) if ...

Incidentally, I was initially a little surprised with a class method,
innocuously called get_site(), that actually creates an instance of its
own type for every qp_site directory it finds. Maybe create_sites()
would be a more indicative name. Also, but this may be only my
aesthetic preference, wouldn't it be clearer to have this as a function
instead of a class method? In any case, neither of these changes would
affect the first problem above in any way.

mario

reply