creating an abstraction layer class to manage resources

2012-02-18 Thread Fabio Dive
Hello all,

I am not a pyramid  expert and I am doing my best to develop further skills.
Maybe my idea was already solved in a more elegant and more convenient
way, so please, if you know that, answer me, it will be very appreciated.

I am developing a project with SQLAlchemy and Beaker Session, to reduce
the number of queries I writed down a custom groupfinder for my pages
factories. This class get the resources first from the session if they
exist
and after from SQLAlchemy DBSession, if they are not founded into the
session
the same class try to load into the server backed session the data for
future use. We are talking about very important user data like the group,
email, capabilities enabled and so on.

Do you think guys this is the best approach to the problem?
If it is I can study develop further the interface to produce something
for everybody and propose a new pyramid module with a bit of time.
I can try to find a way to declare a dynamic number of  session keys
to fit the needs of the user.

thank you for your time in advance.
excuse my poor english

f.

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: Distribution not found error

2012-02-18 Thread Gael Pasgrimaud
On Sat, Feb 18, 2012 at 6:55 AM, Artur Daschevici
a.daschev...@gmail.com wrote:
 Does anyone else have any other ideas...or any ideas on how to debug
 this better?


Have you tried with the activate_this.py script ?

http://pypi.python.org/pypi/virtualenv#using-virtualenv-without-bin-python

 At this point i would pretty much try anything new...well maybe short
 of reinstalling everything from python up.

Your .wsgi is a python script so you can run:
C:\\Python\\Scripts\\Python.exe handler.wsgi
If you have no traceback then it should work with mod_wsgi too.
Add some print statements for debuging. Like print sys.path or import testsite


 --
 You received this message because you are subscribed to the Google Groups 
 pylons-discuss group.
 To post to this group, send email to pylons-discuss@googlegroups.com.
 To unsubscribe from this group, send email to 
 pylons-discuss+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/pylons-discuss?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



What are the files located in the AppName.egg-info used for?

2012-02-18 Thread Tjelvar
Have just run:

$ ./env/bin/pcreate --scaffold=starter AppName
$ cd AppName
$ ./env/bin/python setup.py develop

Which resulted in the directory AppName.egg-info being created:

$ tree AppName.egg-info/
Taster.egg-info/
├── dependency_links.txt
├── entry_points.txt
├── not-zip-safe
├── PKG-INFO
├── requires.txt
├── SOURCES.txt
└── top_level.txt

0 directories, 7 files

Are these files simply logs of the installation process or are they
required for anything?

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: What are the files located in the AppName.egg-info used for?

2012-02-18 Thread Simon Yarde
http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/project.html#the-project-structure

Hope that explains it!

On 18 Feb 2012, at 16:16, Tjelvar tjelvar.ols...@gmail.com wrote:

 Have just run:
 
 $ ./env/bin/pcreate --scaffold=starter AppName
 $ cd AppName
 $ ./env/bin/python setup.py develop
 
 Which resulted in the directory AppName.egg-info being created:
 
 $ tree AppName.egg-info/
 Taster.egg-info/
 ├── dependency_links.txt
 ├── entry_points.txt
 ├── not-zip-safe
 ├── PKG-INFO
 ├── requires.txt
 ├── SOURCES.txt
 └── top_level.txt
 
 0 directories, 7 files
 
 Are these files simply logs of the installation process or are they
 required for anything?
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 pylons-discuss group.
 To post to this group, send email to pylons-discuss@googlegroups.com.
 To unsubscribe from this group, send email to 
 pylons-discuss+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/pylons-discuss?hl=en.
 

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: What are the files located in the AppName.egg-info used for?

2012-02-18 Thread Simon Yarde
Actually, you want this for the detail on eggs..

http://peak.telecommunity.com/DevCenter/EggFormats

On 18 Feb 2012, at 17:24, Simon Yarde simonya...@me.com wrote:

 http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/project.html#the-project-structure
 
 Hope that explains it!
 
 On 18 Feb 2012, at 16:16, Tjelvar tjelvar.ols...@gmail.com wrote:
 
 Have just run:
 
 $ ./env/bin/pcreate --scaffold=starter AppName
 $ cd AppName
 $ ./env/bin/python setup.py develop
 
 Which resulted in the directory AppName.egg-info being created:
 
 $ tree AppName.egg-info/
 Taster.egg-info/
 ├── dependency_links.txt
 ├── entry_points.txt
 ├── not-zip-safe
 ├── PKG-INFO
 ├── requires.txt
 ├── SOURCES.txt
 └── top_level.txt
 
 0 directories, 7 files
 
 Are these files simply logs of the installation process or are they
 required for anything?
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 pylons-discuss group.
 To post to this group, send email to pylons-discuss@googlegroups.com.
 To unsubscribe from this group, send email to 
 pylons-discuss+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/pylons-discuss?hl=en.
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 pylons-discuss group.
 To post to this group, send email to pylons-discuss@googlegroups.com.
 To unsubscribe from this group, send email to 
 pylons-discuss+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/pylons-discuss?hl=en.
 

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: creating an abstraction layer class to manage resources

2012-02-18 Thread Jonathan Vanasco
i tend to structure applications - python, php, whatever - like this:

- I use multiple Database Handles.  This is always at least a reader
and a writer.  On the database level, the reader is privileged to
only select from databases, while the writer may read and write.  If
the application needs a clustered database, the writer points to
Master while the Reader points to Slaves.  In terms of database
connectivity, Readers are also non-transactional, while Writers
are transaction safe.

- Whenever visitors deal with /account administration, I always read
off the Master and use per-request database queries.  I never use
cached data.

- Whenever visitors deal with consuming content , everything is
sourced from the reader.

- On login and preference updates, I cache the core user data.  I
prefer to put this in Memcached ( though now exploring MongoDB and
Riak ), and only use the cookie based Session for account
identifiers and user-flow logic.  I also time this cached data for
10-20 minutes and then force a refresh.  The reason for this - if
someone is browsing on 2 devices, or home  work, they would have 2
different session ids.

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: creating an abstraction layer class to manage resources

2012-02-18 Thread Fabio Dive
On Sat, Feb 18, 2012 at 18:14, Jonathan Vanasco jonat...@findmeon.comwrote:

 i tend to structure applications - python, php, whatever - like this:

 - I use multiple Database Handles.  This is always at least a reader
 and a writer.  On the database level, the reader is privileged to
 only select from databases, while the writer may read and write.  If
 the application needs a clustered database, the writer points to
 Master while the Reader points to Slaves.  In terms of database
 connectivity, Readers are also non-transactional, while Writers
 are transaction safe.

 - Whenever visitors deal with /account administration, I always read
 off the Master and use per-request database queries.  I never use
 cached data.

 - Whenever visitors deal with consuming content , everything is
 sourced from the reader.

 - On login and preference updates, I cache the core user data.  I
 prefer to put this in Memcached ( though now exploring MongoDB and
 Riak ), and only use the cookie based Session for account
 identifiers and user-flow logic.  I also time this cached data for
 10-20 minutes and then force a refresh.  The reason for this - if
 someone is browsing on 2 devices, or home  work, they would have 2
 different session ids.

 --
 You received this message because you are subscribed to the Google Groups
 pylons-discuss group.
 To post to this group, send email to pylons-discuss@googlegroups.com.
 To unsubscribe from this group, send email to
 pylons-discuss+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/pylons-discuss?hl=en.


Thank you Jonathan,
your approach is very interesting, ready to production use.

Do you think it is interesting to have a class layer between
SQLALchemy and beaker session? I mean... I would like
to interface with a class that manage everything, into the
view I call an instance to retrieve the data and I don't repeat
the code.

f.

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: creating an abstraction layer class to manage resources

2012-02-18 Thread Jonathan Vanasco
i personally wouldn' do that, because my SqlAlchemy classes are really
just used for populating a read-only cache -- which is a dict -- and
creating/editing records.

in your case... and I'm just thinking out loud...

1. you could create an abstract class called CacheBacked, which your
Reflected/Declared tables would also intherit from.  you could then
provide a get_by_id(id) function.  Calling that could try to load
from a cache, and then failover to loading form SqlAlchemy.  there are
a lot of problems with that approach though, as SqlAlchemy and your
transaction layer may try to persist the objects.  the interface would
be really awkward too.

2. you could create a wrapper class that proxies a bunch of sqlalchemy
objects and saves them to a cache..

class CacheBacked(object):
 wrapped_sqla_class= None
 data_structure= None
 def load(id):
  self.data_structure= load_from_memory()
  if not data_structure:
 wrapped_instance=
dbSession.query( self.wrapped_sqla_class ).filter_by(id=id).one()
 self.data_structure=
pull_details_of( wrapped_instance )

class Useraccount():
 wrapped_sqla_class= models.Useraccount


although, honestly, i don't like either of those ideas and wouldn't do
them.  hopefully someone here has a good idea ( i just felt it
worthwhile to discuss bad ideas! )

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: Limited traversal

2012-02-18 Thread Andrey Popp
On Fri, Feb 17, 2012 at 01:42:04AM +0400, Andrey Popp wrote:
 On Thu, Feb 16, 2012 at 12:09:36PM -0800, Mike Orr wrote:
  Second, how can I generate URLs to resources without loading the objects
  through this interface?  The home page queries the 30 most recent incidents
  and displays links to them.  request.resource_url() requires a resource
  object, but the home page or browse pages query the database directly and 
  get
  plain ORM objects rather than location-aware ones.  I could make the URLs
  manually but that sucks. I could somehow get the incident resource and
  append the ID, or get the root resource and append incident and the ID, 
  but
  that's not much better.
 
 That's interesting question. I'm thinking of the following construct:
 
   1. Make your resource graph lazy, e.g. producing only proxies which only
   knows its location (pk in database in case of SQLAlchemy) and how to load
   itself (table and parent resources, which impose some query constraints or
   JOIN clauses).
 
   2. Reuse your resource graph in pyramid's traversal engine and in your home
   page view:
 
 def homepage():
   entries_ids = db.entries_ids_for_homepage()
   entries = [root[entries][id] for id in entries_ids]
 
   So you get ``entries`` list of location-aware Entry objects which are loaded
   only if you access their fields, but not __name__ or __parent__ which allows
   you to generate URL for them w/o any overhead.

If someone is still interested in this approach, I've implemented[1]
sqlalchemy.Query.lazy_get(ident) method which works that way. My use-case is
different -- to allow User object to be attached on request without touching
database (user id is encoded in authc cookie), but I think it should work for
constructing lazy resource graph as well.

Implementation based on SQLAlchemy mailing list post[2]. 

[1]: https://gist.github.com/77eb31670a1842f301c2
[2]: https://groups.google.com/forum/?fromgroups#!topic/sqlalchemy/DvofQn6uVI4

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: What are the files located in the AppName.egg-info used for?

2012-02-18 Thread Tjelvar
Dear Simon,

Thank you for your response. I've had a look at the pages you
highlighted. I've also experimented with running the command:

$ .../env/bin/pserver development.ini

before and after deleting the AppName.egg-info directory. The latter
resulting in a distribution not found error:

pkg_resources.DistributionNotFound: AppName

So would it be correct to say that:

The information in the AppName.egg-info directory is required for the
pserve, proutes, pshell and ptweens programs to be able to discover
and import the application.

Regards,

Tjelvar

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: What are the files located in the AppName.egg-info used for?

2012-02-18 Thread Mike Orr
On Sat, Feb 18, 2012 at 5:23 PM, Tjelvar tjelvar.ols...@gmail.com wrote:
 Dear Simon,

 Thank you for your response. I've had a look at the pages you
 highlighted. I've also experimented with running the command:

 $ .../env/bin/pserver development.ini

 before and after deleting the AppName.egg-info directory. The latter
 resulting in a distribution not found error:

 pkg_resources.DistributionNotFound: AppName

 So would it be correct to say that:

 The information in the AppName.egg-info directory is required for the
 pserve, proutes, pshell and ptweens programs to be able to discover
 and import the application.

Egg-info is the application's metadata. It tells Python what the
package's name and version are, which Python packages/modules it
contains, which other distributions it depends on, and what its entry
points are. All this is defined in the package's setup.py. When you
install the package or run python setup.py egg_info, it creates the
egg_info directory.

pserve calls paste.deploy.loadwsgi.loadapp(), which reads the app
section in the INI file, and looks for the entry point specified in
the use= line. It calls Setuptools to find and load this entry point.
Entry point data is in the egg_info directories, so that's why they
must exist.

-- 
Mike Orr sluggos...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: What are the files located in the AppName.egg-info used for?

2012-02-18 Thread Tjelvar
Dear Mike,

Thank you for clarifying that.

Tjelvar

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: Limited traversal

2012-02-18 Thread Michael Merickel
On Sat, Feb 18, 2012 at 3:53 PM, Andrey Popp 8may...@gmail.com wrote:

 My use-case is
 different -- to allow User object to be attached on request without
 touching
 database (user id is encoded in authc cookie), but I think it should work
 for
 constructing lazy resource graph as well.


In Pyramid 1.3 I've updated the cookbook to directly support this idea of a
lazy get via attaching lazily evaluated properties to the request object.
You may consider it as an alternative to a custom Query class.

http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/auth/user_object.html#making-a-user-object-available-as-a-request-attribute

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.