Skip to content

Commit

Permalink
Merge branch 'master' into interdimensional_compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
rowleya committed Oct 16, 2023
2 parents 60fd3ef + cc7fe9e commit 454694e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
13 changes: 10 additions & 3 deletions spinn_front_end_common/interface/abstract_spinnaker_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,16 @@ def __group_collab_or_job(self):
cwd = os.getcwd()
match_obj = SHARED_PATH.match(cwd)
if match_obj:
return self.__get_collab_id_from_folder(
collab = self.__get_collab_id_from_folder(
match_obj.group(SHARED_GROUP))
if collab is not None:
return collab
match_obj = SHARED_WITH_PATH.match(cwd)
if match_obj:
return self.__get_collab_id_from_folder(
collab = self.__get_collab_id_from_folder(
match_obj.group(SHARED_WITH_GROUP))
if collab is not None:
return collab

# Try to use the config to get a group
group = get_config_str_or_none("Machine", "spalloc_group")
Expand All @@ -311,7 +315,10 @@ def __get_collab_id_from_folder(self, folder):
""" Currently hacky way to get the EBRAINS collab id from the
drive folder, replicated from the NMPI collab template.
"""
ebrains_drive_client = ebrains_drive.connect(token=self.__bearer_token)
token = self.__bearer_token
if token is None:
return None
ebrains_drive_client = ebrains_drive.connect(token=token)
repo_by_title = ebrains_drive_client.repos.get_repos_by_name(folder)
if len(repo_by_title) != 1:
logger.warning(f"The repository for collab {folder} could not be"
Expand Down
3 changes: 1 addition & 2 deletions spinn_front_end_common/utilities/base_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import os
import sqlite3
import time
from spinn_utilities.abstract_context_manager import AbstractContextManager
from spinn_front_end_common.data import FecDataView
from spinn_front_end_common.utilities.sqlite_db import SQLiteDB

Expand All @@ -29,7 +28,7 @@ def _timestamp():
return int(time.time() * _SECONDS_TO_MICRO_SECONDS_CONVERSION)


class BaseDatabase(SQLiteDB, AbstractContextManager):
class BaseDatabase(SQLiteDB):
"""
Specific implementation of the Database for SQLite 3.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import logging
from concurrent.futures import ThreadPoolExecutor, wait # @UnresolvedImport
from spinn_utilities.abstract_context_manager import AbstractContextManager
from spinn_utilities.config_holder import get_config_bool, get_config_int
from spinn_utilities.log import FormatAdapter
from spinnman.connections.udp_packet_connections import EIEIOConnection
Expand All @@ -30,7 +29,7 @@
logger = FormatAdapter(logging.getLogger(__name__))


class NotificationProtocol(AbstractContextManager):
class NotificationProtocol(object):
"""
The protocol which hand shakes with external devices about the
database and starting execution.
Expand Down
16 changes: 12 additions & 4 deletions spinn_front_end_common/utilities/sqlite_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
import pathlib
import sqlite3
import struct
from spinn_utilities.abstract_context_manager import AbstractContextManager
from spinn_front_end_common.utilities.exceptions import DatabaseException

logger = logging.getLogger(__name__)


class SQLiteDB(AbstractContextManager):
class SQLiteDB(object):
"""
General support class for SQLite databases. This handles a lot of the
low-level detail of setting up a connection.
Expand Down Expand Up @@ -122,6 +121,12 @@ def __init__(self, database_file=None, *, read_only=False, ddl_file=None,
self.__cursor = None

def _context_entered(self):
"""
Work to do when then context is entered.
May be extended by super classes
"""
if self.__db is None:
raise DatabaseException("database has been closed")
if self.__cursor is not None:
Expand All @@ -130,15 +135,18 @@ def _context_entered(self):
self.__db.execute("BEGIN")
self.__cursor = self.__db.cursor()

def __enter__(self):
self._context_entered()
return self

def __exit__(self, exc_type, exc_val, exc_tb):
if self.__db is not None:
if exc_type is None:
self.__db.commit()
else:
self.__db.rollback()
self.__cursor = None
# calls close
return super().__exit__(exc_type, exc_val, exc_tb)
self.close()

def __del__(self):
self.close()
Expand Down

0 comments on commit 454694e

Please sign in to comment.