Please review the patch with the changes suggested by Endi to refactor
code inorder to maintain references to the global variables and the
utility classes.
A new class PKIDeployer is added to pkihelper.py, whose object is
created in pkispawn/pkidestroy to hold the references and be passed to
the PKIScriptlets.
Declarations for pki_master_dict and pki_slots_dict have been moved to
init method in pkiparser.py from pkiconfig. The compose methods are
called in pkispawn/pkidestroy and then the references passed to the
PKIDeployer object.
This also fixes many issues of tpe E1120 reported by pylint.
--Abhishek
On Wed, 2013-06-05 at 21:38 -0500, Endi Sukma Dewata wrote:
On 5/31/2013 3:38 PM, Abhishek Koneru wrote:
> Please review the patch which fixes a few errors reported by pylint in
> dogtag's python code.
>
> Also find attached the remaining errors to be fixed. Will submit a
> detailed report in my next mail.
>
> How i used pylint:
>
> -- Installed pki packages.
> -- Executed the following command -
> cd /usr/lib/python2.7/sitepackages; pylint -E --include-ids=y pki/
> pki/deployment/ pki/server/ `which pkispawn` `which pkidestroy` `which
> pki-upgrade` `which pki-server-upgrade`
>
> --Abhishek
Looking at the pkihelper.py again, I'm not sure if this is the right
approach. In the original code the classes are instantiated into global
objects and we're calling the methods of these objects like this:
uid = identity.get_uid()
In the new code the methods are converted into static methods:
uid = Identity.get_uid()
The problem is many of these methods actually depend on other global
objects such as 'master', so we haven't really removed the dependency on
global variables.
I'm thinking we probably should encapsulate the global objects into an
object that we can pass around, then we access them as local variables.
For example, in pkispawn we generate the master object and put it in a
Deployer object. Then we pass the deployer object to the scriptlets.
deployer = pki.server.Deployer(master)
instance = scriptlet.PkiScriptlet()
instance.spawn(deployer)
The Deployer class will have methods that generate the old global
objects and we pass the master into those objects:
def get_identity(self):
return Identity(master)
In the scriptlets we can call the methods this way:
identity = deployer.get_identity()
uid = identity.get_uid()
What do you think?
If we do this, I'd suggest we do the conversion one global object at a
time so it's easier to review.