-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved
batching.batch_delete_files
from imio.helpers to be used comm…
…only
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,11 @@ | |
# IMIO <[email protected]> | ||
# | ||
|
||
from .system import error | ||
from .system import trace | ||
|
||
import psycopg2 | ||
from .system import error, trace | ||
|
||
|
||
# ------------------------------------------------------------------------------ | ||
|
||
|