|
5 | 5 | import json |
6 | 6 | import logging |
7 | 7 | import mimetypes |
8 | | -import platform |
9 | 8 | import re |
10 | 9 | import uuid |
11 | 10 | from datetime import datetime, timezone |
|
29 | 28 | from .staged_insert import staged_insert1 as _staged_insert1 |
30 | 29 | from .storage import StorageBackend, build_object_path, verify_or_create_store_metadata |
31 | 30 | from .utils import get_master, is_camel_case, user_choice |
32 | | -from .version import __version__ as version |
33 | 31 |
|
34 | 32 | logger = logging.getLogger(__name__.split(".")[0]) |
35 | 33 |
|
@@ -68,7 +66,6 @@ class Table(QueryExpression): |
68 | 66 | """ |
69 | 67 |
|
70 | 68 | _table_name = None # must be defined in subclass |
71 | | - _log_ = None # placeholder for the Log table object |
72 | 69 |
|
73 | 70 | # These properties must be set by the schema decorator (schemas.py) at class level |
74 | 71 | # or by FreeTable at instance level |
@@ -113,8 +110,6 @@ def declare(self, context=None): |
113 | 110 | except AccessError: |
114 | 111 | # skip if no create privilege |
115 | 112 | pass |
116 | | - else: |
117 | | - self._log("Declared " + self.full_table_name) |
118 | 113 |
|
119 | 114 | def alter(self, prompt=True, context=None): |
120 | 115 | """ |
@@ -144,7 +139,6 @@ def alter(self, prompt=True, context=None): |
144 | 139 | self.__class__._heading = Heading(table_info=self.heading.table_info) |
145 | 140 | if prompt: |
146 | 141 | logger.info("Table altered") |
147 | | - self._log("Altered " + self.full_table_name) |
148 | 142 |
|
149 | 143 | def from_clause(self): |
150 | 144 | """ |
@@ -261,16 +255,6 @@ def full_table_name(self): |
261 | 255 | ) |
262 | 256 | return r"`{0:s}`.`{1:s}`".format(self.database, self.table_name) |
263 | 257 |
|
264 | | - @property |
265 | | - def _log(self): |
266 | | - if self._log_ is None: |
267 | | - self._log_ = Log( |
268 | | - self.connection, |
269 | | - database=self.database, |
270 | | - skip_logging=self.table_name.startswith("~"), |
271 | | - ) |
272 | | - return self._log_ |
273 | | - |
274 | 258 | @property |
275 | 259 | def object_storage(self) -> StorageBackend | None: |
276 | 260 | """Get the default object storage backend for this table.""" |
@@ -627,7 +611,6 @@ def delete_quick(self, get_count=False): |
627 | 611 | query = "DELETE FROM " + self.full_table_name + self.where_clause() |
628 | 612 | self.connection.query(query) |
629 | 613 | count = self.connection.query("SELECT ROW_COUNT()").fetchone()[0] if get_count else None |
630 | | - self._log(query[:255]) |
631 | 614 | return count |
632 | 615 |
|
633 | 616 | def delete( |
@@ -804,7 +787,6 @@ def drop_quick(self): |
804 | 787 | query = "DROP TABLE %s" % self.full_table_name |
805 | 788 | self.connection.query(query) |
806 | 789 | logger.info("Dropped table %s" % self.full_table_name) |
807 | | - self._log(query[:255]) |
808 | 790 | else: |
809 | 791 | logger.info("Nothing to drop: table %s is not declared" % self.full_table_name) |
810 | 792 |
|
@@ -1122,76 +1104,3 @@ def __init__(self, conn, full_table_name): |
1122 | 1104 |
|
1123 | 1105 | def __repr__(self): |
1124 | 1106 | return "FreeTable(`%s`.`%s`)\n" % (self.database, self._table_name) + super().__repr__() |
1125 | | - |
1126 | | - |
1127 | | -class Log(Table): |
1128 | | - """ |
1129 | | - The log table for each schema. |
1130 | | - Instances are callable. Calls log the time and identifying information along with the event. |
1131 | | -
|
1132 | | - :param skip_logging: if True, then log entry is skipped by default. See __call__ |
1133 | | - """ |
1134 | | - |
1135 | | - _table_name = "~log" |
1136 | | - |
1137 | | - def __init__(self, conn, database, skip_logging=False): |
1138 | | - self.database = database |
1139 | | - self.skip_logging = skip_logging |
1140 | | - self._connection = conn |
1141 | | - self._heading = Heading(table_info=dict(conn=conn, database=database, table_name=self.table_name, context=None)) |
1142 | | - self._support = [self.full_table_name] |
1143 | | - |
1144 | | - self._definition = """ # event logging table for `{database}` |
1145 | | - id :int unsigned auto_increment # event order id |
1146 | | - --- |
1147 | | - timestamp = CURRENT_TIMESTAMP : timestamp # event timestamp |
1148 | | - version :varchar(12) # datajoint version |
1149 | | - user :varchar(255) # user@host |
1150 | | - host="" :varchar(255) # system hostname |
1151 | | - event="" :varchar(255) # event message |
1152 | | - """.format(database=database) |
1153 | | - |
1154 | | - super().__init__() |
1155 | | - |
1156 | | - if not self.is_declared: |
1157 | | - self.declare() |
1158 | | - self.connection.dependencies.clear() |
1159 | | - self._user = self.connection.get_user() |
1160 | | - |
1161 | | - @property |
1162 | | - def definition(self): |
1163 | | - return self._definition |
1164 | | - |
1165 | | - def __call__(self, event, skip_logging=None): |
1166 | | - """ |
1167 | | -
|
1168 | | - :param event: string to write into the log table |
1169 | | - :param skip_logging: If True then do not log. If None, then use self.skip_logging |
1170 | | - """ |
1171 | | - skip_logging = self.skip_logging if skip_logging is None else skip_logging |
1172 | | - if not skip_logging: |
1173 | | - try: |
1174 | | - self.insert1( |
1175 | | - dict( |
1176 | | - user=self._user, |
1177 | | - version=version + "py", |
1178 | | - host=platform.uname().node, |
1179 | | - event=event, |
1180 | | - ), |
1181 | | - skip_duplicates=True, |
1182 | | - ignore_extra_fields=True, |
1183 | | - ) |
1184 | | - except DataJointError: |
1185 | | - logger.info("could not log event in table ~log") |
1186 | | - |
1187 | | - def delete(self): |
1188 | | - """ |
1189 | | - bypass interactive prompts and cascading dependencies |
1190 | | -
|
1191 | | - :return: number of deleted items |
1192 | | - """ |
1193 | | - return self.delete_quick(get_count=True) |
1194 | | - |
1195 | | - def drop(self): |
1196 | | - """bypass interactive prompts and cascading dependencies""" |
1197 | | - self.drop_quick() |
0 commit comments