Changeset d0deae5 in rattail
- Timestamp:
- 07/29/2020 01:22:50 AM (3 years ago)
- Branches:
- master
- Children:
- f7aa709
- Parents:
- e16175f
- Location:
- rattail
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
rattail/batch/handlers.py
re16175f rd0deae5 31 31 import datetime 32 32 import warnings 33 import logging 33 34 34 35 from sqlalchemy import orm … … 41 42 from rattail.time import localtime, make_utc 42 43 from rattail.util import progress_loop, load_object 44 45 46 log = logging.getLogger(__name__) 43 47 44 48 … … 185 189 186 190 def purge_batches(self, session, before=None, before_days=90, 187 delete_all_data=True, progress=None, **kwargs): 191 dry_run=False, delete_all_data=None, 192 progress=None, **kwargs): 188 193 """ 189 194 Purge all batches which were executed prior to a given date. … … 196 201 as the cutoff date if ``before`` is not specified. 197 202 203 :param dry_run: Flag indicating that this is a "dry run" and all logic 204 involved should be (made) aware of that fact. 205 198 206 :param delete_all_data: Flag indicating whether *all* data should be 199 207 deleted for each batch being purged. This flag is passed along to 200 :meth:`delete()`; see that for more info. 208 :meth:`delete()`; see that for more info. NOTE: This flag should 209 probably be deprecated, but so far has not been...but ``dry_run`` 210 should be preferred for readability etc. 201 211 202 212 :returns: Integer indicating the number of batches purged. 203 213 """ 214 if delete_all_data and dry_run: 215 raise ValueError("You can enable (n)either of `dry_run` or " 216 "`delete_all_data` but both cannot be True") 217 delete_all_data = not dry_run 218 204 219 if not before: 205 220 before = localtime(self.config).date() - datetime.timedelta(days=before_days) … … 207 222 before = localtime(self.config, before) 208 223 224 log.info("will purge '%s' batches, executed before %s", 225 self.batch_key, before.date()) 226 209 227 old_batches = session.query(self.batch_model_class)\ 210 228 .filter(self.batch_model_class.executed < before)\ 211 .options(orm.joinedload(self.batch_model_class.data_rows)) 229 .options(orm.joinedload(self.batch_model_class.data_rows))\ 230 .all() 231 log.info("found %s batches to purge", len(old_batches)) 212 232 result = Object() 213 233 result.purged = 0 … … 224 244 225 245 session.flush() 246 if old_batches: 247 log.info("%spurged %s '%s' batches", 248 "(would have) " if dry_run else "", 249 result.purged, self.batch_key) 226 250 return result.purged 227 251 … … 721 745 """ 722 746 if delete_all_data: 723 if hasattr(batch, 'delete_data'): 724 batch.delete_data(self.config) 747 self.delete_extra_data(batch, progress=progress) 725 748 726 749 # delete all rows from batch, one by one. maybe would be nicer if we … … 745 768 # rows being deleted 746 769 del batch.data_rows[:] 770 771 def delete_extra_data(self, batch, progress=None, **kwargs): 772 """ 773 Delete all "extra" data for the batch. This method should *not* bother 774 trying to delete the batch itself, or rows thereof. It typically is 775 only concerned with deleting extra files on disk, related to the batch. 776 """ 777 path = self.config.batch_filepath(self.batch_key, batch.uuid) 778 if os.path.exists(path): 779 shutil.rmtree(path) 747 780 748 781 def setup_clone(self, oldbatch, progress=None): -
rattail/commands/batch.py
re16175f rd0deae5 3 3 # 4 4 # Rattail -- Retail Software Framework 5 # Copyright © 2010-20 19Lance Edgar5 # Copyright © 2010-2020 Lance Edgar 6 6 # 7 7 # This file is part of Rattail. … … 224 224 225 225 handler = self.get_handler(args) 226 log.info("purging batches of type: %s", args.batch_type)227 226 session = self.make_session() 228 227 229 228 kwargs = { 230 'd elete_all_data': notargs.dry_run,229 'dry_run': args.dry_run, 231 230 'progress': self.progress, 232 231 } … … 239 238 240 239 purged = handler.purge_batches(session, **kwargs) 241 log.info("%spurged %s batches", "(would have) " if args.dry_run else "", purged)242 240 243 241 if args.dry_run: -
rattail/db/model/batch/core.py
re16175f rd0deae5 3 3 # 4 4 # Rattail -- Retail Software Framework 5 # Copyright © 2010-20 18Lance Edgar5 # Copyright © 2010-2020 Lance Edgar 6 6 # 7 7 # This file is part of Rattail. … … 33 33 import datetime 34 34 import shutil 35 import warnings 35 36 36 37 import six … … 258 259 Delete the data folder for the batch 259 260 """ 261 warnings.warn("This method has been deprecated; please see/use " 262 "BatchHandler.delete_extra_data() instead", 263 DeprecationWarning) 264 260 265 # TODO: should this logic be in the handler instead? 261 266 path = config.batch_filepath(self.batch_key, self.uuid)
Note: See TracChangeset
for help on using the changeset viewer.