Newbie Q: do i need PStore for this or something else?

Background info:
I am writing my very first CGI app in ruby: it’s a dynamic photo-album
(yes, i know it’s been done before, but how is one supposed to learn ?).

Question:
I can’t seem to decide under what format I should save my photo-album and
could use some pointers.

Detail:
The album consists of different sections, each containing a description
and pages. Every page contains the names of the pictures it shows,
descriptions for the pictures and the name of the layout template used.

Solutions:
Here are a few solutions I considered, as well as my thoughts about them

  • Raw I/O
    Invent my own file format and do all the writing and parsing myself;
    stupid.

  • XML
    Since there’s some structure to the document, maybe XML is a good idea
    though it might be overkill in this case.

  • PStore
    Not really sure how it works (limited info available).

  • Marshalling
    Never used it, don’t know if it is appropriate in this situation. (In
    fact I wonder in what situations it is used.)

I’d be glad to hear your thoughts about this subject,
Simon

···


Don’t go around saying the world owes you a living. The world owes you
nothing. It was here first.
– Mark Twain

Vandemoortele Simon wrote:

Background info:
I am writing my very first CGI app in ruby: it’s a dynamic photo-album
(yes, i know it’s been done before, but how is one supposed to learn ?).

sounds like a similar position to me…

  • PStore
    Not really sure how it works (limited info available).

this is what I’m using atm, and as part of my app I have images stored -
so I have this (or something like it):

class Image
attr_accessor :id, :description, :type, :width, :height
def initialize(id, description, type, width, height)
@id, @description, @type, @width, @height =
id, description, type, width, height
end
def == (other)
(other.is_a? Image) &&
other.id == @id &&
other.description == @description &&
other.type == @type &&
other.width == @width &&
other.height == @height
end
end

and I then simply store them in PStore. PStore is easy:

store = PStore.new(“filename”)
images = store[‘images’]

images.push(Image.new(…))

store.transaction do
store[‘images’] = images
end

(other something like that - cant remember off the top of my head)

seems to work ok.

my advice would be to use PStore - store everything as one big graph of
objects…

cheers
dim

Simon,

I’d use a YAML::Store-- easy to use, plus structure and raw-form readability.

Check out YAML4R:
YAML4R - Google Search

···

On Tuesday 21 January 2003 04:18 pm, Vandemoortele Simon wrote:

Background info:
I am writing my very first CGI app in ruby: it’s a dynamic photo-album
(yes, i know it’s been done before, but how is one supposed to learn ?).

Question:
I can’t seem to decide under what format I should save my photo-album and
could use some pointers.

Detail:
The album consists of different sections, each containing a description
and pages. Every page contains the names of the pictures it shows,
descriptions for the pictures and the name of the layout template used.

Solutions:
Here are a few solutions I considered, as well as my thoughts about them

  • Raw I/O
    Invent my own file format and do all the writing and parsing myself;
    stupid.

  • XML
    Since there’s some structure to the document, maybe XML is a good idea
    though it might be overkill in this case.

  • PStore
    Not really sure how it works (limited info available).

  • Marshalling
    Never used it, don’t know if it is appropriate in this situation. (In
    fact I wonder in what situations it is used.)

I’d be glad to hear your thoughts about this subject,
Simon


Bruce R. Williams :: [iusris/#ruby-lang] :: http://www.codedbliss.com

‘It does not require a majority to prevail, but rather an irate,
tireless minority keen to set brush fires in people’s minds.’
– Samuel Adams

I personally would store the images in a publicly accessible file tree,
then store all the metadata in YAML::Store. YAML::Store has the benefit
of being hand-editable, so if you need to make a quick edit, you can.

···

Vandemoortele Simon (delirious_nospamplz@atchoo.be) wrote:

Background info:
I am writing my very first CGI app in ruby: it’s a dynamic photo-album
(yes, i know it’s been done before, but how is one supposed to learn ?).

Question:
I can’t seem to decide under what format I should save my photo-album and
could use some pointers.

Detail:
The album consists of different sections, each containing a description
and pages. Every page contains the names of the pictures it shows,
descriptions for the pictures and the name of the layout template used.


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Background info:
I am writing my very first CGI app in ruby: it’s a dynamic photo-album
(yes, i know it’s been done before, but how is one supposed to learn ?).

Question:
I can’t seem to decide under what format I should save my photo-album and
could use some pointers.

Detail:
The album consists of different sections, each containing a description
and pages. Every page contains the names of the pictures it shows,
descriptions for the pictures and the name of the layout template used.

Solutions:

  • PStore
    Not really sure how it works (limited info available).

since your application is a cgi, requires a database, requires session
management, and should be easy to code i’d look at using my
CGI::Session::Pstore module from

http://www.ruby-lang.org/raa/list.rhtml?name=cgi-sess-pstore

it’s really easy to use.

some examples are at

http://eli/ruby/class/0/presentation/slide.cgi?n=14
http://eli/ruby/class/0/presentation/slide.cgi?n=14
http://eli/ruby/class/0/cgi/session/pstore.cgi

-a

···

On Tue, 21 Jan 2003, Vandemoortele Simon wrote:

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

Bruce Williams wrote:
[snip]

Detail:
The album consists of different sections, each containing a description
and pages. Every page contains the names of the pictures it shows,
descriptions for the pictures and the name of the layout template used.
[snip]
I’d use a YAML::Store-- easy to use, plus structure and raw-form readability.

Check out YAML4R:
YAML4R - Google Search

http://yaml4r.sourceforge.net/ says:

Man 1: What's Yaml?
Man 2: It's for writing data structures in plain text.

haven’t read far, but does this store binary data (photos) in base64 or
something?

cheers
dim

···

On Tuesday 21 January 2003 04:18 pm, Vandemoortele Simon wrote:

Background info:
I am writing my very first CGI app in ruby: it’s a dynamic photo-album
(yes, i know it’s been done before, but how is one supposed to learn ?).

Question:
I can’t seem to decide under what format I should save my photo-album and
could use some pointers.

Detail:
The album consists of different sections, each containing a description
and pages. Every page contains the names of the pictures it shows,
descriptions for the pictures and the name of the layout template used.

Solutions:

  • PStore
    Not really sure how it works (limited info available).

since your application is a cgi, requires a database, requires session
management, and should be easy to code i’d look at using my
CGI::Session::Pstore module from

http://www.ruby-lang.org/raa/list.rhtml?name=cgi-sess-pstore

it’s really easy to use.

some examples are at

http://eli/ruby/class/0/presentation/slide.cgi?n=14
http://eli/ruby/class/0/presentation/slide.cgi?n=14
http://eli/ruby/class/0/cgi/session/pstore.cgi

I see code, but no documentation. Is there any?

···

At 8:58 +0900 1/22/03, ahoward wrote:

On Tue, 21 Jan 2003, Vandemoortele Simon wrote:

-a

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

This is something I would really like to discuss even though I might go
a little of topic (sorry).

I am entirely new to CGI scripting and trying to make an interface to
edit my dynamic photo-album (add sections, pictures, etc). I’ve
discovered in the process how inefficient it can be to code a UI with
! since every time you need more input from the user you have
to send him to another (or the same) script and doing so lose all the
input you have collected
.
Until now I’ve been solving that problem by sending all the collected
input along as ‘hidden params’ but that’s a lot of work.
Is there a better way ? Would that be CGI::Session ?
or CGI::Session::PStore ?

Simon

P.S.: Plz understand that I do have a book about ruby, access to
google and RAA but my experience is so limited that I can’t make
sense of the information I find there. (Maybe I should find my way to
more general information about CGI since that’s the knowledge I’m
lacking. Any pointers ?)

···

ahoward ahoward@fsl.noaa.gov wrote:

since your application is a cgi, requires a database, requires session
management, and should be easy to code i’d look at using my
CGI::Session::Pstore module from


When one burns one’s bridges, what a very nice fire it makes.
– Dylan Thomas

Dmitri Colebatch dim@colebatch.com writes:

Bruce Williams wrote:
[snip]

Detail:
The album consists of different sections, each containing a description
and pages. Every page contains the names of the pictures it shows,
descriptions for the pictures and the name of the layout template used.
[snip]
I’d use a YAML::Store-- easy to use, plus structure and raw-form readability.
Check out YAML4R: http://www.google.com/search?q=YAML4R

http://yaml4r.sourceforge.net/ says:

Man 1: What’s Yaml?
Man 2: It’s for writing data structures in plain text.

haven’t read far, but does this store binary data (photos) in base64
or something?

You could. I assume YAML would just store it as a “string” and encode
it just like string.inspect would in ruby (or something close).

But don’t do that – store the images as separate files in the file
system and store the file names in your Ruby data structure.

···

On Tuesday 21 January 2003 04:18 pm, Vandemoortele Simon wrote:

Yep. Here’s an example of an image stored in a Hash:

 base64: !binary |
   R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
   OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
   +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
   AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
 description: >
  The binary value above is a tiny arrow
  encoded as a gif image.

The `!binary’ typing instructs the YAML loader to load the base64 data as a
binary string.

If I were you, I’d use the YAML document to store metadata and keep your
images in a directory where filenames are recognizable based on the metadata.

Good luck.

_why

···

On Tuesday 21 January 2003 03:24 pm, Dmitri Colebatch wrote:

http://yaml4r.sourceforge.net/ says:

Man 1: What’s Yaml?
Man 2: It’s for writing data structures in plain text.

haven’t read far, but does this store binary data (photos) in base64 or
something?

Dimitri,

As Eric states in the thread, the metadata is what would be saved in YAML. I
hadn’t even thought of saving the acual image there, as merely saving it in a
tagged/id’ed format in a directory would be more efficient. The whole point
of YAML IMHO is readability.

// B

···

On Tuesday 21 January 2003 05:24 pm, Dmitri Colebatch wrote:

Bruce Williams wrote:

On Tuesday 21 January 2003 04:18 pm, Vandemoortele Simon wrote:

[snip]

Detail:
The album consists of different sections, each containing a
description and pages. Every page contains the names of the pictures
it shows, descriptions for the pictures and the name of the layout
template used.

[snip]

I’d use a YAML::Store-- easy to use, plus structure and raw-form
readability.

Check out YAML4R:
YAML4R - Google Search

http://yaml4r.sourceforge.net/ says:

Man 1: What’s Yaml?
Man 2: It’s for writing data structures in plain text.

haven’t read far, but does this store binary data (photos) in base64 or
something?

cheers
dim


Bruce R. Williams :: [iusris/#ruby-lang] :: http://www.codedbliss.com

‘It does not require a majority to prevail, but rather an irate,
tireless minority keen to set brush fires in people’s minds.’
– Samuel Adams

there is an example on the RAA and on the slides i referenced. the reason i
didn’t write much is that it’s use is exactly like that of any other
CGI::Session (MemoryStore or FileStore) which are completely doccumented in
the pickaxe. in fact, it’s hinted there that you may write your own session
database manager, which i did. read the docs for CGI::Session::FileStore and
CGI::Session::MemoryStore and simply extend them such that key and values can
be any Object, not simply String objects.

if you have any questions please do not hesitate to contact me directly.

perhaps i should write some docs? :wink:

-a

···

On Wed, 22 Jan 2003, Paul DuBois wrote:

I see code, but no documentation. Is there any?

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

Simon, there is a better way.

you can actually marshal an entire Ruby object via a single html hidden
parameter. this is what i have done with Jigsaw (my web app framwork). jigsaw
is not yet ready for public consumption (although it is gettting close). but
here is the basic idea:

def marshal_to_html(name, iobj)
data = CGI.escape(Marshal.dump(iobj))
print(%Q{\n})
end

def marshal_from_html(name)
return Marshal.load(CGI.unescape(self[“#{name}”][0])) if
self.params.has_key?(“#{name}”)
end

with Jigsaw i have added these two methods directly to the CGI class itself.

thus if you keep all the data you collect from a user within a sinlge object
you can simply marshal that object from page to page.

···

On Wednesday 22 January 2003 01:39 am, Vandemoortele Simon wrote:

I am entirely new to CGI scripting and trying to make an interface to
edit my dynamic photo-album (add sections, pictures, etc). I’ve
discovered in the process how inefficient it can be to code a UI with
! since every time you need more input from the user you have
to send him to another (or the same) script and doing so lose all the
input you have collected
.
Until now I’ve been solving that problem by sending all the collected
input along as ‘hidden params’ but that’s a lot of work.
Is there a better way ? Would that be CGI::Session ?
or CGI::Session::PStore ?


tom sawyer, aka transami
transami@transami.net

                               .''.
   .''.      .        *''*    :_\/_:     .
  :_\/_:   _\(/_  .:.*_\/_*   : /\ :  .'.:.'.

.‘’.: /\ : ./)\ ‘:’* /\ * : ‘…’. -=:o:=-
:/:‘.:::. | ’ ‘’ * ‘.'/.’ (/’.‘:’.’
: /\ : ::::: = / -= :wink: =- /)\ ’ *
‘…’ ‘:::’ === * /\ * .‘/.'. ‘._____
* | : |. |’ .—"|
* | _ .–’| || | _| |
* | .-‘| __ | | | || |
.-----. | |’ | || | | | | | || |
__’ ’ /“\ | '-.”". ‘-’ ‘-.’ '` |.

This is something I would really like to discuss even though I might go
a little of topic (sorry).

i think it’s on topic. the session management isn’t that complete in it’s
doccumentation and kinda tricky to understand (for me it was anyhow).

I am entirely new to CGI scripting and trying to make an interface to edit
my dynamic photo-album (add sections, pictures, etc). I’ve discovered in the
process how inefficient it can be to code a UI with ! since every time you
need more input from the user you have to send him to another (or the same)
script and doing so lose all the input you have collected. Until now I’ve
been solving that problem by sending all the collected input along as
‘hidden params’ but that’s a lot of work. Is there a better way ? Would
that be CGI::Session ? or CGI::Session::PStore ?

all entirely valid/correct observations. i think everyone deals with state
using hidden params at some point, it’s just a matter of how_much state you
want to deal with that way : when it’s alot of state that becomes pretty
tiresome. sessions, in general, essentially deal with this by using cookies.
if you don’t know this already, cookies are little peices of textual
information that can be stored by your browser at the request of the web
server servering the page you are browsing. the whole thing get pretty
complicated and seem to stir up debate so i’ll state here that i am NO expert
on such matters - but understand enough to write usefull cgi scripts at my job
(which is with the government to take that with a grain of salt :wink: ) …
anyhow, the way sessions work is that the ‘first time’ you browse a page using
them the server sends you down one little cookie - a session key - which
itself is key’d by the page you are browsing. the next time you vist that
page your browser will send that session key to the sever automatically
allowing the server the know ‘hey, it’s you again!’. the session key can then
be used to identify that user (his browser more like) in order to retrieve
information cached about him/her on the server machine. all the client ever
has is the cookie. at this point i must make my disclaimer again, this is
only vaguely correct and much of the handshaking is configurable by the
browser - but i’m ignoring all of that. so at this point the server is able
identify the client and do ‘something’ with that key. one thing might be to
store information about the client in a database (there’s a
cgi::session::postgresql or something like that on the raa), in a file like
cgi::session::filestore (the default session), or in a pstore (if you have my
module). so the point is ANY session manager can do what you desire - it’s
simply a matter of how difficult it will be to write. a
cgi::session::filestore for example could not store any images directly, but
could store the names/paths of them on the local filesystem. a session
managed by postgresql could handle the images directly, but would require you
to install/learn postgresql, storing them using yaml is an option - but also
requires learning another api. cgi::session::pstore is a little tiny thing i
wrote which is neither fast and probably has some bugs (though i’ve used it
extensively finding none so far) but it is easy and doccumented. if you
read the pickaxe cgi::session section and then read the pstore section you
will understand it. here’s an anotated example

#!/usr/local/bin/ruby

require ‘cgi’
require ‘./cgi/session/pstore’

this is what the cgi will cache in it’s session

you could make an ImageData class and perhaps

a Layout class or the like

this class is really silly, it just has a random number

and a Time stamp. also, it know how to display itself

as html

class SessionData
public
attr_accessor :time
attr :n

def to_html
  <<-html
<table border=1>
  <tr>
    <td>n</td><td>#{n}</td>
  </tr>
  <tr>
    <td>time</td><td><strong>#{time}</strong></td>
  </tr>
</table>
  html
end

private
def initialize time = Time.now
@time = time
@n = rand
end
end

cgi = CGI.new ‘html3’

session = CGI::Session.new cgi, ‘database_manager’ => CGI::Session::PStore

or

session =CGI::Session.new cgi,‘database_manager’=>CGI::Session::FileStore

session =CGI::Session.new cgi,‘database_manager’=>CGI::Session::MemoryStore

but these can only store String(key) → String(value)!!

here i’m getting the client’ session (if they have one) or, if this is

the first time the client has been here - instantiating a new one

data = session[‘data’]
data = session[‘data’] = SessionData.new unless data

source = CGI.escape(ENV[‘DOCUMENT_ROOT’] + ENV[‘SCRIPT_NAME’])
server_addr = ENV[‘SERVER_ADDR’]

simply display the session data - note that this page automatically

refreshes every 5 seconds (anoying!)

$content = <<-html



#{data.to_html}


html

this is _critical! we set the time of the session data to be the

current time and then update the session (write it to disk)

data.time = Time.now
session.update

print the page

cgi.out { $content }

the above is simplified a little. you can view it’s output at

http://eli.fsl.noaa.gov/ruby/class/0/cgi/session/pstore.cgi

view the original source at

http://eli.fsl.noaa.gov/ruby/class/0/cgi/session/pstore.html

obviously it requires cgi::session::pstore which you can get from the raa. if
you look at cgi::session::filestore and memorystore you’ll understand how/why
i wrote the pstore version - it’s pattern directly off of those modules, i
certainly didn’t make it up! :wink:

P.S.: Plz understand that I do have a book about ruby, access to google and
RAA but my experience is so limited that I can’t make sense of the
information I find there. (Maybe I should find my way to more general
information about CGI since that’s the knowledge I’m lacking. Any pointers
?)

not really, some of the oreily perl/cgi books are informative though. it took
me a while too, but this group was most informative. in fact it was reading a
thread like this where matz suggested that someone complaining about no object
persistence being support via CGI::Session::MemoryStore and
CGI::Session::FileStore simply write there own CGI::Session::Pstore that
prompted me to do it. after looking at the sources (a great source of
information if you did some sort of binary install you should get them) i
discovered that it was actually pretty simple to do!

-a

···

On Wed, 22 Jan 2003, Vandemoortele Simon wrote:

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

Hi,

I would like to extend an invitation to anyone who would like to
integrate Amrita into Narf.

For those who are wondering:
Amrita… is a popular templating library, notable for being pure
HTML
Narf… the CGI replacement you wished you had when you were
trying to write Web applications with Unit tests.

I envisage three levels of integration:

  1. Making it work at all. This may just extend to adding some
    information to the documentation to explain how.
  2. Integrating with the testing facilities of Narf
  3. Adding some of the form handling facilities that Narf’s built in
    templates support to Amrita

If you are interested, please join the narf mailing list on:
narf-lib-devel@sourceforge.net

CVS accounts will be granted to all who promise to accompany their
patches with tests :-).

-Tom

Bruce Williams wrote:

Dimitri,

As Eric states in the thread, the metadata is what would be saved in YAML. I
hadn’t even thought of saving the acual image there, as merely saving it in a
tagged/id’ed format in a directory would be more efficient. The whole point
of YAML IMHO is readability.

excuse my stupidity… I was about to write an email saying how this
sounds like something I’d read about once called “yet another markup
language”… and, well, I then clicked… :slight_smile:

geez I hate it when I realise how stupid I can be!

thanks everyone (o:

cheers
dim

[snip]

Thx a lot for your many lengthy answers. I will look deeper into some
suggestions.

Simon

···

ahoward ahoward@fsl.noaa.gov wrote:

not really, some of the oreily perl/cgi books are informative though. it took
me a while too, but this group was most informative.

Nothing so needs reforming as other people’s habits.
– Mark Twain