Example #1
0
    def dbconnect(self):
        try:
            dbtype = self.dbtype
            dbstring = self.dbconnectstring
        except:
            dbtype = 'sqlite'
            try:
                os.mkdir(os.path.join(os.path.abspath(self.installdir),'db'))
            except:
                print("db path already created, skipping")
            dbstring = os.path.join(os.path.abspath(self.installdir),'db','pianocktail.db')
        self.dbtype = dbtype
        self.dbconnectstring = dbstring
        try:
            if dbtype == 'sqlite':
#                 if os.access(dbstring, os.F_OK) == False:
#                     f = open(dbstring, 'w')
#                     f.write()
#                     f.close()
                if len(dbstring) > 0:
                    dbstring = '/'+dbstring
            print(dbtype+"://"+dbstring)
            return initdb(dbtype+"://"+dbstring, dbtype, self.debug)
        except Exception,err:
            print("db connection failed : %s" % err)
Example #2
0
'''
Created on 29 sept. 2013

@author: babe
'''
from sqlalchemy import and_, or_
from pyanocktail.dbUtils import initdb, Cocktail, Recipe,\
 Ingredient, Pump, getCocktails, getIngredients, getRecipe,\
 getServe, getPumps
from docutils.nodes import row


if __name__ == '__main__':
    session = initdb('mysql://*****:*****@localhost/testdb',False)
#     print(session)
#     test1 = Pump(1,description='test1')
#     session.add(test1)
#     session.commit()
#     test2 = Ingredient('Jus d\'Orange',1, description='tu prends une orange et la presse !',alcool=False)
#     session.add(test2)
#     session.commit()
#     test3 = Pump(2,description='test3')
#     session.add(test3)
#     session.commit()
#     test4 = Ingredient('Rhum',2, description='no comment')
#     session.add(test4)
#     session.commit()
#     test5 = Cocktail('Rhum-Orange',description='test5')
#     session.add(test5)
#     session.commit()
#     test6 = Recipe(2,4,1)