One other thing I have thought about is putting a utitliy into web2py
that will read the csv file on initialization and check the date-time
stamp on the file.  If the csv file is newer then update the
database.  On exit it will check the database to see if it is
changed.  If it has then it will write a new csv file.  I am just
unclear on where I could put such code.

On Feb 14, 5:02 pm, bfg <[email protected]> wrote:
> Hi,
>
> I just started using web2py a few weeks ago, so I may be missing
> something. I have extended appadmin.py so I can export to a csv file
> (and then check into svn), and import a csv file (from svn).  I am
> having no problem writing the csv file, but I cannot seem to re-
> populate the database with the info.  We don't want to keep the binary
> files under revision control so this seems to be our apparent
> solution.  Before I import the database from the csv file I blow
> everything out of the database directory so I can get a clean import.
> If I go to the python shell built into the web UI it works as I
> expect, it builds the database and imports the data.  When I try and
> do it from the appadmin controller the database does not get
> rebuilt.
>
> Here is my code snippet:
>
> def convert_from_csv_to_database():
>     import os,shutil
>     current_directory = os.getcwd()
>     message = ''
>     try:
>       os.chdir(current_directory+"/applications/enabling_tech/
> databases")
>       #Remove everything from the directory except the csv file
>       shutil.copy2('scidac-overview.csv','../scidac-overview.csv')
>       databases_path = os.getcwd()
>       shutil.rmtree(databases_path)
>       os.mkdir(databases_path)
>       os.chdir(databases_path)
>       shutil.copy2('../scidac-overview.csv','scidac-overview.csv')
>       db.import_from_csv_file(open('scidac-overview.csv','rb'))
>       message = 'Database imported from csv file scidac-overview.csv
> located at: ' + os.getcwd()
>     except:
>       message = "Database could not be imported"
>
>     os.chdir(current_directory)
>
>     return dict(message=message)

Reply via email to