Not tested yet, but it is what I intend to do. It will be a couple of
weeks before
I test this mechanism.
# In db.py before the first table def
# keep current_version current
current version = '0.95'
needs_groups = False
import os
f = open('version.txt')
try:
version = f.read()
f.truncate(0)
f.write(current_version)
f.flush
os.fsync(f.fileno())
f.close()
if version != current_version:
#do stuff
pass
except IOError:
# assume file wasn't there
# so this must be the first time this script has run
needs_groups = True
# define tables, signatures, etc.
.
.
.
if needs_groups:
db.auth_group.insert(....
On Nov 22, 9:03 pm, Anthony <[email protected]> wrote:
> Though that will do an unnecessary db query on every request after the
> install. Anyway, you can do:
>
> if db.auth_group.isempty():
>
> Anthony
>
>
>
>
>
>
>
> On Tuesday, November 22, 2011 6:59:58 PM UTC-5, Limedrop wrote:
>
> > Massimo's solution sure is cunning, but you might something like this
> > a bit more maintainable:
>
> > def install():
> > if db(db.auth_group.id > 0).count() == 0:
> > db.auth_group.insert(role = 'edit')
> > db.auth_group.insert(role = 'moderate')
> > db.auth_group.insert(role = 'comment')
> > return
>
> > install()
>
> > On Nov 23, 11:28 am, Massimo Di Pierro <[email protected]>
> > wrote:
> > > yes because the file gets moved in a different folder after execution.
> > > It is a bit of a hack.
> > > We should think of a better way
>
> > > On Nov 22, 2:41 pm, petrasadi <[email protected]> wrote:
>
> > > > thank you for this, but I have one more question: is this guarantied to
> > > > execute only once (upon installation).- Hide quoted text -
>
> > > - Show quoted text -