Skip to content

Commit

Permalink
Moved batching.batch_delete_files from imio.helpers to be used comm…
Browse files Browse the repository at this point in the history
…only
  • Loading branch information
sgeulette committed Aug 30, 2024
1 parent f9e3df7 commit 632043b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changelog

- Added `utils.add_key_if_value` to add a key in a dic only if value or is not None.
[sgeulette]
- Moved `batching.batch_delete_files` from imio.helpers to be used commonly.
[sgeulette]

1.0.4 (2024-06-11)
------------------
Expand Down
41 changes: 41 additions & 0 deletions imio/pyutils/batching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# encoding: utf-8
# IMIO <[email protected]>
#

"""
This module is just a part of imio.helpers.batching module.
https://github.com/IMIO/imio.helpers/blob/master/src/imio/helpers/batching.py
Following function has been put here because imio.pyutils is common to imio.helpers and imio.updates.
"""

from datetime import datetime

import logging
import os


logger = logging.getLogger("imio.pyutils")


# 7) when all the items are treated, we can delete the dictionary file
def batch_delete_files(batch_keys, config, rename=True):
"""Deletes the file containing the batched keys.
:param batch_keys: the treated keys set
:param config: a config dict {'bn': batch_number, 'bl': batch_last, 'cn': commit_number, 'll': loop_length,
'lc': loop_count, 'pf': infile, 'cf': config_file, 'kc': keys_count, 'lk': last_key,
'ldk': last_dump_key, 'fr'; first_run_bool}
:param rename: do not delete but rename
"""
if batch_keys is None:
return
try:
for key in ("pf", "cf"):
if config[key] and os.path.exists(config[key]):
if rename:
os.rename(config[key], "{}.{}".format(config[key], datetime.now().strftime("%Y%m%d-%H%M%S")))
else:
os.remove(config[key])
except Exception as error:
logger.exception("Error while renaming/deleting the file %s: %s", config["pf"], error)
5 changes: 4 additions & 1 deletion imio/pyutils/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
# IMIO <[email protected]>
#

from .system import error
from .system import trace

import psycopg2
from .system import error, trace


# ------------------------------------------------------------------------------

Expand Down

0 comments on commit 632043b

Please sign in to comment.