Discussion:
[PEAK] ZConfigInterpreter with data from STDIN
Alexey Smishlayev
2015-04-15 12:49:51 UTC
Permalink
Hello!
I am trying to refactor existing peak application. I need to be able to
load ZConfig file from data incoming by STDIN. Now, the loader included
in peak is using files, so I implemented a subclass which should
simulate a file resource (in file zconfig.py). I also searched peak.ini
for any lines regarding zconfig. I copied all settings and changed them
to point to my custom classes (in file custom.ini; "ank.BBS" is my
project package).

In the python script, ZConfigInperpreter was used to get the application
_argv=["ZConfig", scheme, cfgName]
_argv.extend(sys.argv[1:])
return ZConfigInterpreter(
config.makeRoot(),
argv=_argv,
componentName="MYAPP"
)
Now I want to pass no cfgName and get interpreter to process the STDIN.
But the PEAK seem to not find settings which I've put in my .ini file
and I'm stuck.
I've narrowed it down - the
ZConfigInterpreter.lookupComponent('zconfig.schema:'+str(url)) returns
peak.config.load_zconfig.ConfigLoader, instead of my custom class
(STDINConfigLoader from my file). I tried to trace down the stack with
pdb, and it seems that some lookup for
"zconfig.schema:/path/to/schema/file.xml" returns
peak.config.load_zconfig.ZConfigSchemaContext.
I've subclassed that one too, but have no success.

Can anyone, please, help me, how to replace the standard ZConfig classes?

Best regards,
Alexey
PJ Eby
2015-04-15 17:19:29 UTC
Permalink
Have you tried just using "fd.file:stdin" as the cfgName?
Post by Alexey Smishlayev
Hello!
I am trying to refactor existing peak application. I need to be able to load
ZConfig file from data incoming by STDIN. Now, the loader included in peak
is using files, so I implemented a subclass which should simulate a file
resource (in file zconfig.py). I also searched peak.ini for any lines
regarding zconfig. I copied all settings and changed them to point to my
custom classes (in file custom.ini; "ank.BBS" is my project package).
In the python script, ZConfigInperpreter was used to get the application
_argv=["ZConfig", scheme, cfgName]
_argv.extend(sys.argv[1:])
return ZConfigInterpreter(
config.makeRoot(),
argv=_argv,
componentName="MYAPP"
)
Now I want to pass no cfgName and get interpreter to process the STDIN. But
the PEAK seem to not find settings which I've put in my .ini file and I'm
stuck.
I've narrowed it down - the
ZConfigInterpreter.lookupComponent('zconfig.schema:'+str(url)) returns
peak.config.load_zconfig.ConfigLoader, instead of my custom class
(STDINConfigLoader from my file). I tried to trace down the stack with pdb,
and it seems that some lookup for "zconfig.schema:/path/to/schema/file.xml"
returns peak.config.load_zconfig.ZConfigSchemaContext.
I've subclassed that one too, but have no success.
Can anyone, please, help me, how to replace the standard ZConfig classes?
Best regards,
Alexey
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
Alexey Smishlayev
2015-04-15 20:42:34 UTC
Permalink
I looks like it worked. So simple! Great thanks for the advice, PJ!

Alexey
Post by PJ Eby
Have you tried just using "fd.file:stdin" as the cfgName?
Post by Alexey Smishlayev
Hello!
I am trying to refactor existing peak application. I need to be able to load
ZConfig file from data incoming by STDIN. Now, the loader included in peak
is using files, so I implemented a subclass which should simulate a file
resource (in file zconfig.py). I also searched peak.ini for any lines
regarding zconfig. I copied all settings and changed them to point to my
custom classes (in file custom.ini; "ank.BBS" is my project package).
In the python script, ZConfigInperpreter was used to get the application
_argv=["ZConfig", scheme, cfgName]
_argv.extend(sys.argv[1:])
return ZConfigInterpreter(
config.makeRoot(),
argv=_argv,
componentName="MYAPP"
)
Now I want to pass no cfgName and get interpreter to process the STDIN. But
the PEAK seem to not find settings which I've put in my .ini file and I'm
stuck.
I've narrowed it down - the
ZConfigInterpreter.lookupComponent('zconfig.schema:'+str(url)) returns
peak.config.load_zconfig.ConfigLoader, instead of my custom class
(STDINConfigLoader from my file). I tried to trace down the stack with pdb,
and it seems that some lookup for "zconfig.schema:/path/to/schema/file.xml"
returns peak.config.load_zconfig.ZConfigSchemaContext.
I've subclassed that one too, but have no success.
Can anyone, please, help me, how to replace the standard ZConfig classes?
Best regards,
Alexey
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
PJ Eby
2015-04-15 22:48:11 UTC
Permalink
No problem. The whole idea behind adaptation and generic components
in PEAK is so that you don't have to replace things. For that matter,
the idea behind the naming system is that you should be able to turn
arbitrary names into arbitrary things; if the `fd.file:` scheme didn't
already exist, it would be straightforward to make it yourself. (See
the last 80 lines of peak.naming.factories.openable for the code.)

In fact, your original script could have been implemented simply using
a #! line, like '#!/bin/invoke peak ZConfig' at the beginning of your
schema file. Or you could make your app's .ini file executable, with
'#!/bin/invoke peak runIni'. Everywhere the original PEAK framework
tries to make things composable and to map names of things to objects
so that coding isn't needed when you're just gluing together existing
tools.
Post by Alexey Smishlayev
I looks like it worked. So simple! Great thanks for the advice, PJ!
Alexey
Post by PJ Eby
Have you tried just using "fd.file:stdin" as the cfgName?
Post by Alexey Smishlayev
Hello!
I am trying to refactor existing peak application. I need to be able to load
ZConfig file from data incoming by STDIN. Now, the loader included in peak
is using files, so I implemented a subclass which should simulate a file
resource (in file zconfig.py). I also searched peak.ini for any lines
regarding zconfig. I copied all settings and changed them to point to my
custom classes (in file custom.ini; "ank.BBS" is my project package).
In the python script, ZConfigInperpreter was used to get the application
_argv=["ZConfig", scheme, cfgName]
_argv.extend(sys.argv[1:])
return ZConfigInterpreter(
config.makeRoot(),
argv=_argv,
componentName="MYAPP"
)
Now I want to pass no cfgName and get interpreter to process the STDIN. But
the PEAK seem to not find settings which I've put in my .ini file and I'm
stuck.
I've narrowed it down - the
ZConfigInterpreter.lookupComponent('zconfig.schema:'+str(url)) returns
peak.config.load_zconfig.ConfigLoader, instead of my custom class
(STDINConfigLoader from my file). I tried to trace down the stack with pdb,
and it seems that some lookup for
"zconfig.schema:/path/to/schema/file.xml"
returns peak.config.load_zconfig.ZConfigSchemaContext.
I've subclassed that one too, but have no success.
Can anyone, please, help me, how to replace the standard ZConfig classes?
Best regards,
Alexey
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
Alexey Smishlayev
2015-04-16 08:36:07 UTC
Permalink
Yes, I understand and adore the reasoning behind PEAK component
architecture. But it is quite hard to grasp that feeling, especially
because I know a very little subset of PEAK, I'm just unaware of all its
capabilities (:

Alexey
Post by PJ Eby
No problem. The whole idea behind adaptation and generic components
in PEAK is so that you don't have to replace things. For that matter,
the idea behind the naming system is that you should be able to turn
arbitrary names into arbitrary things; if the `fd.file:` scheme didn't
already exist, it would be straightforward to make it yourself. (See
the last 80 lines of peak.naming.factories.openable for the code.)
In fact, your original script could have been implemented simply using
a #! line, like '#!/bin/invoke peak ZConfig' at the beginning of your
schema file. Or you could make your app's .ini file executable, with
'#!/bin/invoke peak runIni'. Everywhere the original PEAK framework
tries to make things composable and to map names of things to objects
so that coding isn't needed when you're just gluing together existing
tools.
Post by Alexey Smishlayev
I looks like it worked. So simple! Great thanks for the advice, PJ!
Alexey
Post by PJ Eby
Have you tried just using "fd.file:stdin" as the cfgName?
Post by Alexey Smishlayev
Hello!
I am trying to refactor existing peak application. I need to be able to load
ZConfig file from data incoming by STDIN. Now, the loader included in peak
is using files, so I implemented a subclass which should simulate a file
resource (in file zconfig.py). I also searched peak.ini for any lines
regarding zconfig. I copied all settings and changed them to point to my
custom classes (in file custom.ini; "ank.BBS" is my project package).
In the python script, ZConfigInperpreter was used to get the application
_argv=["ZConfig", scheme, cfgName]
_argv.extend(sys.argv[1:])
return ZConfigInterpreter(
config.makeRoot(),
argv=_argv,
componentName="MYAPP"
)
Now I want to pass no cfgName and get interpreter to process the STDIN. But
the PEAK seem to not find settings which I've put in my .ini file and I'm
stuck.
I've narrowed it down - the
ZConfigInterpreter.lookupComponent('zconfig.schema:'+str(url)) returns
peak.config.load_zconfig.ConfigLoader, instead of my custom class
(STDINConfigLoader from my file). I tried to trace down the stack with pdb,
and it seems that some lookup for
"zconfig.schema:/path/to/schema/file.xml"
returns peak.config.load_zconfig.ZConfigSchemaContext.
I've subclassed that one too, but have no success.
Can anyone, please, help me, how to replace the standard ZConfig classes?
Best regards,
Alexey
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
Loading...