Created
March 13, 2012 20:52
-
-
Save defnull/2031499 to your computer and use it in GitHub Desktop.
Bottle ResourceManager Preview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bottle import Bottle | |
app = Bottle() | |
# Resource configuration (relative to current file) | |
app.resources.add_path('./data/', base=__file__) | |
# Override default resources with files in test directory | |
app.resources.add_path('/home/marc/dev/test_data/', index=0) | |
# Some functions that need file resources ... | |
def connect_db(): | |
db_file = app.resources.find('sqlite.db') | |
return sqlite3.connect(db_file) | |
def init_db(): | |
with app.resources.open('schema.sql') as fp: | |
db = connect_db() | |
db.cursor().executescript(fp.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, that makes a lot more sense now :)! Great.
Yes, I think something like
get()
is better thanfind()
. Find implies some sort of searching. Maybe get could be a bit confusing as we are in an web/http context where get has a special meaning... but I have nothing better for now.get_path()
orget_abs_path
may be a bit long...hm, what about:
app.ressources["schema.sql"] ?
I guess
would work too?
What about making app.resources available in every template without adding it on each returned dictionary with relative paths?
So I can do something like this in the template:
But maybe that would be a bit to much magic :).