Commit 57dabedb authored by brandt73's avatar brandt73
Browse files

implements file mask selection argument

parent 5dca40c9
......@@ -14,7 +14,15 @@ _Types of changes_:
* `Fixed` for any bug fixes.
* `Security` in case of vulnerabilities.
## [Unreleased]
## [Released]
## [0.8.3] - 2022-02-16
### Added
- Introduced new `file_mask` option to limit the files to process. This is a string value which is used
in a `glob.glob()` call to select only files matching the selected criteria. Example:
`"file_mask": "*.csv"` will only process files with the `.csv` extension.
## [0.8.2] - 2022-02-16
......
......@@ -24,6 +24,8 @@ as an option with all incoming `check` and `receive` requests. See agent
[usage description](mover/description.md#Options) for details.
* `default_destination_dir`: Default target directory for copy or move operations. See agent
[usage description](mover/description.md#Options) for details.
* `file_mask`: Limits the selection of files to a specified file mask. See agent
[usage description](mover/description.md#Options) for details.
## Usage
......
VERSION = (0, 8, 2)
VERSION = (0, 8, 3)
__version__ = ".".join(map(str, VERSION))
......
......@@ -42,6 +42,8 @@ successfully moved files from the source path.
function that will be supplied as a
`key` to `sorted()`. Example: `lambda file: os.path.getmtime(file)` sorts files by last modification.
* `order_reverse`: Boolean, reverses the order from `order` if set to "true".
* `file_mask:` option to limit the files to process. This is a string value which is used
in a `glob.glob()` call to select only files matching the selected criteria.
### Full Example
......@@ -55,7 +57,8 @@ successfully moved files from the source path.
"modified": "not today",
"limit": 10,
"order": "sorted",
"order_reverse": "false"
"order_reverse": "false",
"file_mask": "*.csv"
}
}
```
import glob
import logging
import os
import shutil
......@@ -26,6 +27,7 @@ def move(
order = None
order_reverse = False
limit = 0
file_mask = None
if len(criteria):
keys = criteria.keys()
......@@ -42,6 +44,8 @@ def move(
limit = int(criteria["limit"])
if "order" in keys:
order = criteria["order"]
if "file_mask" in keys:
file_mask = criteria["file_mask"]
if "order_reverse" in keys:
if type(criteria["order_reverse"]) is bool:
order_reverse = criteria["order_reverse"]
......@@ -55,7 +59,13 @@ def move(
order_reverse = criteria["order_reverse"] > 0
try:
source_files = os.listdir(source)
if file_mask:
if source[-1] != "/":
source = source + "/"
source_files = [os.path.basename(x) for x in glob.glob(source + file_mask)]
else:
source_files = os.listdir(source)
if order:
# use special keyword "sorted" for simple sorting
if order == "sorted":
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment