Skip to content

Commit

Permalink
Merge branch 'sqlalchemy-2.0' into sync
Browse files Browse the repository at this point in the history
  • Loading branch information
agateau committed Sep 3, 2024
2 parents f2379cf + d913389 commit 5982266
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions yokadi/core/dbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,17 @@ def getOrCreateProject(projectName, interactive=True, createIfNeeded=True):
@type createIfNeeded: Bool
@return: Project instance or None if user cancel creation or createIfNeeded is False"""
session = db.getSession()
result = session.query(Project).filter_by(name=projectName).all()
if len(result):
return result[0]

if not createIfNeeded:
return None

if interactive and not tui.confirm("Project '%s' does not exist, create it" % projectName):
return None

project = Project(name=projectName)
session.add(project)
print("Added project '%s'" % projectName)
return project
try:
return session.query(Project).filter_by(name=projectName).one()
except (NoResultFound, MultipleResultsFound):
if not createIfNeeded:
return None
if interactive and not tui.confirm("Project '%s' does not exist, create it" % projectName):
return None
project = Project(name=projectName)
session.add(project)
print("Added project '%s'" % projectName)
return project


def createMissingKeywords(lst, interactive=True):
Expand Down

0 comments on commit 5982266

Please sign in to comment.