Errr.. Ya you guys were right. My commands were creating a crap-load
of duplicate groups in the database. In my mind, I figured the
add_group behavior would be similar to the create tables behavior of
web2py : where it only creates/updates the table if the table/fields
are not already there (if my understanding is correct).

@Christopher - I like the concept of having the config file like you
suggested, but it seems out of band with all the other web2py config -
not sure if that's a good or bad thing yet. Still grasping this whole
framework...

Thanks again for the advice everyone.

-Mike

On Apr 2, 6:37 pm, Christopher Steel <chris.st...@gmail.com> wrote:
> automated application initialization...
>
> Automating application setup tasks is something we should probably do
> more of in keeping with the Web2py "zero configuration" spirit. Seeing
> your discussions here inspired me in my quest towards an eventual
> config and/or application setup logging system of sorts.
>
> This is a simple way of tracking completed initialization tasks, like
> setting up new groups and users. It currently uses Joe's code and does
> not hit the database (although it does incorporate global variables).
> It might be interesting to create install logging as well. Please
> review for sanity and improvements. Eventually we might want to look
> into using something like 
> this:http://www.voidspace.org.uk/python/configobj.htmlone of the config
> parsers mentioned in this 
> documenthttp://wiki.python.org/moin/ConfigParserShootout
> but in the mean time the following code seems to get the job done with
> causing too many issue.
>
> it goes in the models directory, I called mine initialization.py. It
> creates and appends to 000_uc_initialization.py In this example I have
> appended a couple of global variables.
>
> comments?
>
> # coding: utf8
> # initialization.py
> import os
> initialization_file_path =
> os.path.join(request.folder,'models','000_uc_initialization.py')
>
> # create an initialization file if we do not have one
> if not 'initialization_file_created' in globals():
>     if not os.path.exists(initialization_file_path):
>         '''
>         if keyfile is found, we create an empty one.
>         '''
>         our_file = open(initialization_file_path,"w")
>         our_text = 'initialization_file_created = True'
>         our_file.writelines(our_text)
>         our_file.close()
> else:
>     print('if a tree falls in the forest does anybody hear it?')
>
> if not 'my_group_created' in globals():
>
>     if not db(db.auth_group).count():
>         db.auth_group.insert(role='root',description='Exactly what you
> think it does')
>         db.auth_group.insert(role='super',description='Supervisor
> access for team manager')
>         db.auth_group.insert(role='user',description='Normal user')
>         our_file = open(initialization_file_path,"a")
>         our_text = 'my_group_created = True'
>         our_file.write(our_text)
>         our_file.close()
> else:
>     print('if a tree falls in the forest does anybody hear it?')
>
> On Apr 1, 10:26 pm, Anthony <abasta...@gmail.com> wrote:
>
>
>
>
>
>
>
> > On Friday, April 1, 2011 2:22:55 PM UTC-4,Mikewrote:
>
> > > Nevermind. I thought there was a builtin web2py way for this but I
> > > just did this instead (after sifting more through the groups):
>
> > > def groupadd(check_group):
> > >     if not db(db.auth_group.role==check_group).count():
> > >      db.auth_group.insert(role=check_group)
>
> > > groupadd('Admins')
> > > groupadd('Maintenance Users')
> > > groupadd('Download Users')
>
> > If that's in a model file, it seems like you're doing an unnecessary
> > database hit on every single request. If you just need to create those three
> > groups one time, why not just do so outside the application code? Or maybe
> > create an action in a controller and just call it once.

Reply via email to